-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_gfs_lambert_totalprecip.ncl
487 lines (395 loc) · 17.1 KB
/
plot_gfs_lambert_totalprecip.ncl
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
; ===========================================
; Plots 4-panel for GFS evaluation
; Created by: Alicia M. Bentley
; Last updated: 9 June 2020
; ===========================================
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
; ===========================================
begin
print("======================")
print("Script has started!")
print("======================")
;================================================================
; Define casename
if (isdefined("eventname")) then
print("Eventname defined on command line: "+eventname)
casename = eventname
else
print("No eventname defined on command line")
casename = "eventname"
end if
;==================================================================
; Define data_directory
if (isdefined("images_path")) then
print("images_path defined on command line: "+images_path)
image_dir = images_path
else
print("No images_path defined on command line")
image_dir = "images_path"
end if
;==================================================================
; Pre-defined domain definitions
minlatlist=(/15.0,35.0,25.0,31.0,40.0,25.5,35.0,42.0,41.0,34.0,40.0,34.0,24.5,12.5,10,20,1,-40,15,10,3/)
maxlatlist=(/60.0,75.0,50.0,43.0,50.0,37.5,44.0,50.0,49.5,43.0,48.0,42.5,35.0,35,27,47.5,60,-1,62.5,29,35/)
minlonlist=(/-135.0,160.0,-120,-125.0,-125.0,-108.0,-108.0,-110.0,-97.0,-97.0,-81.0,-86.0,-92.0,-105,-81,-95,110,137.5,-167.5,-171,-136/)
maxlonlist=(/-60.0,250.0,-72.5,-105.0,-107.0,-90.0,-92.0,-95.0,-80.5,-83.0,-66.5,-72.0,-76.0,-72.5,-55,-57.5,179,192.5,-115,-141,-82/)
regionlist=(/"us","ak","uszoom","sw","nw","t","cp","np","mw","ov","ne","ma","se","gom","pr","nwatl","wpac","spac","epac","hi","epactc"/)
if (isdefined("scriptregion")) then
if (scriptregion .eq. "new")
print("New domain requested. Script will fail if the following variables are not defined with command line arguments: regionname, minlat, minlon, maxlat, maxlon.")
scriptregion=regionname
else
print("Domain defined on command line: "+scriptregion)
scriptregion=str_lower(scriptregion)
end if
else
scriptregion="us"
end if
do c=0,dimsizes(regionlist)-1
if (regionlist(c).eq.scriptregion) then
minlat=minlatlist(c)
minlon=minlonlist(c)
maxlat=maxlatlist(c)
maxlon=maxlonlist(c)
end if
end do
; =================================================================
; Obtaining the date of the forecast requested
scriptyear=toint(str_get_cols(scriptyyyymmddhh,0,3))
scriptmonth=toint(str_get_cols(scriptyyyymmddhh,4,5))
scriptday=toint(str_get_cols(scriptyyyymmddhh,6,7))
scripthour=toint(str_get_cols(scriptyyyymmddhh,8,9))
timeunits="hours since 1800-01-01 00:00"
datemodel=ut_inv_calendar(scriptyear,scriptmonth,scriptday,scripthour,0,0,timeunits,0)
datestart=ut_inv_calendar(scriptyear,scriptmonth,scriptday,scripthour,0,0,timeunits,0)
;===================================================================
;;; Check to see if starting forecast hour was defined with command line argument
if (isdefined("fhr_start")) then
print("Starting forecast defined on command line")
fhrb = toint(fhr_start)
startdate1=datemodel+fhrb
startdate1@units=timeunits
startints=ut_calendar(startdate1,0)
datestart=ut_inv_calendar(toint(startints(:,0)),toint(startints(:,1)),toint(startints(:,2)),toint(startints(:,3)),0,0,timeunits,0)
else
datestart=ut_inv_calendar(scriptyear,scriptmonth,scriptday,scripthour,0,0,timeunits,0)
end if
;;; Check to see if ending forecast hour was defined with command line argument
if (isdefined("fhr_end")) then
print("Ending forecast defined on command line")
fhr_diff = toint(fhr_end) - toint(fhr_start)
fhre = toint(fhr_diff)
else
fhre=toint(0)
end if
enddate1=datestart+fhre
enddate1@units=timeunits
endints=ut_calendar(enddate1,0)
dateend=ut_inv_calendar(toint(endints(:,0)),toint(endints(:,1)),toint(endints(:,2)),toint(endints(:,3)),0,0,timeunits,0)
datemodel@units=timeunits
;;; Check to see if forecast hour increment was defined with command line argument
if (isdefined("fhr_inc")) then
print("Forecast hour increment defined on command line")
fhri = toint(fhr_inc)
else
fhri=6
end if
fdates=ispan(toint(datestart),toint(dateend),fhri)
fhours=ispan(toint(datestart)-toint(datemodel),toint(dateend)-toint(datemodel),fhri)
do h=0,dimsizes(fdates)-1
;print((/fhours(h)/))
thisdate=fdates(h)
thisdate@units=timeunits
modelstrings=tostring(ut_calendar(thisdate,-3))
ms=tostring(ut_calendar(datemodel,-3))
;model date
yearm=str_get_cols(ms,0,3)
monthm=str_get_cols(ms,4,5)
daym=str_get_cols(ms,6,7)
hourm=str_get_cols(ms,8,9)
mdhm=str_get_cols(ms,4,9)
ymm=str_get_cols(ms,0,5)
ymdm=str_get_cols(ms,0,7)
;date of forecast hour
year=str_get_cols(modelstrings,0,3)
month=str_get_cols(modelstrings,4,5)
day=str_get_cols(modelstrings,6,7)
hour=str_get_cols(modelstrings,8,9)
mdh=str_get_cols(modelstrings,4,9)
ymd=str_get_cols(modelstrings,0,7)
monthind=toint(month)
months=(/"","January","February","March","April","May","June","July","August","September","October","November","December"/)
print(" ")
print("Int: YYYYMMDDHH (FXXX): "+ymdm+hourm+" (F"+sprinti("%0.3i",fhours(h))+")")
; ==========================================================================
;Obtaining GFSv16 fcst file
parafile_gfs ="gfsv16."+ymdm+".t"+hourm+"z.pgrb2.0p25.f"+sprinti("%0.3i",fhours(h))+".grib2"
if (isfilepresent(parafile_gfs)) then
print("GFSv16 fcst file found!")
else
print("GFSv16 fcst file is missing...")
system("pwd")
end if
para_gfs=addfile("gfsv16."+ymdm+".t"+hourm+"z.pgrb2.0p25.f"+sprinti("%0.3i",fhours(h))+".grib2","r")
; ----------------------------------------------------------------------------------
;Obtaining GFSv15 fcst file
prodfile_gfs ="gfsv15."+ymdm+".t"+hourm+"z.pgrb2.0p25.f"+sprinti("%0.3i",fhours(h))+".grib2"
if (isfilepresent(prodfile_gfs)) then
print("GFSv15 fcst file found!")
else
print("GFSv15 fcst file is missing...")
system("pwd")
end if
prod_gfs=addfile("gfsv15."+ymdm+".t"+hourm+"z.pgrb2.0p25.f"+sprinti("%0.3i",fhours(h))+".grib2","r")
;-----------------------------------------------------------------------------------
if (scriptregion .eq. "pr" .or. scriptregion .eq. "ak" .or. scriptregion .eq. "epac" .or. scriptregion .eq. "wpac" .or. scriptregion .eq. "spac" .or. scriptregion .eq. "us" .or. scriptregion .eq. "nwatl" .or. scriptregion .eq. "atl" .or. scriptregion .eq. "hi" .or. scriptregion .eq. "epactc") then
CONUS_dom = False
else
CONUS_dom = True
end if
print("scriptregion: "+scriptregion+" | CONUS_dom: "+CONUS_dom(0))
;-------------
if (CONUS_dom .eq. True) then
print("CONUS_dom .eq. True, so looking for Stage-IV analysis...")
anlfile = "../analyses/ST4."+modelstrings+".06h.grb"
if (isfilepresent(anlfile)) then
print("Stage-IV analysis file found!")
else
print("Stage-IV analysis file is missing...")
system("pwd")
end if
anl=addfile(anlfile,"r")
else if (CONUS_dom .eq. False) then
print("CONUS_dom .eq. False, so looking for GFS analysis...")
;print("thisdate: "+thisdate)
thisdate_m6h = thisdate
thisdate_m6h = thisdate - 6
;print("thisdate_m6h: "+thisdate_m6h)
newstrings=tostring(ut_calendar(thisdate_m6h,-3))
; GFS precip analysis date (6h forecast from 6 hours before)
nyear=str_get_cols(newstrings,0,3)
nmonth=str_get_cols(newstrings,4,5)
nday=str_get_cols(newstrings,6,7)
nhour=str_get_cols(newstrings,8,9)
nmdh=str_get_cols(newstrings,4,9)
nymd=str_get_cols(newstrings,0,7)
nmonthind=toint(nmonth)
print("Analysis Date: YYYYMMDDHH (FXXX): "+nymd+nhour+" (F006))")
anlfile ="../analyses/gfs."+nymd+".t"+nhour+"z.pgrb2.0p25.f006.grib2"
print("anlfile: "+anlfile)
if (isfilepresent(anlfile)) then
print("GFS analysis file found!")
else
print("GFS analysis file is missing...")
end if
anl=addfile("../analyses/gfs."+nymd+".t"+nhour+"z.pgrb2.0p25.f006.grib2","r")
end if
end if
; ============================================================================
; ======================= Download data ======================================
; ============================================================================
print("fhours(h): "+fhours(h))
if (fhours(h).eq.0) then
precipprod=prod_gfs->TMP_P0_L103_GLL0({2},:,:)
precippara=para_gfs->TMP_P0_L103_GLL0({2},:,:)
precipprod=precipprod*0.0
precippara=precippara*0.0
precipplotprod=precipprod
precipplotpara=precippara
precipplot_anl=precipprod
else
if (fhours(h).eq.6) then
var = "APCP_P8_L1_GLL0_acc"
else if (fhours(h).gt.6) then
var = "APCP_P8_L1_GLL0_acc"+fhours(h)+"h"
end if
end if
print("var: "+var)
precipprod=prod_gfs->$var$
precippara=para_gfs->$var$
precipprod=precipprod*.03937
precippara=precippara*.03937
precipplotprod=precipprod
precipplotpara=precippara
if (CONUS_dom .eq. True) then
st4_date = cd_inv_calendar(2020,7,19,00,00,00,timeunits,0) ; Specify date formating changed
; print("st4_date: "+st4_date)
cur_date = cd_inv_calendar(toint(year),toint(month),toint(day),toint(hour),00,00,timeunits,0)
; print("cur_date: "+cur_date)
if (cur_date .lt. st4_date) then
precip_anl=anl->A_PCP_GDS5_SFC_acc6h(:,:)
precip_anl=precip_anl*.03937
lat2d = anl->g5_lat_0
lon2d = anl->g5_lon_1
else
precip_anl=anl->APCP_P8_L1_GST0_acc(:,:)
precip_anl=precip_anl*.03937
lat2d = anl->gridlat_0
lon2d = anl->gridlon_0
end if
precip_anl@lat2d = lat2d
precip_anl@lon2d = lon2d
if (fhours(h).eq.6) then
precipplot_anl := precip_anl
precipplot_anl = precipplot_anl*0.0
end if
precipplot_anl=precipplot_anl+precip_anl
else if (CONUS_dom .eq. False) then
precip_anl=anl->APCP_P8_L1_GLL0_acc
precip_anl=precip_anl*.03937
precipplot_anl=precipplot_anl+precip_anl
end if
end if
end if
;-----------------
dif = precipplotprod
dif = precipplotpara - precipplotprod
; dif_anl = slp_anl
; dif_anl = slppara - slp_anl
; slpprod = smth9_Wrap(slpprod,0.50,-0.25,False)
; slppara = smth9_Wrap(slppara,0.50,-0.25,False)
; slp_anl = smth9_Wrap(slp_anl,0.50,0.25,False)
; ============================================================================
; ======================= Make plot ==========================================
; ============================================================================
plot_dir = image_dir+"/"+casename+"/images/"+scriptyyyymmddhh+"/"
system("mkdir -p "+plot_dir)
wks = gsn_open_wks("png", plot_dir+"/gfs_"+scriptregion+"_totalprecip_"+casename+"_"+sprinti("%0.1i",(h)))
;gsn_define_colormap(wks,"BlueWhiteOrangeRed")
gsn_define_colormap(wks,"temp")
;gsn_define_colormap(wks,"MPL_jet")
plot=new(4,"graphic")
res = True
res@mpMinLatF = minlat
res@mpMaxLatF = maxlat
res@mpMinLonF = minlon
res@mpMaxLonF = maxlon
;res@mpOutlineBoundarySets="AllBoundaries"
res@mpOutlineBoundarySets="GeophysicalAndUSStates"
res@mpDataBaseVersion="MediumRes"
res@gsnMaximize=True
res@tmXBLabelFontHeightF=.008
res@tmYLLabelFontHeightF=.008
res@gsnRightString="Total QPF (in.)"
res@gsnAddCyclic=False
res@gsnLeftString="GFSv15 fcst init. "+hourm+"Z "+daym+" "+months(toint(monthm))+ " " +yearm+" valid "+hour+"Z "+day+ " "+months(monthind)+ " " +year+ " (F"+sprinti("%0.2i",fhours(h))+")"
res@mpOutlineDrawOrder="PostDraw"
res@mpFillColor="grey75"
res@cnInfoLabelOn=False
res@mpFillDrawOrder="PreDraw"
res@cnLabelMasking=True
res@mpGeophysicalLineColor="black"
res@mpGeophysicalLineThicknessF=2.0
res@mpNationalLineThicknessF=2.0
;res@cnRasterSmoothingOn=True
res@mpUSStateLineThicknessF=1.0
res@mpCountyLineThicknessF=.5
;res@mpUSStateLineThicknessF=3.0
res@mpNationalLineColor="black"
res@mpUSStateLineColor="black"
res@cnLineLabelsOn=False
res@pmLabelBarHeightF=.05
res@lbLabelFontHeightF=.008
res@gsnLeftStringFontHeightF=.01
res@gsnRightStringFontHeightF=.01
res@cnFillOn=True
res@mpFillOn=True
res@cnFillMode="RasterFill"
res@cnRasterSmoothingOn=True
res@cnLevelSelectionMode="ExplicitLevels"
res@cnFillColors=(/"transparent","lawngreen","green3","green4","blue1","dodgerblue1","cyan1","mediumpurple3","darkorchid3","darkorchid4","red4","red3","darkorange2","darksalmon","yellow1","sienna4","magenta2","lightpink2","mistyrose","oldlace","black"/)
res@cnLinesOn=True
res@mpLimitMode="LatLon"
res@gsnDraw=False
;res@mpProjection="Mercator"
res@mpProjection="LambertConformal"
if scriptregion.eq."spac" then
res@mpLambertParallel1F = -33.0 ; two parallels
res@mpLambertParallel2F = -45.0
else
res@mpLambertParallel1F = 33.0 ; two parallels
res@mpLambertParallel2F = 45.0
end if
res@mpLambertMeridianF = -95.0 ; central meridian
if scriptregion.eq."ak" .or. scriptregion.eq."epac" then
res@mpLambertMeridianF = 215.0 ; central meridian
else if scriptregion.eq."wpac" then
res@mpLambertMeridianF = 145.0 ; central meridian
else if scriptregion.eq."spac" then
res@mpLambertMeridianF = 160.0 ; central meridian
else if scriptregion.eq."pr" then
res@mpLambertMeridianF = 294.0 ; central meridian
else if scriptregion.eq."atl" then
res@mpLambertMeridianF = 355.0 ; central meridian
res@gsnAddCyclic = True
else if scriptregion.eq."hi" then
res@mpLambertMeridianF = 202.0 ; central meridian
else if scriptregion.eq."epactc" then
res@mpLambertMeridianF = 260.0 ; central meridian
end if
end if
end if
end if
end if
end if
end if
res@mpLimitMode = "LatLon"
;res@lbLabelStride=1
res@cnLinesOn=False
res@lbLabelAutoStride=True
res@gsnFrame=False
res@lbLabelBarOn=True
if scriptregion.eq."us" then
res@mpNationalLineThicknessF=2.0
res@mpGeophysicalLineThicknessF=2.0
end if
;; Change Contour Levels Here
;; Last line without a semicolon will be used in all plots
; res@cnLevels=(/.01,0.50,1.00,1.50,2.00,3.0,4.00,5.0,6.00,8.0,10.,15.0,20.0,25.0,30.0,35.0,40.0,45.0,50.0,60.0/)
res@cnLevels=(/.01,0.10,0.25,0.50,0.75,1.00,1.5,2.00,3.0,4.00,5.00,6.0,8.00,10.0,15.0,20.0,25.0,30.0,40.0,45.0/)
; res@cnLevels=(/.01,0.10,0.25,0.50,1.00,1.50,2.0,3.00,4.0,5.00,6.0,7.0,8.00,9.00,10.0,15.0,17.5,20.0,25.0,30.0/)
; res@cnLevels=(/.01,0.10,0.25,0.50,0.75,1.0,1.50,2.0,2.50,3.0,4.0,5.00,6.00,8.00,10.0,12.0,14.0,16.0,18.0,20.0/)
; res@cnLevels=(/.01,0.10,0.25,0.50,0.75,1.0,1.25,1.5,1.75,2.0,2.5,3.00,4.00,5.00,6.00,7.00,7.50,8.00,9.00,10.0/)
res@cnLineLabelInterval=1
res@cnLineLabelDensityF=1.5
plot(0) = gsn_csm_contour_map(wks,precipplotprod,res) ; create a default plot
;---------------------------------------------------------------------
res@gsnLeftString="GFSv16 fcst init. "+hourm+"Z "+daym+" "+months(toint(monthm))+ " " +yearm+" valid "+hour+"Z "+day+ " "+months(monthind)+ " " +year+ " (F"+sprinti("%0.2i",fhours(h))+")"
plot(1) = gsn_csm_contour_map(wks,precipplotpara,res) ; create a default plot
;-------------------------------------------------
resdif=True
resdif=res
resdif@cnFillPalette=("BlueWhiteOrangeRed")
delete(resdif@cnFillColors)
delete(resdif@cnLevels)
resdif@cnLevels:=(/-5,-4,-3,-2,-1.5,-1,-.5,-.25,0,.25,.5,1,1.5,2,3,4,5/)
resdif@gsnLeftString="GFSv16 fcst minus GFSv15 fcst valid "+hour+"Z "+day+ " "+months(monthind)+ " " +year+ " (F"+sprinti("%0.2i",fhours(h))+")"
plot(2) = gsn_csm_contour_map(wks,dif,resdif) ; create a default plot
; -----------------------------------------------
if (CONUS_dom .eq. True) then
model_string = "Stage-IV"
print("Plotting Stage-IV takes a long time...")
else if (CONUS_dom .eq. False) then
model_string = "GFS"
end if
end if
res@gsnLeftString=model_string+" analysis valid "+hour+"Z "+day+ " "+months(monthind)+ " " +year
plot(3) = gsn_csm_contour_map(wks,precipplot_anl,res) ; create a default plot
;-------------------------------------------------
resP=True
resP@gsnMaximize=True
resP@txFontHeightF=.012
resP@gsnPanelLabelBar=False
resP@gsnFrame=False
gsn_panel(wks,plot,(/2,2/),resP)
print("Framing figure")
frame(wks)
print("Deleting workstation")
delete(wks)
system("convert "+plot_dir+"/gfs_"+scriptregion+"_totalprecip_"+casename+"_"+sprinti("%0.1i",(h))+".png -trim +repage "+plot_dir+"/gfs_"+scriptregion+"_totalprecip_"+casename+"_"+sprinti("%0.1i",(h))+".png")
end do
;------------------------------------------------
print("======================")
print("Script has finished!")
print("======================")
end