我试图使用GRIB2和cfgrib从DWD的图标模型中加载xarray文件。大多数变量运行良好,但对于一些变量(如CLCL),xarray.open_dataset会引发以下错误:
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'当我通过grib_ls检查文件时,我得到
$ 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 我在“cfgrib probably”、“#195”和“#213”中看到,这可能是由于使用了本地代码,并且我可能能够使用适当的代码表修复这个问题。DWD确实提供了用于ecCodes的GRIB表,但我不知道如何将它们与cfgrib结合使用。
如何在自定义代码表中使用cfgrib**?或者还有其他方法来加载这些变量?**
发布于 2021-11-19 13:41:41
在没有进一步了解之后,我发布了相同的问题GitHub项目,并在其中找到了回应:解决方案是将自定义代码表的路径添加到ECCODES_DEFINITION_PATH环境变量中:
import os
from pathlib import Path
import xarray
ECCODES_DEFINITION_PATHS = [
# The custom codes I want to use
Path('path/to/the/custom/codes'),
# The codes from my system's ecCodes installation
Path('/usr/share/eccodes/definitions'),
]
os.environ['ECCODES_DEFINITION_PATH'] = ':'.join(
str(p.resolve())
for p in ECCODES_DEFINITION_PATHS
)
x = xarray.open_dataset(...)有可用的详细文档,在ECMWF wiki中。
https://stackoverflow.com/questions/69677667
复制相似问题