【问题标题】:How to fix attribute error for Metpy data from a netcdf file involving xarray如何修复涉及 xarray 的 netcdf 文件中 Metpy 数据的属性错误
【发布时间】:2019-09-27 21:56:02
【问题描述】:

我收到此错误:

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 版本以及您的 Python 版本?我无法使用 Python 3.7 以及最新版本的 MetPy 和 xarray 复制此问题。

标签: python-xarray metpy


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-09-11
    • 1970-01-01
    • 2014-08-25
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多