在 xarray.Dataset 上调用 .metpy.parse_cf() 给出 'ctables' is not defined

calling .metpy.parse_cf() on an xarray.Dataset gives 'ctables' is not defined

在 xarray.Dataset 上调用 .metpy.parse_cf() 给出 'ctables' is not defined

import xarray as xr
import metpy
ds = xr.open_dataset('https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p25deg/Best')
>>> ds.metpy.parse_cf('u-component_of_wind_height_above_ground')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ray/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/metpy/xarray.py", line 512, in parse_cf
    from .plots.mapping import CFProjection
  File "/home/ray/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/metpy/plots/__init__.py", line 19, in <module>
    __all__ = ctables.__all__[:]  # pylint: disable=undefined-variable
NameError: name 'ctables' is not defined

通常 cartopy>=0.18MetPy<=0.12.1 的版本问题。如果您至少可以更新到 MetPy>=0.12.2,应该可以解决此问题。在 MetPy 不再支持的非常旧版本的 cartopy 的某些情况下也观察到这种情况(回到 cartopy=0.14),因此请检查 cartopy 是否也相对 up-to-date。