<p><code>cfgrib</code> uses <code>eccodes</code> under the hood, and not anymore the deprecated <code>grib_api</code> you're using, so that may be the source of the difference you're seeing.
However, regardless of <code>eccodes</code> or <code>grib_api</code> 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 <code>cfgrib</code> is installed (conda, pip...?) would mean it also installed other dependencies that may come with different GRIB tables.
Plus, <code>cfrgib</code> is doing some additional preprocessing when interpreting the data as hypercubes.</p>
<p>If you're using only <code>cfgrib</code> I'd suggest you to forget about <code>grib_ls</code> and use the variable name that <code>cfgrib</code> is finding, which shouldn't change if you don't make any modification in the environment where it is installed.</p>

CC BY-SA 4.0
2024-01-29T09:48:09.563Z
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
Antonio Serrano
CC BY-SA 4.0
2024-01-29T09:51:09.710Z
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.
Antonio Serrano
CC BY-SA 4.0
2024-01-17T10:07:44.043Z
2024-01-17T10:07:44.043Z
Droid
<p>Era5 data for wind</p>
<pre><code>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
</code></pre>
<p>So, grib_ls gives the proper variable name.
Under python, using xarray with cfgrib backend:</p>
<pre><code>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}}
    )
</code></pre>
<p>And ws_dataset is:</p>
<pre><code>&lt;xarray.Dataset&gt;
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...
</code></pre>
<p>So, the variable name has been properly set, but for wdir_dataset:</p>
<pre><code>&lt;xarray.Dataset&gt;
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...
</code></pre>
<p>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.</p>

CC BY-SA 4.0
2024-01-16T11:46:34.670Z
Seems like an issue you need to open the cfgrib github site - https://github.com/ecmwf/cfgrib/issues
gansub
<meteorology>
cfgrib does not take the proper variable name
Antonio Serrano
# cfgrib does not take the proper variable name

(Asked by: username_0 on 2024-01-16)

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.

**Tags:** meteorology

> **Comments:**
> **username_1**: Seems like an issue you need to open the cfgrib github site - https://github.com/ecmwf/cfgrib/issues  

---

## 1 answers

### Answer by username_2 on 2024-01-17. Score: 2

`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.

> **Comments:**
> **username_0**: Thank you, @username_2. 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  
> **username_0**: 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.  

---

