I downloaded ERA5 netcdf data covering the region [30°W-30°E; 0-20°N].
This data downloaded contain horizontal wind components (u, v) and specific humidity (q).
I need to calculate horizontal advection of humidity through the use of Metpy function advection.
I get this error
/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.
The code that i am using is shown below
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))
question from:
https://stackoverflow.com/questions/65857648/issue-with-the-computation-of-advection-in-metpy-solved 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…