How to fix attribute error for Metpy data from a netcdf file involving xarray

筅森魡賤 提交于 2021-01-29 17:53:23

问题


I am getting this error:

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

when I am running my code. The particular lines in particular are:

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 = 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')

The line in bold is where the attribute error is popping up on. I am trying to learn how to use netcdf in metpy for some independent research as well as to learn metpy in general for future projects.


回答1:


The issue here is an out-of-date MetPy version. The Xarray accessor was added in v0.8. To update to the current version of MetPy with the latest functionality, you can upgrade with conda update metpy or pip install --upgrade metpy.



来源:https://stackoverflow.com/questions/58045079/how-to-fix-attribute-error-for-metpy-data-from-a-netcdf-file-involving-xarray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!