前言
谢谢吉林通化气象局崔忠强大佬的投稿 鉴于近期很多气象部门同事询问meteva的配置问题,比如不会链接micaps分布式数据,不会链接天擎数据等等,这里就以一个会商常用图片的绘图, 来把meteva的配置、数据读取、可视化,全流程的走一遍,让大家更加熟悉meteva的使用。本文程序初衷是在国家局会商中看到上海局绘制的单站每个模式的降水预报mesh图(如图1)。所以自己复现了一张。
代码
代码语言:javascript复制#首先还是导入最基础的库包,利用meteva的数据读取模块,需要导入base
import meteva.base as meb
import numpy as np
import datetime
#首先导入一个配置文件。
meb.set_io_config(r"C:UsersadminOneDriveconfigmetevaconfig.ini")
#根据meteva文档,吉林省本省的config.ini的格式如下:
'''
[CIMISS]
DNS = xxx.xxx.xxx.xxx
USER_ID = xxxx
PASSWORD = xxxxx
[MICAPS]
GDS_IP = xxxxxxx
GDS_PORT = xxxxxx
[CMADaaS]
DNS = xxxxxx
PORT = xxxxx
USER_ID = ####
PASSWORD = ####
serviceNodeId = xxxxxxxxxx
'''
#目前气象部门业务常用的就是micaps和cmadaas(也就是天擎)。
#天擎的ip、端口、用户、密码可按照本省天擎配置。这个可以去本地天擎测试接口去查。
#micaps的话,可以去单位的业务电脑,右键桌面micaps图标,选择打开文件所在位置,找到MICAPS.exe.config这个文件,利用记事本打开,找到这一行:
#<add key="xxxxxx" value="xxxxx" /> (
#value对应的就是ip和端口了,每个省份都不一样。
#下面编写主函数
代码语言:javascript复制配置文件设置成功
代码语言:javascript复制#主函数members代表模式产品名称列表, 要和micaps数据目录对应。fhours对应预报时效列表,point对应需要查询站点的经纬度,point_name就是站点名
def draw(members=["ECMWF_HR","GERMAN_HR","GRAPES_GFS","GRAPES_3KM","NCEP_GFS","JAPAN_MR"],fhours=np.arange(12,172,12),point=[125.9,41.7],point_name='集安'):
data_sta=[]#初始化一下储存结果的数组
#我的习惯是上班以后查看前一天20时起报的预报,所以需要求出一个起报时间。
time_now = datetime.datetime.now() - datetime.timedelta(hours = 24)
time0 = datetime.datetime(time_now.year,time_now.month,time_now.day,20,0)
for member in members:#针对每个模式开始循环
data_sta_tmp=[]#存储该模式的结果列表
for fhour in fhours:#针对每一个预报时效循环
path = meb.get_path(r"%s/RAIN12/YYMMDDHH.TTT"%member,time0,fhour)#利用了meteva的get_path函数生成路径,读取某模式某时次的12小时降水数据
try:#由于micaps数据存储经常有漏,且每个模式的预报时效长度不一样,所以要做异常处理
grd = meb.read_griddata_from_gds(path)#利用上述路径读取格点数据
#grd插值到一个格点
sta_data = grd.interp(lon=point[0],lat=point[1])
data_sta_tmp.append(sta_data.values[0,0,0,0])
except:#如果数据有误,传输一个nan进去,保证每个数组的长度相同
data_sta_tmp.append(np.nan)
print(member,' ',fhour,' done')#输出进度
data_sta.append(data_sta_tmp)
#把data转换为numpy格式,以匹配meteva绘图函数
data_sta = np.array(data_sta)
times = []
for fhour in fhours:#生成横坐标标签数组
times.append((time0 datetime.timedelta(hours = int(fhour))).strftime('%d%H'))
name_list_dict2 = {"预报成员":members,
"预报时间":times}
meb.mesh(data_sta,name_list_dict=name_list_dict2,axis_x = "预报时间",
axis_y = "预报成员",annot = 1,cmap= "rain_24h" ,save_path="mesh_sta.png",title="各模式%s站点12小时降水量,起报时间:%s"%(point_name,str(time0)))#调用函数,保存图片
draw()
代码语言:javascript复制ECMWF_HR 12 done
ECMWF_HR 24 done
ECMWF_HR 36 done
ECMWF_HR 48 done
ECMWF_HR 60 done
ECMWF_HR 72 done
ECMWF_HR 84 done
ECMWF_HR 96 done
ECMWF_HR 108 done
ECMWF_HR 120 done
ECMWF_HR 132 done
ECMWF_HR 144 done
ECMWF_HR 156 done
ECMWF_HR 168 done
GERMAN_HR 12 done
GERMAN_HR 24 done
GERMAN_HR 36 done
GERMAN_HR 48 done
GERMAN_HR 60 done
GERMAN_HR 72 done
GERMAN_HR 84 done
GERMAN_HR 96 done
GERMAN_HR 108 done
GERMAN_HR 120 done
GERMAN_HR 132 done
GERMAN_HR 144 done
GERMAN_HR 156 done
GERMAN_HR 168 done
GRAPES_GFS 12 done
GRAPES_GFS 24 done
GRAPES_GFS 36 done
GRAPES_GFS 48 done
GRAPES_GFS 60 done
GRAPES_GFS 72 done
GRAPES_GFS 84 done
GRAPES_GFS 96 done
GRAPES_GFS 108 done
GRAPES_GFS 120 done
GRAPES_GFS 132 done
GRAPES_GFS 144 done
GRAPES_GFS 156 done
GRAPES_GFS 168 done
GRAPES_3KM 12 done
GRAPES_3KM 24 done
GRAPES_3KM 36 done
GRAPES_3KM 48 done
GRAPES_3KM 60 done
GRAPES_3KM 72 done
GRAPES_3KM/RAIN12/24081420.084数据读取错误
GRAPES_3KM 84 done
GRAPES_3KM/RAIN12/24081420.096数据读取错误
GRAPES_3KM 96 done
GRAPES_3KM/RAIN12/24081420.108数据读取错误
GRAPES_3KM 108 done
GRAPES_3KM/RAIN12/24081420.120数据读取错误
GRAPES_3KM 120 done
GRAPES_3KM/RAIN12/24081420.132数据读取错误
GRAPES_3KM 132 done
GRAPES_3KM/RAIN12/24081420.144数据读取错误
GRAPES_3KM 144 done
GRAPES_3KM/RAIN12/24081420.156数据读取错误
GRAPES_3KM 156 done
GRAPES_3KM/RAIN12/24081420.168数据读取错误
GRAPES_3KM 168 done
NCEP_GFS/RAIN12/24081420.012数据读取错误
NCEP_GFS 12 done
NCEP_GFS/RAIN12/24081420.024数据读取错误
NCEP_GFS 24 done
NCEP_GFS/RAIN12/24081420.036数据读取错误
NCEP_GFS 36 done
NCEP_GFS 48 done
NCEP_GFS 60 done
NCEP_GFS 72 done
NCEP_GFS 84 done
NCEP_GFS 96 done
NCEP_GFS 108 done
NCEP_GFS 120 done
NCEP_GFS 132 done
NCEP_GFS 144 done
NCEP_GFS 156 done
NCEP_GFS 168 done
JAPAN_MR 12 done
JAPAN_MR 24 done
JAPAN_MR 36 done
JAPAN_MR 48 done
JAPAN_MR 60 done
JAPAN_MR 72 done
JAPAN_MR 84 done
JAPAN_MR 96 done
JAPAN_MR 108 done
JAPAN_MR 120 done
JAPAN_MR 132 done
JAPAN_MR 144 done
JAPAN_MR 156 done
JAPAN_MR 168 done
检验结果已以图片形式保存至mesh_sta.png
代码语言:javascript复制