前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >python中纬向平均、经向平均、水平流场、水汽柱浓度计算、坐标刻度朝向、label上下角标示例

python中纬向平均、经向平均、水平流场、水汽柱浓度计算、坐标刻度朝向、label上下角标示例

作者头像
自学气象人
发布于 2022-11-14 08:07:49
发布于 2022-11-14 08:07:49
1.5K00
代码可运行
举报
文章被收录于专栏:自学气象人自学气象人
运行总次数:0
代码可运行

一次课程作业画图的code记录。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import pandas as pd
import numpy as np
import xarray as xr
from wrf import to_np,interpz3d,destagger
import glob 
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cmaps
import warnings

warnings.filterwarnings('ignore')
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
file_names = glob.glob('./wrfout_d01_*')
file_names = np.sort(file_names)
file_names = file_names[:3]
file_names

计算温度相关

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#计算TSK的相关数据
TSK_mean_space = []
TSK_mean_time = []
TSK_mean_lat = []
TSK_mean_lon = []
for file in file_names:
    print(file)
    data = xr.open_dataset(file)
    TSK_mean_space_one = np.mean(data['TSK'],axis=0)
    TSK_mean_time_one = (data['TSK'].mean(dim=['south_north','west_east'])).values
    TSK_mean_lat_one = np.mean(data['TSK'],axis=2)
    TSK_mean_lon_one = np.mean(data['TSK'],axis=1)
    TSK_mean_space.append(TSK_mean_space_one)
    TSK_mean_time.append(TSK_mean_time_one)
    TSK_mean_lat.append(TSK_mean_lat_one)
    TSK_mean_lon.append(TSK_mean_lon_one)
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#经向平均
TSK_mean_lon_concat = xr.concat([TSK_mean_lon[0],TSK_mean_lon[1],TSK_mean_lon[2]],'Time')

fig,ax=plt.subplots(1,1,figsize=(2,1),dpi=400)

ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0][0,:],np.arange(0,72,1),TSK_mean_lon_concat,levels=np.arange(260,310,2),cmap='rainbow',extend='both')
ax.set_title('Meridional Average TSK',fontdict={'size':4})
ax.set_ylabel("Simulation hours",fontdict={'size':3})
ax.set_xlabel("lon",fontdict={'size':3})
cb = plt.colorbar(c,shrink=0.9)
cb.set_label('TSK [K]',fontdict={'size':3})
cb.set_ticks([260,270,280,290,300])
cb.ax.tick_params(direction="out",length=1,labelsize=3)
plt.savefig('TSK mean lon.png')
plt.show()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#纬向平均
TSK_mean_lat_concat = xr.concat([TSK_mean_lat[0],TSK_mean_lat[1],TSK_mean_lat[2]],'Time')

fig,ax=plt.subplots(1,1,figsize=(2,1),dpi=400)

ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(np.arange(0,72,1),data['XLAT'][0][:,0],TSK_mean_lat_concat.values.T,levels=np.arange(260,310,2),cmap='rainbow',extend='both')
ax.set_title('Zonal Average TSK',fontdict={'size':4})
ax.set_xlabel("Simulation hours",fontdict={'size':3})
ax.set_ylabel("Lat",fontdict={'size':3})
cb = plt.colorbar(c,shrink=0.9)
cb.set_label('TSK [K]',fontdict={'size':3})
cb.set_ticks([260,270,280,290,300])
cb.ax.tick_params(direction="out",length=1,labelsize=3)
plt.savefig('TSK mean lat.png')
plt.show()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#全球平均温度时间折线
fig,ax = plt.subplots(1,1,figsize=(4,2),dpi=200)

time = np.arange(0,72,1)
ax.plot(time, np.array(TSK_mean_time).flatten(), label="TSK_mean_global", color="blue",  linestyle="-.",linewidth=0.7)
ax.set_xticks([0,12,24,36,48,60,72])
ax.set_xlabel("Simulation hours",fontdict={'size':5})
ax.set_ylabel("TSK [K]",fontdict={'size':5})
ax.set_title('Average TSK',fontdict={'size':5})
ax.tick_params(color = 'gray',length=1,labelsize=5)
plt.savefig('time TSK mean global.png')
plt.show()

#ax.legend()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#画空间分布图
fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=400,subplot_kw={'projection': ccrs.PlateCarree()})


lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())
ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0],data['XLAT'][0],(TSK_mean_space[0]+TSK_mean_space[1]+TSK_mean_space[2])/3.0,levels=np.arange(240,320,2),cmap='rainbow',transform=ccrs.PlateCarree(),extend='both')

ax.coastlines('50m', color='k', lw=0.3)
ax.set_title('The Distribution of Average TSK',fontdict={'size':5})
cb = plt.colorbar(c,shrink=0.25)
cb.set_label('TSK [K]',fontdict={'size':5})
cb.set_ticks([240,255,270,285,300,315])
cb.ax.tick_params(direction="out",length=1,labelsize=5)
plt.savefig('space TSK mean.png')
plt.show()

计算降水相关

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#计算rain的相关数据
data03  = xr.open_dataset(file_names[2])
RAIN_mean_space = (data03['RAINC'][-1] + data03['RAINNC'][-1])/(24*3.0) #unit:mm/h

QFX_mean_space = []
for file in file_names:
    print(file)
    data = xr.open_dataset(file)
    QFX_mean_space_one = np.mean(data['QFX'],axis=0)
    QFX_mean_space.append(QFX_mean_space_one)#画降水空间分布图
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=400,subplot_kw={'projection': ccrs.PlateCarree()})


lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())
ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0],data['XLAT'][0],RAIN_mean_space,levels=np.arange(0,1.5,0.02),cmap='rainbow',transform=ccrs.PlateCarree(),extend='both')

ax.coastlines('50m', color='k', lw=0.3)
ax.set_title('The Distribution of Average Rain',fontdict={'size':5})
cb = plt.colorbar(c,shrink=0.25)
cb.set_label('[mm * $h^{-1}$]',fontdict={'size':5})
cb.set_ticks([0.4,0.8,1.2,])
cb.ax.tick_params(direction="out",length=1,labelsize=5)
plt.savefig('space RAIN mean.png')
plt.show()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#画蒸发空间分布图

fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=400,subplot_kw={'projection': ccrs.PlateCarree()})


lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())
ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0],data['XLAT'][0],10000*(QFX_mean_space[0]+QFX_mean_space[1]+QFX_mean_space[2])/3.0,levels=np.arange(0,1.7,0.05),cmap='rainbow',transform=ccrs.PlateCarree(),extend='both')

ax.coastlines('50m', color='k', lw=0.3)
ax.set_title('The Distribution of Average QFX',fontdict={'size':5})
cb = plt.colorbar(c,shrink=0.25)
cb.set_label('[1.0E-4 kg $m^{-2}$ $s^{-1}$]',fontdict={'size':5})
cb.set_ticks([0.4,0.8,1.2])
cb.ax.tick_params(direction="out",length=1,labelsize=5)
plt.savefig('space QFX mean.png')
plt.show()

TOA 辐射

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#计算TOA的相关数据
TOA_mean_space = []
TOA_mean_lat = []
TOA_mean_lon = []
for file in file_names:
    print(file)
    data = xr.open_dataset(file)
    val = data['SWDNT'] - data['SWUPT'] + data['LWDNT'] - data['LWUPT']
    TOA_mean_space_one = np.mean(val,axis=0)
    TOA_mean_lat_one = np.mean(val,axis=2)
    TOA_mean_lon_one = np.mean(val,axis=1)
    TOA_mean_space.append(TOA_mean_space_one)
    TOA_mean_lat.append(TOA_mean_lat_one)
    TOA_mean_lon.append(TOA_mean_lon_one)
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#画空间分布图
fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=400,subplot_kw={'projection': ccrs.PlateCarree()})


lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())
ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0],data['XLAT'][0],(TOA_mean_space[0]+TOA_mean_space[1]+TOA_mean_space[2])/3.0,levels=np.arange(-80,195,5),cmap='rainbow',transform=ccrs.PlateCarree(),extend='both')

ax.coastlines('50m', color='k', lw=0.3)
ax.set_title('The Distribution of Average TOA',fontdict={'size':5})
cb = plt.colorbar(c,shrink=0.25)
cb.set_label('TOA [W *$m^{-2}$]',fontdict={'size':5})
cb.set_ticks([-50,0,50,100,150])
cb.ax.tick_params(direction="out",length=1,labelsize=5)
plt.savefig('space TOA mean.png')
plt.show()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#TOA经向平均
TOA_mean_lon_concat = xr.concat([TOA_mean_lon[0],TOA_mean_lon[1],TOA_mean_lon[2]],'Time')
TOA_mean_lon_concat = TOA_mean_lon_concat.mean('Time')

fig,ax = plt.subplots(1,1,figsize=(4,2),dpi=200)

time = np.arange(0,72,1)
ax.plot(data['XLONG'][0][0,:], TOA_mean_lon_concat, label="TOA_mean_lon", color="blue",  linestyle="-.",linewidth=0.7)
#ax.set_xticks([-180,-120,24,36,48,60,72])
ax.set_xlabel("longitude",fontdict={'size':5})
ax.set_ylabel("TOA [W *$m^{-2}$]",fontdict={'size':5})
ax.set_title('Meridional Average TOA',fontdict={'size':5})
ax.tick_params(color = 'gray',length=1,labelsize=5)
plt.savefig('TOA mean lon.png')
plt.show()

#ax.legend()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#TOA纬向平均
TOA_mean_lat_concat = xr.concat([TOA_mean_lat[0],TOA_mean_lat[1],TOA_mean_lat[2]],'Time')
TOA_mean_lat_concat = TOA_mean_lat_concat.mean('Time')

fig,ax = plt.subplots(1,1,figsize=(4,2),dpi=200)

time = np.arange(0,72,1)
ax.plot(data['XLAT'][0][:,0], TOA_mean_lat_concat, label="TOA_mean_lat", color="blue",  linestyle="-.",linewidth=0.7)
#ax.set_xticks([-180,-120,24,36,48,60,72])
ax.set_xlabel("latitude",fontdict={'size':5})
ax.set_ylabel("TOA [W *$m^{-2}$]",fontdict={'size':5})
ax.set_title('Zonal Average TOA',fontdict={'size':5})
ax.tick_params(color = 'gray',length=1,labelsize=5)
plt.savefig('TOA mean lat.png')
plt.show()

#ax.legend()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#计算TOA长波的相关数据
TOA_LW_mean_space = []
TOA_LW_mean_lat = []
TOA_LW_mean_lon = []
for file in file_names:
    print(file)
    data = xr.open_dataset(file)
    val = data['LWDNT'] - data['LWUPT']
    TOA_LW_mean_space_one = np.mean(val,axis=0)
    TOA_LW_mean_lat_one = np.mean(val,axis=2)
    TOA_LW_mean_lon_one = np.mean(val,axis=1)
    TOA_LW_mean_space.append(TOA_LW_mean_space_one)
    TOA_LW_mean_lat.append(TOA_LW_mean_lat_one)
    TOA_LW_mean_lon.append(TOA_LW_mean_lon_one)
    
#画空间分布图
fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=400,subplot_kw={'projection': ccrs.PlateCarree()})


lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())
ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0],data['XLAT'][0],(TOA_LW_mean_space[0]+TOA_LW_mean_space[1]+TOA_LW_mean_space[2])/3.0,levels=np.arange(-300,-90,10),cmap='rainbow',transform=ccrs.PlateCarree(),extend='both')

