Search code examples
python-xarraymetpy

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


calling .metpy.parse_cf() on an xarray.Dataset gives '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

Solution

  • This is usually a version issue with cartopy>=0.18 and MetPy<=0.12.1. If you can update to at least MetPy>=0.12.2, that should fix this. This has also been observed in some cases with very old versions of cartopy that MetPy no longer supports (back to cartopy=0.14), so check that cartopy is relatively up-to-date as well.