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
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
'''
|
|
2
|
+
绘制雷达拼图
|
|
3
|
+
'''
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# %%
|
|
7
|
+
import os
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
import cartopy.crs as ccrs
|
|
10
|
+
from parse_pal import parse
|
|
11
|
+
import xarray as xr
|
|
12
|
+
import numpy as np
|
|
13
|
+
from matplotlib.transforms import offset_copy
|
|
14
|
+
import matplotlib.patheffects as path_effects
|
|
15
|
+
from matplotlib.font_manager import FontProperties
|
|
16
|
+
import json
|
|
17
|
+
import matplotlib as mpl
|
|
18
|
+
import matplotlib
|
|
19
|
+
matplotlib.use('pdf')
|
|
20
|
+
# matplotlib.use('MacOSX')
|
|
21
|
+
from cartopy.io.shapereader import Reader
|
|
22
|
+
import pandas as pd
|
|
23
|
+
from multiprocessing import cpu_count, Pool,freeze_support
|
|
24
|
+
|
|
25
|
+
mappath = 'resources/国省市县审图号(GS (2019) 3082号'
|
|
26
|
+
|
|
27
|
+
g_fontfile='resources/fonts/msyhbd.ttc'
|
|
28
|
+
g_font_max = FontProperties(fname=g_fontfile, size=8)
|
|
29
|
+
g_font_mid = FontProperties(fname=g_fontfile, size=6)
|
|
30
|
+
g_font_min = FontProperties(fname=g_fontfile, size=4)
|
|
31
|
+
|
|
32
|
+
mpl.rcParams['font.size'] = 7
|
|
33
|
+
mpl.rcParams['font.weight'] = 'bold'
|
|
34
|
+
mpl.rcParams['font.family'] = 'Times'
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def add_gisinfo(ax,font=None):
|
|
38
|
+
city_file = 'resources/stations/2018年国家级地面气象站-2423.xlsx'
|
|
39
|
+
# city_file = '../common/resources/stations/cma_county_station_info.dat'# cma_city_station_info cma_national_station_info
|
|
40
|
+
|
|
41
|
+
if not os.path.exists(city_file):
|
|
42
|
+
print(city_file +' not exist!')
|
|
43
|
+
return False
|
|
44
|
+
|
|
45
|
+
# cities = pd.read_csv(city_file, delimiter=r"\s+") # cma_city_station_info
|
|
46
|
+
# cities = pd.read_csv(city_file, delimiter=",") # cma_national_station_info
|
|
47
|
+
# cities = pd.read_table(city_file,sep='\s+',header=None,names=['stanum','lat','lon','name','city','province']) # cma_county_station_info
|
|
48
|
+
data = pd.read_excel(city_file, sheet_name = 0,header=0,skiprows=1)
|
|
49
|
+
|
|
50
|
+
names=[]
|
|
51
|
+
lat=[]
|
|
52
|
+
lon=[]
|
|
53
|
+
for i in range(data.shape[0]):
|
|
54
|
+
lat_deg = int(data['纬度'][i]/10000)
|
|
55
|
+
lat_min = int(str(data['纬度'][i])[-4:-2])
|
|
56
|
+
lat_sec = int(str(data['纬度'][i])[-2::])
|
|
57
|
+
tmp_lat = lat_deg + lat_min/60 + lat_sec/3600
|
|
58
|
+
|
|
59
|
+
lon_deg = int(data['经度'][i]/10000)
|
|
60
|
+
lon_min = int(str(data['经度'][i])[-4:-2])
|
|
61
|
+
lon_sec = int(str(data['经度'][i])[-2::])
|
|
62
|
+
tmp_lon = lon_deg + lon_min/60 + lon_sec/3600
|
|
63
|
+
|
|
64
|
+
lat.append(tmp_lat)
|
|
65
|
+
lon.append(tmp_lon)
|
|
66
|
+
names.append(data['站名'][i])
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
cities = pd.DataFrame(data={'name':names, 'lat':lat, 'lon':lon})
|
|
70
|
+
# draw station information
|
|
71
|
+
font = g_font_min
|
|
72
|
+
geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)
|
|
73
|
+
for _, row in cities.iterrows():
|
|
74
|
+
text_transform = offset_copy(geodetic_transform, units='dots', x=-5)
|
|
75
|
+
ax.plot(row['lon'], row['lat'], marker='o', color=[0.2,0.2,0.2], linestyle='None',
|
|
76
|
+
markersize=2, alpha=0.8, transform=ccrs.PlateCarree())
|
|
77
|
+
ax.text(row['lon']-0.01, row['lat'], row['name'], clip_on=True, # city_name
|
|
78
|
+
verticalalignment='center', horizontalalignment='right',
|
|
79
|
+
transform=text_transform, fontproperties=font, color=[0.2,0.2,0.2],
|
|
80
|
+
path_effects=[path_effects.Stroke(linewidth=1, foreground=[1,1,1]),
|
|
81
|
+
path_effects.Normal()])
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def draw_gisinfo(ax,font=None):
|
|
85
|
+
|
|
86
|
+
city_file = 'resources/stations/cma_city_station_info.dat'# cma_city_station_info cma_national_station_info
|
|
87
|
+
|
|
88
|
+
if not os.path.exists(city_file):
|
|
89
|
+
print(city_file +' not exist!')
|
|
90
|
+
return False
|
|
91
|
+
|
|
92
|
+
cities = pd.read_csv(city_file, delimiter=r"\s+") # cma_city_station_info
|
|
93
|
+
# cities = pd.read_csv(city_file, delimiter=",") # cma_national_station_info
|
|
94
|
+
# cities = pd.read_table(city_file,sep='\s+',header=None,names=['stanum','lat','lon','name','city','province']) # cma_county_station_info
|
|
95
|
+
# extract subregion
|
|
96
|
+
|
|
97
|
+
# targetprovince = '吉林省'
|
|
98
|
+
# flag1 = cities['province']==targetprovince
|
|
99
|
+
# cityname = np.unique(cities[flag1]['city'])
|
|
100
|
+
# cityname = np.unique(cities['city'])
|
|
101
|
+
cityname = np.unique(cities['city_name'])
|
|
102
|
+
names=[]
|
|
103
|
+
lat=[]
|
|
104
|
+
lon=[]
|
|
105
|
+
|
|
106
|
+
curdata = cities
|
|
107
|
+
for name in cityname:
|
|
108
|
+
flag2 = curdata['city_name'] == name
|
|
109
|
+
tmp_lat = np.mean(curdata[flag2]['lat'])
|
|
110
|
+
tmp_lon = np.mean(curdata[flag2]['lon'])
|
|
111
|
+
# if name.find('藏族') >0: name = name.strip(name[name.find('藏族')::])
|
|
112
|
+
# if name.find('蒙古') >0: name = name.strip(name[name.find('蒙古')::])
|
|
113
|
+
names.append(name)
|
|
114
|
+
lon.append(tmp_lon)
|
|
115
|
+
lat.append(tmp_lat)
|
|
116
|
+
|
|
117
|
+
cities = pd.DataFrame(data={'name':names, 'lat':lat, 'lon':lon})
|
|
118
|
+
# draw station information
|
|
119
|
+
font = g_font_min
|
|
120
|
+
geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)
|
|
121
|
+
for _, row in cities.iterrows():
|
|
122
|
+
text_transform = offset_copy(geodetic_transform, units='dots', x=-5)
|
|
123
|
+
ax.plot(row['lon'], row['lat'], marker='o', color=[0.2,0.2,0.2], linestyle='None',
|
|
124
|
+
markersize=2, alpha=0.8, transform=ccrs.PlateCarree())
|
|
125
|
+
ax.text(row['lon']-0.05, row['lat'], row['name'], clip_on=True, # city_name
|
|
126
|
+
verticalalignment='center', horizontalalignment='right',
|
|
127
|
+
transform=text_transform, fontproperties=font, color=[0.2,0.2,0.2],
|
|
128
|
+
path_effects=[path_effects.Stroke(linewidth=1, foreground=[1,1,1]),
|
|
129
|
+
path_effects.Normal()])
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def add_china_map_2cartopy(ax, facecolor='none',transform=None,name='province',
|
|
133
|
+
edgecolor='k', lw=0.8, **kwargs):
|
|
134
|
+
"""
|
|
135
|
+
Draw china boundary on cartopy map.
|
|
136
|
+
|
|
137
|
+
:param ax: matplotlib axes instance.
|
|
138
|
+
:param name: map name.
|
|
139
|
+
:param facecolor: fill color, default is none.
|
|
140
|
+
:param edgecolor: edge color.
|
|
141
|
+
:param lw: line width.
|
|
142
|
+
:return: None
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
# map name
|
|
146
|
+
names = {'nation': "BOUL_G", 'province': "BOUL_S",
|
|
147
|
+
'city': "BOUL_D", 'county': "BOUL_X",}
|
|
148
|
+
|
|
149
|
+
if not name in {'nation','province','city','county'}:
|
|
150
|
+
print(name + ' should be nation or province or city or county !')
|
|
151
|
+
return False
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# add 省界
|
|
155
|
+
if transform is None:
|
|
156
|
+
transform = ccrs.PlateCarree()
|
|
157
|
+
|
|
158
|
+
if name == 'county':
|
|
159
|
+
# 添加县边界
|
|
160
|
+
shpfile = mappath + os.sep + names[name] + ".shp"
|
|
161
|
+
ax.add_geometries(
|
|
162
|
+
Reader(shpfile).geometries(), transform,
|
|
163
|
+
path_effects=[path_effects.Stroke(linewidth=lw, foreground=[1,1,1]),path_effects.Normal()],
|
|
164
|
+
facecolor=facecolor, edgecolor=edgecolor, lw=lw-0.5, **kwargs)
|
|
165
|
+
|
|
166
|
+
if name == 'city':
|
|
167
|
+
# 添加市边界
|
|
168
|
+
shpfile = mappath + os.sep + names[name] + ".shp"
|
|
169
|
+
ax.add_geometries(
|
|
170
|
+
Reader(shpfile).geometries(), transform,
|
|
171
|
+
path_effects=[path_effects.Stroke(linewidth=lw+0.2, foreground=[1,1,1]),path_effects.Normal()],
|
|
172
|
+
facecolor=facecolor, edgecolor=edgecolor, lw=lw-0.2, **kwargs)
|
|
173
|
+
|
|
174
|
+
# 添加省边界
|
|
175
|
+
if name == 'province':
|
|
176
|
+
shpfile = mappath + os.sep + names[name] + ".shp"
|
|
177
|
+
ax.add_geometries(
|
|
178
|
+
Reader(shpfile).geometries(), transform,
|
|
179
|
+
path_effects=[path_effects.Stroke(linewidth=lw+0.5, foreground=[1,1,1]),path_effects.Normal()],
|
|
180
|
+
facecolor=facecolor, edgecolor=edgecolor, lw=lw+0.2, **kwargs)
|
|
181
|
+
|
|
182
|
+
def add_private_shp(ax,facecolor='none',transform=None,name='province',edgecolor='k', lw=0.8, **kwargs):
|
|
183
|
+
mappath = '/Users/wenjianzhu/Library/CloudStorage/OneDrive-个人/推广应用/GR2/吉林/地理信息/归档'
|
|
184
|
+
|
|
185
|
+
shpfile = mappath + os.sep + "jilin.shp"
|
|
186
|
+
|
|
187
|
+
ax.add_geometries(
|
|
188
|
+
Reader(shpfile).geometries(), transform,
|
|
189
|
+
path_effects=[path_effects.Stroke(linewidth=lw+0.2, foreground=[1,1,1]),path_effects.Normal()],
|
|
190
|
+
facecolor=facecolor, edgecolor=edgecolor, lw=lw-0.2, **kwargs)
|
|
191
|
+
|
|
192
|
+
def cm_precip():
|
|
193
|
+
"""
|
|
194
|
+
Standardized colormaps from National Weather Service
|
|
195
|
+
https://github.com/blaylockbk/pyBKB_v2/blob/master/BB_cmap/NWS_standard_cmap.py
|
|
196
|
+
|
|
197
|
+
Range of values:
|
|
198
|
+
metric: 0 to 762 millimeters
|
|
199
|
+
english: 0 to 30 inches
|
|
200
|
+
"""
|
|
201
|
+
# The amount of precipitation in inches
|
|
202
|
+
# a = [0,.01,.1,.25,.5,1,1.5,2,3,4,6,8,10,15,20,30]
|
|
203
|
+
a = [0,0.01,0.5,2.5,5,10,15,20,30,40,60,80,100,150,200,250]
|
|
204
|
+
|
|
205
|
+
# Normalize the bin between 0 and 1 (uneven bins are important here)
|
|
206
|
+
norm = [(float(i)-min(a))/(max(a)-min(a)) for i in a]
|
|
207
|
+
|
|
208
|
+
# Color tuple for every bin
|
|
209
|
+
C = np.array(# [255,255,255],
|
|
210
|
+
[ [199,233,192], [161,217,155], [116,196,118], [49,163,83],
|
|
211
|
+
[0,109,44], [255,250,138], [255,204,79], [254,141,60], [252,78,42],
|
|
212
|
+
[214,26,28], [173,0,38], [112,0,38], [59,0,48], [76,0,115], [255,219,255]])
|
|
213
|
+
|
|
214
|
+
# Create a tuple for every color indicating the normalized
|
|
215
|
+
# position on the colormap and the assigned color.
|
|
216
|
+
# COLORS = []
|
|
217
|
+
# for i, n in enumerate(norm):
|
|
218
|
+
# COLORS.append((n, np.array(C[i])/255.))
|
|
219
|
+
|
|
220
|
+
# Create the colormap
|
|
221
|
+
# cmap = mpl.colors.LinearSegmentedColormap.from_list("precipitation", COLORS)
|
|
222
|
+
cmap, norm = mpl.colors.from_levels_and_colors(np.array(a), np.array(C)/255.0, extend='neither')
|
|
223
|
+
return cmap, norm
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def draw_mosaic(data,lat,lon,slat=None,nlat=None,wlon=None,elon=None,outpath=None,outname=None,tstr=None,prefix_title='雷达组合反射率拼图 ',units='dBZ',
|
|
227
|
+
subtitle='',titlecolor='r',thred=None,cb_ratio=0.618,dpi=400,add_title=False):
|
|
228
|
+
|
|
229
|
+
if units == 'dBZ':
|
|
230
|
+
var_cmap,norm = parse('resources/gr2_colors/BR_WDTB_Bright.pal')#BR_WDTB_Bright.pal default_BR_PUP2.pal BR_AVL_BroadcastNegatives.pal
|
|
231
|
+
elif units == 'mm':
|
|
232
|
+
var_cmap,norm = cm_precip()
|
|
233
|
+
elif units == '%':
|
|
234
|
+
var_cmap,norm = parse('resources/gr2_colors/default_CC_ROSE.pal')
|
|
235
|
+
elif units == 'dB':
|
|
236
|
+
var_cmap,norm = parse('resources/gr2_colors/default_ZDR_ROSE.pal')
|
|
237
|
+
elif units == 'deg/km':
|
|
238
|
+
var_cmap,norm = parse('resources/gr2_colors/default_KDP_ROSE.pal')
|
|
239
|
+
elif units == 'cat':
|
|
240
|
+
var_cmap,norm = parse('resources/gr2_colors/default_HCAS.pal')
|
|
241
|
+
else:
|
|
242
|
+
pass
|
|
243
|
+
|
|
244
|
+
# newdata.data.shape[1],newdata.data.shape[0]
|
|
245
|
+
fig= plt.figure(figsize=[6,4],dpi=dpi,clear=True)
|
|
246
|
+
map_panel_axes = [0.1, 0.1, .8, .8]
|
|
247
|
+
# plt.subplots_adjust(top=1,bottom=0,left=0,right=1,hspace=0,wspace=0)
|
|
248
|
+
# projs=ccrs.LambertConformal(central_longitude=(wlon + elon)/2,central_latitude=(slat + nlat)/2,standard_parallels=(20,50))
|
|
249
|
+
projs = ccrs.PlateCarree()
|
|
250
|
+
transforms = ccrs.PlateCarree()
|
|
251
|
+
|
|
252
|
+
ax = plt.axes(map_panel_axes, projection=projs)
|
|
253
|
+
|
|
254
|
+
extent = [wlon, elon, slat, nlat]
|
|
255
|
+
ax.set_extent(extent, crs=ccrs.PlateCarree())
|
|
256
|
+
|
|
257
|
+
# add terrain
|
|
258
|
+
# try:
|
|
259
|
+
# request = TDT_Hillshade() # 地形阴影
|
|
260
|
+
# ax.add_image(request, 10) # level=10 缩放等
|
|
261
|
+
# except:
|
|
262
|
+
# pass
|
|
263
|
+
if not thred is None:
|
|
264
|
+
newdata = np.ma.masked_array(data, data < thred)
|
|
265
|
+
else:
|
|
266
|
+
newdata = data
|
|
267
|
+
grid_lat,grid_lon=np.meshgrid(lat,lon)
|
|
268
|
+
pcm = ax.pcolormesh(grid_lon,grid_lat,newdata.T,cmap=var_cmap,norm=norm,transform=transforms)
|
|
269
|
+
|
|
270
|
+
# add_private_shp(ax)
|
|
271
|
+
|
|
272
|
+
# add_china_map_2cartopy(ax,name='county')
|
|
273
|
+
# add_china_map_2cartopy(ax,name='city')
|
|
274
|
+
add_china_map_2cartopy(ax,name='province',lw=0.5)
|
|
275
|
+
|
|
276
|
+
draw_gisinfo(ax)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
# 添加地图网格
|
|
280
|
+
# ax.minorticks_on()
|
|
281
|
+
# ax.tick_params(direction='out', length=6, width=2, colors='r',grid_color='r', grid_alpha=0.5)
|
|
282
|
+
if elon - wlon > 20:
|
|
283
|
+
lon_step = 5
|
|
284
|
+
elif elon - wlon > 5:
|
|
285
|
+
lon_step = 1
|
|
286
|
+
elif elon - wlon > 1:
|
|
287
|
+
lon_step = 0.5
|
|
288
|
+
else:
|
|
289
|
+
lon_step = 0.2
|
|
290
|
+
|
|
291
|
+
if nlat - slat > 20:
|
|
292
|
+
lat_step = 5
|
|
293
|
+
elif nlat - slat > 5:
|
|
294
|
+
lat_step = 1
|
|
295
|
+
elif nlat - slat > 1:
|
|
296
|
+
lat_step = 0.5
|
|
297
|
+
else:
|
|
298
|
+
lat_step = 0.2
|
|
299
|
+
|
|
300
|
+
lb=ax.gridlines(draw_labels=True,x_inline=False, y_inline=False,xlocs=np.arange(int(wlon)-1,int(elon)+1,lon_step), ylocs=np.arange(int(slat)-1,int(nlat)+1,lat_step),
|
|
301
|
+
linewidth=0.1, color='k', alpha=0.8, linestyle='--')
|
|
302
|
+
# point_lat = 30.72
|
|
303
|
+
# point_lon = 108.57
|
|
304
|
+
# ax.plot(point_lon,point_lat,marker='o',color='r',markersize=4,transform=ccrs.PlateCarree())
|
|
305
|
+
lb.top_labels = None
|
|
306
|
+
lb.right_labels = None
|
|
307
|
+
lb.rotate_labels = False
|
|
308
|
+
# 'Composite Reflectivity '
|
|
309
|
+
titlestr1 = prefix_title + tstr[0:8] + 'T' + tstr[8:12] + ' UTC ' + subtitle
|
|
310
|
+
|
|
311
|
+
if add_title:
|
|
312
|
+
ax.set_title(titlestr1,fontproperties=g_font_mid,loc='left',verticalalignment='top',color=titlecolor)
|
|
313
|
+
# add colorbar
|
|
314
|
+
ax_pos = ax.get_position().bounds
|
|
315
|
+
cbar_axes = [ax_pos[0]+ ax_pos[2]+0.005,(ax_pos[1]+ax_pos[1]+ax_pos[3])/2-ax_pos[3]*cb_ratio/2,0.02,ax_pos[3]*cb_ratio]
|
|
316
|
+
cb_ax = fig.add_axes(cbar_axes)
|
|
317
|
+
if units == 'cat':
|
|
318
|
+
plt.colorbar(mappable=pcm,cax=cb_ax,extend='both',ticks=np.arange(0.5,11.5,1)) # extend='both',ticks=np.arange(-5,80,5)
|
|
319
|
+
elif units == 'dBZ':
|
|
320
|
+
plt.colorbar(mappable=pcm,cax=cb_ax,extend='both',ticks=np.arange(0,80,5))
|
|
321
|
+
else:
|
|
322
|
+
plt.colorbar(mappable=pcm,cax=cb_ax,extend='both')
|
|
323
|
+
cb_ax.text(1.8, 1.035, units, transform=cb_ax.transAxes,va="center", ha="center", font=g_font_min ) # 0.5,1.02
|
|
324
|
+
|
|
325
|
+
if units == 'cat':
|
|
326
|
+
cb_ax.set_yticklabels(['空','地物','晴空','干雪','湿雪','冰晶','霰','大雨滴','小到中雨','大雨','冰雹',],font=g_font_min)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
# DPI=1
|
|
330
|
+
# fig,ax = plt.subplots(figsize=[newdata.data.shape[1],newdata.data.shape[0]],dpi=DPI,clear=True)
|
|
331
|
+
# plt.subplots_adjust(top=1,bottom=0,left=0,right=1,hspace=0,wspace=0)
|
|
332
|
+
|
|
333
|
+
# data = np.ma.masked_array(newdata.data, newdata.data < 10)
|
|
334
|
+
# plt.pcolormesh(data,cmap=ref_cmap,norm=norm)
|
|
335
|
+
# plt.axis("off")
|
|
336
|
+
if os.path.exists(outpath):
|
|
337
|
+
if outname.endswith('.eps'):
|
|
338
|
+
plt.savefig(outpath + os.sep + outname, transparent=False, dpi=dpi,papertype='a4')
|
|
339
|
+
else:
|
|
340
|
+
fig.savefig(outpath + os.sep + outname, bbox_inches="tight",transparent=False, dpi=dpi,)
|
|
341
|
+
# plt.close()
|
|
342
|
+
print(outpath + os.sep + outname + ' saved!')
|
|
343
|
+
# plt.tight_layout()
|
|
344
|
+
# plt.show()
|
|
345
|
+
|
|
346
|
+
def draw_single(param):
|
|
347
|
+
filename = param['filename']
|
|
348
|
+
filepath = param['filepath']
|
|
349
|
+
outpath = param['outpath']
|
|
350
|
+
slat = param['slat']
|
|
351
|
+
nlat = param['nlat']
|
|
352
|
+
wlon = param['wlon']
|
|
353
|
+
elon = param['elon']
|
|
354
|
+
dpi = param['dpi']
|
|
355
|
+
thred = param['thred']
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
outname = filename.replace('.nc','.png')
|
|
359
|
+
tstr = filename.split('.')[2] + filename.split('.')[3]
|
|
360
|
+
data = xr.open_dataset(filepath + os.sep + filename)
|
|
361
|
+
try:
|
|
362
|
+
newdata = data.cref.sel(latitude=slice(slat,nlat),longitude=slice(wlon,elon))
|
|
363
|
+
draw_mosaic(newdata,newdata.latitude.data,newdata.longitude.data,slat,nlat,wlon,elon,outpath,outname,tstr,dpi=dpi,thred=thred)
|
|
364
|
+
except:
|
|
365
|
+
newdata = data.cref.sel(lat=slice(slat,nlat),lon=slice(wlon,elon))
|
|
366
|
+
draw_mosaic(newdata,newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,outpath,outname,tstr,dpi=dpi,thred=thred)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
if __name__ == "__main__":
|
|
372
|
+
freeze_support()
|
|
373
|
+
filepath = '/Users/wenjianzhu/Downloads/CMADAAS/rdmosaic_bin/202307'
|
|
374
|
+
|
|
375
|
+
outpath = '/Users/wenjianzhu/Downloads/20230704万州滑坡/pic'
|
|
376
|
+
|
|
377
|
+
if not os.path.exists(outpath):
|
|
378
|
+
os.makedirs(outpath)
|
|
379
|
+
|
|
380
|
+
# curparam=dict()
|
|
381
|
+
# curparam['filepath'] = filepath
|
|
382
|
+
# curparam['filename'] = filename
|
|
383
|
+
# curparam['outpath'] = outpath
|
|
384
|
+
# curparam['slat'] = 33
|
|
385
|
+
# curparam['nlat'] = 37
|
|
386
|
+
# curparam['wlon'] = 109
|
|
387
|
+
# curparam['elon'] =117
|
|
388
|
+
# curparam['dpi'] = 600
|
|
389
|
+
# curparam['thred'] = 10
|
|
390
|
+
|
|
391
|
+
# draw_single(curparam)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
params=[]
|
|
395
|
+
files = os.listdir(filepath)
|
|
396
|
+
files = sorted(files)
|
|
397
|
+
for filename in files:
|
|
398
|
+
if filename.startswith('.') or filename.startswith('..'):
|
|
399
|
+
continue
|
|
400
|
+
# if filename.split('.')[3][2:4] != '00' and filename.split('.')[3][2:4] != '12' and filename.split('.')[3][2:4] != '30' and filename.split('.')[3][2:4] != '48':
|
|
401
|
+
# continue
|
|
402
|
+
curparam=dict()
|
|
403
|
+
curparam['filepath'] = filepath
|
|
404
|
+
curparam['filename'] = filename
|
|
405
|
+
curparam['outpath'] = outpath
|
|
406
|
+
curparam['slat'] = 28
|
|
407
|
+
curparam['nlat'] = 32.5
|
|
408
|
+
curparam['wlon'] = 105.5
|
|
409
|
+
curparam['elon'] =110.5
|
|
410
|
+
curparam['dpi'] = 300
|
|
411
|
+
curparam['thred'] = 15
|
|
412
|
+
|
|
413
|
+
params.append(curparam)
|
|
414
|
+
|
|
415
|
+
MAXP = int(cpu_count()*0.8)
|
|
416
|
+
pools = Pool(MAXP)
|
|
417
|
+
|
|
418
|
+
pools.map(draw_single, params)
|
|
419
|
+
pools.close()
|
|
420
|
+
pools.join()
|
|
421
|
+
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'''
|
|
2
|
+
将雷达和自动站叠加绘图
|
|
3
|
+
朱文剑
|
|
4
|
+
'''
|
|
5
|
+
|
|
6
|
+
# %%
|
|
7
|
+
import pandas as pd
|
|
8
|
+
import warnings
|
|
9
|
+
warnings.filterwarnings('ignore')
|
|
10
|
+
|
|
11
|
+
from draw_radar_comp_func import DRAW_RADAR_OTHER,ini_params
|
|
12
|
+
from multiprocessing import cpu_count, Pool,freeze_support
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def draw_all(params):
|
|
16
|
+
# sourcepath,outpath,filename,start_lat,end_lat,start_lon,end_lon
|
|
17
|
+
# 河南北部区域
|
|
18
|
+
sourcepath = params['sourcepath']
|
|
19
|
+
outpath = params['outpath']
|
|
20
|
+
radfilename = params['radfilename']
|
|
21
|
+
slat = params['slat']
|
|
22
|
+
nlat = params['nlat']
|
|
23
|
+
wlon = params['wlon']
|
|
24
|
+
elon = params['elon']
|
|
25
|
+
|
|
26
|
+
timestr = radfilename[5:13] + '.' + radfilename[14:20]
|
|
27
|
+
|
|
28
|
+
fontname='resources/fonts/msyhbd.ttc'
|
|
29
|
+
|
|
30
|
+
# 添加中文地名
|
|
31
|
+
|
|
32
|
+
filename = 'resources/中文地理信息原始文件/吉林省所有站点信息.xls'
|
|
33
|
+
|
|
34
|
+
data_guojia = pd.read_excel(filename, sheet_name = '国家站55',header=0,skiprows=0,index_col=None,)
|
|
35
|
+
for jj in range(data_guojia.shape[0]):
|
|
36
|
+
curidx = data_guojia['站名'][jj].find('国家')
|
|
37
|
+
data_guojia['站名'][jj] = data_guojia['站名'][jj].replace( data_guojia['站名'][jj][curidx:],'')
|
|
38
|
+
data_guojia['站名'][jj] = data_guojia['站名'][jj].replace( data_guojia['组织机构'][jj],'')
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
data_guojiatianqi = pd.read_excel(filename, sheet_name = '国家天气站333',header=0,skiprows=0,index_col=None,)
|
|
42
|
+
|
|
43
|
+
for jj in range(data_guojiatianqi.shape[0]):
|
|
44
|
+
data_guojiatianqi['站名'][jj] = data_guojiatianqi['站名'][jj].replace('国家气象观测站','')
|
|
45
|
+
data_guojiatianqi['站名'][jj] = data_guojiatianqi['站名'][jj].replace( data_guojiatianqi['组织机构'][jj],'')
|
|
46
|
+
if data_guojiatianqi['站名'][jj].find('尔罗斯')>=0:
|
|
47
|
+
data_guojiatianqi['站名'][jj] = data_guojiatianqi['站名'][jj].replace('尔罗斯','')
|
|
48
|
+
|
|
49
|
+
data_quyuzhan = pd.read_excel(filename, sheet_name = '区域站1048',header=0,skiprows=0,index_col=None,)
|
|
50
|
+
for jj in range(data_quyuzhan.shape[0]):
|
|
51
|
+
data_quyuzhan['站名'][jj] = data_quyuzhan['站名'][jj].replace('气象观测站','')
|
|
52
|
+
|
|
53
|
+
data_quyuzhan['站名'][jj] = data_quyuzhan['站名'][jj].replace(data_quyuzhan['组织机构'][jj],'')
|
|
54
|
+
if data_quyuzhan['站名'][jj].find('尔罗斯')>=0:
|
|
55
|
+
data_quyuzhan['站名'][jj] = data_quyuzhan['站名'][jj].replace('尔罗斯','')
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
lat=[]
|
|
60
|
+
lon=[]
|
|
61
|
+
staname=[]
|
|
62
|
+
for ng in range(len(data_guojia['经度'])):
|
|
63
|
+
lon.append(data_guojia['经度'][ng])
|
|
64
|
+
lat.append(data_guojia['纬度'][ng])
|
|
65
|
+
staname.append(data_guojia['站名'][ng])
|
|
66
|
+
|
|
67
|
+
for ng in range(len(data_guojiatianqi['经度'])):
|
|
68
|
+
lon.append(data_guojiatianqi['经度'][ng])
|
|
69
|
+
lat.append(data_guojiatianqi['纬度'][ng])
|
|
70
|
+
staname.append(data_guojiatianqi['站名'][ng])
|
|
71
|
+
|
|
72
|
+
# for ng in range(len(data_quyuzhan['经度'])):
|
|
73
|
+
# lon.append(data_quyuzhan['经度'][ng])
|
|
74
|
+
# lat.append(data_quyuzhan['纬度'][ng])
|
|
75
|
+
# staname.append(data_quyuzhan['站名'][ng])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# radfilepath='/Users/wenjianzhu/Downloads/ZZHN'
|
|
80
|
+
radfilepath = sourcepath
|
|
81
|
+
params['radarfile_path'] = radfilepath
|
|
82
|
+
params['radarfile_name'] = radfilename
|
|
83
|
+
params['pic_path'] = outpath
|
|
84
|
+
params['timestr'] = timestr
|
|
85
|
+
params['slat'] = slat
|
|
86
|
+
params['nlat'] = nlat
|
|
87
|
+
params['wlon'] = wlon
|
|
88
|
+
params['elon'] = elon
|
|
89
|
+
params['fontfile'] = fontname
|
|
90
|
+
params['gis_lats'] = lat
|
|
91
|
+
params['gis_lons'] = lon
|
|
92
|
+
params['gis_name'] = staname
|
|
93
|
+
params['breplace'] = True
|
|
94
|
+
params['bdraw_crs'] = True
|
|
95
|
+
params['ref_colorfile'] = '../common/gr2_colors/default_BR_PUP2.pal'
|
|
96
|
+
params['vel_colorfile'] = '../common/gr2_colors/default_BV_PUP2.pal'
|
|
97
|
+
params['figsize_width'] = 4
|
|
98
|
+
params['fontsize_gis'] = 5
|
|
99
|
+
params['fontsize_colorbar'] = 5
|
|
100
|
+
params['fontsize_title'] = 6
|
|
101
|
+
params['mapcolor'] = [0/255,0/255,0/255]
|
|
102
|
+
params['dpi'] = 800
|
|
103
|
+
params['pic_format'] = 'jpg'
|
|
104
|
+
params['bdraw_title_ppi'] = False
|
|
105
|
+
|
|
106
|
+
# params={'radarfile_path':radfilepath,
|
|
107
|
+
# 'radarfile_name':radfilename,
|
|
108
|
+
# 'mosaicfile_path':'',
|
|
109
|
+
# 'mosaicfile_name':'',
|
|
110
|
+
# 'pic_path':outpath,
|
|
111
|
+
# 'timestr':timestr,
|
|
112
|
+
# 'aws_min_file_path':'',
|
|
113
|
+
# 'aws_min_file_name':'',
|
|
114
|
+
# 'aws_hour_file_path':'',
|
|
115
|
+
# 'aws_hour_file_name':'',
|
|
116
|
+
# 'gis_name':staname,
|
|
117
|
+
# 'gis_lats':lat,
|
|
118
|
+
# 'gis_lons':lon,
|
|
119
|
+
# 'slat':slat,
|
|
120
|
+
# 'nlat':nlat,
|
|
121
|
+
# 'wlon':wlon,
|
|
122
|
+
# 'elon':elon,
|
|
123
|
+
# 'ref_colorfile':'../common/gr2_colors/default_BR_PUP2.pal',
|
|
124
|
+
# 'vel_colorfile':'../common/gr2_colors/default_BV_PUP2.pal',
|
|
125
|
+
# 'fontfile':fontname,
|
|
126
|
+
# 'dpi':800,
|
|
127
|
+
# 'pic_format':'png',
|
|
128
|
+
# 'figsize_width':4,
|
|
129
|
+
# 'fontsize_gis':5,
|
|
130
|
+
# 'fontsize_colorbar':5,
|
|
131
|
+
# 'fontsize_title':6,
|
|
132
|
+
# 'mapcolor':[0/255,0/255,0/255],
|
|
133
|
+
# 'breplace':True, #如果图片文件已存在,是否重新绘制
|
|
134
|
+
# 'bdraw_crs':False
|
|
135
|
+
# }
|
|
136
|
+
|
|
137
|
+
_draw_radar_other = DRAW_RADAR_OTHER(params)
|
|
138
|
+
|
|
139
|
+
_draw_radar_other.read_vol_data()
|
|
140
|
+
|
|
141
|
+
# _draw_radar_other.draw_ref_alone(subdir='回波强度',tilt=0,thred=-5)
|
|
142
|
+
_draw_radar_other.draw_ref_alone(subdir='回波强度',tilt=1,thred=-5)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# _draw_radar_other.draw_vel_alone(subdir='径向速度',tilt=0)
|
|
146
|
+
# _draw_radar_other.draw_vel_alone(subdir='径向速度',tilt=1)
|
|
147
|
+
# _draw_radar_other.draw_vel_alone(subdir='径向速度',tilt=2)
|
|
148
|
+
|
|
149
|
+
# _draw_radar_other.draw_vel_pre()
|
|
150
|
+
# _draw_radar_other.draw_vel_wind_barb()
|
|
151
|
+
# _draw_radar_other.draw_vel_wind_quiver()
|
|
152
|
+
# _draw_radar_other.draw_ref_pre()
|
|
153
|
+
# _draw_radar_other.draw_ref_pre_wind_barb()
|
|
154
|
+
|
|
155
|
+
# _draw_radar_other.get_cref_from_radar([_draw_radar_other.g_rad_lat,_draw_radar_other.g_rad_lon])
|
|
156
|
+
# _draw_radar_other.get_cref_from_mosaicfile()
|
|
157
|
+
# _draw_radar_other.get_cref_from_radar([35.6,114.0])
|
|
158
|
+
# _draw_radar_other.draw_cref_pre()
|
|
159
|
+
# _draw_radar_other.draw_cref_wind_barb()
|
|
160
|
+
# _draw_radar_other.draw_cref_wind_quiver()
|
|
161
|
+
# _draw_radar_other.draw_cref_pre_wind_barb()
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# %%
|
|
165
|
+
import os
|
|
166
|
+
if __name__ == '__main__':
|
|
167
|
+
pass
|
|
168
|
+
freeze_support()
|
|
169
|
+
# Pool不支持跨CPU的虚拟服务器,会出现页面不足的错误提示
|
|
170
|
+
|
|
171
|
+
paramfilepath = '/Users/wenjianzhu/Downloads/雷达数据-王婷婷/绘图参数/回波强度'
|
|
172
|
+
# paramfilepath = '/Users/wenjianzhu/Downloads/雷达数据-王婷婷/绘图参数/径向速度'
|
|
173
|
+
# drawinfo = pd.read_csv(paramfilepath + os.sep + 'radardrawlist_20120612.csv',encoding='gb18030')
|
|
174
|
+
# drawinfo = pd.read_csv(paramfilepath + os.sep + 'radardrawlist_20120701.csv',encoding='gb18030')
|
|
175
|
+
# drawinfo = pd.read_csv(paramfilepath + os.sep + 'radardrawlist_20150608.csv',encoding='gb18030')
|
|
176
|
+
# drawinfo = pd.read_csv(paramfilepath + os.sep + 'radardrawlist_20170905.csv',encoding='gb18030')
|
|
177
|
+
drawinfo = pd.read_csv(paramfilepath + os.sep + 'radardrawlist_20210909.csv',encoding='gb18030')
|
|
178
|
+
# drawinfo = pd.read_csv(paramfilepath + os.sep + 'radardrawlist_20190602.csv',encoding='gb18030')
|
|
179
|
+
|
|
180
|
+
params = []
|
|
181
|
+
nums=drawinfo.shape[0]
|
|
182
|
+
# nums=1
|
|
183
|
+
for nn in range(nums):
|
|
184
|
+
pass
|
|
185
|
+
curparam=ini_params()
|
|
186
|
+
curparam['sourcepath'] = drawinfo['sourcepath'].iloc[nn]
|
|
187
|
+
curparam['outpath'] = drawinfo['outpath'].iloc[nn]
|
|
188
|
+
curparam['radfilename'] = drawinfo['filename'].iloc[nn]
|
|
189
|
+
curparam['slat'] = drawinfo['start_lat'].iloc[nn]
|
|
190
|
+
curparam['nlat'] = drawinfo['end_lat'].iloc[nn]
|
|
191
|
+
curparam['wlon'] = drawinfo['start_lon'].iloc[nn]
|
|
192
|
+
curparam['elon'] = drawinfo['end_lon'].iloc[nn]
|
|
193
|
+
# aws_min_delta_t_file_path
|
|
194
|
+
params.append(curparam)
|
|
195
|
+
|
|
196
|
+
# MAXP = int(cpu_count()*0.5)
|
|
197
|
+
MAXP=1#nums
|
|
198
|
+
pools = Pool(MAXP)
|
|
199
|
+
|
|
200
|
+
pools.map(draw_all, params)
|
|
201
|
+
pools.close()
|
|
202
|
+
pools.join()
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|