pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.59k stars 1.08k forks source link

ValueError: unrecognized engine cfgrib must be one of: ['netcdf4', 'scipy', 'store'] while opening grib data #5623

Closed krishnaap closed 2 years ago

krishnaap commented 3 years ago

I could read grib2 files using xarray and cfgrib before with the same code on another PC.

import xarray as xr
import cfgrib
ds = xr.open_dataset('/home//dataset.grib',engine='cfgrib')

but it is showing an error in the current system as follows

ValueError: unrecognized engine cfgrib must be one of: ['netcdf4', 'scipy', 'store']

Traceback (most recent call last):

File "/home/Grib_task3.py", line 11, in ds = xr.open_dataset('/home/dataset.grib',engine='cfgrib')

File "/home/krishna/anaconda3/envs/ide/lib/python3.9/site-packages/xarray/backends/api.py", line 482, in open_dataset backend = plugins.get_backend(engine)

File "/home/krishna/anaconda3/envs/ide/lib/python3.9/site-packages/xarray/backends/plugins.py", line 134, in get_backend raise ValueError(

ValueError: unrecognized engine cfgrib must be one of: ['netcdf4', 'scipy', 'store']

Environment: ide

xr.show_versions()

INSTALLED VERSIONS

commit: None python: 3.9.5 (default, Jun 4 2021, 12:28:51) [GCC 7.5.0] python-bits: 64 OS: Linux OS-release: 5.8.0-59-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_IN LOCALE: ('en_IN', 'ISO8859-1') libhdf5: 1.10.6 libnetcdf: 4.8.0

xarray: 0.18.2 pandas: 1.2.5 numpy: 1.20.2 scipy: 1.7.0 netCDF4: 1.5.7 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.5.0 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: 0.9.9.0 iris: None bottleneck: 1.3.2 dask: 2021.06.2 distributed: 2021.06.2 matplotlib: 3.4.2 cartopy: 0.19.0.post1 seaborn: None numbagg: None pint: 0.17 setuptools: 52.0.0.post20210125 pip: 21.1.3 conda: None pytest: None IPython: 7.22.0 sphinx: 3.2.1

keewis commented 3 years ago

that's usually because of an ImportError for cfgrib. Does import cfgrib succeed for you?

krishnaap commented 3 years ago

@keewis Yes, importing cfgrib working just fine.

krishnaap commented 3 years ago

I tried to run the same thing in jupyter-notebook, on jupyter-notebook it's working fine. I previously tried on Spyder IDE with the same conda environment. Is it an issue with Spyder? Anyway, I can open it on Jupyter-notebook.

ds

xarray.Dataset

Dimensions:
    latitude: 321longitude: 401step: 24time: 4
Coordinates:
    number
    ()
    int64
    ...
    time
    (time)
    datetime64[ns]
    2020-07-02 ... 2020-07-05
    step
    (step)
    timedelta64[ns]
    01:00:00 ... 1 days 00:00:00
    surface
    ()
    float64
    ...
    latitude
    (latitude)
    float64
    40.0 39.9 39.8 39.7 ... 8.2 8.1 8.0
    longitude
    (longitude)
    float64
    60.0 60.1 60.2 ... 99.8 99.9 100.0
    valid_time
    (time, step)
    datetime64[ns]
    ...
Data variables:
    ssrd
    (time, step, latitude, longitude)
    float32
    ...
    tp
    (time, step, latitude, longitude)
    float32
    ...
Attributes:

GRIB_edition :
    1
GRIB_centre :
    ecmf
GRIB_centreDescription :
    European Centre for Medium-Range Weather Forecasts
GRIB_subCentre :
    0
Conventions :
    CF-1.7
institution :
    European Centre for Medium-Range Weather Forecasts
history :
    2021-07-20T22:59 GRIB to CDM+CF via cfgrib-0.9.9.0/ecCodes-2.22.1 with {"source": "/home/dataset.grib", "filter_by_keys": {}, "encode_cf": ["parameter", "time", "geography", "vertical"]}
keewis commented 2 years ago

closing as a environment issue