Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
1 ;************************************************************
3 ; add year_ob_i and year_ob_f
5 ;************************************************************
6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
7 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
8 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
9 ;************************************************************
10 procedure set_line(lines:string,nline:integer,newlines:string)
12 ; add line to ascci/html file
14 nnewlines = dimsizes(newlines)
15 if(nline+nnewlines-1.ge.dimsizes(lines))
16 print("set_line: bad index, not setting anything.")
19 lines(nline:nline+nnewlines-1) = newlines
20 ; print ("lines = " + lines(nline:nline+nnewlines-1))
21 nline = nline + nnewlines
24 ;*************************************************************
30 ; for 6 fields, 12-monthly
34 ;************************************************
36 ;************************************************
40 model_name = "i01.10" + model
42 dirm = "/fis/cgd/cseg/people/jeff/surface_data/"
44 fm = addfile(dirm+film,"r")
48 ;------------------------------------------------
52 data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
54 ; change to unit of observed (u mol/m2/s)
55 ; Model_units [=] gC/m2/s
56 ; 12. = molecular weight of C
62 ;************************************************
64 ;************************************************
66 station = (/"ARM_Oklahoma" \
67 ,"ARM_Oklahoma_burn" \
68 ,"ARM_Oklahoma_control" \
76 ,"Duke_Forest_Hardwoods" \
77 ,"Duke_Forest_Open_Field" \
81 ,"Flagstaff_Managed" \
82 ,"Flagstaff_Unmanaged" \
83 ,"Flagstaff_Wildfire" \
85 ,"FreemanRanch_mesquite" \
88 ,"HarvardForestHemlock" \
89 ,"HowlandForestMain" \
90 ,"HowlandForestWest" \
92 ,"KendallGrasslands" \
93 ,"KennedySpaceCenterPine" \
94 ,"KennedySpaceCenterScrub" \
98 ,"Mead-irrigated-rotation" \
100 ,"Metolius_2nd_YoungPonderosaPine" \
102 ,"MetoliusIntermediatePine" \
103 ,"MetoliusOldPonderosaPine" \
108 ,"NorthCarolina_cc" \
109 ,"NorthCarolina_lp" \
114 ,"SkyOaks_PostFire" \
116 ,"SylvaniaWilderness" \
142 year_ob = (/"2003-2006" \
370 year_ob_long = ind((year_ob_f - year_ob_i) .ge. 4 .and. year_ob_i .le. 2001)
372 print (year_ob_i(year_ob_long))
375 field = (/"NEE Flux" \
383 field_unit = (/"u mol/m2/s" \
391 ;nstation = dimsizes(station)
392 nstation = dimsizes(year_ob_long)
394 data_mod = new ((/nstation, nfield, nmon/),float)
395 data_ob = new ((/nstation, nfield, nmon/),float)
396 lat_ob = new ((/nstation/),float)
397 lon_ob = new ((/nstation/),float)
398 unit_ob = new ((/nfield/),string)
400 diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
401 dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
405 ;-------------------------------------------------
411 diro = diro_root + station(nn)+"/"
412 filo = year_ob_i(nn)+"-"+year_ob_f(nn)+"_L4_m.nc"
413 fo = addfile (diro+filo,"r")
420 data = fo->NEE_or_fMDS
421 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
425 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
429 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
433 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
436 data = fo->GPP_or_MDS
437 data_ob(n,4,:) = dim_avg(data(month|:,year|:))
441 data_ob(n,5,:) = dim_avg(data(month|:,year|:))
445 ;---------------------------------------------------
448 ; film = model_name+"_"+ year_ob(n)+"_MONS_climo.nc"
449 film = model_name+"_"+"1990-2004"+"_MONS_climo.nc"
450 fm = addfile (dirm_root+film,"r")
454 if (ENERGY .eq. "old") then
457 data_mod0(0,:,:,:) = data(:,:,:) * factor
464 data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
469 ; data = fm->SENSIBLE
471 data_mod0(3,:,:,:) = data(:,:,:)
477 data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:)
484 data_mod0(0,:,:,:) = data(:,:,:) * factor
488 data_mod0(1,:,:,:) = data(:,:,:)
492 data_mod0(2,:,:,:) = data(:,:,:)
495 ; data = fm->SENSIBLE
497 data_mod0(3,:,:,:) = data(:,:,:)
502 data_mod0(4,:,:,:) = data(:,:,:) * factor
505 if (model .eq. "cn") then
516 data_mod0(5,:,:,:) = data(:,:,:) * factor
521 ;************************************************************
522 ; interpolate model data into observed station
523 ; note: model is 0-360E, 90S-90N
524 ;************************************************************
526 ; to be able to handle observation at (-89.98,-24.80)
529 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0)
533 data_mod(n,:,:) = yy(:,:,0)
538 ;************************************************************
539 ; compute correlation coef and M score
540 ;************************************************************
544 ccr = new ((/nstation, nfield/),float)
545 M_score = new ((/nstation, nfield/),float)
549 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
550 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
551 M_score(n,m) = (1. -(bias/nmon)) * score_max
555 M_co2 = avg(M_score(:,0))
556 M_rad = avg(M_score(:,1))
557 M_lh = avg(M_score(:,2))
558 M_sh = avg(M_score(:,3))
559 M_gpp = avg(M_score(:,4))
560 M_er = avg(M_score(:,5))
561 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
563 M_energy_co2 = sprintf("%.2f", M_co2)
564 M_energy_rad = sprintf("%.2f", M_rad)
565 M_energy_lh = sprintf("%.2f", M_lh )
566 M_energy_sh = sprintf("%.2f", M_sh )
567 M_energy_gpp = sprintf("%.2f", M_gpp)
568 M_energy_er = sprintf("%.2f", M_er )
569 M_energy_all = sprintf("%.2f", M_all)
571 ;*******************************************************************
572 ; for station line plot
573 ;*******************************************************************
575 ; for x-axis in xyplot
577 mon@long_name = "month"
579 res = True ; plot mods desired
580 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
581 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
582 ;-------------------------------------------------------------------------
583 ; Add a boxed legend using the more simple method
585 res@pmLegendDisplayMode = "Always"
586 ; res@pmLegendWidthF = 0.1
587 res@pmLegendWidthF = 0.08
588 res@pmLegendHeightF = 0.06
589 ; res@pmLegendOrthogonalPosF = -1.17
590 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
591 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
593 ; res@pmLegendParallelPosF = 0.18
594 res@pmLegendParallelPosF = 0.23 ;(rightward)
596 ; res@lgPerimOn = False
597 res@lgLabelFontHeightF = 0.015
598 res@xyExplicitLegendLabels = (/"observed",model_name/)
599 ;-------------------------------------------------------------------
601 res@gsnFrame = False ; Do not draw plot
602 res@gsnDraw = False ; Do not advance frame
604 pres = True ; panel plot mods desired
605 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
606 ; indiv. plots in panel
607 pres@gsnMaximize = True ; fill the page
608 ;-------------------------------------------------------------------
610 plot_data = new((/2,12/),float)
612 plot_data!1 = "month"
619 ;----------------------------
622 plot_name = station(nn)+"_ob"
623 title = station(nn)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
624 res@tiMainString = title
626 wks = gsn_open_wks (plot_type,plot_name)
627 plot=new(nfield,graphic) ; create graphic array
630 plot_data(0,:) = (/data_ob (n,i,:)/)
631 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
632 plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot
635 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
637 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
638 "rm "+plot_name+"."+plot_type)
642 ;----------------------------
645 plot_name = station(nn)+"_model_vs_ob"
646 title = station(nn)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
647 res@tiMainString = title
649 wks = gsn_open_wks (plot_type,plot_name)
650 plot=new(nfield,graphic) ; create graphic array
653 plot_data(0,:) = (/data_ob (n,i,:)/)
654 plot_data(1,:) = (/data_mod(n,i,:)/)
655 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
656 plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot
659 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
661 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
662 "rm "+plot_name+"."+plot_type)
668 ;*******************************************************************
669 ; html table of site: observed
670 ;*******************************************************************
671 output_html = "line_ob.html"
673 header = (/"<HTML>" \
675 ,"<TITLE>CLAMP metrics</TITLE>" \
677 ,"<H1>Energy at Site: Observation</H1>" \
682 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
684 ," <th bgcolor=DDDDDD >Site Name</th>" \
685 ," <th bgcolor=DDDDDD >Latitude</th>" \
686 ," <th bgcolor=DDDDDD >Longitude</th>" \
687 ," <th bgcolor=DDDDDD >Observed</th>" \
690 table_footer = "</table>"
694 lines = new(50000,string)
697 set_line(lines,nline,header)
698 set_line(lines,nline,table_header)
699 ;-----------------------------------------------
707 set_line(lines,nline,row_header)
710 txt1 = sprintf("%5.2f", lat_ob(n))
711 txt2 = sprintf("%5.2f", lon_ob(n))
714 set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
715 set_line(lines,nline,"<th>"+txt1+"</th>")
716 set_line(lines,nline,"<th>"+txt2+"</th>")
717 set_line(lines,nline,"<th>"+txt3+"</th>")
719 set_line(lines,nline,row_footer)
721 ;-----------------------------------------------
722 set_line(lines,nline,table_footer)
723 set_line(lines,nline,footer)
725 ; Now write to an HTML file.
726 idx = ind(.not.ismissing(lines))
727 if(.not.any(ismissing(idx))) then
728 asciiwrite(output_html,lines(idx))
734 ;*******************************************************************
735 ; score and line table : model vs observed
736 ;*******************************************************************
737 output_html = "score+line_vs_ob.html"
739 header = (/"<HTML>" \
741 ,"<TITLE>CLAMP metrics</TITLE>" \
743 ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
747 delete (table_header)
749 "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
751 ," <th bgcolor=DDDDDD >Site Name</th>" \
752 ," <th bgcolor=DDDDDD >Latitude</th>" \
753 ," <th bgcolor=DDDDDD >Longitude</th>" \
754 ," <th bgcolor=DDDDDD >Observed</th>" \
755 ," <th bgcolor=DDDDDD >CO2 Flux</th>" \
756 ," <th bgcolor=DDDDDD >Net Radiation</th>" \
757 ," <th bgcolor=DDDDDD >Latent Heat</th>" \
758 ," <th bgcolor=DDDDDD >Sensible Heat</th>" \
759 ," <th bgcolor=DDDDDD >GPP Glux</th>" \
760 ," <th bgcolor=DDDDDD >Respiration</th>" \
761 ," <th bgcolor=DDDDDD >Average</th>" \
764 table_footer = "</table>"
768 lines = new(50000,string)
771 set_line(lines,nline,header)
772 set_line(lines,nline,table_header)
773 ;-----------------------------------------------
781 set_line(lines,nline,row_header)
784 txt1 = sprintf("%5.2f", lat_ob(n))
785 txt2 = sprintf("%5.2f", lon_ob(n))
787 txt4 = sprintf("%5.2f", M_score(n,0))
788 txt5 = sprintf("%5.2f", M_score(n,1))
789 txt6 = sprintf("%5.2f", M_score(n,2))
790 txt7 = sprintf("%5.2f", M_score(n,3))
791 txt8 = sprintf("%5.2f", M_score(n,4))
792 txt9 = sprintf("%5.2f", M_score(n,5))
793 txt10 = sprintf("%5.2f", avg(M_score(n,:)))
795 set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
796 set_line(lines,nline,"<th>"+txt1+"</th>")
797 set_line(lines,nline,"<th>"+txt2+"</th>")
798 set_line(lines,nline,"<th>"+txt3+"</th>")
799 set_line(lines,nline,"<th>"+txt4+"</th>")
800 set_line(lines,nline,"<th>"+txt5+"</th>")
801 set_line(lines,nline,"<th>"+txt6+"</th>")
802 set_line(lines,nline,"<th>"+txt7+"</th>")
803 set_line(lines,nline,"<th>"+txt8+"</th>")
804 set_line(lines,nline,"<th>"+txt9+"</th>")
805 set_line(lines,nline,"<th>"+txt10+"</th>")
807 set_line(lines,nline,row_footer)
811 set_line(lines,nline,row_header)
813 txt0 = "All_"+sprintf("%.0f", nstation)
825 set_line(lines,nline,"<th>"+txt0+"</th>")
826 set_line(lines,nline,"<th>"+txt1+"</th>")
827 set_line(lines,nline,"<th>"+txt2+"</th>")
828 set_line(lines,nline,"<th>"+txt3+"</th>")
829 set_line(lines,nline,"<th>"+txt4+"</th>")
830 set_line(lines,nline,"<th>"+txt5+"</th>")
831 set_line(lines,nline,"<th>"+txt6+"</th>")
832 set_line(lines,nline,"<th>"+txt7+"</th>")
833 set_line(lines,nline,"<th>"+txt8+"</th>")
834 set_line(lines,nline,"<th>"+txt9+"</th>")
835 set_line(lines,nline,"<th>"+txt10+"</th>")
837 set_line(lines,nline,row_footer)
838 ;-----------------------------------------------
839 set_line(lines,nline,table_footer)
840 set_line(lines,nline,footer)
842 ; Now write to an HTML file.
843 idx = ind(.not.ismissing(lines))
844 if(.not.any(ismissing(idx))) then
845 asciiwrite(output_html,lines(idx))
851 ;***************************************************************************
853 ;***************************************************************************
854 output_dir = model_name+"/ameriflux"
856 system("mv *.png *.html " + output_dir)
857 ;***************************************************************************