Skip to content

Bug: Reading HDF5 NetCDF data #21

@kaedonkers

Description

@kaedonkers

Problem

When importing any dataset from this package, I encountered the following errors:

KeyError: [<class 'netCDF4._netCDF4.Dataset'>, ('./env/lib/python3.12/site-packages/agrifoodpy_data/land/data/UKCEH_LC_1000.nc',), 'r', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False))]

During handling of the above exception, another exception occurred:
OSError: [Errno -101] NetCDF: HDF error: './env/lib/python3.12/site-packages/agrifoodpy_data/land/data/UKCEH_LC_1000.nc'

Solution

The solution I found was to explicitly set the xarray engine to h5netcdf, such that:

xr.open_dataset("./env/lib/python3.12/site-packages/agrifoodpy_data/land/data/UKCEH_LC_1000.nc", 
               engine="h5netcdf",
               )

Request

Please change the agrifoodpy-data/agrifoodpy_data/*/__init__.py files to contain:

with xr.open_dataset(_data_file, engine="h5netcdf") as data:

I would also request that the setup.py is updated to explicitly include the following packages as I had to install them after agrifoodpy-data has been installed due to additional errors when loading data:

INSTALL_REQUIRES = [
      ...
      'hdf5',
      'cftime'
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions