Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
1 ; ***********************************************
2 ; combine 19.metric_plot.ncl and 24.lines.ncl
3 ; ***********************************************
4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
5 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
7 ;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
8 ;************************************************
10 ;************************************************
11 ; read in data: observed
12 ;************************************************
13 diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/"
14 fili = "co2_globalView_98.nc"
15 g = addfile (diri+fili,"r")
19 sta = chartostring(g->STATION)
27 ;**************************************************************
28 ; get only the lowest level at each station
29 ;**************************************************************
31 lat_tmp@_FillValue = 1.e+36
34 if (.not. ismissing(lat_tmp(n))) then
35 indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
36 if (dimsizes(indexes) .gt. 1) then
37 lat_tmp(indexes(1:)) = lat_tmp@_FillValue
43 indexes = ind(.not. ismissing(lat_tmp))
44 ;print (dimsizes(indexes))
49 val_ob = val(indexes,:)
50 ;printVarSummary (val_ob)
51 ;print (lat_ob +"/"+lon_ob)
53 ;************************************************
55 ;************************************************
56 diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
57 ; fili2 = "b30.061m_401_425_MONS_climo_atm.nc"
58 fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc"
60 g = addfile(diri2+fili2,"r")
69 ; get the co2 at the lowest level
72 ; change to unit of observed (u mol/mol)
73 ; Model_units [=] kgCO2 / kgDryAir
74 ; 28.966 = molecular weight of dry air
75 ; 44. = molecular weight of CO2
78 factor = (28.966/44.) * 1e6
83 ; y = where(y0 .lt. 287.,y@_FillValue,y)
85 ; print (min(y)+"/"+max(y))
87 ; interpolate into observed station
88 ; note: model is 0-360E, 90S-90N
90 ; to be able to handle observation at (-89.98,-24.80)
94 i = ind(lon_ob .lt. 0.)
95 lon_ob(i) = lon_ob(i) + 360.
97 yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0)
99 val_model = yo(pts|:,time|:)
100 val_model_0 = val_model
101 ; printVarSummary (val_model)
102 ; print (min(val_model)+"/"+max(val_model))
105 val_model = val_model - conform(val_model,dim_avg(val_model),0)
106 ; print (min(val_model)+"/"+max(val_model))
109 ;--------------------------------------------------------------
111 ;**********************************
113 table_header_name = "Zone"
115 ; column (not including header column)
116 col_header_zone = (/"Stations","Amplitude Ratio", \
117 "Correlation Coef","M score","Combined Score"/)
118 ncol_zone = dimsizes(col_header_zone )
120 ; row (not including header row)
121 row_header_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/)
122 nrow_zone = dimsizes(row_header_zone)
124 ; arrays to be passed to table.
125 value_zone = new ((/nrow_zone, ncol_zone/),string )
126 ;**********************************
128 table_length_zone = 0.4
131 ncr1 = (/1,1/) ; 1 row, 1 column
132 x1 = (/0.005,0.15/) ; Start and end X
133 y1 = (/0.900,0.995/) ; Start and end Y
134 text1 = table_header_name
136 res1@txFontHeightF = 0.03
137 res1@gsFillColor = "CornFlowerBlue"
139 ; Column header (equally space in x2)
140 ncr2 = (/1,ncol_zone/) ; 1 rows, 5 columns
141 x2 = (/x1(1),0.995/) ; start from end of x1
143 text2 = col_header_zone
145 res2@txFontHeightF = 0.015
146 res2@gsFillColor = "Gray"
148 ; Row header (equally space in y2)
149 ncr3 = (/nrow_zone,1/) ; 5 rows, 1 columns
151 y3 = (/1.0-table_length_zone,0.900/) ; end at start of y1
152 text3 = row_header_zone
154 res3@txFontHeightF = 0.02
155 res3@gsFillColor = "Gray"
158 ncr4 = (/nrow_zone,ncol_zone/) ; 5 rows, 5 columns
159 x4 = x2 ; Start and end x
160 y4 = y3 ; Start and end Y
161 text4 = new((/nrow_zone,ncol_zone/),string)
163 color_fill4 = new((/nrow_zone,ncol_zone/),string)
164 color_fill4 = "white"
165 color_fill4(:,ncol_zone-1) = "grey"
167 res4 = True ; Set up resource list
168 ; res4@gsnDebug = True ; Useful to print NDC row,col values used.
169 res4@txFontHeightF = 0.02
170 res4@gsFillColor = color_fill4
173 ;--------------------------------------------------------------
174 ; for station line plot
176 ; for x-axis in xyplot
178 mon@long_name = "month"
181 plot_type_new = "png"
183 res = True ; plot mods desired
184 res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker
185 res@xyLineColors = (/"red","black"/) ; change line color
187 ; Add a boxed legend using the more simple method
189 res@pmLegendDisplayMode = "Always"
190 ; res@pmLegendWidthF = 0.1
191 res@pmLegendWidthF = 0.08
192 res@pmLegendHeightF = 0.06
193 ; res@pmLegendOrthogonalPosF = -1.17
194 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
195 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
197 ; res@pmLegendParallelPosF = 0.18
198 res@pmLegendParallelPosF = 0.23 ;(rightward)
200 ; res@lgPerimOn = False
201 res@lgLabelFontHeightF = 0.015
202 res@xyExplicitLegendLabels = (/"b30.061n","observed"/)
203 ;-------------------------------------------------------------------
208 ; maximum score for the zone, 60N-90N
211 ; index of stations in this zone
212 ind_z = ind(lat_ob .ge. 60.)
214 ; print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
215 ; print (val_ob(ind_z,:))
216 ; print (val_model(ind_z,:))
220 ; maximum score for the zone, 30N-60N
223 ; index of stations in this zone
224 ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
226 ; print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
227 ; print (val_ob(ind_z,:))
228 ; print (val_model(ind_z,:))
232 ; maximum score for the zone, EQ-30N
235 ; index of stations in this zone
236 ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
238 ; print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
239 ; print (val_ob(ind_z,:))
240 ; print (val_model(ind_z,:))
244 ; maximum score for the zone, 90S-EQ
247 ; index of stations in this zone
248 ind_z = ind(lat_ob .lt. 0. )
250 ; print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
251 ; print (val_ob(ind_z,:))
252 ; print (val_model(ind_z,:))
255 npts = dimsizes(ind_z)
257 ;-------------------------------------------------------------------------
260 amp_ob = new((/npts/),float)
261 amp_model = new((/npts/),float)
263 amp_ratio_sta = new((/npts/),float)
264 ccr_sta = new((/npts/),float)
265 M_sta = new((/npts/),float)
266 score_sta = new((/npts/),float)
267 ;-------------------------------------------------------------------------
268 ; for station line plot
274 plot_data = new((/2,12,npts/),float)
275 plot_data_0 = new((/12,npts/),float)
278 plot_data!1 = "month"
280 plot_data@long_name = "CO2 Seasonal"
282 plot_data_0!0 = "month"
283 plot_data_0!1 = "pts"
284 plot_data_0@long_name = "CO2"
285 ;--------------------------------------------------------------------------
287 amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:))
288 amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:))
290 amp_ratio_sta(n) = amp_model(n)/amp_ob(n)
291 ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0)
292 M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.)
293 score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max
295 print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n))
296 ;----------------------------------------------------------------------
297 ; for station line plot
299 plot_data(0,:,n) = (/val_model(ind_z(n),:)/)
300 plot_data(1,:,n) = (/val_ob(ind_z(n),:)/)
302 plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/)
304 plot_name = sta(ind_z(n))
305 title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")"
309 wks = gsn_open_wks (plot_type,plot_name) ; open workstation
310 ;------------------------------------------
313 plot=new(2,graphic) ; create graphic array
314 res@gsnFrame = False ; Do not draw plot
315 res@gsnDraw = False ; Do not advance frame
317 pres = True ; panel plot mods desired
318 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
319 ; indiv. plots in panel
320 pres@gsnMaximize = True ; fill the page
321 ;------------------------------------------
322 res@tiMainString = title ; add title
324 plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1
326 plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2
328 gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot
330 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
331 system("rm "+plot_name+"."+plot_type)
333 ;---------------------------------------------------------------------------
335 ;-------------------------------------------------------------------------
336 ; for line plot in a zone
338 plot_name = "All_"+npts_str
339 title = plot_name + " in "+ zone
343 wks = gsn_open_wks (plot_type,plot_name) ; open workstation
344 ;-----------------------------------------
347 plot=new(2,graphic) ; create graphic array
348 res@gsnFrame = False ; Do not draw plot
349 res@gsnDraw = False ; Do not advance frame
351 pres = True ; panel plot mods desired
352 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
353 ; indiv. plots in panel
354 pres@gsnMaximize = True ; fill the page
355 ;-----------------------------------------
356 res@tiMainString = title ; add title
358 plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1
360 plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2
362 gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot
364 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
365 system("rm "+plot_name+"."+plot_type)
371 ;---------------------------------------------------------------------------
374 amp_ratio_zone = avg(amp_ratio_sta)
375 ccr_zone = avg(ccr_sta)
376 M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts)
377 score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max
379 print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone)
381 text4(z,0) = sprintf("%5.2f", npts)
382 text4(z,1) = sprintf("%5.2f", amp_ratio_zone)
383 text4(z,2) = sprintf("%5.2f", ccr_zone)
384 text4(z,3) = sprintf("%5.2f", M_zone)
385 text4(z,4) = sprintf("%5.2f", score_zone)
386 ;---------------------------------------------------------------------------
387 ; column for station table
388 case_sta = (/"Latitude","Longitude","Amplitude Ratio", \
389 "Correlation Coef","M score","Combined Score"/)
390 nCase_sta = dimsizes(case_sta )
392 ; row for station table
394 nVar_sta = dimsizes(var_sta)
396 ; arrays to be passed to diagram.
397 case_value_sta = new ((/nCase_sta, nVar_sta/),float )
399 case_value_sta(0,:) = (/lat(ind_z)/)
400 case_value_sta(1,:) = (/lon(ind_z)/)
401 case_value_sta(2,:) = (/amp_ratio_sta/)
402 case_value_sta(3,:) = (/ccr_sta/)
403 case_value_sta(4,:) = (/M_sta/)
404 case_value_sta(5,:) = (/score_sta/)
406 ;**************************************************
408 ;**************************************************
410 tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps"
411 ; "png", "gif" [if you have ImageMajik 'convert']
413 tt_opt@tableTitle = "Zone "+ zone
414 plot_name = "table_sta." + zone
416 ; metrics_table(plot_name, var_sta, case_sta , case_value_sta, tt_opt)
421 delete (amp_ratio_sta)
426 delete (case_value_sta)
428 ;**************************************************
430 ;**************************************************
432 text4(4,0) = sum(stringtofloat(text4(0:3,0)))
436 text4(4,4) = sum(stringtofloat(text4(0:3,4)))
438 plot_name = "table_zone"
439 wks = gsn_open_wks (plot_type,plot_name) ; open workstation
441 gsn_table(wks,ncr1,x1,y1,text1,res1)
442 gsn_table(wks,ncr2,x2,y2,text2,res2)
443 gsn_table(wks,ncr3,x3,y3,text3,res3)
444 gsn_table(wks,ncr4,x4,y4,text4,res4)