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.10cn_1948-2004_MONS_climo.nc"
22 ; model_name = "10casa"
23 ; film = "i01.10casa_1948-2004_MONS_climo.nc"
25 system("sed s#model_name#"+model_name+"# table.html > table.html.new")
26 system("mv -f table.html.new table.html")
27 ;--------------------------------------------
28 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
29 fm = addfile(dirm+film,"r")
39 data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
41 ; change to unit of observed (u mol/m2/s)
42 ; Model_units [=] gC/m2/s
43 ; 12. = molecular weight of C
49 data_mod0(0,:,:,:) = data(:,:,:) * factor
53 data_mod0(1,:,:,:) = data(:,:,:)
57 data_mod0(2,:,:,:) = data(:,:,:)
61 data_mod0(3,:,:,:) = data(:,:,:)
64 ; printVarSummary (data_mod0)
65 ;************************************************
66 ; read in data: observed
67 ;************************************************
68 station = (/"BOREAS_NSA_OBS" \
78 year_ob = (/"1994-2004" \
88 field = (/"CO2 Flux" \
94 nstation = dimsizes(station)
96 nfield = dimsizes(field)
98 data_ob = new ((/nstation, nfield, nmon/),float)
99 lat_ob = new ((/nstation/),float)
100 lon_ob = new ((/nstation/),float)
102 diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
105 diri = diri_root + station(n)+"/"
106 fili = station(n)+"_"+year_ob(n)+"_monthly.nc"
107 g = addfile (diri+fili,"r")
113 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
117 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
121 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
125 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
133 ;printVarSummary (data_ob)
135 ;************************************************************
136 ; interpolate model data into observed station
137 ; note: model is 0-360E, 90S-90N
138 ;************************************************************
140 ; to be able to handle observation at (-89.98,-24.80)
144 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
148 data_mod = yy(pts|:,field|:,time|:)
149 ; printVarSummary (data_mod)
151 ;************************************************************
152 ; compute correlation coef and M score
153 ;************************************************************
157 ccr = new ((/nstation, nfield/),float)
158 M_score = new ((/nstation, nfield/),float)
162 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
163 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
164 M_score(n,m) = (1. -(bias/nmon)) * score_max
168 ;*******************************************************************
169 ; for station line plot
170 ;*******************************************************************
172 ; for x-axis in xyplot
174 mon@long_name = "month"
176 res = True ; plot mods desired
177 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
178 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
179 ;-------------------------------------------------------------------------
180 ; Add a boxed legend using the more simple method
182 res@pmLegendDisplayMode = "Always"
183 ; res@pmLegendWidthF = 0.1
184 res@pmLegendWidthF = 0.08
185 res@pmLegendHeightF = 0.06
186 ; res@pmLegendOrthogonalPosF = -1.17
187 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
188 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
190 ; res@pmLegendParallelPosF = 0.18
191 res@pmLegendParallelPosF = 0.23 ;(rightward)
193 ; res@lgPerimOn = False
194 res@lgLabelFontHeightF = 0.015
195 res@xyExplicitLegendLabels = (/"observed",model_name/)
196 ;-------------------------------------------------------------------
198 res@gsnFrame = False ; Do not draw plot
199 res@gsnDraw = False ; Do not advance frame
201 pres = True ; panel plot mods desired
202 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
203 ; indiv. plots in panel
204 pres@gsnMaximize = True ; fill the page
205 ;-------------------------------------------------------------------
207 plot_data = new((/2,12/),float)
209 plot_data!1 = "month"
212 ;----------------------------
215 plot_name = station(n)+"_ob"
216 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
217 res@tiMainString = title
219 wks = gsn_open_wks (plot_type,plot_name)
220 plot=new(4,graphic) ; create graphic array
222 plot_data(0,:) = (/data_ob (n,0,:)/)
223 plot_data@long_name = field(0)
224 plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1
226 plot_data(0,:) = (/data_ob (n,1,:)/)
227 plot_data@long_name = field(1)
228 plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2
230 plot_data(0,:) = (/data_ob (n,2,:)/)
231 plot_data@long_name = field(2)
232 plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3
234 plot_data(0,:) = (/data_ob (n,3,:)/)
235 plot_data@long_name = field(3)
236 plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4
238 gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
240 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
241 system("rm "+plot_name+"."+plot_type)
244 ;----------------------------
247 plot_name = station(n)+"_model_vs_ob"
248 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
249 res@tiMainString = title
251 wks = gsn_open_wks (plot_type,plot_name)
252 plot=new(4,graphic) ; create graphic array
254 plot_data(0,:) = (/data_ob (n,0,:)/)
255 plot_data(1,:) = (/data_mod(n,0,:)/)
256 plot_data@long_name = field(0)
257 plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1
259 plot_data(0,:) = (/data_ob (n,1,:)/)
260 plot_data(1,:) = (/data_mod(n,1,:)/)
261 plot_data@long_name = field(1)
262 plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2
264 plot_data(0,:) = (/data_ob (n,2,:)/)
265 plot_data(1,:) = (/data_mod(n,2,:)/)
266 plot_data@long_name = field(2)
267 plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3
269 plot_data(0,:) = (/data_ob (n,3,:)/)
270 plot_data(1,:) = (/data_mod(n,3,:)/)
271 plot_data@long_name = field(3)
272 plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4
274 gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
276 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
277 system("rm "+plot_name+"."+plot_type)
282 ;*******************************************************************
283 ; for table of site score
284 ;*******************************************************************
289 table_header_name = "Site"
291 ; column (not including header column)
292 col_header = (/"Latitude","Longitude","observed" \
293 ,"CO2 Flux","Net Radiation","Latent Heat" \
294 ,"Sensible Heat","Average" \
296 ncol = dimsizes(col_header)
298 ; row (not including header row)
300 row_header = new ((/nrow/),string )
301 row_header(0:nstation-1) = station(:)
302 row_header(nrow-1) = "All Sites"
305 ncr1 = (/1,1/) ; 1 row, 1 column
306 x1 = (/0.005,0.15/) ; Start and end X
307 y1 = (/0.800,0.895/) ; Start and end Y
308 text1 = table_header_name
310 res1@txFontHeightF = 0.03
311 res1@gsFillColor = "CornFlowerBlue"
313 ; Column header (equally space in x2)
314 ncr2 = (/1,ncol/) ; 1 rows, ncol columns
315 x2 = (/x1(1),0.995/) ; start from end of x1
319 res2@txFontHeightF = 0.010
320 res2@gsFillColor = "Gray"
322 ; Row header (equally space in y2)
323 ncr3 = (/nrow,1/) ; nrow rows, 1 columns
325 y3 = (/1.0-table_length,y1(0)/) ; end at start of y1
328 res3@txFontHeightF = 0.010
329 res3@gsFillColor = "Gray"
332 ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns
333 x4 = x2 ; Start and end x
334 y4 = y3 ; Start and end Y
335 text4 = new((/nrow,ncol/),string)
337 color_fill4 = new((/nrow,ncol/),string)
338 color_fill4 = "white"
339 color_fill4(:,ncol-1) = "grey"
340 color_fill4(nrow-1,:) = "green"
342 res4 = True ; Set up resource list
343 ; res4@gsnDebug = True ; Useful to print NDC row,col values used.
344 res4@txFontHeightF = 0.015
345 res4@gsFillColor = color_fill4
348 ;-------------------------------------------------------------------
352 text4(n,0) = sprintf("%5.2f", lat_ob(n))
353 text4(n,1) = sprintf("%5.2f", lon_ob(n))
354 text4(n,2) = year_ob(n)
355 text4(n,3) = sprintf("%5.2f", M_score(n,0)) ; CO2 Flux
356 text4(n,4) = sprintf("%5.2f", M_score(n,1)) ; Net Radiation
357 text4(n,5) = sprintf("%5.2f", M_score(n,2)) ; Latent Heat
358 text4(n,6) = sprintf("%5.2f", M_score(n,3)) ; Sensible Heat
359 text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields
364 M_co2 = avg(M_score(:,0))
365 M_rad = avg(M_score(:,1))
366 M_lh = avg(M_score(:,2))
367 M_sh = avg(M_score(:,3))
368 M_all = M_co2+ M_rad +M_lh + M_sh
370 text4(nrow-1,0) = "-"
371 text4(nrow-1,1) = "-"
372 text4(nrow-1,2) = "-"
373 text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites
374 text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites
375 text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites
376 text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites
377 text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites
385 M_energy_co2 = sprintf("%.2f", M_co2)
386 system("sed s#M_energy_co2#"+M_energy_co2+"# table.html > table.html.new")
387 system("mv -f table.html.new table.html")
390 M_energy_rad = sprintf("%.2f", M_rad)
391 system("sed s#M_energy_rad#"+M_energy_rad+"# table.html > table.html.new")
392 system("mv -f table.html.new table.html")
395 M_energy_lh = sprintf("%.2f", M_lh)
396 system("sed s#M_energy_lh#"+M_energy_lh+"# table.html > table.html.new")
397 system("mv -f table.html.new table.html")
400 M_energy_sh = sprintf("%.2f", M_sh)
401 system("sed s#M_energy_sh#"+M_energy_sh+"# table.html > table.html.new")
402 system("mv -f table.html.new table.html")
404 ;---------------------------------------------------------------------------
406 plot_name = "table_site_score"
408 wks = gsn_open_wks (plot_type,plot_name)
409 ;------------------------------------------
413 gRes@txFontHeightF = 0.02
416 title_text = "Model " + model_name + " M_Score"
418 gsn_text_ndc(wks,title_text,0.50,0.95,gRes)
419 ;------------------------------------------
421 gsn_table(wks,ncr1,x1,y1,text1,res1)
422 gsn_table(wks,ncr2,x2,y2,text2,res2)
423 gsn_table(wks,ncr3,x3,y3,text3,res3)
424 gsn_table(wks,ncr4,x4,y4,text4,res4)
428 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
429 system("rm "+plot_name+"."+plot_type)
430 ;-------------------------------------------------------------------
431 temp_name = "energy." + model_name
432 system("mkdir -p " + temp_name)
433 system("cp table.html " + temp_name)
434 system("mv *.png " + temp_name)
435 system("tar cf "+ temp_name +".tar " + temp_name)
436 ;-------------------------------------------------------------------