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 ;************************************************
35 ;************************************************
37 ; from command line inputs
39 ;--------------------------------------------------
40 ; edit table.html of current model for movel1_vs_model2
42 if (isvar("compare")) then
43 html_name2 = compare+"/table.html"
44 html_new2 = html_name2 +".new"
46 ; the following only needs to execute once
47 ; system("sed 1,/model_nameA/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \
48 ; "mv -f "+html_new2+" "+html_name2+";"+ \
49 ; "sed 1,/model_nameB/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \
50 ; "mv -f "+html_new2+" "+html_name2+";"+ \
51 ; "sed s#"+modeln+"#"+model_name+"# "+html_name2+" > "+html_new2+";"+ \
52 ; "mv -f "+html_new2+" "+html_name2)
55 ;-------------------------------------
56 ; edit table.html for current model
58 html_name = model_name+"/table.html"
59 html_new = html_name +".new"
61 ; the following only needs to execute once
62 ; system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \
63 ; "mv -f "+html_new+" "+html_name)
64 ;------------------------------------------------
65 fm = addfile(dirm+film2,"r")
69 ;------------------------------------------------
73 ; for 4 fields, 12-monthly
77 data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
79 ; change to unit of observed (u mol/m2/s)
80 ; Model_units [=] gC/m2/s
81 ; 12. = molecular weight of C
85 if (ENERGY .eq. "old") then
88 data_mod0(0,:,:,:) = data(:,:,:) * factor
95 data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
100 ; data = fm->SENSIBLE
102 data_mod0(3,:,:,:) = data(:,:,:)
108 data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:)
115 data_mod0(0,:,:,:) = data(:,:,:) * factor
119 data_mod0(1,:,:,:) = data(:,:,:)
123 data_mod0(2,:,:,:) = data(:,:,:)
127 data_mod0(3,:,:,:) = data(:,:,:)
131 ;************************************************
132 ; read data: observed
133 ;************************************************
135 station = (/"BOREAS_NSA_OBS" \
139 ,"LBA_Tapajos_KM67" \
145 year_ob = (/"1994-2004" \
155 field = (/"CO2 Flux" \
161 nstation = dimsizes(station)
163 nfield = dimsizes(field)
165 data_ob = new ((/nstation, nfield, nmon/),float)
166 lat_ob = new ((/nstation/),float)
167 lon_ob = new ((/nstation/),float)
169 diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
172 diri = diri_root + station(n)+"/"
173 fili = station(n)+"_"+year_ob(n)+"_monthly.nc"
174 g = addfile (diri+fili,"r")
180 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
184 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
188 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
192 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
198 ;************************************************************
199 ; interpolate model data into observed station
200 ; note: model is 0-360E, 90S-90N
201 ;************************************************************
203 ; to be able to handle observation at (-89.98,-24.80)
206 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
210 data_mod = yy(pts|:,field|:,time|:)
212 ;************************************************************
213 ; compute correlation coef and M score
214 ;************************************************************
218 ccr = new ((/nstation, nfield/),float)
219 M_score = new ((/nstation, nfield/),float)
223 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
224 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
225 M_score(n,m) = (1. -(bias/nmon)) * score_max
229 M_co2 = avg(M_score(:,0))
230 M_rad = avg(M_score(:,1))
231 M_lh = avg(M_score(:,2))
232 M_sh = avg(M_score(:,3))
233 M_all = M_co2+ M_rad +M_lh + M_sh
235 M_energy_co2 = sprintf("%.2f", M_co2)
236 M_energy_rad = sprintf("%.2f", M_rad)
237 M_energy_lh = sprintf("%.2f", M_lh )
238 M_energy_sh = sprintf("%.2f", M_sh )
239 M_energy_all = sprintf("%.2f", M_all)
241 ;*******************************************************************
242 ; for station line plot
243 ;*******************************************************************
245 ; for x-axis in xyplot
247 mon@long_name = "month"
249 res = True ; plot mods desired
250 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
251 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
252 ;-------------------------------------------------------------------------
253 ; Add a boxed legend using the more simple method
255 res@pmLegendDisplayMode = "Always"
256 ; res@pmLegendWidthF = 0.1
257 res@pmLegendWidthF = 0.08
258 res@pmLegendHeightF = 0.06
259 ; res@pmLegendOrthogonalPosF = -1.17
260 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
261 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
263 ; res@pmLegendParallelPosF = 0.18
264 res@pmLegendParallelPosF = 0.23 ;(rightward)
266 ; res@lgPerimOn = False
267 res@lgLabelFontHeightF = 0.015
268 res@xyExplicitLegendLabels = (/"observed",model_name/)
269 ;-------------------------------------------------------------------
271 res@gsnFrame = False ; Do not draw plot
272 res@gsnDraw = False ; Do not advance frame
274 pres = True ; panel plot mods desired
275 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
276 ; indiv. plots in panel
277 pres@gsnMaximize = True ; fill the page
278 ;-------------------------------------------------------------------
280 plot_data = new((/2,12/),float)
282 plot_data!1 = "month"
285 ;----------------------------
288 plot_name = station(n)+"_ob"
289 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
290 res@tiMainString = title
292 wks = gsn_open_wks (plot_type,plot_name)
293 plot=new(4,graphic) ; create graphic array
295 plot_data(0,:) = (/data_ob (n,0,:)/)
296 plot_data@long_name = field(0)
297 plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1
299 plot_data(0,:) = (/data_ob (n,1,:)/)
300 plot_data@long_name = field(1)
301 plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2
303 plot_data(0,:) = (/data_ob (n,2,:)/)
304 plot_data@long_name = field(2)
305 plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3
307 plot_data(0,:) = (/data_ob (n,3,:)/)
308 plot_data@long_name = field(3)
309 plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4
311 gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
313 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
314 "rm "+plot_name+"."+plot_type)
318 ;----------------------------
321 plot_name = station(n)+"_model_vs_ob"
322 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
323 res@tiMainString = title
325 wks = gsn_open_wks (plot_type,plot_name)
326 plot=new(4,graphic) ; create graphic array
328 plot_data(0,:) = (/data_ob (n,0,:)/)
329 plot_data(1,:) = (/data_mod(n,0,:)/)
330 plot_data@long_name = field(0)
331 plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1
333 plot_data(0,:) = (/data_ob (n,1,:)/)
334 plot_data(1,:) = (/data_mod(n,1,:)/)
335 plot_data@long_name = field(1)
336 plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2
338 plot_data(0,:) = (/data_ob (n,2,:)/)
339 plot_data(1,:) = (/data_mod(n,2,:)/)
340 plot_data@long_name = field(2)
341 plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3
343 plot_data(0,:) = (/data_ob (n,3,:)/)
344 plot_data(1,:) = (/data_mod(n,3,:)/)
345 plot_data@long_name = field(3)
346 plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4
348 gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
350 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
351 "rm "+plot_name+"."+plot_type)
357 ;*******************************************************************
358 ; html table of site: observed
359 ;*******************************************************************
360 output_html = "line_ob.html"
362 header = (/"<HTML>" \
364 ,"<TITLE>CLAMP metrics</TITLE>" \
366 ,"<H1>Energy at Site: Observation</H1>" \
371 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
373 ," <th bgcolor=DDDDDD >Site Name</th>" \
374 ," <th bgcolor=DDDDDD >Latitude</th>" \
375 ," <th bgcolor=DDDDDD >Longitude</th>" \
376 ," <th bgcolor=DDDDDD >Observed</th>" \
379 table_footer = "</table>"
383 lines = new(50000,string)
386 set_line(lines,nline,header)
387 set_line(lines,nline,table_header)
388 ;-----------------------------------------------
392 set_line(lines,nline,row_header)
395 txt1 = sprintf("%5.2f", lat_ob(n))
396 txt2 = sprintf("%5.2f", lon_ob(n))
399 set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
400 set_line(lines,nline,"<th>"+txt1+"</th>")
401 set_line(lines,nline,"<th>"+txt2+"</th>")
402 set_line(lines,nline,"<th>"+txt3+"</th>")
404 set_line(lines,nline,row_footer)
406 ;-----------------------------------------------
407 set_line(lines,nline,table_footer)
408 set_line(lines,nline,footer)
410 ; Now write to an HTML file.
411 idx = ind(.not.ismissing(lines))
412 if(.not.any(ismissing(idx))) then
413 asciiwrite(output_html,lines(idx))
419 ;*******************************************************************
420 ; score and line table : model vs observed
421 ;*******************************************************************
422 output_html = "score+line_vs_ob.html"
424 header = (/"<HTML>" \
426 ,"<TITLE>CLAMP metrics</TITLE>" \
428 ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
432 delete (table_header)
434 "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
436 ," <th bgcolor=DDDDDD >Site Name</th>" \
437 ," <th bgcolor=DDDDDD >Latitude</th>" \
438 ," <th bgcolor=DDDDDD >Longitude</th>" \
439 ," <th bgcolor=DDDDDD >Observed</th>" \
440 ," <th bgcolor=DDDDDD >CO2 Flux</th>" \
441 ," <th bgcolor=DDDDDD >Net Radiation</th>" \
442 ," <th bgcolor=DDDDDD >Latent Heat</th>" \
443 ," <th bgcolor=DDDDDD >Sensible Heat</th>" \
444 ," <th bgcolor=DDDDDD >Average</th>" \
447 table_footer = "</table>"
451 lines = new(50000,string)
454 set_line(lines,nline,header)
455 set_line(lines,nline,table_header)
456 ;-----------------------------------------------
460 set_line(lines,nline,row_header)
463 txt1 = sprintf("%5.2f", lat_ob(n))
464 txt2 = sprintf("%5.2f", lon_ob(n))
466 txt4 = sprintf("%5.2f", M_score(n,0))
467 txt5 = sprintf("%5.2f", M_score(n,1))
468 txt6 = sprintf("%5.2f", M_score(n,2))
469 txt7 = sprintf("%5.2f", M_score(n,3))
470 txt8 = sprintf("%5.2f", avg(M_score(n,:)))
472 set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
473 set_line(lines,nline,"<th>"+txt1+"</th>")
474 set_line(lines,nline,"<th>"+txt2+"</th>")
475 set_line(lines,nline,"<th>"+txt3+"</th>")
476 set_line(lines,nline,"<th>"+txt4+"</th>")
477 set_line(lines,nline,"<th>"+txt5+"</th>")
478 set_line(lines,nline,"<th>"+txt6+"</th>")
479 set_line(lines,nline,"<th>"+txt7+"</th>")
480 set_line(lines,nline,"<th>"+txt8+"</th>")
482 set_line(lines,nline,row_footer)
486 set_line(lines,nline,row_header)
488 txt0 = "All_"+sprintf("%.0f", nstation)
498 set_line(lines,nline,"<th>"+txt0+"</th>")
499 set_line(lines,nline,"<th>"+txt1+"</th>")
500 set_line(lines,nline,"<th>"+txt2+"</th>")
501 set_line(lines,nline,"<th>"+txt3+"</th>")
502 set_line(lines,nline,"<th>"+txt4+"</th>")
503 set_line(lines,nline,"<th>"+txt5+"</th>")
504 set_line(lines,nline,"<th>"+txt6+"</th>")
505 set_line(lines,nline,"<th>"+txt7+"</th>")
506 set_line(lines,nline,"<th>"+txt8+"</th>")
508 set_line(lines,nline,row_footer)
509 ;-----------------------------------------------
510 set_line(lines,nline,table_footer)
511 set_line(lines,nline,footer)
513 ; Now write to an HTML file.
514 idx = ind(.not.ismissing(lines))
515 if(.not.any(ismissing(idx))) then
516 asciiwrite(output_html,lines(idx))
522 ;**************************************************************************************
524 ;**************************************************************************************
526 if (isvar("compare")) then
527 system("sed 1,/M_energy_co2/s//"+M_energy_co2+"/ "+html_name2+" > "+html_new2+";"+ \
528 "mv -f "+html_new2+" "+html_name2+";"+ \
529 "sed 1,/M_energy_rad/s//"+M_energy_rad+"/ "+html_name2+" > "+html_new2+";"+ \
530 "mv -f "+html_new2+" "+html_name2+";"+ \
531 "sed 1,/M_energy_lh/s//"+M_energy_lh+"/ "+html_name2+" > "+html_new2+";"+ \
532 "mv -f "+html_new2+" "+html_name2+";"+ \
533 "sed 1,/M_energy_sh/s//"+M_energy_sh+"/ "+html_name2+" > "+html_new2+";"+ \
534 "mv -f "+html_new2+" "+html_name2)
537 system("sed s#M_energy_co2#"+M_energy_co2+"# "+html_name+" > "+html_new+";"+ \
538 "mv -f "+html_new+" "+html_name+";"+ \
539 "sed s#M_energy_rad#"+M_energy_rad+"# "+html_name+" > "+html_new+";"+ \
540 "mv -f "+html_new+" "+html_name+";"+ \
541 "sed s#M_energy_lh#"+M_energy_lh+"# "+html_name+" > "+html_new+";"+ \
542 "mv -f "+html_new+" "+html_name+";"+ \
543 "sed s#M_energy_sh#"+M_energy_sh+"# "+html_name+" > "+html_new+";"+ \
544 "mv -f "+html_new+" "+html_name)
546 ;***************************************************************************
548 ;***************************************************************************
549 output_dir = model_name+"/energy"
551 system("mv *.png *.html " + output_dir)
552 ;***************************************************************************