forked from blcc/ncl_plots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_plot_gpi.ncl
1347 lines (1197 loc) · 39.1 KB
/
func_plot_gpi.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/contributed.ncl"
load "/home/pgchiu/walker1/func_read/func_misc.ncl"
load "func_dots.ncl"
load "func_plot_time_series.ncl" ;;plot_time_series(dts,title,filename)
load "func_read_rvke_sst.ncl"
load "func_gpi.ncl"
load "func_plot_trend.ncl"
load "func_dailygpi.ncl"
load "func_plot_coloredScatter.ncl"
;;load "func_avginmons.ncl"
function plotsquare(wks,plot)
begin
;; bottom left corner start clockwise
;;ts = wgt_areaave(gpic(:,{10:25},{110:160}),1.,1.,0) ;; MGR
linex = (/110.,110.,160.,160.,110./)
liney = (/ 10., 25., 25., 10., 10./)
mdrres = True
mdrres@gsLineColor ="red"
mdrres@gsLineThicknessF = 5.0
a = gsn_add_polyline(wks,plot,linex,liney,mdrres)
return a
end
undef("annual_sum")
function annual_sum(monts[*],mon[*])
begin
if(.not.any(mon.eq.0))then
yrts = monts(::12)
yrts = 0
do m = 0,11
mm = m+1
if(any(mm.eq.mon))then
yrts = yrts + monts(m::12)
end if
end do
nm = dimsizes(mon)
else
yrts = month_to_annual(monts,0)
nm = 12
end if
yrts@nmonth = nm
return yrts
end
undef("annual_sum3d") ;; t,y,x
function annual_sum3d(monts[*][*][*],mon[*])
begin
if(.not.any(mon.eq.0))then
yrts = monts(::12,:,:)
yrts = 0
do m = 0,11
mm = m+1
if(any(mm.eq.mon))then
yrts = yrts + monts(m::12,:,:)
end if
end do
nm = dimsizes(mon)
else
yrts = month_to_annual(ts,0)
nm = 12
end if
yrts@nmonth = nm
return yrts
end
undef("read_gpic_datafile")
function read_gpic_datafile(years[*],var)
begin
;; var include: cETA, cRH, cVpot, cVshear, gpimax
;; MqGPI, cMq
mqvar = (/"mqGPI","cMq"/)
if(isatt(years,"dataset"))then
dataset = ""+years@dataset
else
dataset = ""
end if
if(dataset .eq."eraim")then
dataset = ""
end if
ny = dimsizes(years)
if(any(var.eq.mqvar))then
f = addfile("gpi/mqgpi"+dataset+years(0)+".nc","r")
else
f = addfile("gpi/gpi"+dataset+years(0)+"comp.nc","r")
end if
gpiconeyear = f->$var$
dims = dimsizes(gpiconeyear)
dims(0) = ny*12
gpicmons = new(dims,typeof(gpiconeyear))
times = new(ny*12,"integer")
gpicmons!0 = "time"
gpicmons!1 = gpiconeyear!1
gpicmons&$gpicmons!1$ = gpiconeyear&$gpiconeyear!1$
gpicmons!2 = gpiconeyear!2
gpicmons&$gpicmons!2$ = gpiconeyear&$gpiconeyear!2$
gpicmons(0:11,:,:) = (/gpiconeyear/)
times(0:11) = yyyymm_time(years(0),years(0),"integer")
do y = 1, ny-1
if(any(var.eq.mqvar))then
f = addfile("gpi/mqgpi"+dataset+years(y)+".nc","r")
else
f = addfile("gpi/gpi"+dataset+years(y)+"comp.nc","r")
end if
times(y*12:y*12+11) = yyyymm_time(years(y),years(y),"integer")
gpicmons(y*12:y*12+11,:,:) = (/f->$var$/)
end do
gpicmons&time = times
gpicmons@dataset = dataset
return gpicmons
end
undef("read_gpi_datafile")
function read_gpi_datafile(years[*])
begin
ny = dimsizes(years)
if(isatt(years,"dataset"))then
dataset = years@dataset
print("data use: "+dataset)
else
dataset = ""
end if
f = addfile("gpi/gpi"+dataset+years(0)+".nc","r")
gpioneyear = f->gpi
dims = dimsizes(gpioneyear)
dims(0) = ny*12
gpimons = new(dims,typeof(gpioneyear))
times = new(ny*12,"integer")
gpimons!0 = "time"
gpimons!1 = gpioneyear!1
gpimons&$gpimons!1$ = gpioneyear&$gpioneyear!1$
gpimons!2 = gpioneyear!2
gpimons&$gpimons!2$ = gpioneyear&$gpioneyear!2$
gpimons(0:11,:,:) = (/gpioneyear/)
times(0:11) = yyyymm_time(years(0),years(0),"integer")
do y = 1, ny-1
f = addfile("gpi/gpi"+dataset+years(y)+".nc","r")
times(y*12:y*12+11) = yyyymm_time(years(y),years(y),"integer")
gpimons(y*12:y*12+11,:,:) = (/f->gpi/)
end do
gpimons&time = times
return gpimons
end
undef("read_gpiClm")
function read_gpiClm(years[*],mon)
begin
if(isatt(years,"calclm").and.years@calclm)then
gpi = cal_gpiclm(years,mon)
return gpi
else
if(any(mon.eq.0))then
mons = ispan(1,12,1)
else
mons = mon
end if
gpimon = read_gpi_datafile(years)
gpiclm = clmMonTLL(gpimon)
gpiclm&month = ispan(1,12,1)
if(dimsizes(mons).gt.1)then
gpi = dim_avg_n_Wrap(gpiclm({mons},:,:),0)
else
gpi = gpiclm({mons},:,:)
end if
return gpi
end if
print("read_gpiClm() error")
exit
end
undef("plot_gpi")
function plot_gpi(years,mon,title,filename)
begin
gpi = read_gpiClm(years,mon) ;; read averaged gpi/month
datamax = 8.
if(isatt(years,"ano").and.years@ano)then
load "res_years.ncl"
gpiall = read_gpiClm(allyears,mon)
gpi = gpi - gpiall
datamax = 4.0
end if
gpisumlo = linint2_Wrap(gpi&lon,gpi&lat,gpi,False,gpi&lon(1::2),gpi&lat(1::2),0)
res = True
res@filename = filename
res@title = title
if(any(mon.eq.0))then ;; allmon get lower GPI
datamax = 4.0
end if
res@datamax = datamax
;res@plotarea = "Pac"
print(max(gpisumlo({0:40},{110:180})))
res@overmark = max(abs(gpisumlo({0:40},{110:180})))/2
a = plot_dot(gpisumlo,res)
return True
end
undef("plot_dailygpi")
function plot_dailygpi(years,mon[*]:integer,title:string,filename:string)
begin
m1 = (/1,32,60,91,121,152,182,213,244,274,305,335/) ;; 12 day of year
m1 = m1-1
m2 = (/31,59,90,120,151,181,212,243,273,304,334,365/)
m2 = m2-1
dgpi = cal_dailygpi(1995)
dgpiclm = dim_avg_n_Wrap(dgpi,0)
dgpiclm = 0.
nm = dimsizes(mon)
do m = 0,nm-1
dmon = mon(m)-1
dgpiclm = dgpiclm + dim_avg_n(dgpi(m1(dmon):m2(dmon),:,:),0)
end do
dgpiclm = dgpiclm/nm
res = True
res@filename = filename
res@title = title
res@datamax = 8.
lat = fspan(-87.5,87.5,36)
lon = fspan(2.5,357.5,72)
;;dgpiclmlo = linint2_Wrap(dgpiclm&lon,dgpiclm&lat,dgpiclm,False,lon,lat,0)
;;dgpiclmlo!0 = "lat"
;;dgpiclmlo!1 = "lon"
;;dgpiclmlo&lat = lat
;;dgpiclmlo&lon = lon
dgpiclmlo = dgpiclm(1::2,1::2)
dgpiclmlo({17.5},{122.5}) = dgpiclmlo@_FillValue
print(max(dgpiclmlo({0:40},{110:180})))
res@overmark = max(abs(dgpiclmlo({0:40},{110:180})))/2
a = plot_dot(dgpiclmlo({0:40},{110:180}),res)
return True
end
undef("plot_gpic")
function plot_gpic(years[*],mon[*],var[1],title[1],filename[1])
begin
ogpic = read_gpic_datafile(years,var)
gpic = ogpic
gpic = where(ogpic.eq.0,ogpic@_FillValue,ogpic)
gpic!1 = "lat"
gpic!2 = "lon"
gpiclo = linint2_Wrap(gpic&lon,gpic&lat,gpic,False,gpic&lon(1::2),gpic&lat(1::2),0)
gpiclo = log(gpiclo)/log(2.) ;; log2 to emphasis result
;;gpiclo = log(gpiclo)
gpicclm = clmMonTLL(gpiclo)
if(.not.any(mon.eq.0))then
do m = 0, 11
mm = m+1
if(.not.any(mm.eq.mon))then
gpicclm(m,:,:) = gpicclm@_FillValue
end if
end do
end if
pgpicclm = dim_avg_n_Wrap(gpicclm,0)
res = True
res@filename = filename
res@title = title
if(any(mon.eq.0))then
nm = 12
else
nm = dimsizes(mon)
end if
res@datamax = 5.
;res@plotarea = "Pac"
print("value from "+min(pgpicclm({0:40},{110:180}))+" to "+max(pgpicclm({0:40},{110:180})))
res@overmark = max(abs(pgpicclm({0:40},{110:180})))/2
if(filename .ne. "")then
a = plot_dot(pgpicclm,res)
return True
end if
;;wks = gsn_open_wks("ps",var)
;;res = True
;;res@vpWidthF = 0.80 ; make map bigger
;;res@vpHeightF = 0.80
;;res@mpMaxLatF = 60. ; select subregion
;;res@mpMinLatF = -60.
;;res@mpMinLonF = 00.
;;res@mpMaxLonF = 360.
;;res@mpCenterLonF = 180.
;;res@mpFillDrawOrder = "PreDraw"
;;res@cnLevelSpacingF = 10
;;p = gsn_csm_contour_map_ce(wks,ogpic(7,:,:),res)
return pgpicclm
end
undef("plot_gpic_plus")
function plot_gpic_plus(years[*],mon[*],vn1[1],vn2[1],title[1],filename[1])
begin
var1 = plot_gpic(years,mon,vn1,"","")
var2 = plot_gpic(years,mon,vn2,"","")
pgpicclm = var1
pgpicclm = var1+var2
res = True
res@filename = filename
res@title = title
res@datamax = 4.
res@overmark = max(abs(pgpicclm({0:40},{110:180})))/2
a = plot_dot(pgpicclm,res)
return a
end
undef("plot_gpic_ts")
function plot_gpic_ts(yb,ye,mon,var,title,filename)
begin
;title@RightMean = True
years = ispan(yb,ye,1)
copy_VarAtts(yb,years)
ym = yyyymm_time(yb,ye,"integer")
gpic = read_gpic_datafile(years,var)
gpic = where(gpic.le.0,gpic@_FillValue,gpic)
if(isatt(yb,"log").and.yb@log)then
print("take log")
gpic = log(gpic)/log(2.)
end if
if(isatt(yb,"range")[email protected]."MDR")then
ts = wgt_areaave(gpic(:,{10:30},{110:150}),1.,1.,0) ;; MDR
end if
if(isatt(yb,"range")[email protected]."MGR")then
ts = wgt_areaave(gpic(:,{10:25},{110:160}),1.,1.,0) ;; MGR
end if
if(.not.isdefined("ts"))then
ts = wgt_areaave(gpic(:,{0:40},{110:180}),1.,1.,0) ;; WNP
end if
if(isatt(yb,"ano"))then
ano = yb@ano
else
ano = True
end if
ts!0 = "yyyymm"
ts&yyyymm = ym
;;print(ts&$ts!0$+" "+ts)
yrts = annual_sum(ts,mon)
yrts = yrts/yrts@nmonth
yrts!0 = "year"
yrts&$yrts!0$ = years
yrts@yref = 0. ;avg(yrts)
if(ano)then
yrts@ymax = 1.2
yrts@ymin = yrts@ymax*(-1)
yrts = yrts - avg(yrts)
else
yrts@ymax = 5.0
yrts@ymin = -3.0
end if
if(isatt(yb,"plotmode"))then
yrts@plotmode = yb@plotmode
end if
p = plot_time_series(yrts,title,filename)
return yrts
end
undef("plot_gpi_ts")
function plot_gpi_ts(yb,ye,mon,title,filename)
begin
;title@RightMean = True
years = ispan(yb,ye,1)
copy_VarAtts(yb,years)
gpi = read_gpi_datafile(years)
gpisumlo = linint2_Wrap(gpi&lon,gpi&lat,gpi,False,gpi&lon(1::2),gpi&lat(1::2),0)
;;ts = dim_sum_Wrap(dim_sum_Wrap(gpisumlo(:,{0:40},{110:180})))
ts = wgt_areaave(gpisumlo(:,{0:40},{110:180}),1.,1.,0)
yrts = annual_sum(ts,mon)
yrts = yrts / yrts@nmonth
yrts!0 = "year"
yrts&$yrts!0$ = years
yrts@yref = 0.
yrts@ymax = 6. ;4000.
p = plot_time_series(yrts,title,filename)
return yrts
end
undef("cor_gpi_race")
function cor_gpi_race(gpits,mons,var)
begin
;; cal correlation
racename = (/"RACE","race","rvke","RvKE"/)
acename = (/"ACE" ,"ace","TyKE","tyke"/)
tyhrname = (/"TyHr","hr" ,"Hr","TLS","TCD","tcd"/)
tygenname= (/"TyGen","Tygen","gen","TGN"/)
pdiname = (/"pdi","PDI"/)
yb = min(gpits&year)
if(isatt(gpits,"emanuel2005Correcting").and.gpits@emanuel2005Correcting)then
yb@emanuel2005Correcting = True
end if
ye = max(gpits&year)
if(any(var .eq. racename))then
tyind = readmonRACE(yb,ye)
end if
if(any(var .eq. tygenname))then
tyind = readmonTygen(yb,ye)
end if
if(any(var .eq. tyhrname))then
tyind = readmonTyhr(yb,ye)
end if
if(any(var .eq. acename))then
tyind = readmonACE(yb,ye)
end if
if(any(var .eq. pdiname))then
print("read PDI not ready yet.")
exit
tyind = readmonACE(yb,ye)
end if
if(.not.isvar("tyind"))then
print("no ty index named"+var)
exit
end if
;;tyindmonts = dim_sum_Wrap(dim_sum_Wrap(tyind(:,{0:40},{110:180})))
tyindmonts = wgt_areaave_Wrap(tyind(:,{0:40},{110:180}),1.,1.,0)
if(dimsizes(mons).eq.1 .and. mons.eq.0)then
else
do m = 0,11
mm = m+1
if(.not.any(mm.eq.mons))then
tyindmonts(m::12) = 0 ;tyindmonts@_FillValue
end if
end do
end if
tyindyrts = month_to_annual(tyindmonts,0)
cor = escorc(gpits,tyindyrts)
return cor
end
undef("plot_race_all_gpits")
function plot_race_all_gpits(yb[1]:integer,ye[1]:integer,title[1]:string,filename[1]:string)
begin
years = ispan(yb,ye,1)
copy_VarAtts(yb,years)
if(isatt(yb,"mons"))then
mons = yb@mons
else
mons = ispan(1,12,1)
end if
if(isatt(yb,"range"))then
range = yb@range
else
range = "WNP"
end if
gen = readmonTygen(yb,ye)
hr = readmonTyhr(yb,ye)
ace = readmonACE(yb,ye)
race = readmonRACE(yb,ye)
gpi = read_gpi_datafile(years)
if(range.eq."MGR")then
genmonts = wgt_areaave_Wrap( gen(:,{10:25},{110:160}),1.,1.,0)
hrmonts = wgt_areaave_Wrap( hr(:,{10:25},{110:160}),1.,1.,0)
acemonts = wgt_areaave_Wrap( ace(:,{10:25},{110:160}),1.,1.,0)
racemonts = wgt_areaave_Wrap(race(:,{10:25},{110:160}),1.,1.,0)
gpimonts = wgt_areaave_Wrap( gpi(:,{10:25},{110:160}),1.,1.,0)
else
genmonts = wgt_areaave_Wrap( gen(:,{0:40},{110:180}),1.,1.,0)
hrmonts = wgt_areaave_Wrap( hr(:,{0:40},{110:180}),1.,1.,0)
acemonts = wgt_areaave_Wrap( ace(:,{0:40},{110:180}),1.,1.,0)
racemonts = wgt_areaave_Wrap(race(:,{0:40},{110:180}),1.,1.,0)
gpimonts = wgt_areaave_Wrap( gpi(:,{0:40},{110:180}),1.,1.,0)
end if
if(dimsizes(mons).eq.1 .and. mons.eq.0)then
print("allmon")
else
do m = 0,11
mm = m+1
if(.not.any(mm.eq.mons))then
genmonts(m::12) = 0
hrmonts(m::12) = 0
acemonts(m::12) = 0
racemonts(m::12) = 0
gpimonts(m::12) = 0
end if
end do
end if
genyrts = month_to_annual(genmonts,0)
hryrts = month_to_annual(hrmonts,0)
aceyrts = month_to_annual(acemonts,0)
raceyrts = month_to_annual(racemonts,0)
gpiyrts = month_to_annual(gpimonts,0)
allyrts = new((/5,dimsizes(gpiyrts)/),typeof(genyrts))
allyrts(0,:) = dim_standardize(genyrts,1)
allyrts(1,:) = dim_standardize(hryrts,1)
allyrts(2,:) = dim_standardize(aceyrts,1)
allyrts(3,:) = dim_standardize(raceyrts,1)
allyrts(4,:) = dim_standardize(gpiyrts,1)
allyrts!0 = "tyind"
allyrts!1 = "year"
allyrts&year = years
allyrts&tyind = (/"NTC","TCD","ACE","RACE","GPI"/)
if(isatt(yb,"plotmode"))then
allyrts@plotmode = yb@plotmode
end if
a = plot_allts(allyrts,title,filename)
return allyrts
end
undef("plot_ntc_gpits")
function plot_ntc_gpits(yb[1]:integer,ye[1]:integer,title[1]:string,filename[1]:string)
begin
years = ispan(yb,ye,1)
copy_VarAtts(yb,years)
if(isatt(yb,"mons"))then
mons = yb@mons
else
mons = ispan(1,12,1)
end if
if(isatt(yb,"range"))then
range = yb@range
else
range = "WNP"
end if
if(isatt(yb,"nostand"))then
nostand = True
else
nostand = False
end if
gen = readmonTygen(yb,ye)
gpi = read_gpi_datafile(years)
if(range.eq."MGR")then
if(nostand)then
genmonts = dim_sum_n_Wrap( gen(:,{10:25},{110:160}),(/1,2/))
end if
genmonts = wgt_areaave_Wrap( gen(:,{10:25},{110:160}),1.,1.,0)
gpimonts = wgt_areaave_Wrap( gpi(:,{10:25},{110:160}),1.,1.,0)
else
if(nostand)then
genmonts = dim_sum_n_Wrap( gen(:,{0:40},{110:180}),(/1,2/))
else
genmonts = wgt_areaave_Wrap( gen(:,{0:40},{110:180}),1.,1.,0)
end if
gpimonts = wgt_areaave_Wrap( gpi(:,{0:40},{110:180}),1.,1.,0)
end if
if(dimsizes(mons).eq.1 .and. mons.eq.0)then
else
do m = 0,11
mm = m+1
if(.not.any(mm.eq.mons))then
genmonts(m::12) = 0
gpimonts(m::12) = 0
end if
end do
end if
genyrts = month_to_annual(genmonts,0)
gpiyrts = month_to_annual(gpimonts,0)
allyrts = new((/2,dimsizes(gpiyrts)/),typeof(genyrts))
if(nostand)then
allyrts(0,:) = genyrts
allyrts(1,:) = gpiyrts
else
allyrts(0,:) = dim_standardize(genyrts,1)
allyrts(1,:) = dim_standardize(gpiyrts,1)
end if
allyrts!0 = "tyind"
allyrts!1 = "year"
allyrts&year = years
allyrts&tyind = (/"NTC","GPI"/)
if(isatt(yb,"plotmode"))then
allyrts@plotmode = yb@plotmode
end if
a = plot_allts(allyrts,title,filename)
return allyrts
end
undef("plot_gpists")
function plot_gpists(mons,title[1]:string,filename[1]:string)
begin
years = ispan(1965,2008,1)
eyears = ispan(1965,2001,1)
cyears = ispan(1979,2008,1) ;; 1979-2009
gpi = read_gpi_datafile(years)
eyears@dataset = "era40"
egpi = read_gpi_datafile(eyears)
cyears@dataset = "cfsr"
cgpi = read_gpi_datafile(cyears)
gpimonts = wgt_areaave_Wrap( gpi(:,{0:40},{110:180}),1.,1.,0)
egpimonts = wgt_areaave_Wrap(egpi(:,{0:40},{110:180}),1.,1.,0)
cgpimonts = wgt_areaave_Wrap(cgpi(:,{0:40},{110:180}),1.,1.,0)
if(dimsizes(mons).eq.1 .and. mons.eq.0)then
else
do m = 0,11
mm = m+1
if(.not.any(mm.eq.mons))then
gpimonts(m::12) = gpimonts@_FillValue
egpimonts(m::12) = egpimonts@_FillValue
cgpimonts(m::12) = cgpimonts@_FillValue
end if
end do
end if
gpiyrts = month_to_annual(gpimonts,0)
egpiyrts = month_to_annual(egpimonts,0)
cgpiyrts = month_to_annual(cgpimonts,0)
allyrts = new((/3,dimsizes(gpiyrts)/),typeof(gpiyrts))
allyrts!0 = "GPI data"
allyrts!1 = "year"
allyrts&$allyrts!1$ = years
allyrts&$allyrts!0$ = (/"ERAIM+ERA40","ERA40","CFSR"/)
allyrts(0,:) = dim_standardize(gpiyrts,1)
allyrts(1,{eyears}) = dim_standardize(egpiyrts,1)
allyrts(2,{cyears}) = dim_standardize(cgpiyrts,1)
allyrts(0,:) = (/gpiyrts/)
allyrts(1,{eyears}) = (/egpiyrts/)
allyrts(2,{cyears}) = (/cgpiyrts/)
;;print(allyrts(0,:)+" "+allyrts(1,:)+" "+allyrts(2,:))
a = plot_allts(allyrts,title,filename)
return allyrts
end
undef("plot_gpisSSTts")
function plot_gpisSSTts(mons,title[1]:string,filename[1]:string)
begin
years = ispan(1965,2008,1)
gpi = read_gpi_datafile(years)
years@dataset = "eraimsstP1"
gpip1 = read_gpi_datafile(years)
years@dataset = "eraimsstM1"
gpim1 = read_gpi_datafile(years)
years@dataset = "eraimsstP2"
gpip2 = read_gpi_datafile(years)
years@dataset = "eraimsstM2"
gpim2 = read_gpi_datafile(years)
gpimonts = wgt_areaave_Wrap( gpi(:,{0:40},{110:180}),1.,1.,0)
gpim1monts = wgt_areaave_Wrap(gpim1(:,{0:40},{110:180}),1.,1.,0)
gpip1monts = wgt_areaave_Wrap(gpip1(:,{0:40},{110:180}),1.,1.,0)
gpim2monts = wgt_areaave_Wrap(gpim2(:,{0:40},{110:180}),1.,1.,0)
gpip2monts = wgt_areaave_Wrap(gpip2(:,{0:40},{110:180}),1.,1.,0)
if(dimsizes(mons).eq.1 .and. mons.eq.0)then
else
do m = 0,11
mm = m+1
if(.not.any(mm.eq.mons))then
gpimonts(m::12) = gpimonts@_FillValue
gpim1monts(m::12) = gpim1monts@_FillValue
gpip1monts(m::12) = gpip1monts@_FillValue
gpim2monts(m::12) = gpim2monts@_FillValue
gpip2monts(m::12) = gpip2monts@_FillValue
end if
end do
end if
gpiyrts = month_to_annual(gpimonts,0)
gpim1yrts = month_to_annual(gpim1monts,0)
gpip1yrts = month_to_annual(gpip1monts,0)
gpim2yrts = month_to_annual(gpim2monts,0)
gpip2yrts = month_to_annual(gpip2monts,0)
allyrts = new((/5,dimsizes(gpiyrts)/),typeof(gpiyrts))
allyrts!0 = "GPI data"
allyrts!1 = "year"
allyrts&$allyrts!1$ = years
allyrts&$allyrts!0$ = (/"SST-2","SST-1","SST","SST+1","SST+2"/)
allyrts(2,:) = (/gpiyrts/)
allyrts(3,:) = (/gpip1yrts/)
allyrts(1,:) = (/gpim1yrts/)
allyrts(4,:) = (/gpip2yrts/)
allyrts(0,:) = (/gpim2yrts/)
a = plot_allts(allyrts,title,filename)
return allyrts
end
undef("read_vpot_monly")
function read_vpot_monly(years[*]:integer)
begin
ny = dimsizes(years)
dataset = ""
if(isatt(years,"dataset"))then
dataset = years@dataset
end if
f = addfile("gpi/Vpot"+dataset+years(0)+".nc","r")
vpotoneyear = f->Vpot
dims = dimsizes(vpotoneyear)
dims(0) = ny*12
vpotmons = new(dims,typeof(vpotoneyear))
times = new(ny*12,"integer")
lon = lonGlobeF(144, "lon", "longitude", "degrees_east")
vpotmons!0 = "time"
vpotmons!1 = vpotoneyear!1
vpotmons&$vpotmons!1$ = vpotoneyear&$vpotoneyear!1$
vpotmons!2 = vpotoneyear!2
vpotmons&$vpotmons!2$ = lon ;vpotoneyear&$vpotoneyear!2$
vpotmons(0:11,:,:) = (/vpotoneyear/)
times(0:11) = yyyymm_time(years(0),years(0),"integer")
do y = 1, ny-1
f = addfile("gpi/Vpot"+dataset+years(y)+".nc","r")
times(y*12:y*12+11) = yyyymm_time(years(y),years(y),"integer")
vpotmons(y*12:y*12+11,:,:) = (/f->Vpot/)
end do
vpotmons&time = times
return vpotmons
end
undef("read_vpot_clm")
function read_vpot_clm(years[*]:integer,imons[*]:integer)
begin
if(any(imons.eq.0))then
mons = ispan(1,12,1)
else
mons = imons
end if
vpotmonly = read_vpot_monly(years)
vpotclm = clmMonTLL(vpotmonly)
vpot = dim_avg_n_Wrap(vpotclm({mons-1},:,:),0)
return vpot
end
undef("plot_vpot") ;; contour
function plot_vpot(years[*]:integer,mons[*]:integer,title[1]:string,filename[1]:string)
begin
vpot = read_vpot_clm(years,mons)
wks = gsn_open_wks("ps",filename)
gsn_define_colormap(wks,"ViBlGrWhYeOrRe")
res = True
res@vpHeightF = 0.40 ; Changes the aspect ratio
res@vpWidthF = 0.85
res@tmXTOn = False
res@tmYROn = False
res@mpMinLatF = -40.
res@mpMaxLatF = 40.
res@mpMinLonF = 0.
res@mpMaxLonF = 360.
res@mpCenterLonF = 180.
res@cnLinesOn = True
res@cnFillOn = True ; turn on color fill
res@tiMainString = title
res@tiMainFont = 29
res@txFont = 29
res@tmXBLabelFont = 29
res@tmYLLabelFont = 29
res@gsnMajorLatSpacing = 10
res@gsnMajorLonSpacing = 60
res@tiMainFontHeightF = 0.015
res@gsnStringFontHeightF = 0.012
res@tmXBLabelFontHeightF = 0.010
res@tmYLLabelFontHeightF = 0.010
res@tmXBLabelFontHeightF = 0.010
res@tmYLLabelFontHeightF = 0.010
res@lbLabelBarOn = True ; turn on individual lb's
res@lbLabelFont = 21
res@lbLabelFontHeightF = 0.010
res@pmLabelBarOrthogonalPosF = 0.2
res@pmLabelBarWidthF = 0.85
res@pmLabelBarHeightF = 0.04
res@cnLevelSelectionMode = "ExplicitLevels"
;res@cnLevels = (/ 00, 35, 40, 45, 50, 55, 60, 65/)
res@cnLevels = ispan(35, 80,5)
res@cnFillColors = (/ 50, 62, 76, 83, 86, 92, 95, 97, 100, 102 ,102/)
;; res2 = True
;; res2@cnLinesOn = True
;;
;; res2@cnLevelSelectionMode = "ManualLevels"
;; res2@cnMinLevelValF = 8
;; res2@cnMaxLevelValF = 18
;; res2@cnLevelSpacingF = 1 ; set contour spacing
;;
;; res2@cnLineLabelFontHeightF = 0.006
;; res2@cnLineThicknessF = 2.
;; res2@gsnContourZeroLineThicknessF = 0 ; eliminates zero contour
;; res2@gsnContourNegLineDashPattern = 1
;; res2@gsnContourZeroLineThicknessF = 0 ; eliminates zero contour
;; res2@gsnContourNegLineDashPattern = 1
;; res2@cnInfoLabelOn = False
plot = gsn_csm_contour_map_ce(wks,vpot,res)
return vpot
end
;undef("plot_vpot_clm")
function plot_vpot_clm(years[*],imons[*],title[1]:string,filename[1]:string)
begin
if(any(imons.eq.0))then
mons = ispan(1,12,1)
print("mons content 0, set to 1-12")
else
mons = imons
end if
if(isatt(years,"region"))then
region = years@region
else
region = "WNP"
end if
if(isatt(years,"ano"))then
ano = years@ano
else
ano = False
end if
if(isatt(years,"plotsst"))then
plotsst = years@plotsst
else
plotsst = False
end if
if(plotsst)then
SST12 = clmMonTLL(read_ersst(years))
SST12&month = ispan(1,12,1)
SST = dim_avg_n_Wrap(SST12(mons,:,:),0)
delete(SST@long_name)
delete(SST@units)
else
vpot = read_vpot_clm(years,mons)
end if
if(ano)then
load "res_years.ncl"
if(plotsst)then
clmSST12 = clmMonTLL(read_ersst(allyears))
clmSST12&month = ispan(1,12,1)
clmSST = dim_avg_n_Wrap(clmSST12(mons,:,:),0)
SST = SST - clmSST
else
clmvpot = read_vpot_clm(allyears,mons)
vpot = vpot - clmvpot
end if
end if
wks = gsn_open_wks("ps",filename)
gsn_define_colormap(wks,"ViBlGrWhYeOrRe")
res = True
res@gsnDraw = False
res@gsnFrame = False
res@vpHeightF = 0.40 ; Changes the aspect ratio
res@vpWidthF = 0.85
res@tmXTOn = False
res@tmYROn = False
if(region.eq."tropical")then ;; default
res@mpMinLatF = -40.
res@mpMaxLatF = 40.
res@mpMinLonF = 0.
res@mpMaxLonF = 360.
end if
if(region .eq."WNP")then
res@mpMinLatF = 0.
res@mpMaxLatF = 40.
res@mpMinLonF = 110.
res@mpMaxLonF = 180.
end if
res@mpCenterLonF = 180.
res@cnLinesOn = True
res@cnFillOn = True ; turn on color fill
res@tiMainString = title
res@tiMainFont = 29
res@txFont = 29
res@tmXBLabelFont = 29
res@tmYLLabelFont = 29
;res@gsnMajorLatSpacing = 10
;res@gsnMajorLonSpacing = 60
res@tiMainFontHeightF = 0.015
res@gsnStringFontHeightF = 0.012
res@tmXBLabelFontHeightF = 0.010
res@tmYLLabelFontHeightF = 0.010
res@tmXBLabelFontHeightF = 0.010
res@tmYLLabelFontHeightF = 0.010
res@lbLabelBarOn = True ; turn on individual lb's
res@lbLabelFont = 21
res@lbLabelFontHeightF = 0.010
res@pmLabelBarOrthogonalPosF = 0.2
res@pmLabelBarWidthF = 0.85
res@pmLabelBarHeightF = 0.04
res@cnFillDrawOrder = "PreDraw"
res@cnLevelSelectionMode = "ExplicitLevels"
;res@cnLevels = ispan(800,2400,200)
res@cnLevels = ispan(35, 80,5)
res@cnFillColors = (/ 50, 62, 76, 83, 86, 92, 95, 97, 100, 102 ,102/)
if(ano)then
delete(res@cnLevels)
delete(res@cnFillColors)
res@cnLevelSelectionMode = "ManualLevels"
res@gsnSpreadColors = True
if(plotsst)then
res@cnMinLevelValF = -1.
res@cnLevelSpacingF = .1
res@cnMaxLevelValF = 1.
else
res@cnMinLevelValF = -10.
res@cnLevelSpacingF = 1.
res@cnMaxLevelValF = 10.
end if
end if
print("plot: "+filename)
if(plotsst)then
plot = gsn_csm_contour_map_ce(wks,SST,res)
else
plot = gsn_csm_contour_map_ce(wks,vpot,res)
end if
;a = plotsquare(wks,plot) ;; plot MGR square
draw(plot)
frame(wks)
return plot
end
undef("plot_cape_vpot") ;; scatter plot for senVpot*
function plot_cape_vpot(years[*]:integer,mons[*]:integer,title[1]:string,filename[1]:string)
begin
dataset = ""
if(isatt(years,"dataset"))then
dataset = years@dataset
end if
range = "MDR"
if(isatt(years,"range"))then
range = years@range
end if
colorVar = "sst"
if(isatt(years,"colorVar"))then
colorVar = years@colorVar
end if
xaxis = "CAPE"
if(isatt(years,"xaxis"))then
xaxis = years@xaxis
end if
swapXS = False ;; bad coding, but for quick plot...