1 ;************************************************************
3 ;************************************************************
4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
5 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
7 ;************************************************************
8 procedure set_line(lines:string,nline:integer,newlines:string)
10 ; add line to ascci/html file
12 nnewlines = dimsizes(newlines)
13 if(nline+nnewlines-1.ge.dimsizes(lines))
14 print("set_line: bad index, not setting anything.")
17 lines(nline:nline+nnewlines-1) = newlines
18 ; print ("lines = " + lines(nline:nline+nnewlines-1))
19 nline = nline + nnewlines
22 ;*************************************************************
28 ; for 6 fields, 12-monthly
32 ;************************************************
34 ;************************************************
38 model_name = "i01.10" + model
40 dirm = "/fis/cgd/cseg/people/jeff/surface_data/"
42 fm = addfile(dirm+film,"r")
46 ;------------------------------------------------
50 data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
52 ; change to unit of observed (u mol/m2/s)
53 ; Model_units [=] gC/m2/s
54 ; 12. = molecular weight of C
60 ;************************************************
62 ;************************************************
64 station = (/"ARM_Oklahoma" \
65 ,"ARM_Oklahoma_burn" \
66 ,"ARM_Oklahoma_control" \
74 ,"Duke_Forest_Hardwoods" \
75 ,"Duke_Forest_Open_Field" \
79 ,"Flagstaff_Managed" \
80 ,"Flagstaff_Unmanaged" \
81 ,"Flagstaff_Wildfire" \
83 ,"FreemanRanch_mesquite" \
86 ,"HarvardForestHemlock" \
87 ,"HowlandForestMain" \
88 ,"HowlandForestWest" \
90 ,"KendallGrasslands" \
91 ,"KennedySpaceCenterPine" \
92 ,"KennedySpaceCenterScrub" \
96 ,"Mead-irrigated-rotation" \
98 ,"Metolius_2nd_YoungPonderosaPine" \
100 ,"MetoliusIntermediatePine" \
101 ,"MetoliusOldPonderosaPine" \
106 ,"NorthCarolina_cc" \
107 ,"NorthCarolina_lp" \
112 ,"SkyOaks_PostFire" \
114 ,"SylvaniaWilderness" \
140 year_ob = (/"2003-2006" \
216 field = (/"NEE Flux" \
224 field_unit = (/"u mol/m2/s" \
232 nstation = dimsizes(station)
234 data_mod = new ((/nstation, nfield, nmon/),float)
235 data_ob = new ((/nstation, nfield, nmon/),float)
236 lat_ob = new ((/nstation/),float)
237 lon_ob = new ((/nstation/),float)
238 unit_ob = new ((/nfield/),string)
240 diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
241 dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
245 ;-------------------------------------------------
248 diro = diro_root + station(n)+"/"
249 filo = year_ob(n)+"_L4_m.nc"
250 fo = addfile (diro+filo,"r")
257 data = fo->NEE_or_fMDS
258 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
262 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
266 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
270 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
273 data = fo->GPP_or_MDS
274 data_ob(n,4,:) = dim_avg(data(month|:,year|:))
278 data_ob(n,5,:) = dim_avg(data(month|:,year|:))
282 ;---------------------------------------------------
285 ; film = model_name+"_"+ year_ob(n)+"_MONS_climo.nc"
286 film = model_name+"_"+"1990-2004"+"_MONS_climo.nc"
287 fm = addfile (dirm_root+film,"r")
291 if (ENERGY .eq. "old") then
294 data_mod0(0,:,:,:) = data(:,:,:) * factor
301 data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
306 ; data = fm->SENSIBLE
308 data_mod0(3,:,:,:) = data(:,:,:)
314 data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:)
321 data_mod0(0,:,:,:) = data(:,:,:) * factor
325 data_mod0(1,:,:,:) = data(:,:,:)
329 data_mod0(2,:,:,:) = data(:,:,:)
332 ; data = fm->SENSIBLE
334 data_mod0(3,:,:,:) = data(:,:,:)
339 data_mod0(4,:,:,:) = data(:,:,:) * factor
342 if (model .eq. "cn") then
353 data_mod0(5,:,:,:) = data(:,:,:) * factor
358 ;************************************************************
359 ; interpolate model data into observed station
360 ; note: model is 0-360E, 90S-90N
361 ;************************************************************
363 ; to be able to handle observation at (-89.98,-24.80)
366 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0)
370 data_mod(n,:,:) = yy(:,:,0)
375 ;************************************************************
376 ; compute correlation coef and M score
377 ;************************************************************
381 ccr = new ((/nstation, nfield/),float)
382 M_score = new ((/nstation, nfield/),float)
386 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
387 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
388 M_score(n,m) = (1. -(bias/nmon)) * score_max
392 M_co2 = avg(M_score(:,0))
393 M_rad = avg(M_score(:,1))
394 M_lh = avg(M_score(:,2))
395 M_sh = avg(M_score(:,3))
396 M_gpp = avg(M_score(:,4))
397 M_er = avg(M_score(:,5))
398 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
400 M_energy_co2 = sprintf("%.2f", M_co2)
401 M_energy_rad = sprintf("%.2f", M_rad)
402 M_energy_lh = sprintf("%.2f", M_lh )
403 M_energy_sh = sprintf("%.2f", M_sh )
404 M_energy_gpp = sprintf("%.2f", M_gpp)
405 M_energy_er = sprintf("%.2f", M_er )
406 M_energy_all = sprintf("%.2f", M_all)
408 ;*******************************************************************
409 ; for station line plot
410 ;*******************************************************************
412 ; for x-axis in xyplot
414 mon@long_name = "month"
416 res = True ; plot mods desired
417 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
418 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
419 ;-------------------------------------------------------------------------
420 ; Add a boxed legend using the more simple method
422 res@pmLegendDisplayMode = "Always"
423 ; res@pmLegendWidthF = 0.1
424 res@pmLegendWidthF = 0.08
425 res@pmLegendHeightF = 0.06
426 ; res@pmLegendOrthogonalPosF = -1.17
427 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
428 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
430 ; res@pmLegendParallelPosF = 0.18
431 res@pmLegendParallelPosF = 0.23 ;(rightward)
433 ; res@lgPerimOn = False
434 res@lgLabelFontHeightF = 0.015
435 res@xyExplicitLegendLabels = (/"observed",model_name/)
436 ;-------------------------------------------------------------------
438 res@gsnFrame = False ; Do not draw plot
439 res@gsnDraw = False ; Do not advance frame
441 pres = True ; panel plot mods desired
442 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
443 ; indiv. plots in panel
444 pres@gsnMaximize = True ; fill the page
445 ;-------------------------------------------------------------------
447 plot_data = new((/2,12/),float)
449 plot_data!1 = "month"
452 ;----------------------------
455 plot_name = station(n)+"_ob"
456 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
457 res@tiMainString = title
459 wks = gsn_open_wks (plot_type,plot_name)
460 plot=new(nfield,graphic) ; create graphic array
463 plot_data(0,:) = (/data_ob (n,i,:)/)
464 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
465 plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot
468 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
470 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
471 "rm "+plot_name+"."+plot_type)
475 ;----------------------------
478 plot_name = station(n)+"_model_vs_ob"
479 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
480 res@tiMainString = title
482 wks = gsn_open_wks (plot_type,plot_name)
483 plot=new(nfield,graphic) ; create graphic array
486 plot_data(0,:) = (/data_ob (n,i,:)/)
487 plot_data(1,:) = (/data_mod(n,i,:)/)
488 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
489 plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot
492 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
494 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
495 "rm "+plot_name+"."+plot_type)
501 ;*******************************************************************
502 ; html table of site: observed
503 ;*******************************************************************
504 output_html = "line_ob.html"
506 header = (/"<HTML>" \
508 ,"<TITLE>CLAMP metrics</TITLE>" \
510 ,"<H1>Energy at Site: Observation</H1>" \
515 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
517 ," <th bgcolor=DDDDDD >Site Name</th>" \
518 ," <th bgcolor=DDDDDD >Latitude</th>" \
519 ," <th bgcolor=DDDDDD >Longitude</th>" \
520 ," <th bgcolor=DDDDDD >Observed</th>" \
523 table_footer = "</table>"
527 lines = new(50000,string)
530 set_line(lines,nline,header)
531 set_line(lines,nline,table_header)
532 ;-----------------------------------------------
536 set_line(lines,nline,row_header)
539 txt1 = sprintf("%5.2f", lat_ob(n))
540 txt2 = sprintf("%5.2f", lon_ob(n))
543 set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
544 set_line(lines,nline,"<th>"+txt1+"</th>")
545 set_line(lines,nline,"<th>"+txt2+"</th>")
546 set_line(lines,nline,"<th>"+txt3+"</th>")
548 set_line(lines,nline,row_footer)
550 ;-----------------------------------------------
551 set_line(lines,nline,table_footer)
552 set_line(lines,nline,footer)
554 ; Now write to an HTML file.
555 idx = ind(.not.ismissing(lines))
556 if(.not.any(ismissing(idx))) then
557 asciiwrite(output_html,lines(idx))
563 ;*******************************************************************
564 ; score and line table : model vs observed
565 ;*******************************************************************
566 output_html = "score+line_vs_ob.html"
568 header = (/"<HTML>" \
570 ,"<TITLE>CLAMP metrics</TITLE>" \
572 ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
576 delete (table_header)
578 "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
580 ," <th bgcolor=DDDDDD >Site Name</th>" \
581 ," <th bgcolor=DDDDDD >Latitude</th>" \
582 ," <th bgcolor=DDDDDD >Longitude</th>" \
583 ," <th bgcolor=DDDDDD >Observed</th>" \
584 ," <th bgcolor=DDDDDD >CO2 Flux</th>" \
585 ," <th bgcolor=DDDDDD >Net Radiation</th>" \
586 ," <th bgcolor=DDDDDD >Latent Heat</th>" \
587 ," <th bgcolor=DDDDDD >Sensible Heat</th>" \
588 ," <th bgcolor=DDDDDD >GPP Glux</th>" \
589 ," <th bgcolor=DDDDDD >Respiration</th>" \
590 ," <th bgcolor=DDDDDD >Average</th>" \
593 table_footer = "</table>"
597 lines = new(50000,string)
600 set_line(lines,nline,header)
601 set_line(lines,nline,table_header)
602 ;-----------------------------------------------
606 set_line(lines,nline,row_header)
609 txt1 = sprintf("%5.2f", lat_ob(n))
610 txt2 = sprintf("%5.2f", lon_ob(n))
612 txt4 = sprintf("%5.2f", M_score(n,0))
613 txt5 = sprintf("%5.2f", M_score(n,1))
614 txt6 = sprintf("%5.2f", M_score(n,2))
615 txt7 = sprintf("%5.2f", M_score(n,3))
616 txt8 = sprintf("%5.2f", M_score(n,4))
617 txt9 = sprintf("%5.2f", M_score(n,5))
618 txt10 = sprintf("%5.2f", avg(M_score(n,:)))
620 set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
621 set_line(lines,nline,"<th>"+txt1+"</th>")
622 set_line(lines,nline,"<th>"+txt2+"</th>")
623 set_line(lines,nline,"<th>"+txt3+"</th>")
624 set_line(lines,nline,"<th>"+txt4+"</th>")
625 set_line(lines,nline,"<th>"+txt5+"</th>")
626 set_line(lines,nline,"<th>"+txt6+"</th>")
627 set_line(lines,nline,"<th>"+txt7+"</th>")
628 set_line(lines,nline,"<th>"+txt8+"</th>")
629 set_line(lines,nline,"<th>"+txt9+"</th>")
630 set_line(lines,nline,"<th>"+txt10+"</th>")
632 set_line(lines,nline,row_footer)
636 set_line(lines,nline,row_header)
638 txt0 = "All_"+sprintf("%.0f", nstation)
650 set_line(lines,nline,"<th>"+txt0+"</th>")
651 set_line(lines,nline,"<th>"+txt1+"</th>")
652 set_line(lines,nline,"<th>"+txt2+"</th>")
653 set_line(lines,nline,"<th>"+txt3+"</th>")
654 set_line(lines,nline,"<th>"+txt4+"</th>")
655 set_line(lines,nline,"<th>"+txt5+"</th>")
656 set_line(lines,nline,"<th>"+txt6+"</th>")
657 set_line(lines,nline,"<th>"+txt7+"</th>")
658 set_line(lines,nline,"<th>"+txt8+"</th>")
659 set_line(lines,nline,"<th>"+txt9+"</th>")
660 set_line(lines,nline,"<th>"+txt10+"</th>")
662 set_line(lines,nline,row_footer)
663 ;-----------------------------------------------
664 set_line(lines,nline,table_footer)
665 set_line(lines,nline,footer)
667 ; Now write to an HTML file.
668 idx = ind(.not.ismissing(lines))
669 if(.not.any(ismissing(idx))) then
670 asciiwrite(output_html,lines(idx))
676 ;***************************************************************************
678 ;***************************************************************************
679 output_dir = model_name+"/ameriflux"
681 system("mv *.png *.html " + output_dir)
682 ;***************************************************************************