如何修复涉及 xarray 的 netcdf 文件中 Metpy 数据的属性错误
How to fix attribute error for Metpy data from a netcdf file involving xarray
我收到这个错误:
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。
此处的问题是 MetPy 版本过时。 Xarray 访问器是在 v0.8 中添加的。要更新到具有最新功能的当前版本的 MetPy,您可以使用 conda update metpy
或 pip install --upgrade metpy
进行升级。
我收到这个错误:
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。
此处的问题是 MetPy 版本过时。 Xarray 访问器是在 v0.8 中添加的。要更新到具有最新功能的当前版本的 MetPy,您可以使用 conda update metpy
或 pip install --upgrade metpy
进行升级。