1 | ;================================================; |
---|
2 | ; Example ncl script to produce the set of |
---|
3 | ; lat-lon plots for DCMIP-2016 test case 1 |
---|
4 | ; Created by James Kent, Christiane Jablonowski |
---|
5 | ; and Paul Ullrich (University of Michigan) for DCMIP-2012 |
---|
6 | ; |
---|
7 | ; Modified by Colin Zarzycki for DCMIP-2016 |
---|
8 | ; Further modified by Maximo Menchaca for creating gifs |
---|
9 | ; |
---|
10 | ; v1.01 - 6/7/16 |
---|
11 | ; v1.02 - 6/8/16 - Typo in var_choice options |
---|
12 | ;================================================; |
---|
13 | load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" |
---|
14 | load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" |
---|
15 | load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" |
---|
16 | load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl" |
---|
17 | ; ================================================; |
---|
18 | |
---|
19 | ; NOTE, if your model does not output T850 OR P at level |
---|
20 | ; midpoints OR you cannot calculate P from hybrid levels, you |
---|
21 | ; will need to make model specific additions denoted by |
---|
22 | ; CALCPHERE below |
---|
23 | |
---|
24 | ; PRECL needs to be in m/s for contours to plot correctly |
---|
25 | |
---|
26 | begin |
---|
27 | |
---|
28 | ;=================================================; |
---|
29 | ; open file and read in data |
---|
30 | ; GIVEN AS (time,lev,lat,lon) from 0 to n-1 |
---|
31 | ;=================================================; |
---|
32 | |
---|
33 | ; NOTE, that this file needs to be a catted file including all times at daily interval |
---|
34 | ; if you are outputting 1 file per time, you can run "ncrcat dcmip1.files.*.nc cat.nc" |
---|
35 | ; for one file |
---|
36 | |
---|
37 | f = addfile("output_dcmip2016_regular.nc","r") |
---|
38 | |
---|
39 | use_pdf = False |
---|
40 | |
---|
41 | ; Input useful parameters |
---|
42 | |
---|
43 | lat = f->lat |
---|
44 | lon = f->lon |
---|
45 | lev = f->lev |
---|
46 | nlat = getfilevardimsizes(f, "lat" ) |
---|
47 | nlon = getfilevardimsizes(f, "lon" ) |
---|
48 | nlev = getfilevardimsizes(f, "lev" ) |
---|
49 | |
---|
50 | ; We want plots of temperature, vertical velocity and relative vorticity |
---|
51 | ; at the 850 hPa level. We also want surface pressure. |
---|
52 | |
---|
53 | ; Select var_choice 1 - Temperature at 850 hPa |
---|
54 | ; 2 - Large-scale precipitation |
---|
55 | ; 3 - Surface Pressure |
---|
56 | |
---|
57 | do var_choice = 1,3 |
---|
58 | ; var_choice = 1 |
---|
59 | |
---|
60 | if (var_choice .eq. 1) then ; Select T |
---|
61 | |
---|
62 | if (isfilevar(f,"T850")) then |
---|
63 | |
---|
64 | varload = f->T850 |
---|
65 | |
---|
66 | else |
---|
67 | |
---|
68 | ; we interp T to the 850 hPa level |
---|
69 | varload0 = f->T ; T is a 4D var |
---|
70 | varload = f->T(:,0,:,:) |
---|
71 | ; Calculate P using hybrid coefficients |
---|
72 | ; If you have pressure as a variable just do |
---|
73 | ; P = f->P |
---|
74 | ; CALCPHERE |
---|
75 | hyam = f->hyam |
---|
76 | hybm = f->hybm |
---|
77 | P0 = f->P0 |
---|
78 | PS = f->PS |
---|
79 | P = 0.0*varload0 |
---|
80 | P = pres_hybrid_ccm(PS,P0,hyam,hybm) |
---|
81 | P!0 = "time" |
---|
82 | P!1 = "lev" |
---|
83 | P!2 = "lat" |
---|
84 | P!3 = "lon" |
---|
85 | ; interp to 850 hPa level |
---|
86 | plevel = 85000.0 |
---|
87 | varload = int2p_n(P,varload0,plevel,2,1) |
---|
88 | |
---|
89 | end if |
---|
90 | |
---|
91 | filename_string = "DYNAMICO-case161latlonT850" |
---|
92 | |
---|
93 | else if (var_choice .eq. 2) then ; Select Large-scale precipitation |
---|
94 | |
---|
95 | varload = f->PRECT |
---|
96 | ; varload=varload*8.64e7 |
---|
97 | filename_string = "DYNAMICO-case161latlonPRECT" |
---|
98 | |
---|
99 | else if (var_choice .eq. 3) then ; Select PS |
---|
100 | filename_string = "DYNAMICO-case161latlonPS" |
---|
101 | |
---|
102 | varload = f->PS |
---|
103 | |
---|
104 | end if |
---|
105 | end if |
---|
106 | end if |
---|
107 | |
---|
108 | if(use_pdf) then |
---|
109 | wks = gsn_open_wks("pdf",filename_string) ; output using X11 |
---|
110 | else |
---|
111 | wks = gsn_open_wks("png",filename_string) ; output using png |
---|
112 | end if |
---|
113 | |
---|
114 | ; We want the output at days 6, 9, 12 and 15. If your model |
---|
115 | ; output is in 6 hourly intervals this becomes indices 24, 36, 48 and 60 |
---|
116 | |
---|
117 | do d = 0,23 |
---|
118 | day_curr = d*5 |
---|
119 | |
---|
120 | ; day6 = 24 |
---|
121 | ; day9 = 36 |
---|
122 | ; day12 = 48 |
---|
123 | ; day15 = 60 |
---|
124 | |
---|
125 | var1 = varload(d,:,:) |
---|
126 | ; var2 = varload(day9,:,:) |
---|
127 | ; var3 = varload(day12,:,:) |
---|
128 | ; var4 = varload(day15,:,:) |
---|
129 | |
---|
130 | ; We don't want long-name in the plots |
---|
131 | |
---|
132 | var1@long_name = " " |
---|
133 | ; var2@long_name = " " |
---|
134 | ; var3@long_name = " " |
---|
135 | ; var4@long_name = " " |
---|
136 | |
---|
137 | ; Delete loaded data |
---|
138 | |
---|
139 | ; delete(varload) |
---|
140 | |
---|
141 | ; We now produce the plot |
---|
142 | |
---|
143 | ; plot = new (4, graphic) ; define plot - need 4 panels |
---|
144 | |
---|
145 | res1 = True |
---|
146 | res1@gsnDraw = False ; panel plot |
---|
147 | res1@gsnFrame = False ; don't draw yet |
---|
148 | res1@cnFillOn = True |
---|
149 | res1@cnLinesOn = True |
---|
150 | res1@gsnSpreadColors = True |
---|
151 | res1@lbLabelAutoStride = True |
---|
152 | res1@gsnCenterString = "" |
---|
153 | res1@tiMainString = "" |
---|
154 | res1@vpWidthF = 0.38 |
---|
155 | res1@vpHeightF = 0.19 |
---|
156 | res1@cnLevelSelectionMode = "ManualLevels" |
---|
157 | res1@cnInfoLabelOn = False ; don't give each |
---|
158 | res1@cnLineLabelsOn = False ; panel its own |
---|
159 | res1@lbLabelBarOn = False ; label bar |
---|
160 | |
---|
161 | pres = True |
---|
162 | pres@gsnMaximize = True |
---|
163 | pres@gsnPanelLabelBar = True ; Communal label bar |
---|
164 | pres@gsnPanelLeft = 0.1 |
---|
165 | pres@gsnPanelRight = 0.9 |
---|
166 | pres@pmLabelBarOrthogonalPosF = -0.03 |
---|
167 | pres@gsnFrame = False |
---|
168 | pres@lbLabelStride = 1 |
---|
169 | |
---|
170 | res1@sfXArray = lon ; uses lon as plot x-axis |
---|
171 | res1@sfYArray = lat ; uses lat for y axis |
---|
172 | res1@trYReverse = False ; reverses y-axis, false |
---|
173 | res1@tiYAxisString = "" ; y-axis title |
---|
174 | res1@tiXAxisString = "" ; x-axis title |
---|
175 | |
---|
176 | if (var_choice .eq. 1) then ;================ Temperature plot ==================== |
---|
177 | |
---|
178 | pltTitle="DYNAMICO Case 161, T850 hPa" ; Plot title if required |
---|
179 | pres@txString = pltTitle |
---|
180 | |
---|
181 | ; Change the output type and name |
---|
182 | |
---|
183 | gsn_define_colormap(wks,"gui_default") |
---|
184 | |
---|
185 | res1@cnMaxLevelValF = 295.0 ; max contour color label |
---|
186 | res1@cnMinLevelValF = 280.0 ; min contour color label |
---|
187 | res1@cnLevelSpacingF = 1.0 ; contour color spacing ; choose a colormap |
---|
188 | |
---|
189 | else if (var_choice .eq. 2) then ;================ Large-scale precipitation plot ==================== |
---|
190 | |
---|
191 | pltTitle="DYNAMICO Case 161, Large-scale precipitation" ; Plot title if required |
---|
192 | pres@txString = pltTitle |
---|
193 | |
---|
194 | var1@units = " " |
---|
195 | ; var2@units = " " |
---|
196 | ; var3@units = " " |
---|
197 | ; var4@units = " " |
---|
198 | |
---|
199 | res1@cnLinesOn = False ; Turn lines off for clearer plot |
---|
200 | |
---|
201 | ; Change the output type and name |
---|
202 | |
---|
203 | gsn_define_colormap(wks,"gui_default") |
---|
204 | |
---|
205 | ; Note that the maximum might be larger than these contour spacing values |
---|
206 | |
---|
207 | res1@cnMaxLevelValF = 1e-4 ; max contour color label |
---|
208 | res1@cnMinLevelValF = 0.0 ; min contour color label |
---|
209 | res1@cnLevelSpacingF = 1e-5 ; contour color spacing ; choose a colormap |
---|
210 | |
---|
211 | else if (var_choice .eq. 3) then ;================ Surface Pressure plot ==================== |
---|
212 | |
---|
213 | pltTitle="DYNAMICO Case 161, PS" ; Plot title if required |
---|
214 | pres@txString = pltTitle |
---|
215 | |
---|
216 | ; Convert to hPa |
---|
217 | |
---|
218 | var1=var1/100.0 |
---|
219 | ; var2=var2/100.0 |
---|
220 | ; var3=var3/100.0 |
---|
221 | ; var4=var4/100.0 |
---|
222 | |
---|
223 | var1@units = "hPa " |
---|
224 | ; var2@units = "hPa " |
---|
225 | ; var3@units = "hPa " |
---|
226 | ; var4@units = "hPa " |
---|
227 | |
---|
228 | ; Change the output type and name |
---|
229 | |
---|
230 | gsn_define_colormap(wks,"gui_default") |
---|
231 | |
---|
232 | res1@cnMaxLevelValF = 1005.0 ; max contour color label |
---|
233 | res1@cnMinLevelValF = 995.0 ; min contour color label |
---|
234 | res1@cnLevelSpacingF = 1.0 ; contour color spacing ; choose a colormap |
---|
235 | |
---|
236 | end if ;============== end plot choice =============== |
---|
237 | end if ;============== end plot choice =============== |
---|
238 | end if ;============== end plot choice =============== |
---|
239 | |
---|
240 | res1@gsnCenterString = "t = " + day_curr + " min" |
---|
241 | plot = gsn_csm_contour(wks,var1(:,:),res1) ; plot var1 |
---|
242 | |
---|
243 | ; res1@gsnCenterString = "t = 9" |
---|
244 | ; plot(1) = gsn_csm_contour(wks,var2(:,:),res1) ; plot var2 |
---|
245 | ; |
---|
246 | ; res1@gsnCenterString = "t = 12" |
---|
247 | ; plot(2) = gsn_csm_contour(wks,var3(:,:),res1) ; plot var3 |
---|
248 | ; |
---|
249 | ; res1@gsnCenterString = "t = 15" |
---|
250 | ; plot(3) = gsn_csm_contour(wks,var4(:,:),res1) ; plot var4 |
---|
251 | |
---|
252 | gsn_panel(wks,plot,(/1,1/),pres) ; 2x2 plot |
---|
253 | |
---|
254 | ; Add latitude and longitude labels |
---|
255 | |
---|
256 | txres3 = True |
---|
257 | txres3@txAngleF = 90. |
---|
258 | txres3@txFontHeightF = 0.02 |
---|
259 | gsn_text_ndc(wks,"Latitude",0.08,0.49,txres3) |
---|
260 | |
---|
261 | txres3@txAngleF = 0. |
---|
262 | gsn_text_ndc(wks,"Longitude",0.5,0.22,txres3) |
---|
263 | |
---|
264 | frame(wks) |
---|
265 | |
---|
266 | end do |
---|
267 | delete(varload) |
---|
268 | cmd = "convert -delay 25 "+ filename_string+"*.png "+filename_string+".gif" |
---|
269 | system(cmd) |
---|
270 | cmd = "rm "+filename_string+"*.png" |
---|
271 | system(cmd) |
---|
272 | end do |
---|
273 | |
---|
274 | end |
---|
275 | |
---|
276 | |
---|
277 | |
---|
278 | |
---|
279 | |
---|
280 | |
---|