ax.coastlines('50m', color='k', lw=0.3)
ax.set_title('The Distribution of Average TOA_LW',fontdict={'size':5})
cb = plt.colorbar(c,shrink=0.25)
cb.set_label('TOA [W *$m^{-2}$]',fontdict={'size':5})
cb.set_ticks([-300,-250,-200,-150,-100])
cb.ax.tick_params(direction="out",length=1,labelsize=5)
plt.savefig('space TOA_LW mean.png')
plt.show()


#TOA经向平均
TOA_LW_mean_lon_concat = xr.concat([TOA_LW_mean_lon[0],TOA_LW_mean_lon[1],TOA_LW_mean_lon[2]],'Time')
TOA_LW_mean_lon_concat = TOA_LW_mean_lon_concat.mean('Time')

fig,ax = plt.subplots(1,1,figsize=(4,2),dpi=200)

time = np.arange(0,72,1)
ax.plot(data['XLONG'][0][0,:], TOA_LW_mean_lon_concat, label="TOA_LW_mean_lon", color="blue",  linestyle="-.",linewidth=0.7)
#ax.set_xticks([-180,-120,24,36,48,60,72])
ax.set_xlabel("longitude",fontdict={'size':5})
ax.set_ylabel("TOA [W *$m^{-2}$]",fontdict={'size':5})
ax.set_title('Meridional Average TOA_LW',fontdict={'size':5})
ax.tick_params(color = 'gray',length=1,labelsize=5)
plt.savefig('TOA_LW mean lon.png')
plt.show()

#ax.legend()

#TOA纬向平均
TOA_LW_mean_lat_concat = xr.concat([TOA_LW_mean_lat[0],TOA_LW_mean_lat[1],TOA_LW_mean_lat[2]],'Time')
TOA_LW_mean_lat_concat = TOA_LW_mean_lat_concat.mean('Time')

fig,ax = plt.subplots(1,1,figsize=(4,2),dpi=200)

time = np.arange(0,72,1)
ax.plot(data['XLAT'][0][:,0], TOA_LW_mean_lat_concat, label="TOA_LW_mean_lat", color="blue",  linestyle="-.",linewidth=0.7)
#ax.set_xticks([-180,-120,24,36,48,60,72])
ax.set_xlabel("latitude",fontdict={'size':5})
ax.set_ylabel("TOA [W *$m^{-2}$]",fontdict={'size':5})
ax.set_title('Zonal Average TOA_LW',fontdict={'size':5})
ax.tick_params(color = 'gray',length=1,labelsize=5)
plt.savefig('TOA_LW mean lat.png')
plt.show()

#ax.legend()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#计算TOA长波的相关数据
TOA_SW_mean_space = []
TOA_SW_mean_lat = []
TOA_SW_mean_lon = []
for file in file_names:
    print(file)
    data = xr.open_dataset(file)
    val = data['SWDNT'] - data['SWUPT']
    TOA_SW_mean_space_one = np.mean(val,axis=0)
    TOA_SW_mean_lat_one = np.mean(val,axis=2)
    TOA_SW_mean_lon_one = np.mean(val,axis=1)
    TOA_SW_mean_space.append(TOA_SW_mean_space_one)
    TOA_SW_mean_lat.append(TOA_SW_mean_lat_one)
    TOA_SW_mean_lon.append(TOA_SW_mean_lon_one)
    
#画空间分布图
fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=400,subplot_kw={'projection': ccrs.PlateCarree()})


lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())
ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0],data['XLAT'][0],(TOA_SW_mean_space[0]+TOA_SW_mean_space[1]+TOA_SW_mean_space[2])/3.0,levels=np.arange(100,400,20),cmap='rainbow',transform=ccrs.PlateCarree(),extend='both')

