-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfunc_plot_yr_onset.ncl
342 lines (321 loc) · 10.2 KB
/
func_plot_yr_onset.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
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "func_dailytopentad.ncl"
load "func_smsi.ncl"
;load "func_read_era_all.ncl"
load "func_read_reanalysis.ncl"
undef("plot_onset")
function plot_onset(u[*][*],v[*][*],rain[*],ores)
begin
;; u,v is time-p, rain is time(penta)
title = ores@title
filename = ores@filename
if(isatt(ores,"race"))then
race = ores@race
end if
times = u&$u!0$
levs = u&$u!1$
nlev = dimsizes(levs)
nt = dimsizes(times)
smsindex = smsi(rain,u,v)
res = True
res@gsnFrame = False
res@gsnDraw = False
res@vpXF = 0.1
res@vpHeightF = 0.2 ; change aspect ratio of plot
res@vpWidthF = 0.7
res@trXMaxF = 73
res@trXMinF = 1
res@trXMaxF = 72
res@trXMinF = 25
;; fonts setup
res@tiMainFont = 21
res@tiMainPosition = "Left"
res@tiMainJust = "centerLeft"
res@tiMainFontHeightF = 0.015
res@tiXAxisFont = 21
res@tiXAxisFontHeightF = 0.015
res@tiYAxisFont = 21
res@tiYAxisFontHeightF = 0.015
res@tmXBLabelFont = 21
res@tmXBLabelFontHeightF = 0.015
res@tmYLLabelFont = 21
res@tmYLLabelFontHeightF = 0.015
res@tmYRLabelFont = 21
res@tmYRLabelFontHeightF = 0.015
;; tickmarks
res@tmXBAutoPrecision = False
res@tmXBFormat = "f"
res@tmXBMaxTicks = 18
res@tmXBMinorOn = True
res@tmXBMajorOutwardLengthF = 0.006
res@tmXBMajorLengthF = 0.006
res@tmXBMinorOutwardLengthF = 0.003
res@tmXBMinorLengthF = 0.003
res@tmYLMajorThicknessF = 4.0
res@tmYLMajorOutwardLengthF = 0.006
res@tmYLMajorLengthF = 0.006
res@tmYLMinorOutwardLengthF = 0.003
res@tmYLMode = "Explicit"
res@tmYLValues = fspan(0,nlev-1,nlev-1)
res@tmYLLabels = levs
;; borders
res@tmBorderThicknessF = 3.0
res@tmYRMajorThicknessF = 4.0
res@tmYRMajorOutwardLengthF = 0.006
res@tmYRMajorLengthF = 0.006
res@tmYRMinorOutwardLengthF = 0.003
xyres = res
xyres@xyMarkLineMode = "MarkLines"
xyres@xyMarker = 16 ; choose type of marker
xyres@xyLineThicknessF = 3.0
xyres@xyLineColor = "blue4"
xyres@xyMarkerColor = xyres@xyLineColor
xyres@tmYLOn = False
xyres@trYMaxF = 20.
xyres2= xyres
xyres2@xyLineColor = "transparent"
xyres2@xyMarker = 0 ; choose type of marker
;xyres2@xyMarkerColor = 0
xyres@xyCurveDrawOrder = "PreDraw"
res@tiMainString = title
res@vcGlyphStyle = "WindBarb"
;res@trYMaxF = ind(levs.eq.100)
res@trYMinF = 0
res@vcRefAnnoOn = False
res@vcRefLengthF = 0.025
res@vcVectorDrawOrder = "PostDraw"
res@tmYROn = False
empty = rain
empty = empty@_FillValue
wks = gsn_open_wks("ps",filename)
gsn_define_colormap(wks,"prcp_3")
plotbarb = gsn_vector(wks,u(lev|:,time|:),v(lev|:,time|:),res)
plotxy = gsn_csm_xy2(wks,times,rain,rain,xyres2,xyres)
delete_VarAtts(xyres,"gsnFrame")
delete_VarAtts(xyres,"gsnDraw")
if(isatt(ores,"refline"))then
refline = ores@refline
xyres@gsLineColor = "red"
xyres@gsLineThicknessF = 2.0
gsn_polyline(wks,plotxy,(/0,nt/),(/refline,refline/),xyres)
end if
if(isatt(ores,"fftrain"))then
fftrain = fftfilter(rain,ores@fftrain)
xyres@gsLineColor = "darkgreen"
xyres@gsLineThicknessF = 3.0
xyres@gsLineDashPattern = 2
gsn_polyline(wks,plotxy,times,fftrain,xyres)
end if
if(isatt(ores,"onset"))then
fftrain = fftfilter(rain,ores@fftrain)
xyres@gsLineColor = "goldenrod4"
xyres@gsLineThicknessF = 3.0
xyres@gsLineDashPattern = 1
onoffset = wnponset(rain,u,v)
onset = onoffset(0)+1
offset = onoffset(1)+1
if(any(ismissing(onoffset)))then
print("find onset error")
else
gsn_polyline(wks,plotxy,(/onset,onset/),(/0,100/),xyres)
;gsn_polyline(wks,plotxy,(/offset,offset/),(/0,100/),xyres)
end if
end if
if( isvar("race"))then
xyres@gsLineColor = "mediumpurple4"
xyres@gsLineThicknessF = 3.0
xyres@gsLineDashPattern = 8
print(max(race))
maxrace = 0.03
maxrace = 1.80
race = race/maxrace*xyres@trYMaxF
gsn_polyline(wks,plotxy,times,race,xyres)
end if
overlay(plotbarb,plotxy)
draw(plotbarb)
frame(wks)
return True
end
undef("plot_yr_onset")
function plot_yr_onset(year,filename)
begin
;; read u,v,p
pentau = read_ncep_cmap_penta(year,"u")
printVarSummary(pentau)
pentav = read_ncep_cmap_penta(year,"v")
pentar = read_ncep_cmap_penta(year,"r")
res = True
res@title = "WNP(120E-150E,5N-20N) Wind barb & CMAP "+year
res@filename = filename
res@refline = 6
res@fftrain = 12
res@onset = True
;; add RACE data
if (isatt(filename,"race"))then
varname = "race"
res@race = read_jtwc_race_penta(year,varname)
print("add race line")
end if
p = plot_onset(pentau,pentav,pentar,res)
return True
end
undef("read_ncep_cmap_penta")
function read_ncep_cmap_penta(year,varname)
begin
datad = "../ncep_v2_daily/"
if(isatt(varname,"odims"))then
odims = varname@odims
else
odims = "TZ"
end if
if(varname.eq."u")then
df = addfile(datad+"uwnd."+year+".nc","r")
uwnd = df->uwnd
dailyu = short2flt(uwnd(:,:,::-1,:))
if (odims.eq."TZ")then
dailyu = dailyu*1.94
dailyu@units = "knots"
pentau = yrdailytopentadTL(dim_avg_Wrap(dim_avg_Wrap(dailyu(:,:,{5:20},{120:150}))))
pentau!1 = "lev"
pentau&lev = uwnd&level
end if
if (odims.eq."TZYX")then
pentau = yrdailytopentadTLn(dailyu(:,:,:,:))
pentau!1 = "lev"
pentau&lev = uwnd&level
pentau!2 = "lat"
pentau!3 = "lon"
pentau&lat = dailyu&$dailyu!2$
pentau&lon = dailyu&$dailyu!3$
end if
return pentau
end if
if(varname.eq."v")then
df = addfile(datad+"vwnd."+year+".nc","r")
vwnd = df->vwnd
dailyv = short2flt(vwnd(:,:,::-1,:))
if (odims.eq."TZ")then
dailyv = dailyv*1.94
dailyv@units = "knots"
pentav = yrdailytopentadTL(dim_avg_Wrap(dim_avg_Wrap(dailyv(:,:,{5:20},{120:150}))))
pentav!1 = "lev"
pentav&lev = vwnd&level
end if
if (odims.eq."TZYX")then
pentav = yrdailytopentadTLn(dailyv(:,:,:,:))
pentav!1 = "lev"
pentav&lev = vwnd&level
pentav!2 = "lat"
pentav!3 = "lon"
pentav&lat = dailyv&$dailyv!2$
pentav&lon = dailyv&$dailyv!3$
end if
return pentav
end if
if(varname.eq."r")then
df = addfile("/walker1/pgchiu/cmap/precip.pentad.mean.nc","r")
precip = df->precip
ptime = ut_calendar(precip&time,-2) ; as YYYYMMDD
precip&time = ptime
if (odims.eq."TZ")then
pentar = dim_avg_Wrap(dim_avg_Wrap(precip({year*10000:(year+1)*10000-1},{5:20},{120:150})))
end if
if (odims.eq."TZYX")then
pentar = precip({year*10000:(year+1)*10000-1},:,:)
cmaplat= pentar&lat
pentar!1 = "cmaplat"
pentar&cmaplat = cmaplat
end if
pentar&time = fspan(1,73,73)
return pentar
end if
end
undef("read_jtwc_race_penta")
function read_jtwc_race_penta(year,varname)
begin
if(isatt(varname,"odims"))then
odims = varname@odims
else
odims = "TZ"
end if
if(varname.eq."race")then
df = addfile("/walker2/pgchiu/data/ncl/daily_RACE.nc","r")
dailyRACE = df->race
if (odims.eq."TZ")then
;pentaRACE = dailytopentad(dim_avg_Wrap(dim_avg_Wrap(dailyRACE({year*10000:(year+1)*10000-1},{5:20},{120:150}))))
pentaRACE = dailytopentad(dim_sum_Wrap(dim_sum_Wrap(dailyRACE({year*10000:(year+1)*10000-1},:,:))))
end if
if (odims.eq."TYX")then
pentaRACE = yrdailytopentadTLn(dailyRACE({year*10000:(year+1)*10000-1},:,:))
end if
return pentaRACE
end if
end
undef("plot_clm_onset")
function plot_clm_onset(filename)
begin
;; read u,v,p
yb = 1979
ye = 2007
ny = ye-yb+1
pentau = read_ncep_cmap_penta(yb,"u")
pentav = read_ncep_cmap_penta(yb,"v")
pentar = read_ncep_cmap_penta(yb,"r")
race = read_jtwc_race_penta(yb,"race")
do year = yb+1,ye
pentau = pentau + read_ncep_cmap_penta(year,"u")
pentav = pentav + read_ncep_cmap_penta(year,"v")
pentar = pentar + read_ncep_cmap_penta(year,"r")
race = race + read_jtwc_race_penta(year,"race")
end do
pentau = pentau /ny
pentav = pentav /ny
pentar = pentar /ny
race = race/ny
res = True
res@title = "WNP(120E-150E,5N-20N) Wind barb & CMAP cli"
res@filename = filename
res@refline = 6
res@fftrain = 12
res@race = race
res@onset = True
p = plot_onset(pentau,pentav,pentar,res)
return True
end
undef("plot_compset_onset")
function plot_compset_onset(years,filename)
begin
;; read u,v,p
ny = dimsizes(years)
if(isatt(years,"title"))then
title = years@title
else
title = ""
end if
if(isatt(filename,"title"))then
title = filename@title
end if
pentau = read_ncep_cmap_penta(years(0),"u")
pentav = read_ncep_cmap_penta(years(0),"v")
pentar = read_ncep_cmap_penta(years(0),"r")
race = read_jtwc_race_penta(years(0),"race")
do y = 1, ny-1
pentau = pentau + read_ncep_cmap_penta(years(y),"u")
pentav = pentav + read_ncep_cmap_penta(years(y),"v")
pentar = pentar + read_ncep_cmap_penta(years(y),"r")
race = race + read_jtwc_race_penta(years(y),"race")
end do
pentau = pentau /ny
pentav = pentav /ny
pentar = pentar /ny
race = race/ny
res = True
res@title = "WNP(120E-150E,5N-20N) Wind barb & CMAP "+title
res@filename = filename
res@refline = 6
res@fftrain = 12
res@race = race
res@onset = True
p = plot_onset(pentau,pentav,pentar,res)
return True
end