我无法从 GFS 数据中绘制来自 metpy.calc 的 Q 向量;ax.set_extent
应用and时,我无法正确绘制向量ax.quiver
计算代码:
import metpy.calc as mpcalc
query.variables('Temperature_isobaric', 'Geopotential_height_isobaric',
'u-component_of_wind_isobaric', 'v-component_of_wind_isobaric')
data = subset_access.get_data(query)
lat = data.variables['lat'][:]
lon = data.variables['lon'][:]
press = data.variables['isobaric'][:] * units.Pa
# Make the pressure same dimensions as the temperature and winds
pressure_for_calc = press[:, None, None]
temperature = data.variables['Temperature_isobaric'][0] * units.kelvin
u = data.variables['u-component_of_wind_isobaric'][0] * units.meter /
units.second
v = data.variables['v-component_of_wind_isobaric'][0] * units.meter /
units.second
dx, dy = mpcalc.lat_lon_grid_deltas(lon, lat)
现在我试图通过 q-vector 函数运行 dx 和 dy:
Q = mpcalc.q_vector(u,v,temperature,pressure_for_calc,dx,dy)
但是我收到了一个错误,我认为这与 dx 和 dy 尺寸有关:
IndexError: too many indices for array
dx.shape, dy.shape
>>> ((101, 160), (100, 161))
好的,这显然是个问题;我需要一个一维数组,所以我探测了温度数组的形状:
print(temperature.shape)
>>> (31, 101, 161)
因此,我尝试获取 dx 和 dy 的子集:
print(dx[:,0].shape, dy[0,:].shape)
>>> (101,) (161,)
然后我认为这应该与 temp 和 press 数组对齐,并根据这些子集再次尝试计算:
Q = mpcalc.q_vector(u,v,temperature,pressure_for_calc,dx[0,:],dy[:,0])
没有错误,现在感觉很好。检查我假设为 x 和 y 分量的 Q 的尺寸:
print(Q[0].shape, Q[1].shape)
>>> (31, 101, 161)
>>> (31, 101, 161)
好像要排队...
但是,当我查看 lats 和 lons 的尺寸时:
lat.shape, lon.shape
>>> ((101,), (161,))
从 dx 和 dy 的形状看好像是倒退的?
我是否遗漏了什么,或者我只是去计算 Q 向量完全错误?这是我的第一次尝试,我不确定我所做的是否正确。
当我尝试用任何投影绘制它们时,真正的问题来了ax.quiver
绘图代码:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
# Set Projection of Data
datacrs = ccrs.PlateCarree()
# Set Projection of Plot
plotcrs = ccrs.LambertConformal()
# Add Map Features
states_provinces = cfeature.NaturalEarthFeature(category='cultural',
name='admin_1_states_provinces_lakes',scale='50m', facecolor='none')
country_borders = cfeature.NaturalEarthFeature(category='cultural',
name='admin_0_countries',scale='50m', facecolor='none')
# Lat/Lon Extents [lon0,lon1,lat0,lat1]
extent = [-130., -70, 20., 60.]
# Create a plot
fig = plt.figure(figsize=(17., 11.))
# Add the map
ax = plt.subplot(111, projection=plotcrs)
# Add state boundaries to plot
ax.add_feature(states_provinces, edgecolor='k', linewidth=1)
# Add country borders to plot
ax.add_feature(country_borders, edgecolor='black', linewidth=1)
lon_slice = slice(None, None, 8)
lat_slice = slice(None, None, 8)
ax.quiver(lon[lon_slice],lat[lat_slice],Q[0][0,lon_slice,lat_slice], Q[1][0,lon_slice,lat_slice],
color='k',transform=plotcrs)
ax.set_extent(extent, datacrs)
plt.show()
结果地图:
当我忽略它时,ax.set_extent
它似乎绘制了 Q 向量,只是现在没有地图背景......
所以我想我的两个问题是:
1)我是否根据 GFS 数据适当地计算了 Q 向量?
2)我在绘图中缺少什么?