1 ;************************************************************
2 ; sort by latitude in decending order (N->S)
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 field = (/"NEE Flux" \
378 field_unit = (/"u mol/m2/s" \
386 nstation = dimsizes(station)
388 data_mod = new ((/nstation, nfield, nmon/),float)
389 data_ob = new ((/nstation, nfield, nmon/),float)
390 lat_ob = new ((/nstation/),float)
391 lon_ob = new ((/nstation/),float)
392 unit_ob = new ((/nfield/),string)
394 diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
395 dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
399 ;-------------------------------------------------
402 diro = diro_root + station(n)+"/"
403 filo = year_ob_i(n)+"-"+year_ob_f(n)+"_L4_m.nc"
404 fo = addfile (diro+filo,"r")
411 data = fo->NEE_or_fMDS
412 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
416 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
420 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
424 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
427 data = fo->GPP_or_MDS
428 data_ob(n,4,:) = dim_avg(data(month|:,year|:))
432 data_ob(n,5,:) = dim_avg(data(month|:,year|:))
436 ;---------------------------------------------------
439 ; film = model_name+"_"+ year_ob(n)+"_MONS_climo.nc"
440 film = model_name+"_"+"1990-2004"+"_MONS_climo.nc"
441 fm = addfile (dirm_root+film,"r")
445 if (ENERGY .eq. "old") then
448 data_mod0(0,:,:,:) = data(:,:,:) * factor
455 data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
460 ; data = fm->SENSIBLE
462 data_mod0(3,:,:,:) = data(:,:,:)
468 data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:)
475 data_mod0(0,:,:,:) = data(:,:,:) * factor
479 data_mod0(1,:,:,:) = data(:,:,:)
483 data_mod0(2,:,:,:) = data(:,:,:)
486 ; data = fm->SENSIBLE
488 data_mod0(3,:,:,:) = data(:,:,:)
493 data_mod0(4,:,:,:) = data(:,:,:) * factor
496 if (model .eq. "cn") then
507 data_mod0(5,:,:,:) = data(:,:,:) * factor
512 ;************************************************************
513 ; interpolate model data into observed station
514 ; note: model is 0-360E, 90S-90N
515 ;************************************************************
517 ; to be able to handle observation at (-89.98,-24.80)
520 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0)
524 data_mod(n,:,:) = yy(:,:,0)
530 ;************************************************************
531 ; compute correlation coef and M score
532 ;************************************************************
536 ccr = new ((/nstation, nfield/),float)
537 M_score = new ((/nstation, nfield/),float)
541 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
542 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
543 M_score(n,m) = (1. -(bias/nmon)) * score_max
547 M_co2 = avg(M_score(:,0))
548 M_rad = avg(M_score(:,1))
549 M_lh = avg(M_score(:,2))
550 M_sh = avg(M_score(:,3))
551 M_gpp = avg(M_score(:,4))
552 M_er = avg(M_score(:,5))
553 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
555 M_energy_co2 = sprintf("%.2f", M_co2)
556 M_energy_rad = sprintf("%.2f", M_rad)
557 M_energy_lh = sprintf("%.2f", M_lh )
558 M_energy_sh = sprintf("%.2f", M_sh )
559 M_energy_gpp = sprintf("%.2f", M_gpp)
560 M_energy_er = sprintf("%.2f", M_er )
561 M_energy_all = sprintf("%.2f", M_all)
563 ;*******************************************************************
564 ; for station line plot
565 ;*******************************************************************
567 ; for x-axis in xyplot
569 mon@long_name = "month"
571 res = True ; plot mods desired
572 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
573 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
574 ;-------------------------------------------------------------------------
575 ; Add a boxed legend using the more simple method
577 res@pmLegendDisplayMode = "Always"
578 ; res@pmLegendWidthF = 0.1
579 res@pmLegendWidthF = 0.08
580 res@pmLegendHeightF = 0.06
581 ; res@pmLegendOrthogonalPosF = -1.17
582 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
583 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
585 ; res@pmLegendParallelPosF = 0.18
586 res@pmLegendParallelPosF = 0.23 ;(rightward)
588 ; res@lgPerimOn = False
589 res@lgLabelFontHeightF = 0.015
590 res@xyExplicitLegendLabels = (/"observed",model_name/)
591 ;-------------------------------------------------------------------
593 res@gsnFrame = False ; Do not draw plot
594 res@gsnDraw = False ; Do not advance frame
596 pres = True ; panel plot mods desired
597 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
598 ; indiv. plots in panel
599 pres@gsnMaximize = True ; fill the page
600 ;-------------------------------------------------------------------
602 plot_data = new((/2,12/),float)
604 plot_data!1 = "month"
607 ;----------------------------
610 plot_name = station(n)+"_ob"
611 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
612 res@tiMainString = title
614 wks = gsn_open_wks (plot_type,plot_name)
615 plot=new(nfield,graphic) ; create graphic array
618 plot_data(0,:) = (/data_ob (n,i,:)/)
619 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
620 plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot
623 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
625 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
626 "rm "+plot_name+"."+plot_type)
630 ;----------------------------
633 plot_name = station(n)+"_model_vs_ob"
634 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
635 res@tiMainString = title
637 wks = gsn_open_wks (plot_type,plot_name)
638 plot=new(nfield,graphic) ; create graphic array
641 plot_data(0,:) = (/data_ob (n,i,:)/)
642 plot_data(1,:) = (/data_mod(n,i,:)/)
643 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
644 plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot
647 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
649 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
650 "rm "+plot_name+"."+plot_type)
656 ;###################################################################
657 ; for the following tables,
658 ; sort by latitude in decending order (N->S)
659 ; sort by lat in decending order (N->S)
661 isort = dim_pqsort(lat_ob,-1)
663 station_sort = station(isort)
664 lat_ob_sort = lat_ob(isort)
665 lon_ob_sort = lon_ob(isort)
666 year_ob_sort = year_ob(isort)
667 M_score_sort = M_score(isort,:)
671 ;###################################################################
672 ;*******************************************************************
673 ; html table of site: observed
674 ;*******************************************************************
675 output_html = "line_ob.html"
677 header = (/"<HTML>" \
679 ,"<TITLE>CLAMP metrics</TITLE>" \
681 ,"<H1>Energy at Site: Observation</H1>" \
686 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
688 ," <th bgcolor=DDDDDD >Site Name</th>" \
689 ," <th bgcolor=DDDDDD >Latitude</th>" \
690 ," <th bgcolor=DDDDDD >Longitude</th>" \
691 ," <th bgcolor=DDDDDD >Observed</th>" \
694 table_footer = "</table>"
698 lines = new(50000,string)
701 set_line(lines,nline,header)
702 set_line(lines,nline,table_header)
703 ;-----------------------------------------------
707 set_line(lines,nline,row_header)
709 txt0 = station_sort(n)
710 txt1 = sprintf("%5.2f", lat_ob_sort(n))
711 txt2 = sprintf("%5.2f", lon_ob_sort(n))
712 txt3 = year_ob_sort(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 ;-----------------------------------------------
777 set_line(lines,nline,row_header)
779 txt0 = station_sort(n)
780 txt1 = sprintf("%5.2f", lat_ob_sort(n))
781 txt2 = sprintf("%5.2f", lon_ob_sort(n))
782 txt3 = year_ob_sort(n)
783 txt4 = sprintf("%5.2f", M_score_sort(n,0))
784 txt5 = sprintf("%5.2f", M_score_sort(n,1))
785 txt6 = sprintf("%5.2f", M_score_sort(n,2))
786 txt7 = sprintf("%5.2f", M_score_sort(n,3))
787 txt8 = sprintf("%5.2f", M_score_sort(n,4))
788 txt9 = sprintf("%5.2f", M_score_sort(n,5))
789 txt10 = sprintf("%5.2f", avg(M_score_sort(n,:)))
791 set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
792 set_line(lines,nline,"<th>"+txt1+"</th>")
793 set_line(lines,nline,"<th>"+txt2+"</th>")
794 set_line(lines,nline,"<th>"+txt3+"</th>")
795 set_line(lines,nline,"<th>"+txt4+"</th>")
796 set_line(lines,nline,"<th>"+txt5+"</th>")
797 set_line(lines,nline,"<th>"+txt6+"</th>")
798 set_line(lines,nline,"<th>"+txt7+"</th>")
799 set_line(lines,nline,"<th>"+txt8+"</th>")
800 set_line(lines,nline,"<th>"+txt9+"</th>")
801 set_line(lines,nline,"<th>"+txt10+"</th>")
803 set_line(lines,nline,row_footer)
807 set_line(lines,nline,row_header)
809 txt0 = "All_"+sprintf("%.0f", nstation)
821 set_line(lines,nline,"<th>"+txt0+"</th>")
822 set_line(lines,nline,"<th>"+txt1+"</th>")
823 set_line(lines,nline,"<th>"+txt2+"</th>")
824 set_line(lines,nline,"<th>"+txt3+"</th>")
825 set_line(lines,nline,"<th>"+txt4+"</th>")
826 set_line(lines,nline,"<th>"+txt5+"</th>")
827 set_line(lines,nline,"<th>"+txt6+"</th>")
828 set_line(lines,nline,"<th>"+txt7+"</th>")
829 set_line(lines,nline,"<th>"+txt8+"</th>")
830 set_line(lines,nline,"<th>"+txt9+"</th>")
831 set_line(lines,nline,"<th>"+txt10+"</th>")
833 set_line(lines,nline,row_footer)
834 ;-----------------------------------------------
835 set_line(lines,nline,table_footer)
836 set_line(lines,nline,footer)
838 ; Now write to an HTML file.
839 idx = ind(.not.ismissing(lines))
840 if(.not.any(ismissing(idx))) then
841 asciiwrite(output_html,lines(idx))
847 ;***************************************************************************
849 ;***************************************************************************
850 output_dir = model_name+"/ameriflux"
852 system("mv *.png *.html " + output_dir)
853 ;***************************************************************************