3
$\begingroup$

Era5 data for wind

grib_ls -p shortName,name,paramId,table2Version,indicatorOfParameter era5_wdir-ws.grib
ws     Wind speed       10   128   10
ws     Wind speed       10   128   10
ws     Wind speed       10   128   10
...
wdir   Wind direction   3031   3   31
wdir   Wind direction   3031   3   31
wdir   Wind direction   3031   3   31

So, grib_ls gives the proper variable name. Under python, using xarray with cfgrib backend:

ws_dataset = xr.open_dataset(
    grib_file_path_wind_str,
    engine='cfgrib',
    indexpath='',    # Evita que cfgrib cree un fichero índice
    backend_kwargs={'filter_by_keys': {'table2Version': 128,
                                       'indicatorOfParameter': 10}}
)
wdir_dataset = xr.open_dataset(
        grib_file_path_wind_str,
        engine='cfgrib',
        indexpath='',
        backend_kwargs={'filter_by_keys': {'table2Version': 3,
                                           'indicatorOfParameter': 31}}
    )

And ws_dataset is:

<xarray.Dataset>
Dimensions:     (time: 8760, latitude: 13, longitude: 23)
Coordinates:
    number      int64 0
  * time        (time) datetime64[ns] 2010-01-01 ... 2010-12-31T23:00:00
    step        timedelta64[ns] 00:00:00
    surface     float64 0.0
  * latitude    (latitude) float64 30.0 29.75 29.5 29.25 ... 27.5 27.25 27.0
  * longitude   (longitude) float64 -18.5 -18.25 -18.0 ... -13.5 -13.25 -13.0
    valid_time  (time) datetime64[ns] ...
Data variables:
    ws          (time, 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:                 2024-01-16T10:25 GRIB to CDM+CF via cfgrib-0.9.1...

So, the variable name has been properly set, but for wdir_dataset:

<xarray.Dataset>
Dimensions:     (time: 8760, latitude: 13, longitude: 23)
Coordinates:
    number      int64 ...
  * time        (time) datetime64[ns] 2010-01-01 ... 2010-12-31T23:00:00
    step        timedelta64[ns] ...
    surface     float64 ...
  * latitude    (latitude) float64 30.0 29.75 29.5 29.25 ... 27.5 27.25 27.0
  * longitude   (longitude) float64 -18.5 -18.25 -18.0 ... -13.5 -13.25 -13.0
    valid_time  (time) datetime64[ns] ...
Data variables:
    p3031       (time, 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:                 2024-01-16T10:25 GRIB to CDM+CF via cfgrib-0.9.1...

Why does the grib tool grib_ls get the proper variable name and cfgrib not? I have installed both grib tools and python/xarray/cfgrib under a conda environment, and use them from that conda environment.

$\endgroup$
1

1 Answer 1

2
$\begingroup$

cfgrib uses eccodes under the hood, and not anymore the deprecated grib_api you're using, so that may be the source of the difference you're seeing. However, regardless of eccodes or grib_api the name of the variables only depends on the GRIB tables installed and shouldn't depend on the executable used. Understanding which grib tables are used is a pain in the ...., especially because the way cfgrib is installed (conda, pip...?) would mean it also installed other dependencies that may come with different GRIB tables. Plus, cfrgib is doing some additional preprocessing when interpreting the data as hypercubes.

If you're using only cfgrib I'd suggest you to forget about grib_ls and use the variable name that cfgrib is finding, which shouldn't change if you don't make any modification in the environment where it is installed.

$\endgroup$
2
  • $\begingroup$ Thank you, @Droid. I use eccodes, not grib_api. eccodes provides the same command line grib tools as grib api, and with the same names, as is the case for grib_ls. And I use both eccodes and cfgrib from the conda environment. /home/aserranot/miniconda3/envs/dask/bin/grib_ls, /home/aserranot/miniconda3/envs/dask/lib/python3.10/site-packages/cfgrib/__init__.py, codes_info: Default definition files path is used: /home/aserranot/miniconda3/envs/dask/share/eccodes/definitions $\endgroup$ Commented Jan 29 at 9:48
  • $\begingroup$ I also have to say that I have a system (non-conda) installation of eccodes, but the "which grib_ls" command (see above) shows that I am using the conda version. $\endgroup$ Commented Jan 29 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.