-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
493 lines (421 loc) · 19.2 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
from __future__ import print_function
import numpy as np
import matplotlib as mpl
mpl.use('agg')
import pylab
from matplotlib.patches import Circle
from matplotlib.lines import Line2D
import json
from datetime import datetime, timedelta
from params import vec2comp
_seg_hghts = [0, 3, 6, 9, 12, 18]
_seg_colors = ['r', '#00ff00', '#008800', '#993399', 'c']
def _total_seconds(td):
return td.days * 24 * 3600 + td.seconds + td.microseconds * 1e-6
def _fmt_timedelta(td):
seconds = int(_total_seconds(td))
periods = [
('dy', 60*60*24),
('hr', 60*60),
('min', 60),
('sec', 1)
]
strings=[]
for period_name,period_seconds in periods:
if seconds > period_seconds:
period_value, seconds = divmod(seconds,period_seconds)
strings.append("%s %s" % (period_value, period_name))
return " ".join(strings)
def _plot_param_table(parameters, web=False):
storm_dir, storm_spd = parameters['storm_motion']
trans = pylab.gca().transAxes
line_space = 0.028
start_x = 1.02
start_y = 1.04 - line_space #1
line_y = start_y
kwargs = {'color':'k', 'fontsize':10, 'clip_on':False, 'transform':trans}
pylab.text(start_x + 0.175, start_y, "Parameter Table", ha='center', fontweight='bold', **kwargs)
spacer = Line2D([start_x, start_x + 0.361], [line_y - line_space * 0.48] * 2, color='k', linestyle='-', transform=trans, clip_on=False)
pylab.gca().add_line(spacer)
line_y -= line_space * 1.5
pylab.text(start_x + 0.095, line_y - 0.0025, "BWD (kts)", fontweight='bold', **kwargs)
if not web:
pylab.text(start_x + 0.22, line_y - 0.0025, "SRH (m$^2$s$^{-2}$)", fontweight='bold', **kwargs)
else:
# Awful, awful hack for matplotlib without a LaTeX distribution
pylab.text(start_x + 0.22, line_y - 0.0025, "SRH (m s )", fontweight='bold', **kwargs)
pylab.text(start_x + 0.305, line_y + 0.009, "2 -2", fontweight='bold', color='k', fontsize=6, clip_on=False, transform=trans)
line_y -= line_space
pylab.text(start_x, line_y, "0-1 km", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['shear_mag_1km']) else "%d" % int(parameters['shear_mag_1km'])
pylab.text(start_x + 0.095, line_y, val, **kwargs)
val = "--" if np.isnan(parameters['srh_1km']) else "%d" % int(parameters['srh_1km'])
pylab.text(start_x + 0.22, line_y, val, **kwargs)
line_y -= line_space
pylab.text(start_x, line_y, "0-3 km", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['shear_mag_3km']) else "%d" % int(parameters['shear_mag_3km'])
pylab.text(start_x + 0.095, line_y, val, **kwargs)
val = "--" if np.isnan(parameters['srh_3km']) else "%d" % int(parameters['srh_3km'])
pylab.text(start_x + 0.22, line_y, val, **kwargs)
line_y -= line_space
pylab.text(start_x, line_y, "0-6 km", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['shear_mag_6km']) else "%d" % int(parameters['shear_mag_6km'])
pylab.text(start_x + 0.095, line_y, val, **kwargs)
spacer = Line2D([start_x, start_x + 0.361], [line_y - line_space * 0.48] * 2, color='k', linestyle='-', transform=trans, clip_on=False)
pylab.gca().add_line(spacer)
line_y -= 1.5 * line_space
pylab.text(start_x, line_y, "Storm Motion:", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['storm_motion']).any() else "%03d/%02d kts" % (storm_dir, storm_spd)
pylab.text(start_x + 0.26, line_y + 0.001, val, **kwargs)
line_y -= line_space
bl_dir, bl_spd = parameters['bunkers_left']
pylab.text(start_x, line_y, "Bunkers Left Mover:", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['bunkers_left']).any() else "%03d/%02d kts" % (bl_dir, bl_spd)
pylab.text(start_x + 0.26, line_y + 0.001, val, **kwargs)
line_y -= line_space
br_dir, br_spd = parameters['bunkers_right']
if not web:
pylab.text(start_x, line_y, "Bunkers Right Mover:", fontweight='bold', **kwargs)
else:
pylab.text(start_x, line_y - 0.005, "Bunkers Right Mover:", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['bunkers_right']).any() else "%03d/%02d kts" % (br_dir, br_spd)
if not web:
pylab.text(start_x + 0.26, line_y + 0.001, val, **kwargs)
else:
pylab.text(start_x + 0.26, line_y - 0.001, val, **kwargs)
line_y -= line_space
mn_dir, mn_spd = parameters['mean_wind']
pylab.text(start_x, line_y, "0-6 km Mean Wind:", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['mean_wind']).any() else "%03d/%02d kts" % (mn_dir, mn_spd)
pylab.text(start_x + 0.26, line_y + 0.001, val, **kwargs)
spacer = Line2D([start_x, start_x + 0.361], [line_y - line_space * 0.48] * 2, color='k', linestyle='-', transform=trans, clip_on=False)
pylab.gca().add_line(spacer)
line_y -= 1.5 * line_space
if not web:
pylab.text(start_x, line_y, "Critical Angle:", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['critical']) else "%d$^{\circ}$" % int(parameters['critical'])
pylab.text(start_x + 0.18, line_y - 0.00, val, **kwargs)
else:
pylab.text(start_x, line_y - 0.0075, "Critical Angle:", fontweight='bold', **kwargs)
val = "--" if np.isnan(parameters['critical']) else "%d deg" % int(parameters['critical'])
pylab.text(start_x + 0.18, line_y - 0.0075, val, **kwargs)
def _plot_data(data, parameters):
storm_dir, storm_spd = parameters['storm_motion']
bl_dir, bl_spd = parameters['bunkers_left']
br_dir, br_spd = parameters['bunkers_right']
mn_dir, mn_spd = parameters['mean_wind']
u, v = vec2comp(data['wind_dir'], data['wind_spd'])
alt = data['altitude']
storm_u, storm_v = vec2comp(storm_dir, storm_spd)
bl_u, bl_v = vec2comp(bl_dir, bl_spd)
br_u, br_v = vec2comp(br_dir, br_spd)
mn_u, mn_v = vec2comp(mn_dir, mn_spd)
seg_idxs = np.searchsorted(alt, _seg_hghts)
try:
seg_u = np.interp(_seg_hghts, alt, u, left=np.nan, right=np.nan)
seg_v = np.interp(_seg_hghts, alt, v, left=np.nan, right=np.nan)
ca_u = np.interp(0.5, alt, u, left=np.nan, right=np.nan)
ca_v = np.interp(0.5, alt, v, left=np.nan, right=np.nan)
except ValueError:
seg_u = np.nan * np.array(_seg_hghts)
seg_v = np.nan * np.array(_seg_hghts)
ca_u = np.nan
ca_v = np.nan
mkr_z = np.arange(16)
mkr_u = np.interp(mkr_z, alt, u, left=np.nan, right=np.nan)
mkr_v = np.interp(mkr_z, alt, v, left=np.nan, right=np.nan)
for idx in range(len(_seg_hghts) - 1):
idx_start = seg_idxs[idx]
idx_end = seg_idxs[idx + 1]
if not np.isnan(seg_u[idx]):
pylab.plot([seg_u[idx], u[idx_start]], [seg_v[idx], v[idx_start]], '-', color=_seg_colors[idx], linewidth=1.5)
if idx_start < len(data['rms_error']) and data['rms_error'][idx_start] == 0.:
# The first segment is to the surface wind, draw it in a dashed line
pylab.plot(u[idx_start:(idx_start + 2)], v[idx_start:(idx_start + 2)], '--', color=_seg_colors[idx], linewidth=1.5)
pylab.plot(u[(idx_start + 1):idx_end], v[(idx_start + 1):idx_end], '-', color=_seg_colors[idx], linewidth=1.5)
else:
pylab.plot(u[idx_start:idx_end], v[idx_start:idx_end], '-', color=_seg_colors[idx], linewidth=1.5)
if not np.isnan(seg_u[idx + 1]):
pylab.plot([u[idx_end - 1], seg_u[idx + 1]], [v[idx_end - 1], seg_v[idx + 1]], '-', color=_seg_colors[idx], linewidth=1.5)
for upt, vpt, rms in list(zip(u, v, data['rms_error']))[idx_start:idx_end]:
rad = np.sqrt(2) * rms
circ = Circle((upt, vpt), rad, color=_seg_colors[idx], alpha=0.05)
pylab.gca().add_patch(circ)
pylab.plot(mkr_u, mkr_v, 'ko', ms=10)
for um, vm, zm in zip(mkr_u, mkr_v, mkr_z):
if not np.isnan(um):
pylab.text(um, vm - 0.1, str(zm), va='center', ha='center', color='white', size=6.5, fontweight='bold')
try:
pylab.plot([storm_u, u[0]], [storm_v, v[0]], 'c-', linewidth=0.75)
pylab.plot([u[0], ca_u], [v[0], ca_v], 'm-', linewidth=0.75)
except IndexError:
pass
if not (np.isnan(bl_u) or np.isnan(bl_v)):
pylab.plot(bl_u, bl_v, 'ko', markersize=5, mfc='none')
pylab.text(bl_u + 0.5, bl_v - 0.5, "LM", ha='left', va='top', color='k', fontsize=10)
if not (np.isnan(br_u) or np.isnan(br_v)):
pylab.plot(br_u, br_v, 'ko', markersize=5, mfc='none')
pylab.text(br_u + 0.5, br_v - 0.5, "RM", ha='left', va='top', color='k', fontsize=10)
if not (np.isnan(mn_u) or np.isnan(mn_v)):
pylab.plot(mn_u, mn_v, 's', color='#a04000', markersize=5, mfc='none')
pylab.text(mn_u + 0.6, mn_v - 0.6, "MEAN", ha='left', va='top', color='#a04000', fontsize=10)
smv_is_brm = (storm_u == br_u and storm_v == br_v)
smv_is_blm = (storm_u == bl_u and storm_v == bl_v)
smv_is_mnw = (storm_u == mn_u and storm_v == mn_v)
if not (np.isnan(storm_u) or np.isnan(storm_v)) and not (smv_is_brm or smv_is_blm or smv_is_mnw):
pylab.plot(storm_u, storm_v, 'k+', markersize=6)
pylab.text(storm_u + 0.5, storm_v - 0.5, "SM", ha='left', va='top', color='k', fontsize=10)
def _plot_background(min_u, max_u, min_v, max_v):
max_ring = int(np.ceil(max(
np.hypot(min_u, min_v),
np.hypot(min_u, max_v),
np.hypot(max_u, min_v),
np.hypot(max_u, max_v)
)))
pylab.axvline(x=0, linestyle='-', color='#999999')
pylab.axhline(y=0, linestyle='-', color='#999999')
for irng in range(10, max_ring, 10):
ring = Circle((0., 0.), irng, linestyle='dashed', fc='none', ec='#999999')
pylab.gca().add_patch(ring)
if irng <= max_u - 10:
rng_str = "%d kts" % irng if max_u - 20 < irng <= max_u - 10 else "%d" % irng
pylab.text(irng + 0.5, -0.5, rng_str, ha='left', va='top', fontsize=9, color='#999999', clip_on=True, clip_box=pylab.gca().get_clip_box())
def plot_hodograph(data, parameters, fname=None, web=False, fixed=False, archive=False):
img_title = "%s VWP %s" % (data.rid, data['time'].strftime("%m-%d-%Y %H:%M:%SZ"))
if fname is not None:
img_file_name = fname
else:
img_file_name = "%s_vad.png" % data.rid
u, v = vec2comp(data['wind_dir'], data['wind_spd'])
sat_age = 6 * 3600
if fixed or len(u) == 0:
ctr_u, ctr_v = 20, 20
size = 120
else:
ctr_u = u.mean()
ctr_v = v.mean()
size = max(u.max() - u.min(), v.max() - v.min()) + 20
size = max(120, size)
min_u = ctr_u - size / 2
max_u = ctr_u + size / 2
min_v = ctr_v - size / 2
max_v = ctr_v + size / 2
now = datetime.utcnow()
img_age = now - data['time']
age_cstop = min(_total_seconds(img_age) / sat_age, 1) * 0.4
age_color = mpl.cm.get_cmap('hot')(age_cstop)[:-1]
age_str = "Image Generation: %s [%s old]" % (now.strftime("%m-%d-%Y %H:%M:%SZ"), _fmt_timedelta(img_age))
pylab.figure(figsize=(10, 7.5), dpi=300) #7.5
fig_wid, fig_hght = pylab.gcf().get_size_inches()
fig_aspect = fig_wid / fig_hght
axes_left = 0.005 #0.05
axes_bot = 0.03 #0.05
axes_hght = 0.93 #0.9
axes_wid = axes_hght / fig_aspect
pylab.axes((axes_left, axes_bot, axes_wid, axes_hght))
_plot_background(min_u, max_u, min_v, max_v)
_plot_data(data, parameters)
_plot_param_table(parameters, web=web)
pylab.xlim(min_u, max_u)
pylab.ylim(min_v, max_v)
pylab.xticks([])
pylab.yticks([])
pylab.title(img_title, color=age_color,fontweight='bold')
pylab.text(0., -0.01, age_str, transform=pylab.gca().transAxes, ha='left', va='top', fontsize=9, color=age_color)
web_brand = "http://www.autumnsky.us/vad/"
pylab.text(1.0, -0.01, web_brand, transform=pylab.gca().transAxes, ha='right', va='top', fontsize=9)
### PyART L3 Plot ###
radll={'TJBQ': ('18.485', '-67.143'),
'KGLD': ('39.36694', '-101.7'),
'KBIS': ('46.77083', '-100.76028'),
'KBOX': ('41.95583', '-71.1375'),
'KBRO': ('25.91556', '-97.41861'),
'KDAX': ('38.50111', '-121.67667'),
'KLBB': ('33.65417', '-101.81361'),
'KLWX': ('38.97628', '-77.48751'),
'KMOB': ('30.67944', '-88.23972'),
'KTFX': ('47.45972', '-111.38444'),
'KMPX': ('44.84889', '-93.56528'),
'KRLX': ('38.31194', '-81.72389'),
'KTLH': ('30.3975', '-84.32889'),
'KYUX': ('32.49528', '-114.65583'),
'PAEC': ('64.51139', '-165.295'),
'RKJK': ('35.92417', '126.62222'),
'KPBZ': ('40.53167', '-80.21833'),
'KAMX': ('25.61056', '-80.41306'),
'KBYX': ('24.59694', '-81.70333'),
'KDDC': ('37.76083', '-99.96833'),
'KFCX': ('37.02417', '-80.27417'),
'KFTG': ('39.78667', '-104.54528'),
'KICX': ('37.59083', '-112.86222'),
'KLOT': ('41.60444', '-88.08472'),
'KLVX': ('37.97528', '-85.94389'),
'KLZK': ('34.83639', '-92.26194'),
'KMHX': ('34.77583', '-76.87639'),
'KMLB': ('28.11306', '-80.65444'),
'KOTX': ('47.68056', '-117.62583'),
'PACG': ('56.85278', '-135.52917'),
'KHDX': ('33.07639', '-106.12222'),
'KTYX': ('43.75583', '-75.68'),
'PHWA': ('19.095', '-155.56889'),
'PAPD': ('65.03556', '-147.49917'),
'PGUA': ('13.45444', '144.80833'),
'PHKI': ('21.89417', '-159.55222'),
'RKSG': ('36.95972', '127.01833'),
'KCBW': ('46.03917', '-67.80694'),
'KBBX': ('39.49611', '-121.63167'),
'KBUF': ('42.94861', '-78.73694'),
'KGGW': ('48.20639', '-106.62417'),
'KGRK': ('30.72167', '-97.38278'),
'KJAX': ('30.48444', '-81.70194'),
'KILX': ('40.15056', '-89.33667'),
'KIWX': ('41.40861', '-85.7'),
'KLTX': ('33.98917', '-78.42917'),
'KMQT': ('46.53111', '-87.54833'),
'KMSX': ('47.04111', '-113.98611'),
'KMXX': ('32.53667', '-85.78972'),
'KNQA': ('35.34472', '-89.87333'),
'KOHX': ('36.24722', '-86.5625'),
'KPAH': ('37.06833', '-88.77194'),
'KPUX': ('38.45944', '-104.18139'),
'KUEX': ('40.32083', '-98.44167'),
'LPLA': ('38.73028', '-27.32167'),
'PHKM': ('20.12556', '-155.77778'),
'TJRV': ('18.256', '-65.637'),
'KARX': ('43.82278', '-91.19111'),
'KHGX': ('29.47194', '-95.07889'),
'KBHX': ('40.49833', '-124.29194'),
'KGYX': ('43.89139', '-70.25694'),
'KHPX': ('36.73667', '-87.285'),
'KLSX': ('38.69889', '-90.68278'),
'KMUX': ('37.15528', '-121.8975'),
'KNKX': ('32.91889', '-117.04194'),
'KABX': ('35.14972', '-106.82333'),
'KAKQ': ('36.98389', '-77.0075'),
'KAPX': ('44.90722', '-84.71972'),
'KBGM': ('42.19972', '-75.985'),
'KDIX': ('39.94694', '-74.41111'),
'KDYX': ('32.53833', '-99.25417'),
'KESX': ('35.70111', '-114.89139'),
'KFDR': ('34.36222', '-98.97611'),
'KFFC': ('33.36333', '-84.56583'),
'KGSP': ('34.88306', '-82.22028'),
'KMBX': ('48.3925', '-100.86444'),
'KHNX': ('36.31417', '-119.63111'),
'KHTX': ('34.93056', '-86.08361'),
'KIND': ('39.7075', '-86.28028'),
'KRIW': ('43.06611', '-108.47667'),
'KSFX': ('43.10583', '-112.68528'),
'KSGF': ('37.23528', '-93.40028'),
'KVAX': ('30.89', '-83.00194'),
'KEMX': ('31.89361', '-110.63028'),
'KFWS': ('32.57278', '-97.30278'),
'KINX': ('36.175', '-95.56444'),
'KMRX': ('36.16833', '-83.40194'),
'KOAX': ('41.32028', '-96.36639'),
'KSOX': ('33.81778', '-117.635'),
'KVWX': ('38.26', '-87.7247'),
'KGWX': ('33.89667', '-88.32889'),
'KMAX': ('42.08111', '-122.71611'),
'KOKX': ('40.86556', '-72.86444'),
'KRGX': ('39.75417', '-119.46111'),
'KVBX': ('34.83806', '-120.39583'),
'PAKC': ('58.67944', '-156.62944'),
'KCLE': ('41.41306', '-81.86'),
'KEOX': ('31.46028', '-85.45944'),
'KMAF': ('31.94333', '-102.18889'),
'KVNX': ('36.74083', '-98.1275'),
'KLGX': ('47.1158', '-124.1069'),
'KPDT': ('45.69056', '-118.85278'),
'KVTX': ('34.41167', '-119.17861'),
'KDFX': ('29.2725', '-100.28028'),
'KAMA': ('35.23333', '-101.70889'),
'KATX': ('48.19472', '-122.49444'),
'KBMX': ('33.17194', '-86.76972'),
'KDGX': ('32.28', '-89.98444'),
'KDLH': ('46.83694', '-92.20972'),
'KDOX': ('38.82556', '-75.44'),
'KDTX': ('42.69972', '-83.47167'),
'KEAX': ('38.81028', '-94.26417'),
'KENX': ('42.58639', '-74.06444'),
'KFDX': ('34.63528', '-103.62944'),
'KFSX': ('34.57444', '-111.19833'),
'KGJX': ('39.06222', '-108.21306'),
'KGRR': ('42.89389', '-85.54472'),
'KMKX': ('42.96778', '-88.55056'),
'KICT': ('37.65444', '-97.4425'),
'KILN': ('39.42028', '-83.82167'),
'KLIX': ('30.33667', '-89.82528'),
'KLRX': ('40.73972', '-116.80278'),
'KMTX': ('41.26278', '-112.44694'),
'KSHV': ('32.45056', '-93.84111'),
'KTBW': ('27.70528', '-82.40194'),
'KTLX': ('35.33306', '-97.2775'),
'KTWX': ('38.99694', '-96.2325'),
'KCAE': ('33.94861', '-81.11861'),
'KBLX': ('45.85389', '-108.60611'),
'KCBX': ('43.49083', '-116.23444'),
'KCXX': ('44.51111', '-73.16639'),
'KJKL': ('37.59083', '-83.31306'),
'KEWX': ('29.70361', '-98.02806'),
'KGRB': ('44.49833', '-88.11111'),
'KJGX': ('32.675', '-83.35111'),
'KPOE': ('31.15528', '-92.97583'),
'KRAX': ('35.66528', '-78.49'),
'KRTX': ('45.715', '-122.96417'),
'KSJT': ('31.37111', '-100.49222'),
'KUDX': ('44.125', '-102.82944'),
'PABC': ('60.79278', '-161.87417'),
'KEYX': ('35.09778', '-117.56'),
'KFSD': ('43.58778', '-96.72889'),
'KSRX': ('35.29056', '-94.36167'),
'PHMO': ('21.13278', '-157.18'),
'RODN': ('26.30194', '127.90972'),
'KCYS': ('41.15194', '-104.80611'),
'KABR': ('45.45583', '-98.41306'),
'KCLX': ('32.65556', '-81.04222'),
'KCRP': ('27.78389', '-97.51083'),
'KDVN': ('41.61167', '-90.58083'),
'KEPZ': ('31.87306', '-106.6975'),
'KEVX': ('30.56417', '-85.92139'),
'KIWA': ('33.28917', '-111.66917'),
'KLCH': ('30.125', '-93.21583'),
'KLNX': ('41.95778', '-100.57583'),
'KMVX': ('47.52806', '-97.325'),
'PAHG': ('60.72591', '-151.35146'),
'PAIH': ('59.46194', '-146.30111'),
'TJUA': ('18.1175', '-66.07861'),
'KDMX': ('41.73111', '-93.72278'),
'KCCX': ('40.92306', '-78.00389')}
import shutil
import urllib.request
import cartopy.crs as ccrs
from cartopy.feature import ShapelyFeature
from cartopy.io.shapereader import Reader
import pyart
fp='' #*** File path directory to store L3 data file. Ex: '/home/[user]/data/L3/'
url=f'https://tgftp.nws.noaa.gov/SL.us008001/DF.of/DC.radar/DS.p19r0/SI.{data.rid.lower()}/sn.last'
with urllib.request.urlopen(url) as response, open(f'{fp}{data.rid}', 'wb') as out_file:
shutil.copyfileobj(response, out_file)
myradar=pyart.io.read(f'{fp}{data.rid}')
t=pyart.util.datetime_from_radar(myradar).strftime("%m-%d-%Y %H:%M:%SZ")
dat=myradar.get_field(0,'reflectivity')
lla=myradar.get_gate_lat_lon_alt(0)
lat=lla[0]
lon=lla[1]
latr=float(radll[data.rid][0]) #ns
lonr=float(radll[data.rid][1]) #we
w=lonr-3
e=lonr+3
n=latr+3
s=latr-3
fs='' #*** File path to US state shapefile. Shapefile found in repo: 'cb_2016_us_state_20m.shp'. URL for zip that has the shapefile: https://www2.census.gov/geo/tiger/GENZ2016/shp/cb_2016_us_state_20m.zip
state=ShapelyFeature(Reader(fs).geometries(),ccrs.PlateCarree(),facecolor='None')
ax=pylab.axes([.7029, .16, .3, .66],projection=ccrs.PlateCarree()) #left,bottom,width,height
ax.set_extent([w,e,n,s],crs=ccrs.PlateCarree())
ax.add_feature(state,linewidth=.7,edgecolor='k')
ax.pcolormesh(lon,lat,dat.squeeze(),transform=ccrs.PlateCarree(),cmap='pyart_Carbone42',vmin=-10)
ax.text(0.008, 0.01,t,transform=ax.transAxes,fontweight='bold',fontsize=5)
ax.text(0.865, 0.012,'@Py_ART',transform=ax.transAxes,fontweight='bold',fontsize=5)
pylab.savefig(img_file_name, dpi=300) #dpi=pylab.gcf().dpi)
pylab.close()