如果直接从 NOMADS GFS 源中提取数据,看起来您的数据应该是 yx 维度顺序(这也是 MetPylat_lon_grid_deltas
函数假定的顺序)。因此,我认为脚本中关于维度排序的内容有些混乱。解决这个问题,并额外使用 MetPy 的一些 xarray 集成功能来清理实现,我们有:
预 MetPy v1.0
# Imports
import metpy.calc as mpcalc
from metpy.units import units
import xarray as xr
# Open data and parse for CRS
data = xr.open_dataset('http://nomads.ncep.noaa.gov/dods/gfs_0p25_1hr/gfs20201230/gfs_0p25_1hr_12z').metpy.parse_cf()
# Subset out the desired data
# Note that this leaves in time, but that can also be selected out if only
# one time is needed and you want to have smaller data arrays to compute on
t7 = data['tmpprs'].sel(lev=700.0,lat=slice(15, 70),lon=slice(220, 310))
u7 = data['ugrdprs'].sel(lev=700.0,lat=slice(15, 70),lon=slice(220, 310)).squeeze()
v7 = data['vgrdprs'].sel(lev=700.0,lat=slice(15, 70),lon=slice(220, 310)).squeeze()
h7 = data['hgtprs'].sel(lev=700.0,lat=slice(15, 70),lon=slice(220, 310)).squeeze()
# Clean up the xarray metadata for MetPy's use, since provided data is missing
# the units attribute
t7.attrs['units'] = 'K'
u7.attrs['units'] = v7.attrs['units'] = 'm/s'
h7.attrs['units'] = 'm'
# Get grid deltas
dx, dy = mpcalc.grid_deltas_from_dataarray(t7)
# Compute frontogenesis
h7_fgen = mpcalc.frontogenesis(t7, u7, v7, dx, dy)
发布 MetPy v1.0
在 MetPy v1.0 中,网格参数自动从 DataArray 输入中提取,因此,这可以简化为
# Imports
import metpy.calc as mpcalc
from metpy.units import units
import xarray as xr
# Open data and parse for CRS
data = xr.open_dataset('http://nomads.ncep.noaa.gov/dods/gfs_0p25_1hr/gfs20201230/gfs_0p25_1hr_12z').metpy.parse_cf()
# Subset out the desired data
t7 = data['tmpprs'].sel(lev=700.0,lat=slice(15, 70),lon=slice(220, 310))
u7 = data['ugrdprs'].sel(lev=700.0,lat=slice(15, 70),lon=slice(220, 310)).squeeze()
v7 = data['vgrdprs'].sel(lev=700.0,lat=slice(15, 70),lon=slice(220, 310)).squeeze()
h7 = data['hgtprs'].sel(lev=700.0,lat=slice(15, 70),lon=slice(220, 310)).squeeze()
# Clean up the xarray metadata for MetPy's use, since provided data is missing
# the units attribute
t7.attrs['units'] = 'K'
u7.attrs['units'] = v7.attrs['units'] = 'm/s'
h7.attrs['units'] = 'm'
# Compute frontogenesis
h7_fgen = mpcalc.frontogenesis(t7, u7, v7)