Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load GRIB variables with "unknown" typeOfLevel using custom ecCodes tables #266

Closed
torfsen opened this issue Nov 2, 2021 · 3 comments
Closed

Comments

@torfsen
Copy link

torfsen commented Nov 2, 2021

I've posted this question on StackOverflow before but didn't get any answers. Feel free to answer it there and/or close this ticket.

I'm trying to load GRIB2 files from DWD's ICON model using xarray and cfgrib. Most variables work fine, but for some (like for example CLCL), xarray.open_dataset raises the following error:

Traceback (most recent call last):
  File "/shared/conda/envs/devtools/lib/python3.8/site-packages/xarray/core/dataset.py", line 1398, in _construct_dataarray
    variable = self._variables[name]
KeyError: 'CLCL'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "DAT-2634/grib_file_loaders.py", line 276, in <module>
    df_cfgrib_sf = read_cfgrib_sf(grib_fns, nodes, params)
  File "DAT-2634/grib_file_loaders.py", line 115, in read_cfgrib_sf
    x = xr.open_dataset(
  File "/shared/conda/envs/devtools/lib/python3.8/site-packages/xarray/core/dataset.py", line 1502, in __getitem__
    return self._construct_dataarray(key)
  File "/shared/conda/envs/devtools/lib/python3.8/site-packages/xarray/core/dataset.py", line 1400, in _construct_dataarray
    _, name, variable = _get_virtual_variable(
  File "/shared/conda/envs/devtools/lib/python3.8/site-packages/xarray/core/dataset.py", line 173, in _get_virtual_variable
    ref_var = variables[ref_name]
KeyError: 'CLCL'

when I inspect the file via grib_ls I get

$ grib_ls ICON_europe_reg_0.125x0.125_2021101900_f000.grib2 | grep CLCL
2            edzw         20211019     fc           regular_ll   0            unknown      800          CLCL         grid_simple 

I've read in the issues #195 and #213 that this is probably due to the use of local codes and that I might be able to fix the issue using the appropriate code tables. DWD does provide GRIB tables for ecCodes, but I'm not sure how to use them in combination with cfgrib.

How can I use the custom code tables with cfgrib? Or is there another way to load these variables?

@iainrussell
Copy link
Member

Hello @torfsen,

Once you have the tables downloaded and put somewhere on disk, you need to set the environment variable "ECCODES_DEFINITION_PATH" to point to where the new tables are. See the bottom of this page, which also describes how to create the tables (which you do not need to do of course!)
https://confluence.ecmwf.int/display/UDOC/Creating+your+own+local+definitions+-+ecCodes+GRIB+FAQ

Cheers,
Iain

@torfsen
Copy link
Author

torfsen commented Nov 19, 2021

Thanks, @iainrussell, that was exactly what I was looking for. Adding the path of the custom code tables (and that of the base tables that come with ecCodes) to ECCODES_DEFINITION_PATH worked wonderfully.

@torfsen torfsen closed this as completed Nov 19, 2021
@iainrussell
Copy link
Member

Brilliant, thanks for letting me know @torfsen !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants