- 积分
- 26
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2022-12-20
- 最后登录
- 1970-1-1
|
发表于 2023-2-18 15:05:18
|
显示全部楼层
大家可以帮忙看看这段代码吗?这是单层水汽通量的,但不知是哪里错了。
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.mpl.ticker as cticker
import cartopy.io.shapereader as shpreader
from cartopy.io.shapereader import Reader
plt.rcParams['font.sans-serif'] = ['Times New Roman']
f_shum = xr.open_dataset('E:/shum.nc')
f_u = xr.open_dataset('E:/uwnd.nc')
f_v = xr.open_dataset('E:/vwnd.nc')
time = f_u['time'].loc['2020-7-15':'2021-01-15']
def water_vapor(day, lev):
# for j in pd.date_range(data1.loc[i]['start_day'],data1.loc[i]['end_day'],freq='D'):
fu = f_u['uwnd'].loc[day, :, 90:10, -10:180].sel(level=lev)
fv = f_v['vwnd'].loc[day, :, 90:10, -10:180].sel(level=lev)
fq = f_shum['shum'].loc[day, :, 90:10, -10:180].sel(level=lev)
lon = fu['lon']
lat = fu['lat']
qv_u_gc = np.zeros((np.size(lat), np.size(lon)))
qv_v_gc = np.zeros((np.size(lat), np.size(lon)))
qv_u_gc[:, :] = (fu * fq / 9.8 * 100).mean(axis=0)
qv_v_gc[:, :] = (fv * fq / 9.8 * 100).mean(axis=0)
return lon, lat, qv_u_gc, qv_v_gc
def contour_map(fig):
leftlon, rightlon, lowerlat, upperlat = (90, 150, 10, 60)
img_extent = [leftlon, rightlon, lowerlat, upperlat]
fig.set_extent(img_extent, crs=ccrs.PlateCarree())
spec1 = 10
spec2 = 10
shp_path = r'E:\shp'
yellow = cfeature.ShapelyFeature(
Reader(shp_path +'Export.shp').geometries(),
ccrs.PlateCarree(), edgecolor='b',
facecolor='none'
)
fig.add_feature(yellow, linewidth=1.5, zorder=2)
fig.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.6, zorder=2)
fig.set_xticks(np.arange(leftlon, rightlon + spec1, spec1), crs=ccrs.PlateCarree())
fig.set_yticks(np.arange(lowerlat, upperlat + spec2, spec2), crs=ccrs.PlateCarree())
fig.xaxis.set_major_formatter(LONGITUDE_FORMATTER)
fig.yaxis.set_major_formatter(LATITUDE_FORMATTER)
fig.xaxis.set_minor_locator(plt.MultipleLocator(5))
fig.yaxis.set_minor_locator(plt.MultipleLocator(2)) # 数字表示分刻度大小
fig.tick_params(axis='both', labelsize=12, length=6, width=1, direction='out')
fig.set_extent(img_extent, crs=ccrs.PlateCarree())
fig.spines['geo'].set_linewidth(1)
# 创建画布
fig = plt.figure(figsize=(12, 16))
proj = ccrs.PlateCarree()
f_ax = fig.add_axes([0.1, 0.1, 0.4, 0.25], projection=proj)
contour_map(f_ax)
lons, lats, qu, qv, = water_vapor(time, 850)
v = f_ax.quiver(lons, lats, qu, qv, pivot='mid', width=0.006, headwidth=2.5, scale=25, transform=ccrs.PlateCarree())
f_ax.quiverkey(
v,
X=0.15, Y=0.95, U=3,
label='300 kg/(m$\cdot$ s)',
labelpos='E',
fontproperties={'size': 12}
)
fig.savefig('E:/graduate/water_vapor.jpg', transparent='True', dpi=300, bbox_inches='tight', pad_inches=0) |
|