【发布时间】:2021-11-30 18:45:55
【问题描述】:
我正在尝试绘制一个 500 hPa 的涡度并不断遇到 valueerror 并且无法弄清楚。尝试了几个想法,包括我的导师的想法,但仍然没有奏效。我的代码没有完成,试图在完成绘图之前找出错误。有没有人有任何想法?感谢您的帮助!!!
这就是我得到的:
ValueError Traceback (most recent call last)
<ipython-input-7-7aee4011a39a> in <module>
4 f = mpcalc.coriolis_parameter(np.deg2rad(lats)).to(units('1/sec'))
5
----> 6 avor = mpcalc.absolute_vorticity(uwnd_500, vwnd_500, dx=dx, dy=dy, x_dim=- 1, y_dim=- 2)
7
8 avor = ndimage.gaussian_filter(avor, sigma=3, order=0) * units('1/s')
/opt/tljh/user/lib/python3.7/site-packages/metpy/xarray.py in wrapper(*args, **kwargs)
1488 )
1489 else:
-> 1490 raise ValueError('Must provide latitude argument or input DataArray with '
1491 'latitude/longitude coordinates.')
1492
ValueError: Must provide latitude argument or input DataArray with latitude/longitude coordinates.
到目前为止,这是我的代码:
ds = xr.open_dataset('https://thredds.ucar.edu/thredds/dodsC/casestudies/'
'python-gallery/GFS_20101026_1200.nc').metpy.parse_cf()
# Set subset slice for the geographic extent of data to limit download
lon_slice = slice(200, 350)
lat_slice = slice(85, 10)
# Grab lat/lon values (GFS will be 1D)
lats = ds.lat.sel(lat=lat_slice).values
lons = ds.lon.sel(lon=lon_slice).values
level = 500 * units.hPa
hght_500 = ds.Geopotential_height_isobaric.metpy.sel(
vertical=level, lat=lat_slice, lon=lon_slice).metpy.unit_array.squeeze()
tmpk_500 = ds.Temperature_isobaric.metpy.sel(
vertical=level, lat=lat_slice, lon=lon_slice).metpy.unit_array.squeeze()
uwnd_500 = ds['u-component_of_wind_isobaric'].metpy.sel(
vertical=level, lat=lat_slice, lon=lon_slice).metpy.unit_array.squeeze()
vwnd_500 = ds['v-component_of_wind_isobaric'].metpy.sel(
vertical=level, lat=lat_slice, lon=lon_slice).metpy.unit_array.squeeze()
# Get a sensible datetime format
vtime = ds.time.data[0].astype('datetime64[ms]').astype('O')
dx, dy = mpcalc.lat_lon_grid_deltas(lons, lats)
#Data Calculations
f = mpcalc.coriolis_parameter(np.deg2rad(lats)).to(units('1/sec'))
avor = mpcalc.absolute_vorticity(uwnd_500, vwnd_500, dx=dx, dy=dy, latitude=None, x_dim=- 1, y_dim=- 2)
avor = ndimage.gaussian_filter(avor, sigma=3, order=0) * units('1/s')
vort_adv = mpcalc.advection(avor, [uwnd_500, vwnd_500], (dx, dy)) * 1e9
# Set map projection
mapcrs = ccrs.LambertConformal(central_longitude=-100, central_latitude=35,
standard_parallels=(30, 60))
# Set projection of the data (GFS is lat/lon)
datacrs = ccrs.PlateCarree()
# Start figure and limit the graphical area extent
fig = plt.figure(1, figsize=(14, 12))
ax = plt.subplot(111, projection=mapcrs)
ax.set_extent([-130, -72, 20, 55], ccrs.PlateCarree())
# Add map features of Coastlines and States
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))
ax.add_feature(cfeature.STATES.with_scale('50m'))
【问题讨论】:
-
您使用的是什么版本的 MetPy?
-
我正在使用 MetPy 1.1