forked from NCAR/CESM_postprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_vertical_zonal_mean_chem_obs_mls.ncl
402 lines (370 loc) · 11.3 KB
/
plot_vertical_zonal_mean_chem_obs_mls.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
; NCL script
; plot_vertical_zonal_mean_chem_obs_mls.ncl
; Simone Tilmes, Oct 2015
;**************************************
; compare to HALOE observations
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; BRH
load "$DIAG_CODE/functions_contrib.ncl"
load "$DIAG_CODE/functions_vertical.ncl"
begin
compare = getenv("COMPARE")
plot_type = getenv("PLOTTYPE")
color_type = getenv("COLORTYPE")
rgb_file = getenv("RGB_FILE")
season = getenv("SEASON")
version = getenv("DIAG_VERSION")
wkdir = getenv("WKDIR")
time_stamp = getenv("TIMESTAMP")
case_names = getenv("CASENAMES")
ncdf_mode = getenv("NCDF_MODE")
infile1 = getenv("TEST_INPUT") ; case1 input filename
infile2 = getenv("CNTL_INPUT") ; case2 input filename
testcase = getenv("TEST_CASE")
compcase = getenv("STD_CASE")
;mg_micro = getenv("MG_MICRO")
use_waccm_levs = getenv("USE_WACCM_LEVS")
use_chem_levs = getenv("USE_CHEM_LEVS")
;************************************************************************
p0 = 1000. ; mb required by vinth2p
interp = 2 ; log interpolation
extrap = False ; no extrapolation past psfc.
;************************************************************************
vars = (/"CO","H2O","HCL","HNO3","N2O","O3","T"/)
vars_mls = (/"CO","H2O","HCl","HNO3","N2O","O3","Temperature"/)
units = (/"ppb","ppm","ppb","ppb","ppb","ppm","K"/)
factor = (/1.e+09,1.e+06,1.e+09,1.e+09,1.e+09,1.e+06,1./)
; con(:)=cfactor(v)*(/1,2,3,4,5,6,7,8,9,10,11,12,13,14,16/)+offset(v)
; dcon(:)=dfactor(v)*(/-1.8,-1.5,-1.2,-.9,-.6,-.3,-.1,0,.1,.3,.6,.9,1.2,1.5,1.8/)
cfactor = (/5.,0.5,1.,1.,20.,0.5,5./)
dfactor = (/20.,20.,20.,20.,20.,20.,20./)
offset = (/0.,2.,0.,0.,0.,0.,170./)
nvars = dimsizes(vars)
; contour levels
con = new((/15/),float)
dcon = new ((/15/),float)
do v = 0,nvars-1
;do v = 5,5
; loop over variables
;************************************************************************
; read MLS climatology:
; get MOPITT information
; mls = "$OBS_DATA/MLS_"+vars(v)+"_"+season+"_climo.nc"
f_mls = "/glade/p/acd/tilmes/climos/MLS/MLS_"+vars(v)+"_"+season+"_climo.nc"
mls = addfile(f_mls,"r")
mls_var = mls->$vars_mls(v)$
mls_lev = mls->lev
mls_lat = mls->lat
mls_var@units = units(v)
mls_var@long_name = vars(v)
;************************************************************************
; CASE 1 MODEL
nc=1
inptr1 = addfile(infile1,"r")
if (case_names .eq. "True") then
case1 = getenv("CASE1")
else
case1 = inptr1@case ; case name
end if
case1 = str_strip(case1)
if (isatt(inptr1,"yrs_averaged")) then
yrs_ave1 = inptr1@yrs_averaged
end if
tmp = inptr1->lat
if (typeof(tmp).eq."double") then
lat1 = dble2flt(tmp)
else
lat1 = tmp
end if
delete(tmp)
lev1 = inptr1->lev
lon1 = inptr1->lon
nlat1 = dimsizes(lat1)
nlon1 = dimsizes(lon1)
nlev1 = dimsizes(lev1)
hyam1 = inptr1->hyam
hybm1 = inptr1->hybm
tmp = inptr1->PS
if (typeof(tmp).eq."double") then
ps1 = dble2flt(tmp)
else
ps1 = tmp
end if
delete(tmp)
model1= mls_var
model1_diff = mls_var
if (isfilevar(inptr1,vars(v))) then
var1_model = inptr1->$vars(v)$
; interpolate to measurement levels
press1 = pres_hybrid_ccm(ps1,p0,hyam1,hybm1)
pp1 = press1 ; mbar
var1 = int2p_n_Wrap (pp1,var1_model,mls_lev,interp,1)
; zonal mean
var_zm1 = dim_avg_n_Wrap(var1,3)
; regrid to mls latitudes
var_zmlat1 = linint1_n_Wrap(lat1,var_zm1,False,mls_lat,0,2)
var_zm_lat1 = (var_zmlat1(0,:,:))
delete(var1_model)
delete(var1)
delete(var_zm1)
delete(var_zmlat1)
else
var_zm_lat1=mls_var
end if
delete(lat1)
delete(lev1)
delete(hyam1)
delete(hybm1)
model1 = (/var_zm_lat1*factor(v)/)
if vars(v).ne."T" then
model1_diff = (/(100*(model1-mls_var)/mls_var)/)
model1_diff@units = "%"
else
model1_diff = (/model1-mls_var/)
model1_diff@units = units(v)
end if
model1@units = units(v)
model1@long_name = vars(v)
; CASE 2 IS OBS (OR MODEL)
nc=2
if (compare .ne. "OBS") then
; CASE 2 MODEL
inptr2 = addfile(infile2,"r")
if (case_names .eq. "True") then
case2 = getenv("CASE2")
else
case2 = inptr2@case ; case name
end if
case2 = str_strip(case2)
if (isatt(inptr2,"yrs_averaged")) then
yrs_ave2 = inptr2@yrs_averaged
end if
tmp = inptr2->lat
if (typeof(tmp).eq."double") then
lat2 = dble2flt(tmp)
else
lat2 = tmp
end if
delete(tmp)
lev2 = inptr2->lev
lon2 = inptr2->lon
nlat2 = dimsizes(lat2)
nlon2 = dimsizes(lon2)
nlev2 = dimsizes(lev2)
hyam2 = inptr2->hyam
hybm2 = inptr2->hybm
tmp = inptr2->PS
if (typeof(tmp).eq."double") then
ps2 = dble2flt(tmp)
else
ps2 = tmp
end if
delete(tmp)
model2 = mls_var
model2_diff = mls_var
if (isfilevar(inptr2,vars(v))) then
var2_model = inptr2->$vars(v)$
; interpolate to measurement levels
press2 = pres_hybrid_ccm(ps2,p0,hyam2,hybm2)
pp2 = press2 ; mbar
var2 = int2p_n_Wrap (pp2,var2_model,mls_lev,interp,1)
; zonal mean
var_zm2 = dim_avg_n_Wrap(var2,3)
; regrid to mls latitudes
var_zmlat2 = linint1_n_Wrap(lat2,var_zm2,False,mls_lat,0,2)
var_zm_lat2 = (var_zmlat2(0,:,:))
delete(var2_model)
delete(var2)
delete(var_zm2)
delete(var_zmlat2)
else
var_zm_lat2=mls_var
end if
delete(lat2)
delete(lev2)
delete(hyam2)
delete(hybm2)
model2 = (/var_zm_lat2*factor(v)/)
if vars(v).ne."T" then
model2_diff = (/(100*(model2-mls_var)/mls_var)/)
model2_diff@units = "%"
else
model2_diff = (/model2-mls_var /)
model2_diff@units = units(v)
end if
model2@units = units(v)
model2@long_name = vars(v)
end if
;**********************************************************************
; common resources for contour plots
cnplot = new(nc*3,"graphic")
cres = True
cres@gsnDraw = False
cres@gsnFrame = False
cres@trXReverse = False
cres@tiYAxisString = "Pressure (mb)"
cres@txFontHeightF = 0.023
if (color_type .eq. "COLOR") then
cres@cnLevelSelectionMode = "ExplicitLevels"
cres@cnFillOn = True
cres@cnLinesOn = False
cres@cnLineLabelsOn = False
cres@lbTitleOn = True
cres@lbLabelFontHeightF = 0.018
cres@lbTitleFontHeightF = 0.02
cmap = RGBtoCmap(rgb_file)
else
cres@cnLevelSelectionMode = "ManualLevels"
cres@cnLinesOn = True
cres@cnLineLabelsOn = True
cres@cnLineLabelInterval = 1
cres@cnLineLabelFontHeightF = .02
cres@cnInfoLabelFontHeightF = .02
cnlvls = 15
diffcnlvls = 12
end if
;-------------------------------------------
; common resoureces for panel plot
pan = True
pan@gsnMaximize = True
;if nc.eq.2 then
;pan@gsnPaperOrientation = "landscape"
;else
pan@gsnPaperOrientation = "portrait"
;end if
pan@txFontHeightF = 0.018
pan@gsnFrame = False
;***********************************************************
pan@txString = vars(v)+" "+season
con(:)=cfactor(v)*(/1,2,3,4,5,6,7,8,9,10,11,12,13,14,16/)+offset(v)
dcon(:)=dfactor(v)*(/-1.8,-1.5,-1.2,-.9,-.6,-.3,-.1,0,.1,.3,.6,.9,1.2,1.5,1.8/)
cres@trYMaxF = 1.
; cres@trYMaxF = max(mls_lev)
cres@trYMaxF = 100.
data_mls = mls_var ; model data(lev,lat)
data_mls&lev@units = "hPa"
;------------------------- Open files for plots -----------------------------
set_prefix = "wset2_mls_"
if (color_type .eq. "COLOR") then
wks = gsn_open_wks(plot_type,wkdir+set_prefix+season+"_"+vars(v)+"_c")
gsn_define_colormap(wks,cmap)
else
wks = gsn_open_wks(plot_type,wkdir+set_prefix+season+"_"+vars(v))
end if
;-------------------------------------------------------------------------
; case plots of latitude(x) vs. pressure/height(y)
; if (any(vars(v) .eq. linear)) then
; cres@trYLog = False
; else
cres@trYLog = True
; end if
min1 = min(data_mls)
max1 = max(data_mls)
min2 = min(model1)
max2 = max(model1)
min3 = min(model2)
max3 = max(model2)
if (color_type .eq. "COLOR") then
cres@lbLabelStride = 2
cres@lbOrientation = "Horizontal"
cres@cnLevels = con(:)
cres@lbTitleString = "MIN = "+sprintf("%6.2f",min1)+ \
" MAX = "+sprintf("%6.2f",max1)
else
minab = min((/min1,min2/))
maxab = min((/max1,max2/))
mnmxint = nice_mnmxintvl (minab,maxab,cnlvls,False)
cres@cnMinLevelValF = mnmxint(0)
cres@cnMaxLevelValF = mnmxint(1)
cres@cnLevelSpacingF = mnmxint(2)
end if
if (isvar("yrs_ave1")) then
main_case1 = case1+" (yrs "+yrs_ave1+")"
else
main_case1 = case1
end if
cres@cnLevels = con(:)
cres@tiMainString = "MLS 2005-2014"
cres@lbTitleString = "MIN = "+sprintf("%6.2f",min1)+ \
" MAX = "+sprintf("%6.2f",max1)
cnplot(0) = gsn_csm_pres_hgt(wks,data_mls,cres)
cres@lbTitleString = "MIN = "+sprintf("%6.2f",min2)+ \
" MAX = "+sprintf("%6.2f",max2)
cres@tiMainString = main_case1
cnplot(1) = gsn_csm_pres_hgt(wks,model1,cres)
cres@tiMainString = case1+" - MLS"
cres@lbTitleString = "% Difference"
cres@cnLevels = dcon(:)
cnplot(2) = gsn_csm_pres_hgt(wks,model1_diff,cres)
if nc.eq.2 then
if (isvar("yrs_ave1")) then
main_case2 = case2+" (yrs "+yrs_ave2+")"
else
main_case2 = case2
end if
cres@cnLevels = con(:)
cres@lbTitleString = "MIN = "+sprintf("%6.2f",min1)+ \
" MAX = "+sprintf("%6.2f",max1)
cres@tiMainString = "MLS 2005-2014"
cnplot(1) = gsn_csm_pres_hgt(wks,data_mls,cres)
cres@tiMainString = main_case1
cres@lbTitleString = "MIN = "+sprintf("%6.2f",min2)+ \
" MAX = "+sprintf("%6.2f",max2)
cnplot(2) = gsn_csm_pres_hgt(wks,model1,cres)
cres@tiMainString = main_case2
cres@lbTitleString = "MIN = "+sprintf("%6.2f",min3)+ \
" MAX = "+sprintf("%6.2f",max3)
cnplot(3) = gsn_csm_pres_hgt(wks,model2,cres)
cres@lbTitleString = "% Difference"
cres@tiMainString = case1+" - MLS"
cres@cnLevels = dcon(:)
cnplot(4) = gsn_csm_pres_hgt(wks,model1_diff,cres)
cres@tiMainString = case2+" - MLS"
cnplot(5) = gsn_csm_pres_hgt(wks,model2_diff,cres)
end if
; if (color_type .eq. "MONO") then
; cnplot(0) = ZeroNegDashLineContour(cnplot(0))
; else
; delete (cres@lbTitleString)
; end if
; if (color_type .eq. "COLOR") then
; cres@lbTitleString = "MIN = "+sprintf("%6.2f",min2)+ \
; " MAX = "+sprintf("%6.2f",max2)
; end if
if (color_type .eq. "MONO") then
cnplot(1) = ZeroNegDashLineContour(cnplot(1))
else
delete (cres@cnLevels)
delete (cres@lbLabelStride)
delete (cres@lbOrientation)
delete (cres@lbTitleString)
end if
delete (cres@tiMainString)
delete (min1)
delete (max1)
delete (min2)
delete (max2)
if (time_stamp .eq. "True") then
pan@gsnPanelBottom = 0.05
gsn_panel(wks,cnplot,(/nc*3,2/),pan) ; panel plot
infoTimeStamp(wks,0.011,"DIAG Version: "+version)
else
gsn_panel(wks,cnplot,(/nc*3,2/),pan) ; panel plot
end if
frame (wks)
delete (cres@trYMinF)
delete (cres@trYMaxF)
delete(var_zm_lat1)
delete (model1)
delete (model1_diff)
delete (data_mls)
if (compare.ne."OBS") then
delete (model2)
delete(var_zm_lat2)
delete (model2_diff)
end if
delete(mls_var)
delete(mls_lev)
end do ;v
end