0

我收到此错误:

AttributeError: 'Dataset' object has no attribute 'metpy' 

当我运行我的代码时。特别是特定的行是:

import Scientific.IO.NetCDF as S
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import xarray as xr
import metpy
# Any import of metpy will activate the accessors
import metpy.calc as mpcalc
#from metpy.testing import get_test_data
from metpy.units import units
# Open the netCDF file as a xarray Datase


#
datadir='C:/Users/stratusshow/AppData/Local/lxss/home/stratus/PROJECT/NEWPROJECT/FEB012017/nam_218_20170131_1200_000.nc'
data = xr.open_dataset(datadir,decode_cf=True)
# To parse the full dataset, we can call parse_cf without an argument, and assign the returned
# Dataset.

数据 = data.metpy.parse_cf()

# If we instead want just a single variable, we can pass that variable name to parse_cf and
# it will return just that data variable as a DataArray.
data_var = data.metpy.parse_cf('Temperature_isobaric')

粗体线是弹出属性错误的位置。我正在尝试学习如何在metpy中使用netcdf进行一些独立研究,以及为未来的项目学习metpy。

4

1 回答 1

1

这里的问题是过时的 MetPy 版本。在 v0.8 中添加了 Xarray 访问器。要使用最新功能更新到当前版本的 MetPy,您可以使用conda update metpy或进行升级pip install --upgrade metpy

于 2019-09-27T13:56:02.200 回答