Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
1 ;************************************************************
2 ; required command line input parameters:
3 ; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl
5 ; using gsn_table for all
6 ; output: line plot for each site (4 fields)
8 ;************************************************************
9 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
10 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
11 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
12 ;************************************************************
13 procedure set_line(lines:string,nline:integer,newlines:string)
15 ; add line to ascci/html file
17 nnewlines = dimsizes(newlines)
18 if(nline+nnewlines-1.ge.dimsizes(lines))
19 print("set_line: bad index, not setting anything.")
22 lines(nline:nline+nnewlines-1) = newlines
23 ; print ("lines = " + lines(nline:nline+nnewlines-1))
24 nline = nline + nnewlines
27 ;*************************************************************
33 ; for 6 fields, 12-monthly
37 ;************************************************
39 ;************************************************
43 model_name = "i01.10" + model
45 dirm = "/fis/cgd/cseg/people/jeff/surface_data/"
47 fm = addfile(dirm+film,"r")
51 ;------------------------------------------------
55 data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
57 ; change to unit of observed (u mol/m2/s)
58 ; Model_units [=] gC/m2/s
59 ; 12. = molecular weight of C
65 ;************************************************
67 ;************************************************
69 station = (/"Duke_Forest_Hardwoods" \
70 ,"Duke_Forest_Open_Field" \
75 year_ob = (/"2003-2005" \
81 field = (/"CO2 Flux" \
89 nstation = dimsizes(station)
91 data_mod = new ((/nstation, nfield, nmon/),float)
92 data_ob = new ((/nstation, nfield, nmon/),float)
93 lat_ob = new ((/nstation/),float)
94 lon_ob = new ((/nstation/),float)
96 diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/"
97 dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
101 ;-------------------------------------------------
104 diro = diro_root + station(n)+"/"
105 filo = year_ob(n)+"_L4_m.nc"
106 fo = addfile (diro+filo,"r")
113 data = fo->NEE_or_fMDS
114 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
118 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
122 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
126 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
129 data = fo->GPP_or_MDS
130 data_ob(n,4,:) = dim_avg(data(month|:,year|:))
134 data_ob(n,5,:) = dim_avg(data(month|:,year|:))
138 ;---------------------------------------------------
141 film = model_name+"_"+year_ob(n)+"_MONS_climo.nc"
142 fm = addfile (dirm_root+film,"r")
146 if (ENERGY .eq. "old") then
149 data_mod0(0,:,:,:) = data(:,:,:) * factor
156 data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
161 ; data = fm->SENSIBLE
163 data_mod0(3,:,:,:) = data(:,:,:)
169 data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:)
176 data_mod0(0,:,:,:) = data(:,:,:) * factor
180 data_mod0(1,:,:,:) = data(:,:,:)
184 data_mod0(2,:,:,:) = data(:,:,:)
187 ; data = fm->SENSIBLE
189 data_mod0(3,:,:,:) = data(:,:,:)
194 data_mod0(4,:,:,:) = data(:,:,:) * factor
197 if (model .eq. "cn") then
208 data_mod0(5,:,:,:) = data(:,:,:) * factor
213 ;************************************************************
214 ; interpolate model data into observed station
215 ; note: model is 0-360E, 90S-90N
216 ;************************************************************
218 ; to be able to handle observation at (-89.98,-24.80)
221 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0)
225 data_mod(n,:,:) = yy(:,:,0)
230 ;************************************************************
231 ; compute correlation coef and M score
232 ;************************************************************
236 ccr = new ((/nstation, nfield/),float)
237 M_score = new ((/nstation, nfield/),float)
241 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
242 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
243 M_score(n,m) = (1. -(bias/nmon)) * score_max
247 M_co2 = avg(M_score(:,0))
248 M_rad = avg(M_score(:,1))
249 M_lh = avg(M_score(:,2))
250 M_sh = avg(M_score(:,3))
251 M_gpp = avg(M_score(:,4))
252 M_er = avg(M_score(:,5))
253 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
255 M_energy_co2 = sprintf("%.2f", M_co2)
256 M_energy_rad = sprintf("%.2f", M_rad)
257 M_energy_lh = sprintf("%.2f", M_lh )
258 M_energy_sh = sprintf("%.2f", M_sh )
259 M_energy_gpp = sprintf("%.2f", M_gpp)
260 M_energy_er = sprintf("%.2f", M_er )
261 M_energy_all = sprintf("%.2f", M_all)
263 ;*******************************************************************
264 ; for station line plot
265 ;*******************************************************************
267 ; for x-axis in xyplot
269 mon@long_name = "month"
271 res = True ; plot mods desired
272 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
273 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
274 ;-------------------------------------------------------------------------
275 ; Add a boxed legend using the more simple method
277 res@pmLegendDisplayMode = "Always"
278 ; res@pmLegendWidthF = 0.1
279 res@pmLegendWidthF = 0.08
280 res@pmLegendHeightF = 0.06
281 ; res@pmLegendOrthogonalPosF = -1.17
282 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
283 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
285 ; res@pmLegendParallelPosF = 0.18
286 res@pmLegendParallelPosF = 0.23 ;(rightward)
288 ; res@lgPerimOn = False
289 res@lgLabelFontHeightF = 0.015
290 res@xyExplicitLegendLabels = (/"observed",model_name/)
291 ;-------------------------------------------------------------------
293 res@gsnFrame = False ; Do not draw plot
294 res@gsnDraw = False ; Do not advance frame
296 pres = True ; panel plot mods desired
297 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
298 ; indiv. plots in panel
299 pres@gsnMaximize = True ; fill the page
300 ;-------------------------------------------------------------------
302 plot_data = new((/2,12/),float)
304 plot_data!1 = "month"
307 ;----------------------------
310 plot_name = station(n)+"_ob"
311 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
312 res@tiMainString = title
314 wks = gsn_open_wks (plot_type,plot_name)
315 plot=new(nfield,graphic) ; create graphic array
317 plot_data(0,:) = (/data_ob (n,0,:)/)
318 plot_data@long_name = field(0)
319 plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1
321 plot_data(0,:) = (/data_ob (n,1,:)/)
322 plot_data@long_name = field(1)
323 plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2
325 plot_data(0,:) = (/data_ob (n,2,:)/)
326 plot_data@long_name = field(2)
327 plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3
329 plot_data(0,:) = (/data_ob (n,3,:)/)
330 plot_data@long_name = field(3)
331 plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4
333 plot_data(0,:) = (/data_ob (n,4,:)/)
334 plot_data@long_name = field(4)
335 plot(4)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 5
337 plot_data(0,:) = (/data_ob (n,5,:)/)
338 plot_data@long_name = field(5)
339 plot(5)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 6
341 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
343 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
344 "rm "+plot_name+"."+plot_type)
348 ;----------------------------
351 plot_name = station(n)+"_model_vs_ob"
352 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
353 res@tiMainString = title
355 wks = gsn_open_wks (plot_type,plot_name)
356 plot=new(nfield,graphic) ; create graphic array
358 plot_data(0,:) = (/data_ob (n,0,:)/)
359 plot_data(1,:) = (/data_mod(n,0,:)/)
360 plot_data@long_name = field(0)
361 plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1
363 plot_data(0,:) = (/data_ob (n,1,:)/)
364 plot_data(1,:) = (/data_mod(n,1,:)/)
365 plot_data@long_name = field(1)
366 plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2
368 plot_data(0,:) = (/data_ob (n,2,:)/)
369 plot_data(1,:) = (/data_mod(n,2,:)/)
370 plot_data@long_name = field(2)
371 plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3
373 plot_data(0,:) = (/data_ob (n,3,:)/)
374 plot_data(1,:) = (/data_mod(n,3,:)/)
375 plot_data@long_name = field(3)
376 plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4
379 plot_data(0,:) = (/data_ob (n,4,:)/)
380 plot_data(1,:) = (/data_mod(n,4,:)/)
381 plot_data@long_name = field(4)
382 plot(4)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 5
385 plot_data(0,:) = (/data_ob (n,5,:)/)
386 plot_data(1,:) = (/data_mod(n,5,:)/)
387 plot_data@long_name = field(5)
388 plot(5)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 6
390 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
392 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
393 "rm "+plot_name+"."+plot_type)
399 ;*******************************************************************
400 ; html table of site: observed
401 ;*******************************************************************
402 output_html = "line_ob.html"
404 header = (/"<HTML>" \
406 ,"<TITLE>CLAMP metrics</TITLE>" \
408 ,"<H1>Energy at Site: Observation</H1>" \
413 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
415 ," <th bgcolor=DDDDDD >Site Name</th>" \
416 ," <th bgcolor=DDDDDD >Latitude</th>" \
417 ," <th bgcolor=DDDDDD >Longitude</th>" \
418 ," <th bgcolor=DDDDDD >Observed</th>" \
421 table_footer = "</table>"
425 lines = new(50000,string)
428 set_line(lines,nline,header)
429 set_line(lines,nline,table_header)
430 ;-----------------------------------------------
434 set_line(lines,nline,row_header)
437 txt1 = sprintf("%5.2f", lat_ob(n))
438 txt2 = sprintf("%5.2f", lon_ob(n))
441 set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
442 set_line(lines,nline,"<th>"+txt1+"</th>")
443 set_line(lines,nline,"<th>"+txt2+"</th>")
444 set_line(lines,nline,"<th>"+txt3+"</th>")
446 set_line(lines,nline,row_footer)
448 ;-----------------------------------------------
449 set_line(lines,nline,table_footer)
450 set_line(lines,nline,footer)
452 ; Now write to an HTML file.
453 idx = ind(.not.ismissing(lines))
454 if(.not.any(ismissing(idx))) then
455 asciiwrite(output_html,lines(idx))
461 ;*******************************************************************
462 ; score and line table : model vs observed
463 ;*******************************************************************
464 output_html = "score+line_vs_ob.html"
466 header = (/"<HTML>" \
468 ,"<TITLE>CLAMP metrics</TITLE>" \
470 ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
474 delete (table_header)
476 "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
478 ," <th bgcolor=DDDDDD >Site Name</th>" \
479 ," <th bgcolor=DDDDDD >Latitude</th>" \
480 ," <th bgcolor=DDDDDD >Longitude</th>" \
481 ," <th bgcolor=DDDDDD >Observed</th>" \
482 ," <th bgcolor=DDDDDD >CO2 Flux</th>" \
483 ," <th bgcolor=DDDDDD >Net Radiation</th>" \
484 ," <th bgcolor=DDDDDD >Latent Heat</th>" \
485 ," <th bgcolor=DDDDDD >Sensible Heat</th>" \
486 ," <th bgcolor=DDDDDD >GPP Glux</th>" \
487 ," <th bgcolor=DDDDDD >Respiration</th>" \
488 ," <th bgcolor=DDDDDD >Average</th>" \
491 table_footer = "</table>"
495 lines = new(50000,string)
498 set_line(lines,nline,header)
499 set_line(lines,nline,table_header)
500 ;-----------------------------------------------
504 set_line(lines,nline,row_header)
507 txt1 = sprintf("%5.2f", lat_ob(n))
508 txt2 = sprintf("%5.2f", lon_ob(n))
510 txt4 = sprintf("%5.2f", M_score(n,0))
511 txt5 = sprintf("%5.2f", M_score(n,1))
512 txt6 = sprintf("%5.2f", M_score(n,2))
513 txt7 = sprintf("%5.2f", M_score(n,3))
514 txt8 = sprintf("%5.2f", M_score(n,4))
515 txt9 = sprintf("%5.2f", M_score(n,5))
516 txt10 = sprintf("%5.2f", avg(M_score(n,:)))
518 set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
519 set_line(lines,nline,"<th>"+txt1+"</th>")
520 set_line(lines,nline,"<th>"+txt2+"</th>")
521 set_line(lines,nline,"<th>"+txt3+"</th>")
522 set_line(lines,nline,"<th>"+txt4+"</th>")
523 set_line(lines,nline,"<th>"+txt5+"</th>")
524 set_line(lines,nline,"<th>"+txt6+"</th>")
525 set_line(lines,nline,"<th>"+txt7+"</th>")
526 set_line(lines,nline,"<th>"+txt8+"</th>")
527 set_line(lines,nline,"<th>"+txt9+"</th>")
528 set_line(lines,nline,"<th>"+txt10+"</th>")
530 set_line(lines,nline,row_footer)
534 set_line(lines,nline,row_header)
536 txt0 = "All_"+sprintf("%.0f", nstation)
548 set_line(lines,nline,"<th>"+txt0+"</th>")
549 set_line(lines,nline,"<th>"+txt1+"</th>")
550 set_line(lines,nline,"<th>"+txt2+"</th>")
551 set_line(lines,nline,"<th>"+txt3+"</th>")
552 set_line(lines,nline,"<th>"+txt4+"</th>")
553 set_line(lines,nline,"<th>"+txt5+"</th>")
554 set_line(lines,nline,"<th>"+txt6+"</th>")
555 set_line(lines,nline,"<th>"+txt7+"</th>")
556 set_line(lines,nline,"<th>"+txt8+"</th>")
557 set_line(lines,nline,"<th>"+txt9+"</th>")
558 set_line(lines,nline,"<th>"+txt10+"</th>")
560 set_line(lines,nline,row_footer)
561 ;-----------------------------------------------
562 set_line(lines,nline,table_footer)
563 set_line(lines,nline,footer)
565 ; Now write to an HTML file.
566 idx = ind(.not.ismissing(lines))
567 if(.not.any(ismissing(idx))) then
568 asciiwrite(output_html,lines(idx))
574 ;***************************************************************************
576 ;***************************************************************************
577 output_dir = model_name+"/ameriflux"
579 system("mv *.png *.html " + output_dir)
580 ;***************************************************************************