""" WRF后处理程序 slp 20230116 byp """ import netCDF4 import wrf import os import glob import re import matplotlib.pyplot # 读取数据###############################################################开始 var = 'UV' # 变量:海平面气压SLP diagnostic = 'UV' # wrf-python提供的诊断变量:slp\rh title = '风速 2米$\mathbf{(K)}$' # 图片标题 '海平面气压$\mathbf{(hPa)}$'/'相对湿度 2米$\mathbf{(\%)}$' # 变量的数值范围及间隔 data_range_min = 0 data_range_max = 400 data_interval = 5 dir_name = "./data/WRF/" dir_output = './output/image/' list_of_files = glob.glob(dir_name+'*') latest_file = max(list_of_files, key=os.path.getctime) # 最新文件 print(latest_file) mat = re.search(r"(\d{4}-\d{1,2}-\d{1,2}_\d{1,2})", latest_file) # 正则匹配时间 dir_time_file = 'wrfout_d01_'+latest_file[mat.span()[0]:] dir_time = latest_file[mat.span()[0]:mat.span()[1]].replace('-', '').replace('_', '') data_nc = netCDF4.Dataset(dir_name+dir_time_file) # print(data_nc) # print(data_nc.variables['U10'].shape) # print(data_nc.variables['U10'][1][1][1]) # print(data_nc.variables['V10'].shape) # print(data_nc.variables['V10'][1][1][1]) u = wrf.getvar(data_nc, 'U10', timeidx=1) u = u.values[1][10] v = wrf.getvar(data_nc, 'V10', timeidx=1) v = v.values[1][10] fig = matplotlib.pyplot.figure() ax = matplotlib.pyplot.axes() ax.barbs(u, v) matplotlib.pyplot.show()