ax.coastlines('50m', color='k', lw=0.3)
ax.set_title('The Distribution of Average TOA_SW',fontdict={'size':5})
cb = plt.colorbar(c,shrink=0.25)
cb.set_label('TOA [W *$m^{-2}$]',fontdict={'size':5})
cb.set_ticks([100,150,200,250,300,350,400])
cb.ax.tick_params(direction="out",length=1,labelsize=5)
plt.savefig('space TOA_SW mean.png')
plt.show()


#TOA经向平均
TOA_SW_mean_lon_concat = xr.concat([TOA_SW_mean_lon[0],TOA_SW_mean_lon[1],TOA_SW_mean_lon[2]],'Time')
TOA_SW_mean_lon_concat = TOA_SW_mean_lon_concat.mean('Time')

fig,ax = plt.subplots(1,1,figsize=(4,2),dpi=200)

time = np.arange(0,72,1)
ax.plot(data['XLONG'][0][0,:], TOA_SW_mean_lon_concat, label="TOA_SW_mean_lon", color="blue",  linestyle="-.",linewidth=0.7)
#ax.set_xticks([-180,-120,24,36,48,60,72])
ax.set_xlabel("longitude",fontdict={'size':5})
ax.set_ylabel("TOA [W *$m^{-2}$]",fontdict={'size':5})
ax.set_title('Meridional Average TOA_SW',fontdict={'size':5})
ax.tick_params(color = 'gray',length=1,labelsize=5)
plt.savefig('TOA_SW mean lon.png')
plt.show()

#ax.legend()

#TOA纬向平均
TOA_SW_mean_lat_concat = xr.concat([TOA_SW_mean_lat[0],TOA_SW_mean_lat[1],TOA_SW_mean_lat[2]],'Time')
TOA_SW_mean_lat_concat = TOA_SW_mean_lat_concat.mean('Time')

fig,ax = plt.subplots(1,1,figsize=(4,2),dpi=200)

time = np.arange(0,72,1)
ax.plot(data['XLAT'][0][:,0], TOA_SW_mean_lat_concat, label="TOA_SW_mean_lat", color="blue",  linestyle="-.",linewidth=0.7)
#ax.set_xticks([-180,-120,24,36,48,60,72])
ax.set_xlabel("latitude",fontdict={'size':5})
ax.set_ylabel("TOA [W *$m^{-2}$]",fontdict={'size':5})
ax.set_title('Zonal Average TOA_SW',fontdict={'size':5})
ax.tick_params(color = 'gray',length=1,labelsize=5)
plt.savefig('TOA_SW mean lat.png')
plt.show()

#ax.legend()

水平流场

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#风800hpq空间分布图
z_list=[8000.,5000.,2000.]
result_U=[]
result_V=[]
for file in file_names:
    print(file)
    ds = xr.open_dataset(file)
    U = destagger(ds['U'],3,meta=True)
    V = destagger(ds['V'],2,meta=True)
    P = ds['PB']+ds['P']
    U_inter = interpz3d(U,P,np.array(z_list))
    V_inter = interpz3d(V,P,np.array(z_list))
    result_U.append(U_inter)
    result_V.append(V_inter)
    

#画流场
fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=200,subplot_kw={'projection': ccrs.PlateCarree(central_longitude=180)})

lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())

ax.tick_params(color = 'gray',direction='in',labelsize=5,length=0.9)

ax.streamplot(data['XLONG'][0].values,data['XLAT'][0].values,result_U[-1][-1,0,:,:].values ,(xr.concat(result_V,'Time').mean('Time'))[0].values, transform=ccrs.PlateCarree(),linewidth=0.7,arrowsize=0.5,density=1)

ax.coastlines('50m', color='k', lw=0.15)

ax.set_title('Wind (800hpa)',fontdict={'size':10})
plt.savefig('Wind (800hpa).png')
plt.show()

水汽

按照此公式计算

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#计算水汽柱浓度

