Metpy中平流计算的问题



我下载了ERA5 netcdf数据覆盖区域[30°W-30°E;0-20°N]。下载的数据包含水平风分量(u, v)和比湿度(q)。我需要通过使用Metpy函数平流来计算湿度的水平平流.

我得到这个错误

/usr/local/lib/python3.8/dist-packages/metpy/xarray.py:1445: UserWarning: Vertical dimension number not found. Defaulting to (..., Z, Y, X) order.
warnings.warn(
Traceback (most recent call last):
File "temp_avect_calc.py", line 33, in <module>
adv = mpcalc.advection(q, [u, v], (dx, dy))
File "/usr/local/lib/python3.8/dist-packages/metpy/xarray.py", line 1470, in wrapper
grid_deltas_from_dataarray(grid_prototype, kind='actual')
File "/usr/local/lib/python3.8/dist-packages/metpy/xarray.py", line 1380, in grid_deltas_from_dataarray
geod=f.metpy.pyproj_crs.get_geod()))
File "/usr/local/lib/python3.8/dist-packages/metpy/xarray.py", line 253, in pyproj_crs
return self.crs.to_pyproj()
File "/usr/local/lib/python3.8/dist-packages/metpy/xarray.py", line 233, in crs
raise AttributeError('crs attribute is not available.')
AttributeError: crs attribute is not available.

我使用的代码如下所示

import cartopy.crs as ccrs
import metpy.calc as mpcalc
from metpy.units import units
import xarray as xr
fname  =  "uwnd_vwnd_shum_750hPa_2019.nc"
ds = xr.open_dataset(fname)
lat = ds["latitude"][::-1]
lon = ds["longitude"]

u = ds["u"][:,  ::-1, :] 
v = ds["v"][:,  ::-1, :] 
q = ds["q"][:,  ::-1, :] 

dx, dy = mpcalc.lat_lon_grid_deltas(lon, lat)
adv = mpcalc.advection(q, [u, v], (dx, dy))

根据您提供的错误,看起来您正在使用MetPy 1.0。如果是这种情况,则metpy.calc.advection的函数签名已经更改[link],也可以使用xarray [example]进行简化。您可以放弃计算网格间距,因为这将从纬度和经度坐标中拉入。为此,您必须显式地让MetPy解析数据集中的一些信息以创建crs信息,在本例中是来自经纬度的信息。下面的示例应该在MetPy 1.0上使用您的数据。

ds = xr.open_dataset(fname).metpy.parse_cf()
adv = mpcalc.advection(ds["q"], ds["u"], ds["v"])

相关内容

  • 没有找到相关文章

最新更新