Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
1 ; ***********************************************
2 ; using gsn_table for all
3 ; output: line plot for each site (4 fields)
5 ; ***********************************************
6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
7 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
8 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
9 ;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
10 ;************************************************
16 ;************************************************
18 ;************************************************
20 ; film = "i01.06cn_1798-2004_MONS_climo.nc"
22 ; model_name = "06casa"
23 ; film = "i01.06casa_1798-2004_MONS_climo.nc"
26 ; film = "i01.10cn_1948-2004_MONS_climo.nc"
29 film = "i01.10casa_1948-2004_MONS_climo.nc"
30 ;--------------------------------------------
31 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
32 fm = addfile(dirm+film,"r")
42 data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
44 ; change to unit of observed (u mol/m2/s)
45 ; Model_units [=] gC/m2/s
46 ; 12. = molecular weight of C
52 data_mod0(0,:,:,:) = data(:,:,:) * factor
56 data_mod0(1,:,:,:) = data(:,:,:)
60 data_mod0(2,:,:,:) = data(:,:,:)
64 data_mod0(3,:,:,:) = data(:,:,:)
67 ; printVarSummary (data_mod0)
68 ;************************************************
69 ; read in data: observed
70 ;************************************************
71 station = (/"BOREAS_NSA_OBS" \
81 year_ob = (/"1994-2004" \
91 field = (/"CO2 Flux" \
97 nstation = dimsizes(station)
99 nfield = dimsizes(field)
101 data_ob = new ((/nstation, nfield, nmon/),float)
102 lat_ob = new ((/nstation/),float)
103 lon_ob = new ((/nstation/),float)
105 diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
108 diri = diri_root + station(n)+"/"
109 fili = station(n)+"_"+year_ob(n)+"_monthly.nc"
110 g = addfile (diri+fili,"r")
116 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
120 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
124 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
128 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
136 ;printVarSummary (data_ob)
138 ;************************************************************
139 ; interpolate model data into observed station
140 ; note: model is 0-360E, 90S-90N
141 ;************************************************************
143 ; to be able to handle observation at (-89.98,-24.80)
147 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
151 data_mod = yy(pts|:,field|:,time|:)
152 ; printVarSummary (data_mod)
154 ;************************************************************
155 ; compute correlation coef and M score
156 ;************************************************************
160 ccr = new ((/nstation, nfield/),float)
161 M_score = new ((/nstation, nfield/),float)
165 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
166 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
167 M_score(n,m) = (1. -(bias/nmon)) * score_max
171 ;*******************************************************************
172 ; for station line plot
173 ;*******************************************************************
175 ; for x-axis in xyplot
177 mon@long_name = "month"
179 res = True ; plot mods desired
180 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
181 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
182 ;-------------------------------------------------------------------------
183 ; Add a boxed legend using the more simple method
185 res@pmLegendDisplayMode = "Always"
186 ; res@pmLegendWidthF = 0.1
187 res@pmLegendWidthF = 0.08
188 res@pmLegendHeightF = 0.06
189 ; res@pmLegendOrthogonalPosF = -1.17
190 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
191 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
193 ; res@pmLegendParallelPosF = 0.18
194 res@pmLegendParallelPosF = 0.23 ;(rightward)
196 ; res@lgPerimOn = False
197 res@lgLabelFontHeightF = 0.015
198 res@xyExplicitLegendLabels = (/"observed",model_name/)
199 ;-------------------------------------------------------------------
201 res@gsnFrame = False ; Do not draw plot
202 res@gsnDraw = False ; Do not advance frame
204 pres = True ; panel plot mods desired
205 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
206 ; indiv. plots in panel
207 pres@gsnMaximize = True ; fill the page
208 ;-------------------------------------------------------------------
210 plot_data = new((/2,12/),float)
212 plot_data!1 = "month"
215 ;----------------------------
218 plot_name = station(n)+"_ob"
219 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
220 res@tiMainString = title
222 wks = gsn_open_wks (plot_type,plot_name)
223 plot=new(4,graphic) ; create graphic array
225 plot_data(0,:) = (/data_ob (n,0,:)/)
226 plot_data@long_name = field(0)
227 plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1
229 plot_data(0,:) = (/data_ob (n,1,:)/)
230 plot_data@long_name = field(1)
231 plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2
233 plot_data(0,:) = (/data_ob (n,2,:)/)
234 plot_data@long_name = field(2)
235 plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3
237 plot_data(0,:) = (/data_ob (n,3,:)/)
238 plot_data@long_name = field(3)
239 plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4
241 gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
243 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
244 system("rm "+plot_name+"."+plot_type)
247 ;----------------------------
250 plot_name = station(n)+"_model_vs_ob"
251 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
252 res@tiMainString = title
254 wks = gsn_open_wks (plot_type,plot_name)
255 plot=new(4,graphic) ; create graphic array
257 plot_data(0,:) = (/data_ob (n,0,:)/)
258 plot_data(1,:) = (/data_mod(n,0,:)/)
259 plot_data@long_name = field(0)
260 plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1
262 plot_data(0,:) = (/data_ob (n,1,:)/)
263 plot_data(1,:) = (/data_mod(n,1,:)/)
264 plot_data@long_name = field(1)
265 plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2
267 plot_data(0,:) = (/data_ob (n,2,:)/)
268 plot_data(1,:) = (/data_mod(n,2,:)/)
269 plot_data@long_name = field(2)
270 plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3
272 plot_data(0,:) = (/data_ob (n,3,:)/)
273 plot_data(1,:) = (/data_mod(n,3,:)/)
274 plot_data@long_name = field(3)
275 plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4
277 gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
279 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
280 system("rm "+plot_name+"."+plot_type)
285 ;*******************************************************************
286 ; for table of site score
287 ;*******************************************************************
292 table_header_name = "Site"
294 ; column (not including header column)
295 col_header = (/"Latitude","Longitude","observed" \
296 ,"CO2 Flux","Net Radiation","Latent Heat" \
297 ,"Sensible Heat","Average" \
299 ncol = dimsizes(col_header)
301 ; row (not including header row)
303 row_header = new ((/nrow/),string )
304 row_header(0:nstation-1) = station(:)
305 row_header(nrow-1) = "All Sites"
308 ncr1 = (/1,1/) ; 1 row, 1 column
309 x1 = (/0.005,0.15/) ; Start and end X
310 y1 = (/0.800,0.895/) ; Start and end Y
311 text1 = table_header_name
313 res1@txFontHeightF = 0.03
314 res1@gsFillColor = "CornFlowerBlue"
316 ; Column header (equally space in x2)
317 ncr2 = (/1,ncol/) ; 1 rows, ncol columns
318 x2 = (/x1(1),0.995/) ; start from end of x1
322 res2@txFontHeightF = 0.010
323 res2@gsFillColor = "Gray"
325 ; Row header (equally space in y2)
326 ncr3 = (/nrow,1/) ; nrow rows, 1 columns
328 y3 = (/1.0-table_length,y1(0)/) ; end at start of y1
331 res3@txFontHeightF = 0.010
332 res3@gsFillColor = "Gray"
335 ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns
336 x4 = x2 ; Start and end x
337 y4 = y3 ; Start and end Y
338 text4 = new((/nrow,ncol/),string)
340 color_fill4 = new((/nrow,ncol/),string)
341 color_fill4 = "white"
342 color_fill4(:,ncol-1) = "grey"
343 color_fill4(nrow-1,:) = "green"
345 res4 = True ; Set up resource list
346 ; res4@gsnDebug = True ; Useful to print NDC row,col values used.
347 res4@txFontHeightF = 0.015
348 res4@gsFillColor = color_fill4
351 ;-------------------------------------------------------------------
355 text4(n,0) = sprintf("%5.2f", lat_ob(n))
356 text4(n,1) = sprintf("%5.2f", lon_ob(n))
357 text4(n,2) = year_ob(n)
358 text4(n,3) = sprintf("%5.2f", M_score(n,0)) ; CO2 Flux
359 text4(n,4) = sprintf("%5.2f", M_score(n,1)) ; Net Radiation
360 text4(n,5) = sprintf("%5.2f", M_score(n,2)) ; Latent Heat
361 text4(n,6) = sprintf("%5.2f", M_score(n,3)) ; Sensible Heat
362 text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields
367 M_co2 = avg(M_score(:,0))
368 M_rad = avg(M_score(:,1))
369 M_lh = avg(M_score(:,2))
370 M_sh = avg(M_score(:,3))
371 M_all = M_co2+ M_rad +M_lh + M_sh
373 text4(nrow-1,0) = "-"
374 text4(nrow-1,1) = "-"
375 text4(nrow-1,2) = "-"
376 text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites
377 text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites
378 text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites
379 text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites
380 text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites
387 ;---------------------------------------------------------------------------
389 plot_name = "table_site_score"
391 wks = gsn_open_wks (plot_type,plot_name)
392 ;------------------------------------------
396 gRes@txFontHeightF = 0.02
399 title_text = "Model " + model_name + " M_Score"
401 gsn_text_ndc(wks,title_text,0.50,0.95,gRes)
402 ;------------------------------------------
404 gsn_table(wks,ncr1,x1,y1,text1,res1)
405 gsn_table(wks,ncr2,x2,y2,text2,res2)
406 gsn_table(wks,ncr3,x3,y3,text3,res3)
407 gsn_table(wks,ncr4,x4,y4,text4,res4)
411 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
412 system("rm "+plot_name+"."+plot_type)
413 ;-------------------------------------------------------------------
414 temp_name = "temp." + model_name
415 system("mkdir -p " + temp_name)
416 system("mv *.png " + temp_name)
417 system("tar cf "+ temp_name +".tar " + temp_name)
418 ;-------------------------------------------------------------------