result=[]
for file in file_names:
    #读取数据
    ds = xr.open_dataset(file)
    #提取计算水汽柱浓度的变量
    P = ds['PH']+ds['PHB']
    gmp=P/9.81
    z = gmp[:,1:31,:,:]-gmp[:,0:30,:,:]
    z = z.rename({"bottom_top_stag": "bottom_top"})
    #计算水汽柱浓度
    q_sumone = ((1.0/ds['ALT'])*ds['QVAPOR']*z).sum(axis=1)  #unit:kg/m2
    result.append(q_sumone)
    
q_all = xr.concat(result,dim='Time')
q_mean = q_all.mean(axis=0)
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#水汽柱浓度空间分布图
fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=400,subplot_kw={'projection': ccrs.PlateCarree()})


lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())
ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0],data['XLAT'][0],q_mean,levels=np.arange(0,65,2),cmap='rainbow',transform=ccrs.PlateCarree(),extend='both')

ax.coastlines('50m', color='k', lw=0.3)
ax.set_title('Qvapor Column Concentration',fontdict={'size':5})
cb = plt.colorbar(c,shrink=0.25)
cb.set_label('[kg/m2]',fontdict={'size':5})
cb.ax.tick_params(direction="out",length=1,labelsize=5)
cb.set_ticks([0,10,20,30,40,50,60])
plt.savefig('qvapor column concentration.png')
plt.show()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#水汽800hpq空间分布图
z_list=[8000.,]
result_q=[]
for file in file_names:
    print(file)
    ds = xr.open_dataset(file)
    qvapor = ds['QVAPOR']
    P = ds['PB']+ds['P']
    qvapor_800 = interpz3d(qvapor,P,np.array(z_list))
    result_q.append(qvapor_800)
    

fig,ax=plt.subplots(1,1,figsize=(4,4),dpi=400,subplot_kw={'projection': ccrs.PlateCarree()})


lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_extent([-180,180,-20,75],crs = ccrs.PlateCarree()) 
ax.set_xticks(np.arange(-180,181,30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20,76,15), crs=ccrs.PlateCarree())
ax.tick_params(color = 'gray',direction='in',length=1,labelsize=3)

c = ax.contourf(data['XLONG'][0],data['XLAT'][0],1.0e6*(xr.concat(result_q,'Time').mean('Time')[0]),levels=np.arange(1.5,4,0.1),cmap='rainbow',transform=ccrs.PlateCarree(),extend='both')

ax.coastlines('50m', color='k', lw=0.3)
ax.set_title('The Distribution of Avarage Qvapor (800 hpa)',fontdict={'size':5})
cb = plt.colorbar(c,shrink=0.25)
cb.set_label('[1.0E-6 kg kg-1]',fontdict={'size':5})
cb.ax.tick_params(direction="out",length=1,labelsize=5)
cb.set_ticks([1.5,2.0,2.5,3.0,3.5,4.0])
plt.savefig('qvapor 800 hpa')
plt.show()

