-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotMap.ncl
1415 lines (1138 loc) · 48 KB
/
plotMap.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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"
load "readGEFS.ncl"
load "readGDAS.ncl"
load "readConsensus.ncl"
load "readClimo.ncl"
load "utilityFuncs.ncl"
FILETYPE_MAP = "png"
; FILETYPE_MAP = "X11"
; FILETYPE_MAP@wkHeight = 800
; FILETYPE_MAP@wkWidth = 800
FILETYPE_SS = "png"
TRIM_WIDTH = 112
PLOT_RESIZE = "75%"
SYNC_TIMES = True ; Only
; Temporary
perturb = sprinti( "%0.2i", ispan(0,20,1) )
members = "p"+perturb
members(0) = "c00"
delete(perturb)
; For spread-skill plots
N_ENS = 21 ; Only used for Kolczynski et al. 2011 corrections (currently commented out)
BIN_SIZE = 10000 ; Number of points per bin
; Functions
; Sort
if isdefined("sortIntoBins") then undef("sortIntoBins") end if
function sortIntoBins \\
( \\
binSize : integer, \\
x[*] : numeric, \\
y[*] : numeric \\
)
local nX, nBins, sortLoc, bins, xBinAvg, yBinAvg, xBinStdDev, yBinStdDev
begin
; determine number of bins
nX = dimsizes(x)
nBins = nX/binSize
; sort by x
sortLoc = dim_pqsort( x, 1 )
x = x(sortLoc)
y = y(sortLoc)
bins = new( (/nBins+1/), typeof(x) )
xBinAvg = new( (/nBins/), typeof(x) )
xBinStdDev = new( (/nBins/), typeof(x) )
yBinAvg = new( (/nBins/), typeof(y) )
yBinStdDev = new( (/nBins/), typeof(y) )
do i=0, nBins-1
binBegin = i*binSize
binEnd = binBegin+binSize-1
bins(i) = x( binBegin )
bins(i+1) = x( binEnd )
xBinAvg(i) = avg( x(binBegin:binEnd) )
yBinAvg(i) = avg( y(binBegin:binEnd) )
xBinStdDev(i) = stddev( x(binBegin:binEnd) )
yBinStdDev(i) = stddev( y(binBegin:binEnd) )
end do
bins@xBinAvg = xBinAvg
bins@yBinAvg = yBinAvg
bins@xBinStdDev = xBinStdDev
bins@yBinStdDev = yBinStdDev
return bins
end ; sortIntoBins
if isdefined("findLevelDim") then undef("findLevelDim") end if
function findLevelDim \\
( \\
variable : numeric \\
)
local dimNames, dimName, i
begin
dimNames = getvardims(variable)
do i=0, dimsizes(dimNames)-1
dimName = dimNames(i)
if( str_get_cols(dimName, 0, 2) .eq. "lv_" ) then
dimName@index = i
return dimName
end if
end do
; print("No dimension name begining with 'lv_' found!")
; printVarSummary(variable)
dimName = default_fillvalue("string")
dimName@index = -1
return dimName
end ; findLevelDim
if isdefined("rectifyLevels") then undef("rectifyLevels") end if
function rectifyLevels \\
(
forecast : numeric, \\
obs : numeric \\
)
local forecastLevelDim, obsLevelDim, obsLevels, forecastLevels, newObs, index
begin
newObs = obs
forecastLevelDim = findLevelDim(forecast)
obsLevelDim = findLevelDim(obs)
if( ismissing(forecastLevelDim) .and. .not. ismissing(obsLevelDim) ) then
print("Slicing single forecast level " + forecast@level + " from multi-level obs")
obsLevels = obs&$obsLevelDim$
index = ind(obsLevels.eq.forecast@level)
if(.not. ismissing(index) ) then
newObs := slice( newObs, obsLevelDim@index, index )
else
print("FATAL: level not found in obs!")
end if
else
if ( .not. ismissing(forecastLevelDim) .and. .not. ismissing(obsLevelDim) ) then
;
; GDAS has more vertical levels than the ensemble forecast, so regrid in vertical if the field has a vertical component
;
forecastLevels = forecast&$forecastLevelDim$
obsLevels = newObs&$obsLevelDim$
if([email protected]@units) then
if([email protected]."hPa" .and. [email protected]."Pa") then
obsLevels = obsLevels * 100
obsLevels@units = "Pa"
end if
if([email protected]."Pa" .and. [email protected]."hPa") then
obsLevels = obsLevels / 100
obsLevels@units = "hPa"
end if
end if
if( dimsizes(forecastLevels).ne.dimsizes(obsLevels) .or. .not. all( forecastLevels .eq. obsLevels ) ) then
print("Reducing " + obsLevelDim + " in " + obs@long_name + " to " + forecastLevelDim)
newObs := int2p_n_Wrap( obsLevels, newObs, forecastLevels, 1, obsLevelDim@index )
end if
end if
end if
return newObs
end ; rectifyLevels
if( isdefined("loadDefaultMapRes") ) then undef("loadDefaultMapRes") end if
function loadDefaultMapRes()
local mapRes
begin
mapRes = True
; do not advance frame immediately
mapRes@gsnDraw = False
mapRes@gsnFrame = False
mapRes@gsnAddCyclic = True
; map attributes
mapRes@mpDataBaseVersion = "MediumRes" ; Default is LowRes
mapRes@mpOutlineDrawOrder = "PostDraw" ; Draw map outlines last
mapRes@mpDataSetName = "Earth..4"
mapRes@mpGridLineDashPattern = 2 ; Dashed lat/lon Lines
mapRes@mpGridAndLimbOn = True ; Draw lat/lon Lines
mapRes@mpFillOn = False ; don't fill land grey
mapRes@mpProjection = "Hammer"
mapRes@gsnStringFontHeightF = 0.017
mapRes@mpPerimOn = False
; tick mark attributes
mapRes@tmXTOn = False ; Turn off top tick marks
mapRes@tmXTLabelsOn = False ; Turn off top tick labels
mapRes@tmYROn = False ; Turn off right tick marks
mapRes@tmYRLabelsOn = False ; Turn off right tick labels
; contour attributes
mapRes@cnFillOn = True
mapRes@cnFillMode = "RasterFill"
mapRes@cnLinesOn = False
mapRes@cnLineLabelsOn = False
mapRes@cnInfoLabelOn = False
mapRes@cnLevelSelectionMode = "ManualLevels"
mapRes@cnSpanFillPalette = True
; label bar
mapRes@lbLabelBarOn = False ; we are plotting a joint label bar, so turn of the individual ones
return mapRes
end ; loadDefaultMapRes
if( isdefined("loadDefaultPanelRes") ) then undef("loadDefaultPanelRes") end if
function loadDefaultPanelRes()
local panelRes
begin
panelRes = True
panelRes@gsnPanelLabelBar = True
panelRes@lbLabelAutoStride = True
panelRes@lbOrientation = "Vertical"
panelRes@lbLabelFontHeightF = 0.012
panelRes@gsnFrame = False
panelRes@gsnDraw = False
return panelRes
end ; loadDefaultPanelRes
if( isdefined("loadDefaultZonalRes") ) then undef("loadDefaultZonalRes") end if
function loadDefaultZonalRes()
local zonalRes
begin
zonalRes = True
zonalRes@gsnDraw = False
zonalRes@gsnFrame = False
zonalRes@gsnStringFontHeightF = 0.038
; tick mark attributes
zonalRes@tmXTOn = False ; Turn off top tick marks
zonalRes@tmXTLabelsOn = False ; Turn off top tick labels
zonalRes@tmYROn = False ; Turn off right tick marks
zonalRes@tmYRLabelsOn = False ; Turn off right tick labels
; contour attributes
zonalRes@cnFillOn = True
zonalRes@cnFillMode = "RasterFill"
zonalRes@cnLinesOn = False
zonalRes@cnLineLabelsOn = False
zonalRes@cnInfoLabelOn = False
zonalRes@cnLevelSelectionMode = "ManualLevels"
zonalRes@cnSpanFillPalette = True
; axis attributes
zonalRes@trXReverse = True
zonalRes@tmYRMode = "Automatic"
zonalRes@trYMinF = 100
zonalRes@vpWidthF = 1.5
; label bar
zonalRes@lbLabelBarOn = False ; we are plotting a joint label bar, so turn of the individual ones
return zonalRes
end ; loadDefaultZonalRes
if( isdefined("loadDefaultSpreadSkillRes") ) then undef("loadDefaultSpreadSkillRes") end if
function loadDefaultSpreadSkillRes()
local xyRes
begin
xyRes = True
xyRes@tmXTOn = False
xyRes@tmYROn = False
xyRes@tiXAxisString = "Bin Mean Ensemble Variance"
xyRes@tiYAxisString = "Intra-bin Error Variance"
xyRes@tiMainConstantSpacingF = 1.0
return xyRes
end ; loadDefaultSpreadSkillRes
if( isdefined("loadDefaultNormSpreadSkillRes") ) then undef("loadDefaultNormSpreadSkillRes") end if
function loadDefaultNormSpreadSkillRes()
local xyRes
begin
xyRes = True
xyRes@tmXTOn = False
xyRes@tmYROn = False
xyRes@tiXAxisString = "Bin Mean Variance of Ensemble/Climo"
xyRes@tiYAxisString = "Intra-bin Variance of Error/Climo"
xyRes@tiMainConstantSpacingF = 1.0
return xyRes
end ; loadDefaultSpreadSkillRes
if( isdefined("readPlotAtts") ) then undef("readPlotAtts") end if
function readPlotAtts( res[1]: logical, filename[1]: string )
local input, atts, values, nAtts, a
begin
print( "Reading attributes from file " + filename )
nclVer = str_get_cols( get_ncl_version(), 0, 3 )
if( .not. fileexists(filename) ) then
print( "Attribute file " + filename + " not found, using defaults" )
return res
end if
input = str_split_csv( asciiread( filename, -1, "string" ), "=", 1 )
; print(input)
if( input(0,0).eq."missing" ) then return res end if
atts = input(:,0)
values = input(:,1)
nAtts = dimsizes(atts)
res = True
do a=0, nAtts-1
if( isatt( res, atts(a) ) ) then delete( res@$atts(a)$ ) end if
; print( "Setting " + atts(a) + " to " + values(a) + " from " + filename )
res@$atts(a)$ = values(a)
end do ; a
return res
end ; readPlotAtts
if( isdefined("makeMapSpreadPlot") ) then undef("makeMapSpreadPlot") end if
procedure makeMapSpreadPlot ( \\
outfile[1] : graphic, \\
ensSDtimeAvg[*][*] : numeric, \\
rmseTimeAvg[*][*] : numeric, \\
spreadSkillRatio[*][*] : numeric, \\
spreadMapRes[1] : logical, \\
rmseMapRes[1] : logical, \\
ratioMapRes[1] : logical, \\
twoPlotPanelRes[1] : logical, \\
bottomPanelRes[1] : logical \\
)
local plots, errorPanelId, mapPanelId, outlierPanelId
begin
plots = new(3, graphic)
plots(0) = gsn_csm_contour_map( outfile, ensSDtimeAvg, spreadMapRes )
plots(1) = gsn_csm_contour_map( outfile, rmseTimeAvg, rmseMapRes )
plots(2) = gsn_csm_contour_map( outfile, spreadSkillRatio, ratioMapRes )
topPanelId = gsn_panel_return( outfile, plots(0:1), (/2,1/), twoPlotPanelRes )
bottomPanelId = gsn_panel_return( outfile, plots(2), (/1,1/), bottomPanelRes )
maximize_output( outfile, True )
end ; makeMapSpreadPlot
if( isdefined("makeMapOutlierPlot") ) then undef("makeMapOutlierPlot") end if
procedure makeMapOutlierPlot ( \\
outfile[1] : graphic, \\
spreadSkillRatio[*][*] : numeric, \\
outlierPercentage[*][*] : numeric, \\
errorTimeAvg[*][*] : numeric, \\
ratioMapRes[1] : logical, \\
outlierMapRes[1] : logical, \\
biasMapRes[1] : logical, \\
topPanelRes[1] : logical, \\
middlePanelRes[1] : logical, \\
bottomPanelRes[1] : logical \\
)
local plots, errorPanelId, mapPanelId, outlierPanelId
begin
plots = new(3, graphic)
plots(0) = gsn_csm_contour_map( outfile, spreadSkillRatio, ratioMapRes )
plots(1) = gsn_csm_contour_map( outfile, outlierPercentage, outlierMapRes )
plots(2) = gsn_csm_contour_map( outfile, errorTimeAvg, biasMapRes )
topPanelId = gsn_panel_return( outfile, plots(0), (/1,1/), topPanelRes )
middlePanelId = gsn_panel_return( outfile, plots(1), (/1,1/), middlePanelRes )
bottomPanelId = gsn_panel_return( outfile, plots(2), (/1,1/), bottomPanelRes )
maximize_output( outfile, True )
end ; makeMapOutlierPlot
if( isdefined("makeZonalSpreadPlot") ) then undef("makeZonalSpreadPlot") end if
procedure makeZonalSpreadPlot ( \\
outfile[1] : graphic, \\
ensSDtimeAvg[*][*] : numeric, \\
rmseTimeAvg[*][*] : numeric, \\
spreadSkillRatio[*][*] : numeric, \\
spreadZonalRes[1] : logical, \\
rmseZonalRes[1] : logical, \\
ratioZonalRes[1] : logical, \\
twoPlotPanelRes[1] : logical, \\
bottomPanelRes[1] : logical \\
)
local plots, errorPanelId, mapPanelId
begin
plots = new(3, graphic)
plots(0) = gsn_csm_pres_hgt( outfile, ensSDtimeAvg, spreadZonalRes )
plots(1) = gsn_csm_pres_hgt( outfile, rmseTimeAvg, rmseZonalRes )
plots(2) = gsn_csm_pres_hgt( outfile, spreadSkillRatio, ratioZonalRes )
topPanelId = gsn_panel_return( outfile, plots(0:1), (/2,1/), twoPlotPanelRes )
bottomPanelId = gsn_panel_return( outfile, plots(2), (/1,1/), bottomPanelRes )
maximize_output( outfile, True )
end ; makeZonalSpreadPlot
if( isdefined("makeZonalOutlierPlot") ) then undef("makeZonalOutlierPlot") end if
procedure makeZonalOutlierPlot ( \\
outfile[1] : graphic, \\
spreadSkillRatio[*][*] : numeric, \\
outlierPercentage[*][*] : numeric, \\
errorTimeAvg[*][*] : numeric, \\
ratioZonalRes[1] : logical, \\
outlierZonalRes[1] : logical, \\
biasZonalRes[1] : logical, \\
topPanelRes[1] : logical, \\
middlePanelRes[1] : logical, \\
bottomPanelRes[1] : logical \\
)
local plots, errorPanelId, mapPanelId, outlierPanelId
begin
plots = new(3, graphic)
plots(0) = gsn_csm_pres_hgt( outfile, spreadSkillRatio, ratioZonalRes )
plots(1) = gsn_csm_pres_hgt( outfile, outlierPercentage, outlierZonalRes )
plots(2) = gsn_csm_pres_hgt( outfile, errorTimeAvg, biasZonalRes )
topPanelId = gsn_panel_return( outfile, plots(0), (/1,1/), topPanelRes )
middlePanelId = gsn_panel_return( outfile, plots(1), (/1,1/), middlePanelRes )
bottomPanelId = gsn_panel_return( outfile, plots(2), (/1,1/), bottomPanelRes )
maximize_output( outfile, True )
end ; makeZonalOutlierPlot
if( isdefined("makeXYbinPlot") ) then undef("makeXYbinPlot") end if
procedure makeXYbinPlot ( \\
outfile[1] : graphic, \\
x[*] : numeric, \\
y[*] : numeric, \\
xBins[*] : numeric, \\
yErrors[*] : numeric, \\
xyResIn[1] : logical, \\
binRes[1] : logical, \\
regLineRes[1] : logical \\
)
local outfile, errorBars, points, xx, xy, yx, yy, i, plot, xyRes, binRes, regY, regLineRes, pointRes, idealLineRes, ideal, linreg2
begin
xyRes = True
xyRes@gsnDraw = False ; don't draw
xyRes@gsnFrame = False ; don't advance frame
xyRes@gsnMaximize = True
xyRes@xyMarkLineModes = (/"Markers"/)
xyRes@xyMarkers = (/16/)
xyRes@xyMarkerColors = (/"blue"/)
xyRes@xyMarkerSizeF = 0.002
xyRes@tmXMajorGrid = True
xyRes@tmXMajorGridLineDashPattern = 2
xyRes@trXMinF = xBins(0)
xyRes@trXMaxF = xBins( dimsizes(xBins)-1 )
xyRes@tmYMajorGrid = True
xyRes@tmYMajorGridLineDashPattern = 2
; pointRes = True
; pointRes@gsMarkerIndex = xyRes@xyMarkers
; pointRes@gsMarkerColor = xyRes@xyMarkerColors
; pointRes@gsMarkerSizeF = xyRes@xyMarkerSizeF
copy_VarAtts(xyResIn, xyRes)
plot = gsn_csm_xy(outfile, x, y, xyRes)
errorBars = new( (/ 2, dimsizes(x) /), graphic )
do i=0, dimsizes(x)-1
xx = (/ xBins(i) , xBins(i+1) /)
xy = (/ y(i) , y(i) /)
errorBars(0,i) = gsn_add_polyline(outfile, plot, xx, xy, binRes)
yx = (/ x(i) , x(i) /)
yy = (/ y(i) - yErrors(i) , y(i) + yErrors(i) /)
errorBars(1,i) = gsn_add_polyline(outfile, plot, yx, yy, binRes)
end do
if( regLineRes .and. all( isatt( regLineRes, (/ "slope", "intercept" /) ) ) ) then
regY = x * regLineRes@slope + regLineRes@intercept
linreg = gsn_add_polyline(outfile, plot, x, regY, regLineRes)
; corrected per Kolczynski et al. 2011
regY = x * regLineRes@correctedSlope + regLineRes@correctedIntercept
regLineRes@gsLineDashPattern = 2
linreg2 = gsn_add_polyline(outfile, plot, x, regY, regLineRes)
end if
idealLineRes = True
idealLineRes@gsLineColor = "grey"
ideal = gsn_add_polyline(outfile, plot, (/ xyRes@trXMinF, xyRes@trXMaxF/), (/ xyRes@trYMinF, xyRes@trYMaxF/), idealLineRes )
; points = gsn_add_polymarker(outfile, plot, x, y, pointRes)
draw(outfile)
frame(outfile)
return
end ; makeXYbinPlot
if( isdefined("makeSpreadSkillPlot") ) then undef("makeSpreadSkillPlot") end if
procedure makeSpreadSkillPlot ( \\
outfile[1] : graphic, \\
ensSD[*] : numeric, \\
ensError[*] : numeric, \\
ensSize[1] : integer, \\
binSize[1] : integer, \\
xyPlotRes[1] : logical, \\
polyRes[1] : logical, \\
regLineRes[1] : logical \\
)
local bins, ensVarBinAvg, errorBinVar, slope, gammaParameter
begin
ensVar = ensSD^2
bins = sortIntoBins( binSize, ensVar, ensError )
ensVarBinAvg = bins@xBinAvg
errorBinVar = bins@yBinStdDev ^2
if( regLineRes ) then
slope = regline( ensVarBinAvg, errorBinVar )
regLineRes@slope = slope
regLineRes@intercept = slope@yintercept
regLineRes@gsLineColor = "blue"
xyPlotRes@gsnRightString = "y=" + sprintf( "%0.3f", slope) + "x + " + sprintf( "%0.3f", slope@yintercept )
; corrected per Kolczynski et al. 2011
gammaParameter = 2.0 * avg( ensVar^2 ) / variance( ensVar )
regLineRes@correctedSlope = slope / ( 1 - gammaParameter/(ensSize+1) )
regLineRes@correctedIntercept = slope@yintercept + slope * avg( ensVar ) / ( 1 - (ensSize+1)/gammaParameter )
xyPlotRes@gsnRightString = "y=" + sprintf( "%0.3f", slope) + "x + " + sprintf( "%0.3f", slope@yintercept ) + "~C~" + \\
"y'=" + sprintf( "%0.3f", regLineRes@correctedSlope) + "x + " + sprintf( "%0.3f", regLineRes@correctedIntercept )
end if
makeXYbinPlot( outfile, ensVarBinAvg, errorBinVar, bins, errorBinVar*0, xyPlotRes, polyRes, regLineRes )
end ; makeSpreadSkillPlot
; ****************
; Main program
; ****************
begin
; read input file
input = asciiread( inputFilename, 32, "string" )
ensemblePaths = str_split( input(0), "," )
ensGridTypes = str_split( input(1), "," )
experimentNames = str_split( input(2), "," )
startYYYYMMDDHHs = str_split( input(3), "," )
endYYYYMMDDHHs = str_split( input(4), "," )
forecastFrequenciesHr = stringtointeger( str_split( input(5), "," ) )
leadTimeHr = stringtointeger( input(6) )
variableLabel = input(7)
variableName = input(8)
variableNiceName = input(9)
avgVariableName = str_sub_str(variableName, "P1", "P2")
verificationPath = input(10)
verificationVariableName= input(11)
verificationType = input(12)
verifGrid = input(13)
useClimatology = input(14).eq."True"
climatologyPath = input(15)
climoVariableName = input(16)
climatologyGrid = input(17)
outputPath = input(18)
spreadMapAttFilename = input(19)
spreadZonalAttFilename = input(20)
rmseMapAttFilename = input(21)
rmseZonalAttFilename = input(22)
ratioMapAttFilename = input(23)
ratioZonalAttFilename = input(24)
biasMapAttFilename = input(25)
biasZonalAttFilename = input(26)
outlierMapAttFilename = input(27)
outlierZonalAttFilename = input(28)
spreadSkillAttFilename = input(29)
normSpreadSkillAttFilename = input(30)
deleteAttFiles = input(31).eq."True"
experimentNameList = NewList("fifo")
ensSDtimeAvgList = NewList("fifo")
rmseTimeAvgList = NewList("fifo")
spreadSkillRatioList = NewList("fifo")
errorTimeAvgList = NewList("fifo")
ensSDlist = NewList("fifo")
errorList = NewList("fifo")
ensSDnormList = NewList("fifo")
errorNormList = NewList("fifo")
outlierPercentageList = NewList("fifo")
spreadTimeAvgMax = 0.0
ratioMax = 0.0
errorTimeAvgMax = 0.0
spreadMax = 0.0
normSpreadMax = 0.0
outlierMax = 0.0
nExperiments = dimsizes(experimentNames)
; If we are syncing times, produce a list of times available for all experiments
if(SYNC_TIMES) then
do e=0, nExperiments-1, 1
ensemblePath = ensemblePaths(e)
ensGridType = ensGridTypes(e)
startYYYYMMDDHH = startYYYYMMDDHHs(e)
endYYYYMMDDHH = endYYYYMMDDHHs(e)
forecastFrequencyHr = forecastFrequenciesHr(e)
; break input time strings into its different components
startYear = stringtointeger( str_get_cols( startYYYYMMDDHH, 0, 3) )
startMonth = stringtointeger( str_get_cols( startYYYYMMDDHH, 4, 5) )
startDay = stringtointeger( str_get_cols( startYYYYMMDDHH, 6, 7) )
startHour = stringtointeger( str_get_cols( startYYYYMMDDHH, 8, 9) )
endYear = stringtointeger( str_get_cols( endYYYYMMDDHH, 0, 3) )
endMonth = stringtointeger( str_get_cols( endYYYYMMDDHH, 4, 5) )
endDay = stringtointeger( str_get_cols( endYYYYMMDDHH, 6, 7) )
endHour = stringtointeger( str_get_cols( endYYYYMMDDHH, 8, 9) )
; convert times into epoch-seconds
startTime = cd_inv_calendar( startYear, startMonth, startDay, startHour, 0, 0, "seconds since 1970-1-1 00:00:00", 0 )
endTime = cd_inv_calendar( endYear, endMonth, endDay, endHour, 0, 0, "seconds since 1970-1-1 00:00:00", 0 )
forecastFrequency = forecastFrequencyHr * 3600;
; build array with all of the initialization times
nTimes = doubletointeger( (endTime - startTime) / forecastFrequency ) + 1
if(nTimes .gt. 1)
initTimes = fspan( startTime, endTime, nTimes )
else
initTimes = startTime
end if
copy_VarAtts( startTime, initTimes )
; print( cd_string(initTimes, "%Y%N%D%H") )
avgVariableName = str_sub_str(variableName, "P1", "P2")
validTimes = validGEFSmean( ensemblePath, ensGridType, initTimes, leadTimeHr, avgVariableName )
nTimes = dimsizes(validTimes)
if(e.eq.0) then
syncTimes = validTimes
else
; only keep times already included in previously processed experiments
syncTimes := validTimes( get1Dindex_Include( validTimes, syncTimes ) )
end if
; print( experimentNames(e) + ":" + cd_string(initTimes, "%Y%N%D%H") )
; print("syncTimes:" + cd_string(syncTimes, "%Y%N%D%H") )
delete(validTimes)
validTimes = validGEFS( ensemblePath, ensGridType, members, initTimes, leadTimeHr, variableName )
nTimes = dimsizes(validTimes)
if(e.eq.0) then
syncTimesFull = validTimes
else
; only keep times already included in previously processed experiments
syncTimesFull := validTimes( get1Dindex_Include( validTimes, syncTimesFull ) )
end if
delete(validTimes)
delete(initTimes)
end do ; e=0, nExperiments-1, 1
print("Initialization times used for mean/spread:")
print( " " + cd_string(syncTimes, "%Y%N%D%H") )
print("Initialization times used for full ensemble:")
print( " " + cd_string(syncTimesFull, "%Y%N%D%H") )
delete(nTimes)
end if ; (SYNC_TIMES)
nTimes = new(nExperiments, integer)
nTimesFull = new(nExperiments, integer)
do e=0, nExperiments-1, 1
experimentName = experimentNames(e)
print( "Computing data for " + experimentName )
ensemblePath = ensemblePaths(e)
ensGridType = ensGridTypes(e)
if(SYNC_TIMES) then
initTimes = syncTimes
else
; build array with all of the initialization times
startYYYYMMDDHH = startYYYYMMDDHHs(e)
endYYYYMMDDHH = endYYYYMMDDHHs(e)
forecastFrequencyHr = forecastFrequenciesHr(e)
; break input time strings into its different components
startYear = stringtointeger( str_get_cols( startYYYYMMDDHH, 0, 3) )
startMonth = stringtointeger( str_get_cols( startYYYYMMDDHH, 4, 5) )
startDay = stringtointeger( str_get_cols( startYYYYMMDDHH, 6, 7) )
startHour = stringtointeger( str_get_cols( startYYYYMMDDHH, 8, 9) )
endYear = stringtointeger( str_get_cols( endYYYYMMDDHH, 0, 3) )
endMonth = stringtointeger( str_get_cols( endYYYYMMDDHH, 4, 5) )
endDay = stringtointeger( str_get_cols( endYYYYMMDDHH, 6, 7) )
endHour = stringtointeger( str_get_cols( endYYYYMMDDHH, 8, 9) )
; convert times into epoch-seconds
startTime = cd_inv_calendar( startYear, startMonth, startDay, startHour, 0, 0, "seconds since 1970-1-1 00:00:00", 0 )
endTime = cd_inv_calendar( endYear, endMonth, endDay, endHour, 0, 0, "seconds since 1970-1-1 00:00:00", 0 )
forecastFrequency = forecastFrequencyHr * 3600;
nTimes(e) = doubletointeger( (endTime - startTime) / forecastFrequency ) + 1
initTimes = fspan( startTime, endTime, nTimes(e) )
copy_VarAtts( startTime, initTimes )
; print( cd_string(initTimes, "%Y%N%D%H") )
initTimes := validGEFSmean( ensemblePath, ensGridType, avgVariableName, initTimes, leadTimeHr )
; print( cd_string(initTimes, "%Y%N%D%H") )
delete(startYYYYMMDDHH)
delete(endYYYYMMDDHH)
delete(forecastFrequencyHr)
delete(startYear)
delete(startMonth)
delete(startDay)
delete(startHour)
delete(endYear)
delete(endMonth)
delete(endDay)
delete(endHour)
delete(startTime)
delete(endTime)
delete(forecastFrequency)
end if ; (.not.SYNC_TIMES)
nTimes(e) = dimsizes(initTimes)
leadTime = leadTimeHr * 3600
; compute valid times
validTimes = initTimes + leadTime
copy_VarAtts( initTimes, validTimes )
ensMean = readGEFSmean( ensemblePath, ensGridType, initTimes, leadTimeHr, avgVariableName )
ensSD = readGEFSspread( ensemblePath, ensGridType, initTimes, leadTimeHr, avgVariableName )
if(verificationType.eq."gdas") then
obs = readGDAS( verificationPath, verifGrid, validTimes, verificationVariableName )
else if (verificationType.eq."consensus") then
obs = readConsensus( verificationPath, verifGrid, validTimes, verificationVariableName )
else if (verificationType.eq."control") then
obs = readGEFS( verificationPath, verifGrid, "gec00", validTimes, 0, verificationVariableName )
else
print("Fatal error: unknown verification type specified (plotMap.ncl:main)")
status_exit(2)
end if end if end if
dimNames = getvardims(ensMean)
timeDim = ind(dimNames.eq."initialization_time")
; if(any(abs(ensMean).gt.1E5)) then
; print("Possibly missing data for " + experimentName)
; do t=0, nTimes(e)-1, 1
; print(cd_string(initTimes(t), "%Y%N%D_%H" ) + "" )
; end do
; ensMean = ensMean@_FillValue
; end if
;
; GDAS has more vertical levels than the ensemble forecast, so regrid in vertical if the field has a vertical component
;
obs := rectifyLevels(ensMean, obs)
if( any( dimsizes(ensMean) .ne. dimsizes(obs) ) ) then
print("FATAL: Dimensions of ensMean and obs do not match!")
printVarSummary(ensMean)
printVarSummary(obs)
end if
error = ensMean - obs
copy_VarMeta(ensMean, error)
error@long_name = "Error in ensemble mean"
if( .not.ismissing(timeDim) ) then
ensVar = ensSD^2
copy_VarMeta(ensSD, ensVar)
ensVar@long_name = "ensemble variance"
ensSDtimeAvg = dim_avg_n_Wrap( ensVar, timeDim )
ensSDtimeAvg = sqrt( ensSDtimeAvg )
rmseTimeAvg = dim_rmsd_n_Wrap( ensMean, obs, timeDim )
errorTimeAvg = dim_avg_n_Wrap( error, timeDim )
delete(ensVar)
else
ensSDtimeAvg = ensSD
rmseTimeAvg = abs( ensMean - obs )
errorTimeAvg = error
end if ; ( .not.ismissing(timeDim) )
spreadSkillRatio = ( ensSDtimeAvg/where(rmseTimeAvg.gt.1E-9, rmseTimeAvg, 1E-9) - 1.0 ) * 100
copy_VarMeta( ensSDtimeAvg, spreadSkillRatio )
spreadSkillRatio@long_name = "Percent difference from ideal spread-skill ratio"
spreadSkillRatio@units = "%"
ListPush( experimentNameList, echo(experimentName) )
ListPush( ensSDtimeAvgList, echo(ensSDtimeAvg) )
ListPush( rmseTimeAvgList, echo(rmseTimeAvg) )
ListPush( spreadSkillRatioList, echo(spreadSkillRatio) )
ListPush( errorTimeAvgList, echo(errorTimeAvg) )
ListPush( ensSDlist, echo(ensSD) )
ListPush( errorList, echo(error) )
ensSDtimeAvg_1D = ndtooned(ensSDtimeAvg)
rmseTimeAvg_1D = ndtooned(rmseTimeAvg)
spreadSkillRatio_1D = ndtooned(spreadSkillRatio)
errorTimeAvg_1D = ndtooned(errorTimeAvg)
ensSD_1D = ndtooned(ensSD)
qsort(ensSDtimeAvg_1D)
qsort(rmseTimeAvg_1D)
qsort(spreadSkillRatio_1D)
qsort(errorTimeAvg_1D)
qsort(ensSD_1D)
percentile = dimsizes(ensSDtimeAvg_1D)/100 * 92
spreadTimeAvgMax = max( (/spreadTimeAvgMax, ensSDtimeAvg_1D(percentile), rmseTimeAvg_1D(percentile) /) )
ratioMax = max( (/ratioMax, spreadSkillRatio_1D(percentile) /) )
errorTimeAvgMax = max( (/errorTimeAvgMax, abs( errorTimeAvg_1D(percentile) ) /) )
spreadMax = max( (/spreadMax, ensSD_1D( dimsizes(ensSD_1D)/100 * 98 ) /) )
if(useClimatology) then
climoMean = readClimoMean( climatologyPath, climatologyGrid, validTimes, climoVariableName )
climoSD = readClimoStdDev( climatologyPath, climatologyGrid, validTimes, climoVariableName )
;
; Climo has fewer vertical levels than the ensemble forecast, so regrid in vertical if the field has a vertical component
;
ensMean_climo = rectifyLevels(climoMean, ensMean)
ensSD_climo = rectifyLevels(climoMean, ensSD)
error_climo = rectifyLevels(climoMean, error)
ensSD_norm = ensSD_climo/climoSD
error_norm = error_climo/climoSD
copy_VarCoords(ensSD_climo, ensSD_norm)
copy_VarCoords(error_climo, error_norm)
ListPush( ensSDnormList, echo(ensSD_norm) )
ListPush( errorNormList, echo(error_norm) )
ensSDnorm_1D = ndtooned(ensSD_norm)
qsort(ensSDnorm_1D)
normSpreadMax = max( (/normSpreadMax, ensSDnorm_1D( dimsizes(ensSDnorm_1D)/100 * 98 ) /) )
delete(climoMean)
delete(climoSD)
delete(ensMean_climo)
delete(ensSD_climo)
delete(error_climo)
delete(ensSD_norm)
delete(error_norm)
delete(ensSDnorm_1D)
end if ; useClimatology
delete(initTimes)
delete(validTimes)
delete(ensMean)
delete(ensSD)
delete(obs)
delete(error)
delete(ensSDtimeAvg)
delete(rmseTimeAvg)
delete(spreadSkillRatio)
delete(errorTimeAvg)
delete(ensSDtimeAvg_1D)
delete(rmseTimeAvg_1D)
delete(spreadSkillRatio_1D)
delete(errorTimeAvg_1D)
delete(ensSD_1D)
delete(percentile)
delete(dimNames)
delete(timeDim)
if(SYNC_TIMES) then
initTimes = syncTimesFull
else
; build array with all of the initialization times
startYYYYMMDDHH = startYYYYMMDDHHs(e)
endYYYYMMDDHH = endYYYYMMDDHHs(e)
forecastFrequencyHr = forecastFrequenciesHr(e)
; break input time strings into its different components
startYear = stringtointeger( str_get_cols( startYYYYMMDDHH, 0, 3) )
startMonth = stringtointeger( str_get_cols( startYYYYMMDDHH, 4, 5) )
startDay = stringtointeger( str_get_cols( startYYYYMMDDHH, 6, 7) )
startHour = stringtointeger( str_get_cols( startYYYYMMDDHH, 8, 9) )
endYear = stringtointeger( str_get_cols( endYYYYMMDDHH, 0, 3) )
endMonth = stringtointeger( str_get_cols( endYYYYMMDDHH, 4, 5) )
endDay = stringtointeger( str_get_cols( endYYYYMMDDHH, 6, 7) )
endHour = stringtointeger( str_get_cols( endYYYYMMDDHH, 8, 9) )
; convert times into epoch-seconds
startTime = cd_inv_calendar( startYear, startMonth, startDay, startHour, 0, 0, "seconds since 1970-1-1 00:00:00", 0 )
endTime = cd_inv_calendar( endYear, endMonth, endDay, endHour, 0, 0, "seconds since 1970-1-1 00:00:00", 0 )
forecastFrequency = forecastFrequencyHr * 3600;
nTimesFull(e) = doubletointeger( (endTime - startTime) / forecastFrequency ) + 1
initTimes = fspan( startTime, endTime, nTimesFull(e) )
copy_VarAtts( startTime, initTimes )
; print( cd_string(initTimes, "%Y%N%D%H") )
initTimes := validGEFS( ensemblePath, ensGridType, members, initTimes, leadTimeHr, variableName )
; print( cd_string(initTimes, "%Y%N%D%H") )
delete(startYYYYMMDDHH)
delete(endYYYYMMDDHH)
delete(forecastFrequencyHr)
delete(startYear)
delete(startMonth)
delete(startDay)
delete(startHour)
delete(endYear)
delete(endMonth)
delete(endDay)
delete(endHour)
delete(startTime)
delete(endTime)
delete(forecastFrequency)
end if ; (.not.SYNC_TIMES)
nTimesFull(e) = dimsizes(initTimes)
; compute valid times
validTimes = initTimes + leadTime
copy_VarAtts( initTimes, validTimes )
ens = readGEFS( ensemblePath, ensGridType, members, initTimes, leadTimeHr, variableName )
if(verificationType.eq."gdas") then
obs = readGDAS( verificationPath, verifGrid, validTimes, verificationVariableName )
else if (verificationType.eq."consensus") then
obs = readConsensus( verificationPath, verifGrid, validTimes, verificationVariableName )
else if (verificationType.eq."control") then
obs = readGEFS( verificationPath, verifGrid, "gec00", validTimes, 0, verificationVariableName )
else
print("Fatal error: unknown verification type specified (plotMap.ncl:main)")
status_exit(2)
end if end if end if
; ====================
; Calculate outliers
; ====================
dimNames = getvardims(ens)
memberDim = ind(dimNames.eq."ensemble_member")
ensMin = dim_min_n_Wrap(ens, memberDim)
ensMax = dim_max_n_Wrap(ens, memberDim)
delete(dimNames)
dimNames = getvardims(ensMin)
leadDim = ind(dimNames.eq."lead_time_hr")
ensMin := dim_avg_n_Wrap(ensMin, leadDim) ; the lead_time_hr should be degenerate, so this just removes it without risking removing other degenerate dims with rm_single_dims
ensMax := dim_avg_n_Wrap(ensMax, leadDim) ; the lead_time_hr should be degenerate, so this just removes it without risking removing other degenerate dims with rm_single_dims
delete(dimNames)
dimNames = getvardims(ensMin)
timeDim = ind(dimNames.eq."initialization_time")
; The member pgrb files have even fewer levels, so reduce obs levels again