metradar 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metradar/__init__.py +7 -0
- metradar/cnrad_level2.py +1326 -0
- metradar/comm_func.py +135 -0
- metradar/construct_aws_refvpr_mainprog.py +515 -0
- metradar/construct_aws_refvpr_mainprog_cams.py +310 -0
- metradar/construct_aws_refvpr_mainprog_datan3d.py +386 -0
- metradar/construct_aws_refvpr_mainprog_swan.py +306 -0
- metradar/decode_fmt_pyart.py +200 -0
- metradar/decode_pup_rose.py +1993 -0
- metradar/draw_mosaic_new.py +421 -0
- metradar/draw_radar_aws_jilin_new.py +206 -0
- metradar/draw_radar_comp_func.py +1379 -0
- metradar/exceptions.py +50 -0
- metradar/geo_transforms_pyart.py +627 -0
- metradar/get_cross_section_from_pyart.py +354 -0
- metradar/get_tlogp_from_sharppy.py +93 -0
- metradar/grid.py +281 -0
- metradar/grid_data.py +64 -0
- metradar/main_pydda.py +653 -0
- metradar/make_gif.py +24 -0
- metradar/make_mosaic_mp_archive.py +538 -0
- metradar/mosaic_merge.py +64 -0
- metradar/mosaic_quickdraw.py +338 -0
- metradar/nowcast_by_pysteps.py +219 -0
- metradar/oa_couhua.py +166 -0
- metradar/oa_dig_func.py +955 -0
- metradar/parse_pal.py +148 -0
- metradar/pgmb_io.py +169 -0
- metradar/prepare_for_radar_draw.py +197 -0
- metradar/read_new_mosaic.py +33 -0
- metradar/read_new_mosaic_func.py +231 -0
- metradar/retrieve_cmadaas.py +3126 -0
- metradar/retrieve_micaps_server.py +2061 -0
- metradar/rose_structer.py +807 -0
- metradar/trans_nc_pgmb.py +62 -0
- metradar/trans_new_mosaic_nc.py +309 -0
- metradar/trans_polor2grid_func.py +203 -0
- metradar-0.1.0.dist-info/METADATA +12 -0
- metradar-0.1.0.dist-info/RECORD +41 -0
- metradar-0.1.0.dist-info/WHEEL +5 -0
- metradar-0.1.0.dist-info/top_level.txt +1 -0
metradar/main_pydda.py
ADDED
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
'''
|
|
5
|
+
多普勒雷达三维风场反演脚本
|
|
6
|
+
朱文剑
|
|
7
|
+
2021.4
|
|
8
|
+
'''
|
|
9
|
+
# %%
|
|
10
|
+
|
|
11
|
+
import pyart
|
|
12
|
+
import pydda
|
|
13
|
+
import os
|
|
14
|
+
import matplotlib.pyplot as plt
|
|
15
|
+
import matplotlib
|
|
16
|
+
from get_tlogp_from_sharppy import get_profile
|
|
17
|
+
import numpy as np
|
|
18
|
+
import configparser
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
import math
|
|
21
|
+
import argparse
|
|
22
|
+
import shutil
|
|
23
|
+
import sys
|
|
24
|
+
from decode_fmt_pyart import read_cnrad_fmt
|
|
25
|
+
# import warnings
|
|
26
|
+
# warnings.filterwarnings("ignore")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class GET_WIND_3D:
|
|
30
|
+
# sub function for reading config file
|
|
31
|
+
def ConfigFetchError(Exception):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
def _get_config_from_rcfile(self,rcfile):
|
|
35
|
+
"""
|
|
36
|
+
Get configure information from config_dk_met_io.ini file.
|
|
37
|
+
"""
|
|
38
|
+
# print(os.getcwd())
|
|
39
|
+
rc = rcfile
|
|
40
|
+
print(rc)
|
|
41
|
+
try:
|
|
42
|
+
config = configparser.ConfigParser()
|
|
43
|
+
config.read(rc,encoding='UTF-8')
|
|
44
|
+
except IOError as e:
|
|
45
|
+
raise self.ConfigFetchError(str(e))
|
|
46
|
+
except Exception as e:
|
|
47
|
+
raise self.ConfigFetchError(str(e))
|
|
48
|
+
|
|
49
|
+
return config
|
|
50
|
+
|
|
51
|
+
def myprint(self,message):
|
|
52
|
+
f = open('process_info.txt','at+',encoding='utf-8')
|
|
53
|
+
f.write(message)
|
|
54
|
+
f.write('\n')
|
|
55
|
+
f.close()
|
|
56
|
+
print(message)
|
|
57
|
+
|
|
58
|
+
def write_to_progress_cross(self,value):
|
|
59
|
+
f = open(self.picpath + os.sep + 'progress_cross.txt','wt')
|
|
60
|
+
f.write(str(value))
|
|
61
|
+
f.close()
|
|
62
|
+
print('current progress = %d'%value + "%")
|
|
63
|
+
|
|
64
|
+
def write_to_progress_main(self,value):
|
|
65
|
+
f = open('progress_main.txt','wt')
|
|
66
|
+
f.write(str(value))
|
|
67
|
+
f.close()
|
|
68
|
+
print('current progress = %d'%value + "%")
|
|
69
|
+
|
|
70
|
+
def rad(self,d):
|
|
71
|
+
return d * np.pi / 180.0
|
|
72
|
+
|
|
73
|
+
def getDistance(self,lat1, lng1, lat2, lng2):
|
|
74
|
+
# 计算两点间的距离,单位为千米
|
|
75
|
+
EARTH_REDIUS = 6378.137
|
|
76
|
+
radLat1 = self.rad(lat1)
|
|
77
|
+
radLat2 = self.rad(lat2)
|
|
78
|
+
a = radLat1 - radLat2
|
|
79
|
+
b = self.rad(lng1) - self.rad(lng2)
|
|
80
|
+
s = 2 * math.asin(math.sqrt(math.pow(math.sin(a/2), 2) + math.cos(radLat1) * math.cos(radLat2) * math.pow(math.sin(b/2), 2)))
|
|
81
|
+
s = s * EARTH_REDIUS
|
|
82
|
+
return s
|
|
83
|
+
|
|
84
|
+
def write_to_gisinfo(self,):
|
|
85
|
+
try:
|
|
86
|
+
fout = open(self.picpath + os.sep + 'gisinfo.txt','wt',encoding='utf-8')
|
|
87
|
+
fout.write('minLat=%.3f\n'%self.lat_min[0])
|
|
88
|
+
fout.write('maxLat=%.3f\n'%self.lat_max[0])
|
|
89
|
+
fout.write('minLon=%.3f\n'%self.lon_min[0])
|
|
90
|
+
fout.write('maxLon=%.3f\n'%self.lon_max[0])
|
|
91
|
+
self.myprint('minLat=%.3f'%self.lat_min[0])
|
|
92
|
+
self.myprint('maxLat=%.3f'%self.lat_max[0])
|
|
93
|
+
self.myprint('minLon=%.3f'%self.lon_min[0])
|
|
94
|
+
self.myprint('maxLon=%.3f'%self.lon_max[0])
|
|
95
|
+
fout.close()
|
|
96
|
+
return True
|
|
97
|
+
except:
|
|
98
|
+
self.myprint(self.picpath + os.sep + 'gisinfo.txt' + ' open error!')
|
|
99
|
+
return False
|
|
100
|
+
|
|
101
|
+
def __init__(self,inifile='config.ini'):
|
|
102
|
+
pass
|
|
103
|
+
self.error=False
|
|
104
|
+
if os.path.exists('process_info.txt'):
|
|
105
|
+
os.remove('process_info.txt')
|
|
106
|
+
|
|
107
|
+
if not os.path.exists(inifile):
|
|
108
|
+
self.myprint(inifile + ' 不存在,请检查')
|
|
109
|
+
config = self._get_config_from_rcfile(inifile)
|
|
110
|
+
self.xlims = np.array(config['PARAM_SETTINGS']['XLIM'].split(', ')).astype(np.int64)
|
|
111
|
+
self.ylims = np.array(config['PARAM_SETTINGS']['YLIM'].split(', ')).astype(np.int64)
|
|
112
|
+
self.zlims = np.array(config['PARAM_SETTINGS']['ZLIM'].split(', ')).astype(int)
|
|
113
|
+
self.time_files = config['PARAM_SETTINGS']['TIME_FILES']
|
|
114
|
+
if len(self.time_files) !=14:
|
|
115
|
+
self.myprint('时间参数设置错误,请重新设置 TIME_FILES 参数')
|
|
116
|
+
self.error=True
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
self.standard_lat = float(config['PARAM_SETTINGS']['CENTER_LAT'])
|
|
120
|
+
self.standard_lon = float(config['PARAM_SETTINGS']['CENTER_LON'])
|
|
121
|
+
|
|
122
|
+
self.ana_lat = float(config['PARAM_SETTINGS']['ANA_LAT'])
|
|
123
|
+
self.ana_lon = float(config['PARAM_SETTINGS']['ANA_LON'])
|
|
124
|
+
# bshowpic = int(config['PARAM_SETTINGS']['SHOW_PIC'])
|
|
125
|
+
self.bsavepic = int(config['PARAM_SETTINGS']['SAVE_PIC'])
|
|
126
|
+
if self.bsavepic == False:
|
|
127
|
+
self.myprint('参数设置中设定不保存图片!')
|
|
128
|
+
|
|
129
|
+
self.bshowpic = False
|
|
130
|
+
if not self.bshowpic:
|
|
131
|
+
matplotlib.use('Agg')
|
|
132
|
+
else:
|
|
133
|
+
matplotlib.use('MacOSX')
|
|
134
|
+
|
|
135
|
+
self.radars = config['PARAM_SETTINGS']['RADAR_SITES'].split(', ')
|
|
136
|
+
self.radarfilepath = config['PATH_SETTINGS']['RADAR_FILE_PATH']
|
|
137
|
+
self.outpath = config['PATH_SETTINGS']['OUT_PATH']
|
|
138
|
+
self.picpath = config['PATH_SETTINGS']['PIC_PATH']
|
|
139
|
+
self.tlogp_filepath = config['PATH_SETTINGS']['TLOG_PATH']
|
|
140
|
+
self.tlogp_filename = config['PATH_SETTINGS']['TLOG_FILE']
|
|
141
|
+
|
|
142
|
+
if not os.path.exists(self.outpath):
|
|
143
|
+
os.makedirs(self.outpath)
|
|
144
|
+
|
|
145
|
+
if not os.path.exists(self.picpath):
|
|
146
|
+
os.makedirs(self.picpath)
|
|
147
|
+
|
|
148
|
+
self.xreso = int(config['PARAM_SETTINGS']['XRESO'])
|
|
149
|
+
self.yreso = int(config['PARAM_SETTINGS']['YRESO'])
|
|
150
|
+
self.zreso = int(config['PARAM_SETTINGS']['ZRESO'])
|
|
151
|
+
|
|
152
|
+
self.lon_min,self.lat_min=pyart.core.cartesian_to_geographic_aeqd(self.xlims[0]*1000,self.ylims[0]*1000,self.standard_lon,self.standard_lat)
|
|
153
|
+
self.lon_max,self.lat_max=pyart.core.cartesian_to_geographic_aeqd(self.xlims[1]*1000,self.ylims[1]*1000,self.standard_lon,self.standard_lat)
|
|
154
|
+
|
|
155
|
+
if not self.write_to_gisinfo():
|
|
156
|
+
self.write_to_progress_main(100)
|
|
157
|
+
self.error=True
|
|
158
|
+
self.myprint('write_to_gisinfo error!')
|
|
159
|
+
return None
|
|
160
|
+
|
|
161
|
+
self.g_xlim = (self.xlims[0]*1000,self.xlims[1]*1000)
|
|
162
|
+
self.g_ylim = (self.ylims[0]*1000,self.ylims[1]*1000)
|
|
163
|
+
self.g_zlim = (self.zlims[0]*1000,self.zlims[1]*1000)
|
|
164
|
+
self.g_numx = int(len(range(self.xlims[0],self.xlims[1]))*1000/self.xreso+1) # x方向格点数
|
|
165
|
+
self.g_numy = int(len(range(self.ylims[0],self.ylims[1]))*1000/self.yreso+1) # y方向格点数
|
|
166
|
+
self.g_numz = int(len(range(self.zlims[0],self.zlims[1]))*1000/self.zreso+1) # z方向格点数
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def draw_all_pic(self,bdrawhori=True,):
|
|
171
|
+
resultnames = []
|
|
172
|
+
files = os.listdir(self.outpath)
|
|
173
|
+
valid_files = []
|
|
174
|
+
|
|
175
|
+
self.write_to_progress_cross(0)
|
|
176
|
+
for ff in files:
|
|
177
|
+
if ff.find('.nc')<=0:
|
|
178
|
+
continue
|
|
179
|
+
else:
|
|
180
|
+
valid_files.append(ff)
|
|
181
|
+
|
|
182
|
+
if len(valid_files) == 0:
|
|
183
|
+
self.myprint('未找到nc格式的三维风场数据文件,请先调用--getwind方法')
|
|
184
|
+
return False
|
|
185
|
+
|
|
186
|
+
for ff in valid_files:
|
|
187
|
+
resultnames.append(self.outpath + os.sep + ff)
|
|
188
|
+
self.myprint(ff)
|
|
189
|
+
|
|
190
|
+
# ana_lat = 32.787
|
|
191
|
+
# ana_lon = 119.376
|
|
192
|
+
s_x = self.getDistance(self.ana_lat,self.ana_lon,self.ana_lat,self.standard_lon)
|
|
193
|
+
s_y = self.getDistance(self.ana_lat,self.ana_lon,self.standard_lat,self.ana_lon)
|
|
194
|
+
self.myprint('拼图中心经度为:%.3f'%self.standard_lon)
|
|
195
|
+
self.myprint('拼图中心纬度为:%.3f'%self.standard_lat)
|
|
196
|
+
self.myprint('垂直剖面经度为:%.3f'%self.ana_lon)
|
|
197
|
+
self.myprint('垂直剖面纬度为:%.3f'%self.ana_lat)
|
|
198
|
+
self.myprint('X方向偏移量为:%d'%s_x)
|
|
199
|
+
self.myprint('Y方向偏移量为:%d'%s_y)
|
|
200
|
+
|
|
201
|
+
# lev_xz = 55
|
|
202
|
+
# lev_yz = 51
|
|
203
|
+
lev_yz = int((self.xlims[0] - s_x)/(self.xreso/1e3))
|
|
204
|
+
lev_xz = int((s_y- self.ylims[0])/(self.yreso/1e3))
|
|
205
|
+
self.myprint('X方向层次为:%d'%lev_xz)
|
|
206
|
+
self.myprint('Y方向层次为:%d'%lev_yz)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
Grids = [pyart.io.read_grid(resultname) for resultname in resultnames]
|
|
210
|
+
|
|
211
|
+
x=Grids[0].x['data']
|
|
212
|
+
y=Grids[0].y['data']
|
|
213
|
+
z=Grids[0].z['data']
|
|
214
|
+
|
|
215
|
+
uwind=Grids[0].fields['u']['data']
|
|
216
|
+
vwind=Grids[0].fields['v']['data']
|
|
217
|
+
wwind=Grids[0].fields['w']['data']
|
|
218
|
+
|
|
219
|
+
# vor_stretch = Grids[0].fields['vor_stretch']['data']
|
|
220
|
+
# vor_tilt = Grids[0].fields['vor_tilt']['data']
|
|
221
|
+
|
|
222
|
+
picpath_horiz_bar = self.picpath + os.sep + '水平风场'
|
|
223
|
+
picpath_horiz_stream = self.picpath + os.sep + '水平流场'
|
|
224
|
+
picpath_xz_bar = self.picpath + os.sep + 'XZ方向垂直风场'
|
|
225
|
+
picpath_xz_stream = self.picpath + os.sep + 'XZ方向垂直流场'
|
|
226
|
+
picpath_yz_bar = self.picpath + os.sep + 'YZ方向垂直风场'
|
|
227
|
+
picpath_yz_stream = self.picpath + os.sep + 'YZ方向垂直流场'
|
|
228
|
+
|
|
229
|
+
picpath_vor_stretch = self.picpath + os.sep + '拉伸涡度'
|
|
230
|
+
picpath_vor_tilt = self.picpath + os.sep + '倾斜涡度'
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
if not os.path.exists(picpath_horiz_bar):
|
|
235
|
+
os.makedirs(picpath_horiz_bar)
|
|
236
|
+
if not os.path.exists(picpath_horiz_stream):
|
|
237
|
+
os.makedirs(picpath_horiz_stream)
|
|
238
|
+
if not os.path.exists(picpath_xz_bar):
|
|
239
|
+
os.makedirs(picpath_xz_bar)
|
|
240
|
+
if not os.path.exists(picpath_xz_stream):
|
|
241
|
+
os.makedirs(picpath_xz_stream)
|
|
242
|
+
if not os.path.exists(picpath_yz_bar):
|
|
243
|
+
os.makedirs(picpath_yz_bar)
|
|
244
|
+
if not os.path.exists(picpath_yz_stream):
|
|
245
|
+
os.makedirs(picpath_yz_stream)
|
|
246
|
+
if not os.path.exists(picpath_vor_stretch):
|
|
247
|
+
os.makedirs(picpath_vor_stretch)
|
|
248
|
+
if not os.path.exists(picpath_vor_tilt):
|
|
249
|
+
os.makedirs(picpath_vor_tilt)
|
|
250
|
+
|
|
251
|
+
if bdrawhori:
|
|
252
|
+
# draw barbs
|
|
253
|
+
for ll in range(10): # self.g_numz
|
|
254
|
+
fig, ax = plt.subplots(figsize=(8, 6))
|
|
255
|
+
pydda.vis.plot_horiz_xsection_barbs(Grids, ax, 'reflectivity', level=ll,
|
|
256
|
+
# w_vel_contours=[3, 5,],
|
|
257
|
+
cmap='pyart_NWSRef', vmin=0, vmax=70,
|
|
258
|
+
barb_spacing_x_km=5,
|
|
259
|
+
barb_spacing_y_km=5,
|
|
260
|
+
show_lobes=False)
|
|
261
|
+
ax.set_xlim(self.xlims.tolist())
|
|
262
|
+
ax.set_ylim(self.ylims.tolist())
|
|
263
|
+
ax.set_title(ax.get_title().replace('PyDDA','MultiRadar'))
|
|
264
|
+
picfilename = 'horiz_xsection_barbs_%02d_%s.png'%(ll+1,self.time_files)
|
|
265
|
+
if self.bsavepic:
|
|
266
|
+
fig.savefig(picpath_horiz_bar + os.sep + picfilename,
|
|
267
|
+
format='png', transparent=False, dpi=300, pad_inches = 0)
|
|
268
|
+
self.myprint(picpath_horiz_bar + os.sep + picfilename + ' saved!')
|
|
269
|
+
plt.close(fig)
|
|
270
|
+
|
|
271
|
+
# draw streamline
|
|
272
|
+
for ll in range(10): # self.g_numz
|
|
273
|
+
|
|
274
|
+
fig, ax = plt.subplots(figsize=(8, 6))
|
|
275
|
+
pydda.vis.plot_horiz_xsection_streamlines(Grids, ax, 'reflectivity', level=ll,
|
|
276
|
+
cmap='pyart_NWSRef', vmin=0, vmax=70,
|
|
277
|
+
# w_vel_contours=[3, 5,],
|
|
278
|
+
show_lobes=False,
|
|
279
|
+
)
|
|
280
|
+
ax.set_xlim(self.xlims.tolist())
|
|
281
|
+
ax.set_ylim(self.ylims.tolist())
|
|
282
|
+
ax.set_title(ax.get_title().replace('PyDDA','MultiRadar'))
|
|
283
|
+
picfilename = 'horiz_xsection_streamlines_%02d_%s.png'%(ll+1,self.time_files)
|
|
284
|
+
if self.bsavepic:
|
|
285
|
+
fig.savefig(picpath_horiz_stream + os.sep + picfilename,
|
|
286
|
+
format='png', transparent=False, dpi=300, pad_inches = 0)
|
|
287
|
+
self.myprint(picpath_horiz_stream + os.sep + picfilename + ' saved!')
|
|
288
|
+
|
|
289
|
+
plt.close(fig)
|
|
290
|
+
|
|
291
|
+
# # draw stretch vortex pic
|
|
292
|
+
# for ll in range(self.g_numz):
|
|
293
|
+
|
|
294
|
+
# fig, axes = plt.subplots(figsize=(8, 6))
|
|
295
|
+
|
|
296
|
+
# # DPI = fig.get_dpi()
|
|
297
|
+
# # fig.set_size_inches(1200.0/float(DPI),900.0/float(DPI))
|
|
298
|
+
# plt.tight_layout(pad=0, h_pad=0, w_pad=0, rect=(0.035,0.01,0.91,0.9))
|
|
299
|
+
# ax = plt.axes()
|
|
300
|
+
# #ax.set_extent([-5000, 5000, -2500, 7500])
|
|
301
|
+
# levels=np.arange(-10,12, 2)
|
|
302
|
+
# colors = [(1, 0, 1),(0.23,0.58,0.96),(1, 1, 1),(1,0.75,0.24),(1,0,0)]
|
|
303
|
+
# cm = LinearSegmentedColormap.from_list("wbyr", colors, N=100)
|
|
304
|
+
# cset1=ax.contourf(x, y,vor_stretch[ll,:,:],cmap=cm,levels=levels, extend='both', origin='image')
|
|
305
|
+
# ax1 = fig.add_axes([0.912, 0.3, 0.03, 0.55])
|
|
306
|
+
# cbar=fig.colorbar(cset1,cax=ax1,orientation='vertical',ticks=levels)
|
|
307
|
+
|
|
308
|
+
# ax.barbs(x[::3],y[::3],uwind[ll,::3,::3], vwind[ll,::3,::3],flagcolor=(0.1,0.2,0.1,0),length=4.5,linewidth=0.6,
|
|
309
|
+
# barb_increments=dict(half=2, full=4, flag=20),sizes=dict(emptybarb=0.0), barbcolor=['k'],rounding=True,flip_barb=False)
|
|
310
|
+
|
|
311
|
+
# picfilename = 'vor_stretch_%02d_%s.png'%(ll+1,self.time_files)
|
|
312
|
+
# if self.bsavepic:
|
|
313
|
+
# fig.savefig(picpath_vor_stretch + os.sep + picfilename,
|
|
314
|
+
# format='png', transparent=False, dpi=300, pad_inches = 0)
|
|
315
|
+
# self.myprint(picpath_vor_stretch + os.sep + picfilename + ' saved!')
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
# plt.close(fig)
|
|
319
|
+
|
|
320
|
+
# # draw tilt vortex pic
|
|
321
|
+
# for ll in range(self.g_numz):
|
|
322
|
+
|
|
323
|
+
# fig, axes = plt.subplots(figsize=(8, 6))
|
|
324
|
+
|
|
325
|
+
# # DPI = fig.get_dpi()
|
|
326
|
+
# # fig.set_size_inches(1200.0/float(DPI),900.0/float(DPI))
|
|
327
|
+
# plt.tight_layout(pad=0, h_pad=0, w_pad=0, rect=(0.035,0.01,0.91,0.9))
|
|
328
|
+
# ax = plt.axes()
|
|
329
|
+
# #ax.set_extent([-5000, 5000, -2500, 7500])
|
|
330
|
+
# levels=np.arange(-10,12, 2)
|
|
331
|
+
# colors = [(1, 0, 1),(0.23,0.58,0.96),(1, 1, 1),(1,0.75,0.24),(1,0,0)]
|
|
332
|
+
# cm = LinearSegmentedColormap.from_list("wbyr", colors, N=100)
|
|
333
|
+
# cset1=ax.contourf(x, y,vor_tilt[ll,:,:],cmap=cm,levels=levels, extend='both', origin='image')
|
|
334
|
+
# ax1 = fig.add_axes([0.912, 0.3, 0.03, 0.55])
|
|
335
|
+
# cbar=fig.colorbar(cset1,cax=ax1,orientation='vertical',ticks=levels)
|
|
336
|
+
|
|
337
|
+
# ax.barbs(x[::3],y[::3],uwind[ll,::3,::3], vwind[ll,::3,::3],flagcolor=(0.1,0.2,0.1,0),length=4.5,linewidth=0.6,
|
|
338
|
+
# barb_increments=dict(half=2, full=4, flag=20),sizes=dict(emptybarb=0.0), barbcolor=['k'],rounding=True,flip_barb=False)
|
|
339
|
+
|
|
340
|
+
# picfilename = 'vor_tilt_%02d_%s.png'%(ll+1,self.time_files)
|
|
341
|
+
# if self.bsavepic:
|
|
342
|
+
# fig.savefig(picpath_vor_tilt + os.sep + picfilename,
|
|
343
|
+
# format='png', transparent=False, dpi=300, pad_inches = 0)
|
|
344
|
+
# self.myprint(picpath_vor_tilt + os.sep + picfilename + ' saved!')
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
# plt.close(fig)
|
|
348
|
+
|
|
349
|
+
try:
|
|
350
|
+
#=================
|
|
351
|
+
fig, ax = plt.subplots(figsize=(8, 4))
|
|
352
|
+
pydda.vis.plot_xz_xsection_barbs(Grids, ax, 'reflectivity', level=lev_xz,
|
|
353
|
+
# w_vel_contours=[3, 5,],
|
|
354
|
+
cmap='pyart_NWSRef', vmin=0, vmax=70,
|
|
355
|
+
barb_spacing_x_km=2.0,
|
|
356
|
+
barb_spacing_z_km=1.0)
|
|
357
|
+
ax.set_xlim(self.xlims.tolist())
|
|
358
|
+
ax.set_title(ax.get_title().replace('PyDDA','MultiRadar'))
|
|
359
|
+
picfilename = 'xz_xsection_barbs_%06d_%06d_%s.png'%(self.ana_lat*1000,self.ana_lon*1000,self.time_files)
|
|
360
|
+
|
|
361
|
+
if self.bsavepic:
|
|
362
|
+
fig.savefig(picpath_xz_bar + os.sep + picfilename,
|
|
363
|
+
format='png', transparent=False, dpi=300, pad_inches = 0)
|
|
364
|
+
self.myprint(picpath_xz_bar + os.sep + picfilename + ' saved!')
|
|
365
|
+
plt.close(fig)
|
|
366
|
+
self.write_to_progress_cross(25)
|
|
367
|
+
except:
|
|
368
|
+
self.myprint('可能是垂直剖面的经纬度超出范围了,请重新设置再尝试!')
|
|
369
|
+
#=================
|
|
370
|
+
try:
|
|
371
|
+
fig, ax = plt.subplots(figsize=(8, 4))
|
|
372
|
+
pydda.vis.plot_xz_xsection_streamlines(Grids, None, 'reflectivity', level=lev_xz,
|
|
373
|
+
cmap='pyart_NWSRef', vmin=0, vmax=70,
|
|
374
|
+
# w_vel_contours=[3, 5,],
|
|
375
|
+
)
|
|
376
|
+
ax.set_xlim(self.xlims.tolist())
|
|
377
|
+
ax.set_title(ax.get_title().replace('PyDDA','MultiRadar'))
|
|
378
|
+
picfilename = 'xz_xsection_streamlines_%06d_%06d_%s.png'%(self.ana_lat*1000,self.ana_lon*1000,self.time_files)
|
|
379
|
+
if self.bsavepic:
|
|
380
|
+
fig.savefig(picpath_xz_stream + os.sep + picfilename,
|
|
381
|
+
format='png', transparent=False, dpi=300, pad_inches = 0)
|
|
382
|
+
self.myprint(picpath_xz_stream + os.sep + picfilename + ' saved!')
|
|
383
|
+
plt.close(fig)
|
|
384
|
+
self.write_to_progress_cross(50)
|
|
385
|
+
except:
|
|
386
|
+
self.myprint('可能是垂直剖面的经纬度超出范围了,请重新设置再尝试!')
|
|
387
|
+
#=================
|
|
388
|
+
try:
|
|
389
|
+
fig, ax = plt.subplots(figsize=(8, 4))
|
|
390
|
+
pydda.vis.plot_yz_xsection_barbs(Grids, None, 'reflectivity', level=lev_yz,
|
|
391
|
+
# w_vel_contours=[ 3, 5, ],
|
|
392
|
+
cmap='pyart_NWSRef', vmin=0, vmax=70,
|
|
393
|
+
barb_spacing_y_km=2,
|
|
394
|
+
barb_spacing_z_km=1)
|
|
395
|
+
ax.set_xlim(self.ylims.tolist())
|
|
396
|
+
ax.set_title(ax.get_title().replace('PyDDA','MultiRadar'))
|
|
397
|
+
picfilename = 'yz_xsection_barbs_%06d_%06d_%s.png'%(self.ana_lat*1000,self.ana_lon*1000,self.time_files)
|
|
398
|
+
if self.bsavepic:
|
|
399
|
+
fig.savefig(picpath_yz_bar + os.sep + picfilename,
|
|
400
|
+
format='png', transparent=False, dpi=300, pad_inches = 0)
|
|
401
|
+
self.myprint(picpath_yz_bar + os.sep + picfilename + ' saved!')
|
|
402
|
+
plt.close(fig)
|
|
403
|
+
self.write_to_progress_cross(75)
|
|
404
|
+
except:
|
|
405
|
+
self.myprint('可能是垂直剖面的经纬度超出范围了,请重新设置再尝试!')
|
|
406
|
+
#=================
|
|
407
|
+
try:
|
|
408
|
+
fig, ax = plt.subplots(figsize=(8, 4))
|
|
409
|
+
pydda.vis.plot_yz_xsection_streamlines(Grids, None, 'reflectivity', level=lev_yz,
|
|
410
|
+
cmap='pyart_NWSRef', vmin=0, vmax=70,
|
|
411
|
+
# w_vel_contours=[3, 5, ],
|
|
412
|
+
)
|
|
413
|
+
ax.set_xlim(self.ylims.tolist())
|
|
414
|
+
ax.set_title(ax.get_title().replace('PyDDA','MultiRadar'))
|
|
415
|
+
picfilename = 'yz_xsection_streamlines_%06d_%06d_%s.png'%(self.ana_lat*1000,self.ana_lon*1000,self.time_files)
|
|
416
|
+
if self.bsavepic:
|
|
417
|
+
fig.savefig(picpath_yz_stream + os.sep + picfilename,
|
|
418
|
+
format='png', transparent=False, dpi=300, pad_inches = 0)
|
|
419
|
+
self.myprint(picpath_yz_stream + os.sep + picfilename + ' saved!')
|
|
420
|
+
plt.close(fig)
|
|
421
|
+
self.write_to_progress_cross(100)
|
|
422
|
+
except:
|
|
423
|
+
self.myprint('可能是垂直剖面的经纬度超出范围了,请重新设置再尝试!')
|
|
424
|
+
return True
|
|
425
|
+
|
|
426
|
+
def do_wind_retrievel(self):
|
|
427
|
+
|
|
428
|
+
self.write_to_progress_main(0)
|
|
429
|
+
|
|
430
|
+
filepaths = []
|
|
431
|
+
filenames = []
|
|
432
|
+
# print('kevin')
|
|
433
|
+
# import pdb; pdb.set_trace()
|
|
434
|
+
for rd in self.radars:
|
|
435
|
+
curpath = self.radarfilepath + os.sep + rd
|
|
436
|
+
filepaths.append(curpath)
|
|
437
|
+
files = os.listdir(curpath)
|
|
438
|
+
files = sorted(files)
|
|
439
|
+
|
|
440
|
+
files = [ff for ff in files if ff.find('Z_RADR')>=0]
|
|
441
|
+
times = [datetime.strptime(ff[15:29], '%Y%m%d%H%M%S').timestamp() for ff in files]
|
|
442
|
+
|
|
443
|
+
# files = [ff for ff in files if ff.find('ar2v')>=0]
|
|
444
|
+
# times = [datetime.strptime(ff[5:13]+ff[14:20], '%Y%m%d%H%M%S').timestamp() for ff in files]
|
|
445
|
+
|
|
446
|
+
if len(times) == 0:
|
|
447
|
+
self.myprint('未找到 %s 雷达站的有效数据文件,请检查!'%rd)
|
|
448
|
+
self.write_to_progress_main(100)
|
|
449
|
+
return False
|
|
450
|
+
|
|
451
|
+
ct = datetime.strptime(self.time_files, '%Y%m%d%H%M%S').timestamp()
|
|
452
|
+
cidx = np.where(abs(np.array(times) - ct)==min(abs(np.array(times)-ct)))[0][0]
|
|
453
|
+
if min(abs(np.array(times)-ct)) > 180:
|
|
454
|
+
self.myprint('查找到 %s 雷达的资料中离规定时间最近的文件的观测时间与规定时间的差超过了180秒,请知悉!'%rd)
|
|
455
|
+
self.myprint('找到的 %s 雷达的资料中与规定时间最接近的文件名为 %s '%(rd,files[cidx]))
|
|
456
|
+
filenames.append(files[cidx])
|
|
457
|
+
|
|
458
|
+
self.write_to_progress_main(5)
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
# filename1 = 'HAJS.20200612.053920.ar2v'
|
|
462
|
+
# filename2 = 'NJJS.20200612.054229.ar2v'
|
|
463
|
+
# filename3 = 'TZJS.20200612.054032.ar2v'
|
|
464
|
+
radar_objs=[]
|
|
465
|
+
grid_objs=[]
|
|
466
|
+
self.outname_grid=[]
|
|
467
|
+
self.valid_radars=len(filenames)
|
|
468
|
+
for nn in range(self.valid_radars):
|
|
469
|
+
outname = filenames[nn].split('.')
|
|
470
|
+
self.outname_grid.append(filenames[nn].replace(outname[-1],'grid.nc'))
|
|
471
|
+
|
|
472
|
+
for nn in range(self.valid_radars):
|
|
473
|
+
pass
|
|
474
|
+
|
|
475
|
+
# radar_objs.append(pyart.io.read_nexrad_archive(filepaths[nn] + os.sep + filenames[nn]))
|
|
476
|
+
radar_objs.append(read_cnrad_fmt(filepaths[nn] + os.sep + filenames[nn]))
|
|
477
|
+
|
|
478
|
+
self.myprint('read %s over!'%filenames[nn])
|
|
479
|
+
|
|
480
|
+
grid_objs.append(pyart.map.grid_from_radars(
|
|
481
|
+
(radar_objs[nn],),
|
|
482
|
+
grid_origin=[self.standard_lat,self.standard_lon],
|
|
483
|
+
weighting_function = 'BARNES2',
|
|
484
|
+
grid_shape=(self.g_numz, self.g_numy, self.g_numx),
|
|
485
|
+
grid_limits=(self.g_zlim, self.g_ylim, self.g_xlim),
|
|
486
|
+
fields=['reflectivity','velocity']))
|
|
487
|
+
self.myprint('grid over!')
|
|
488
|
+
|
|
489
|
+
# radar1 = pyart.io.read_nexrad_archive(filepath1 + os.sep + filename1)
|
|
490
|
+
# print('read %s over!'%filename1)
|
|
491
|
+
self.write_to_progress_main(20)
|
|
492
|
+
|
|
493
|
+
# step 2=============风场反演
|
|
494
|
+
|
|
495
|
+
# 添加探空数据
|
|
496
|
+
if not os.path.exists(self.tlogp_filepath + os.sep + self.tlogp_filename):
|
|
497
|
+
self.myprint(self.tlogp_filepath + os.sep + self.tlogp_filename + ' not exists! please check!')
|
|
498
|
+
self.write_to_progress_main(100)
|
|
499
|
+
return False
|
|
500
|
+
|
|
501
|
+
profile = get_profile(self.tlogp_filepath,self.tlogp_filename)
|
|
502
|
+
u_init, v_init, w_init = pydda.initialization.make_wind_field_from_profile(
|
|
503
|
+
grid_objs[0], profile, vel_field='velocity')
|
|
504
|
+
# u_init, v_init, w_init = None,None,None
|
|
505
|
+
self.myprint('探空数据 %s 加载完毕!'%self.tlogp_filename)
|
|
506
|
+
# 速度退模糊暂时空缺,后期补上
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
#进行多雷达三维风场反演
|
|
510
|
+
# try:
|
|
511
|
+
Grids = pydda.retrieval.get_dd_wind_field(grid_objs, u_init,
|
|
512
|
+
v_init, w_init, Co=100.0, Cm=1500.0,
|
|
513
|
+
Cz=0, vel_name='velocity', refl_field='reflectivity',
|
|
514
|
+
frz=5000.0,max_iterations=120,
|
|
515
|
+
mask_outside_opt=True,upper_bc=1,)# print=self.myprint
|
|
516
|
+
# except:
|
|
517
|
+
# self.myprint('get_dd_wind_field error!')
|
|
518
|
+
# self.write_to_progress_main(100)
|
|
519
|
+
# return False
|
|
520
|
+
|
|
521
|
+
for nn in range(self.valid_radars):
|
|
522
|
+
Grids[nn].fields['reflectivity']['data'][Grids[nn].fields['reflectivity']['data']<10] = np.ma.masked
|
|
523
|
+
pyart.io.write_grid(self.outpath + os.sep + self.outname_grid[nn], Grids[nn])
|
|
524
|
+
|
|
525
|
+
# exclude masked gates from the gridding
|
|
526
|
+
# gatefilter = pyart.filters.GateFilter(Grids)
|
|
527
|
+
# gatefilter.exclude_masked('reflectivity')
|
|
528
|
+
|
|
529
|
+
self.myprint('write data to nc over!')
|
|
530
|
+
self.write_to_progress_main(80)
|
|
531
|
+
# print('All levels = %d'%g_numz)
|
|
532
|
+
|
|
533
|
+
# 计算拉伸涡度和倾斜涡度
|
|
534
|
+
# self.calc_vortex(Grids)
|
|
535
|
+
|
|
536
|
+
# self.draw_all_pic()
|
|
537
|
+
|
|
538
|
+
self.write_to_progress_main(100)
|
|
539
|
+
# if bshowpic:
|
|
540
|
+
# plt.show()
|
|
541
|
+
|
|
542
|
+
if os.path.exists('process_info.txt'):
|
|
543
|
+
shutil.copyfile('process_info.txt',self.picpath + os.sep + 'process_info.txt')
|
|
544
|
+
|
|
545
|
+
#计算拉伸涡度和倾斜涡度
|
|
546
|
+
def calc_vortex(self,Grids):
|
|
547
|
+
self.myprint('starting calc_vortex......')
|
|
548
|
+
files = os.listdir(self.outpath)
|
|
549
|
+
if len(files)==0:
|
|
550
|
+
self.myprint('no files in output path!')
|
|
551
|
+
return False
|
|
552
|
+
filename = files[0]
|
|
553
|
+
|
|
554
|
+
# Grids = pyart.io.read_grid(self.outpath + os.sep + filename)
|
|
555
|
+
# dataset = nc.Dataset(self.outpath + os.sep + filename)
|
|
556
|
+
|
|
557
|
+
uwind=Grids[0].fields['u']['data']
|
|
558
|
+
vwind=Grids[0].fields['v']['data']
|
|
559
|
+
wwind=Grids[0].fields['w']['data']
|
|
560
|
+
|
|
561
|
+
dudz,dudy,dudx = np.gradient(uwind)
|
|
562
|
+
dvdz,dvdy,dvdx = np.gradient(vwind)
|
|
563
|
+
dwdz,dwdy,dwdx = np.gradient(wwind)
|
|
564
|
+
|
|
565
|
+
vor_stretch_data = np.zeros(uwind.shape,dtype=float)
|
|
566
|
+
vor_tilt_data = np.zeros(uwind.shape,dtype=float)
|
|
567
|
+
for lev in range(uwind.shape[0]):
|
|
568
|
+
# picname="stretch_%03d.png"%lev
|
|
569
|
+
# print(lev)
|
|
570
|
+
|
|
571
|
+
div=dudx[lev,:,:] + dvdy[lev,:,:]
|
|
572
|
+
vor=dvdx[lev,:,:] - dudy[lev,:,:]
|
|
573
|
+
|
|
574
|
+
u=uwind[lev,:,:]
|
|
575
|
+
v=vwind[lev,:,:]
|
|
576
|
+
#dw
|
|
577
|
+
|
|
578
|
+
#拉伸项
|
|
579
|
+
vor_stretch_data[lev,:,:]=vor*div
|
|
580
|
+
|
|
581
|
+
#倾斜项
|
|
582
|
+
vor_tilt_data[lev,:,:]=dwdy[lev,:,:]*dudz[lev,:,:]-dwdx[lev,:,:]*dvdz[lev,:,:]
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
vor_stretch = {'data':vor_stretch_data,'_FillValue':-9999.0,'long_name':'stretch vortex','units':'m-2/s-2','coordinates':'z,y,x'}
|
|
586
|
+
vor_tilt = {'data':vor_tilt_data,'_FillValue':-9999.0,'long_name':'tilting vortex','units':'m-2/s-2','coordinates':'z,y,x'}
|
|
587
|
+
|
|
588
|
+
for nn in range(len(Grids)):
|
|
589
|
+
Grids[nn].add_field('vor_stretch',vor_stretch,replace_existing=True)
|
|
590
|
+
|
|
591
|
+
Grids[nn].add_field('vor_tilt',vor_tilt,replace_existing=True)
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
pyart.io.write_grid(self.outpath + os.sep + self.outname_grid[nn], Grids[nn])
|
|
595
|
+
self.myprint(self.outname_grid[nn] + ' updated with vor_stretch and vor_tilt!')
|
|
596
|
+
kkk=0
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
if __name__ == "__main__":
|
|
600
|
+
'''
|
|
601
|
+
有两个函数可以调用:
|
|
602
|
+
python main_pydda.py config_3dwind.ini --getwind
|
|
603
|
+
python main_pydda.py config_3dwind.ini --drawcross
|
|
604
|
+
其中第一个用来计算并绘图,第二个用来单独绘制任意点的垂直剖面
|
|
605
|
+
'''
|
|
606
|
+
with open('current_pid.txt','wt') as f:
|
|
607
|
+
f.write('%s'%str(os.getpid()))
|
|
608
|
+
def mainprog(inifile):
|
|
609
|
+
|
|
610
|
+
_getwind = GET_WIND_3D(inifile)
|
|
611
|
+
if not _getwind.error:
|
|
612
|
+
_getwind.do_wind_retrievel()
|
|
613
|
+
_getwind.draw_all_pic()
|
|
614
|
+
|
|
615
|
+
else:
|
|
616
|
+
print('GET_WIND_3D Init error!')
|
|
617
|
+
sys.exit(-1)
|
|
618
|
+
|
|
619
|
+
def drawpic_cross(inifile):
|
|
620
|
+
_getwind = GET_WIND_3D(inifile)
|
|
621
|
+
if not _getwind.error:
|
|
622
|
+
_getwind.draw_all_pic(bdrawhori=False)
|
|
623
|
+
else:
|
|
624
|
+
print('GET_WIND_3D Init error!')
|
|
625
|
+
sys.exit(-1)
|
|
626
|
+
|
|
627
|
+
parser = argparse.ArgumentParser(description='Do radar 3d wind retrievel.')
|
|
628
|
+
parser.add_argument('inifile', metavar='inifile', type=str,
|
|
629
|
+
help='ini filename for the mainprog')
|
|
630
|
+
|
|
631
|
+
parser.add_argument('--getwind', dest='mainprog', action='store_const',
|
|
632
|
+
const=mainprog,
|
|
633
|
+
help='do 3d wind retrievel')
|
|
634
|
+
|
|
635
|
+
parser.add_argument('--drawcross', dest='drawpic_cross', action='store_const',
|
|
636
|
+
const=drawpic_cross,
|
|
637
|
+
help='draw XZ and YZ pic')
|
|
638
|
+
BDEBUG=True
|
|
639
|
+
|
|
640
|
+
if BDEBUG:
|
|
641
|
+
print('当前为debug模式,所以直接读取主目录下的config.ini, 请注意!')
|
|
642
|
+
mainprog('metradar/config_3dwind.ini')
|
|
643
|
+
|
|
644
|
+
else:
|
|
645
|
+
args = parser.parse_args()
|
|
646
|
+
if not args.mainprog is None:
|
|
647
|
+
args.mainprog(args.inifile)
|
|
648
|
+
|
|
649
|
+
if not args.drawpic_cross is None:
|
|
650
|
+
args.drawpic_cross(args.inifile)
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
# %%
|
metradar/make_gif.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
from PIL import Image
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
filepath = 'pic'
|
|
8
|
+
outpath = 'pic'
|
|
9
|
+
filenames = os.listdir(filepath)
|
|
10
|
+
filenames = sorted(filenames)
|
|
11
|
+
images = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
for filename in filenames:
|
|
16
|
+
if filename.startswith('.') or filename.startswith('..'):
|
|
17
|
+
continue
|
|
18
|
+
if not filename.endswith('.png'):
|
|
19
|
+
continue
|
|
20
|
+
|
|
21
|
+
images.append(Image.open(filepath + os.sep + filename))
|
|
22
|
+
print(filename + ' added!')
|
|
23
|
+
images[0].save(outpath + os.sep + '雷达外推示例.gif', format='GIF',
|
|
24
|
+
append_images=images[1:], save_all=True, duration=int(500), loop=0)
|