手动计算水汽柱浓度的另外一种公式:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
'''
result=[]
for file in file_names:
    #读取数据
    ds = xr.open_dataset(file)
    #提取计算水汽柱浓度的变量
    P = ds['P']+ds['PB']
    g = 9.81
    P_top = (ds['P_TOP'].values[0])*np.ones((1,90,180))
    P_TOP = xr.DataArray(P_top, ds['PSFC'].coords,ds['PSFC'].dims)
    P = (xr.concat([ds['PSFC'].rename({"Time": "bottom_top"}),((P[0,0:29,:,:]+P[0,1:30,:,:])/2.0),P_TOP.rename({"Time": "bottom_top"})],'bottom_top'))
    P = P[0:30,:,:] -P[1:31,:,:]
    #计算水汽柱浓度
    q_sumone = ((ds['QVAPOR'][0]/g)*P).sum(axis=0)  #unit:kg/m2
    result.append(q_sumone)

q_all = xr.concat(result,dim='Time')
q_mean = q_all.mean(axis=0)
'''
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-10-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 自学气象人 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
Kubernetes学习笔记(一)
Kubernetes API,集群的统一入口,各组件协调者,以RESTful API提供接口服务,所有对象资源的增删改查和监听操作都交给APISer ver处理后再提交给Etcd存储。
用户10662715
2025/04/24
730
kubernetes监控架构核心组件Metrics-server
如何查看各节点的资源使用情况? 如何监控kubernetes集群资源?自kubernetes 1.8开始,资源使用指标(如容器 CPU 和内存使用率)通过 Metrics API 在 Kubernet
公众号: 云原生生态圈
2021/11/15
1.6K0
kubernetes监控架构核心组件Metrics-server
Prometheus性能调优-什么是高基数问题以及如何解决?
•PrometheusMissingRuleEvaluations•PrometheusRuleFailures
东风微鸣
2022/12/01
2.2K0
Prometheus性能调优-什么是高基数问题以及如何解决?
Kubernetes 集群部署 Metrics Server 获取集群 Metric 数据
Kubernetes 从 v1.8 开始,资源使用情况的监控可以通过 Metrics API 的形式获取,具体的组件为 Metrics Server,用来替换之前的 Heapster,Heapster从 v1.11 开始逐渐被废弃。
玖柒的小窝
2021/10/23
4760
Kubernetes 集群部署 Metrics Server 获取集群 Metric 数据
K8s监控之Metrics-Server指标获取链路分析
Metrics-server基于cAdvisor收集指标数据,获取、格式化后以metrics API的形式从apiserver对外暴露,核心作用是为kubectl top以及HPA等组件提供决策指标支持。
壹贝
2022/11/30
4.1K1
「走进k8s」Kubernetes1.15.1的Pod 自动扩缩容(23)
1. 用于支持自动扩缩容的 CPU/memory HPA metrics:metrics-server;2. 通用的监控方案:使用第三方可以获取 Prometheus 格式监控指标的监控系统,如 Prometheus Operator;3. 事件传输:使用第三方工具来传输、归档 kubernetes events;
IT架构圈
2019/08/23
2.8K0
kubernetes(十六) k8s 弹性伸缩
常规的做法是给集群资源预留保障集群可用,通常20%左右。这种方式看似没什么问题,但放到Kubernetes中,就会发现如下2个问题。
alexhuiwang
2020/09/23
3.6K0
kubernetes(十六) k8s 弹性伸缩
09 Jan 2024 在kind中部署metrics-server
你会发现不work,需要在metrics-server的deployment中args部分添加一行- --kubelet-insecure-tls,让kubelet忽略tls证书验证,这样才能正常工作。
俊采
2024/01/10
1850
Metrics Server 部署
从Kubernetes 1.8开始,资源使用指标(如容器 CPU 和内存使用率)通过Metrics API在 Kubernetes 中获取, Metrics Server 替代了Heapster。Metrics Server 实现了Resource Metrics API,Metrics Server 是集群范围资源使用数据的聚合器。Metrics Server 从每个节点上的 Kubelet 公开的Summary API中采集指标信息
YP小站
2020/06/04
1.6K0
腾讯云TKE-Metrics-Server案例: TKE中自建Metrics-Server问题
用户想在TKE环境中自己部署metrics-server去获取监控数据, 想对监控系统有更多的控制权,好多用户会选择在TKE中自己部署一套Metrics-Server + Prometheus + Grafana
朱瑞卿
2020/10/24
1.3K0
kubernetes 指标采集组件 metrics-server 的部署
metrics-server 是一个采集集群中指标的组件,类似于 cadvisor,在 v1.8 版本中引入,官方将其作为 heapster 的替代者,metric-server 属于 core metrics(核心指标),提供 API metrics.k8s.io,仅可以查看 node、pod 当前 CPU/Memory/Storage 的资源使用情况,也支持通过 Metrics API 的形式获取,以此数据提供给 Dashboard、HPA、scheduler 等使用。
田飞雨
2019/12/18
3.8K0
kubernetes系列教程(十九)使用metric-server让HPA弹性伸缩愉快运行
kubernetes监控指标大体可以分为两类:核心监控指标和自定义指标,核心监控指标是kubernetes内置稳定可靠监控指标,早期由heapster完成,现由metric-server实现;自定义指标用于实现核心指标的扩展,能够提供更丰富的指标支持,如应用状态指标,自定义指标需要通过Aggregator和k8s api集成,当前主流通过promethues实现。
HappyLau谈云计算
2020/01/22
6K2
kubernetes系列教程(十九)使用metric-server让HPA弹性伸缩愉快运行
kubernetes | metrics-server部署
基于centos7.9,docker-ce-20.10.18,kubelet-1.22.3-0
Amadeus
2022/10/25
9810
kubernetes | metrics-server部署
TKE上部署metrics-server
修改对应的metrics-server-deployment.yaml文件,需要改镜像源,国外的镜像需要科学上网下载,还需要添加如下参数
聂伟星
2020/08/13
1.2K0
Kubernetes 集群部署 Metrics Server 获取集群 Metric 数据
Kubernetes 从 v1.8 开始,资源使用情况的监控可以通过 Metrics API 的形式获取,具体的组件为 Metrics Server,用来替换之前的 Heapster,Heapster从 v1.11 开始逐渐被废弃。
高楼Zee
2021/10/27
3.4K1
揭开K8s适配CgroupV2内存虚高的迷局
在Almalinux替换CentOS的过程中,我们通过kubectl top nodes命令观察到了两个相同规格的节点(只有cgroup版本不同)。在分别调度两个相同的Pod后,我们预期它们的内存使用量应该相近。然而,我们发现使用了cgroupv2的节点的内存使用量比使用了cgroupv1的节点多了约280Mi。
zouyee
2023/11/15
7420
揭开K8s适配CgroupV2内存虚高的迷局
Kubernetes运维之容器编排Deployment动态扩缩容
HPA(Horizontal Pod Autoscaler)的实现是一个控制循环,由controller manager的–horizontal-pod-autoscaler-sync-period参数指定周期(默认值为15秒)。每个周期内,controller manager根据每个HorizontalPodAutoscaler定义中指定的指标查询资源利用率。controller manager可以从resource metrics API(pod 资源指标)和custom metrics API(自定义指标)获取指标。
王先森sec
2023/04/24
1.2K0
Kubernetes运维之容器编排Deployment动态扩缩容
聊聊docker容器的memory限制
所谓Cache,就是为了弥补高速设备和低速设备之间的矛盾而设立的一个中间层。 缓冲(Buffer)是根据磁盘的读写设计的,它把分散的写操作集中进行,减少磁盘碎片和硬盘的反复寻道,从而提高系统性能。
code4it
2024/04/08
4440
Prometheus 如何做到“活学活用”,大牛总结的避坑指南
监控系统的历史悠久,是一个很成熟的方向,而 Prometheus 作为新生代的开源监控系统,慢慢成为了云原生体系的事实标准,也证明了其设计很受欢迎。
民工哥
2020/09/15
9080
Prometheus 如何做到“活学活用”,大牛总结的避坑指南
浅谈 Kubernetes Metrics Server
1、Metrics Servrer 原理介绍 1.1、Metrics Server 概念和功能 概念 Metrics Server 是 Kubernetes 集群核心监控数据的聚合器,Metrics Server 从 Kubelet 收集资源指标,并通过 Merics API 在 Kubernetes APIServer 中提供给缩放资源对象 HPA 使用。也可以通过 Metrics API 提供的 Kubectl top 查看 Pod 资源占用情况,从而实现对资源的自动缩放。 功能 主要是基于 Kuber
用户5166556
2020/06/01
4.4K0
推荐阅读
相关推荐
Kubernetes学习笔记(一)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档