Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
1 ;************************************************************
3 ; sort by latitude in decending order (N->S)
4 ; add year_ob_i and year_ob_f
6 ;************************************************************
7 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
8 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
9 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
10 ;************************************************************
11 procedure set_line(lines:string,nline:integer,newlines:string)
13 ; add line to ascci/html file
15 nnewlines = dimsizes(newlines)
16 if(nline+nnewlines-1.ge.dimsizes(lines))
17 print("set_line: bad index, not setting anything.")
20 lines(nline:nline+nnewlines-1) = newlines
21 ; print ("lines = " + lines(nline:nline+nnewlines-1))
22 nline = nline + nnewlines
25 ;*************************************************************
31 ; for 6 fields, 12-monthly
34 ;************************************************
36 ;************************************************
40 model_name = "i01.10" + model
42 ;************************************************
44 ;************************************************
46 station = (/"ARM_Oklahoma" \
47 ,"ARM_Oklahoma_burn" \
48 ,"ARM_Oklahoma_control" \
56 ,"Duke_Forest_Hardwoods" \
57 ,"Duke_Forest_Open_Field" \
61 ,"Flagstaff_Managed" \
62 ,"Flagstaff_Unmanaged" \
63 ,"Flagstaff_Wildfire" \
65 ,"FreemanRanch_mesquite" \
68 ,"HarvardForestHemlock" \
69 ,"HowlandForestMain" \
70 ,"HowlandForestWest" \
72 ,"KendallGrasslands" \
73 ,"KennedySpaceCenterPine" \
74 ,"KennedySpaceCenterScrub" \
78 ,"Mead-irrigated-rotation" \
80 ,"Metolius_2nd_YoungPonderosaPine" \
82 ,"MetoliusIntermediatePine" \
83 ,"MetoliusOldPonderosaPine" \
96 ,"SylvaniaWilderness" \
122 year_ob = (/"2003-2006" \
350 field = (/"NEE Flux" \
358 field_unit = (/"u mol/m2/s" \
366 nstation = dimsizes(station)
367 nfield = dimsizes(field)
368 ;-------------------------------------------------
373 data_ob = new ((/nstation, nfield, nmon/),float)
374 lat_ob = new ((/nstation/),float)
375 lon_ob = new ((/nstation/),float)
377 diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
381 diro = diro_root + station(n)+"/"
382 filo = year_ob_i(n)+"-"+year_ob_f(n)+"_L4_m.nc"
383 fo = addfile (diro+filo,"r")
390 data = fo->NEE_or_fMDS
391 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
394 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
397 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
400 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
402 data = fo->GPP_or_MDS
403 data_ob(n,4,:) = dim_avg(data(month|:,year|:))
406 data_ob(n,5,:) = dim_avg(data(month|:,year|:))
413 ;---------------------------------------------------
416 dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
417 film = model_name+"_"+"1990-2004"+"_MONS_climo.nc"
418 fm = addfile (dirm_root+film,"r")
422 ; change to unit of observed (u mol/m2/s)
423 ; Model_units [=] gC/m2/s
424 ; 12. = molecular weight of C
436 data_mod0 = new ((/nfield, nmon, nlat, nlon/),float)
437 data_mod = new ((/nstation, nfield, nmon/),float)
439 if (ENERGY .eq. "old") then
442 data_mod0(0,:,:,:) = data(:,:,:) * factor
448 data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
453 ; data = fm->SENSIBLE
455 data_mod0(3,:,:,:) = data(:,:,:)
460 data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)
467 data_mod0(0,:,:,:) = data(:,:,:) * factor
470 data_mod0(1,:,:,:) = data(:,:,:)
473 data_mod0(2,:,:,:) = data(:,:,:)
475 ; data = fm->SENSIBLE
477 data_mod0(3,:,:,:) = data(:,:,:)
481 data_mod0(4,:,:,:) = data(:,:,:) * factor
483 if (model .eq. "cn") then
494 data_mod0(5,:,:,:) = data(:,:,:) * factor
499 ;************************************************************
500 ; interpolate model data into observed station
501 ; note: model is 0-360E, 90S-90N
502 ;************************************************************
504 ; to be able to handle observation at (-89.98,-24.80)
507 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
512 data_mod(n,:,:) = yy(:,:,n)
518 ;************************************************************
519 ; compute correlation coef and M score
520 ;************************************************************
524 ccr = new ((/nstation, nfield/),float)
525 M_score = new ((/nstation, nfield/),float)
529 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
530 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
531 M_score(n,m) = (1. -(bias/nmon)) * score_max
535 M_co2 = avg(M_score(:,0))
536 M_rad = avg(M_score(:,1))
537 M_lh = avg(M_score(:,2))
538 M_sh = avg(M_score(:,3))
539 M_gpp = avg(M_score(:,4))
540 M_er = avg(M_score(:,5))
541 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
543 M_energy_co2 = sprintf("%.2f", M_co2)
544 M_energy_rad = sprintf("%.2f", M_rad)
545 M_energy_lh = sprintf("%.2f", M_lh )
546 M_energy_sh = sprintf("%.2f", M_sh )
547 M_energy_gpp = sprintf("%.2f", M_gpp)
548 M_energy_er = sprintf("%.2f", M_er )
549 M_energy_all = sprintf("%.2f", M_all)
551 ;*******************************************************************
552 ; for station line plot
553 ;*******************************************************************
555 ; for x-axis in xyplot
557 mon@long_name = "month"
559 res = True ; plot mods desired
560 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
561 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
562 ;-------------------------------------------------------------------------
563 ; Add a boxed legend using the more simple method
565 res@pmLegendDisplayMode = "Always"
566 ; res@pmLegendWidthF = 0.1
567 res@pmLegendWidthF = 0.08
568 res@pmLegendHeightF = 0.06
569 ; res@pmLegendOrthogonalPosF = -1.17
570 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
571 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
573 ; res@pmLegendParallelPosF = 0.18
574 res@pmLegendParallelPosF = 0.23 ;(rightward)
576 ; res@lgPerimOn = False
577 res@lgLabelFontHeightF = 0.015
578 res@xyExplicitLegendLabels = (/"observed",model_name/)
579 ;-------------------------------------------------------------------
581 res@gsnFrame = False ; Do not draw plot
582 res@gsnDraw = False ; Do not advance frame
584 pres = True ; panel plot mods desired
585 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
586 ; indiv. plots in panel
587 pres@gsnMaximize = True ; fill the page
588 ;-------------------------------------------------------------------
590 plot_data = new((/2,12/),float)
592 plot_data!1 = "month"
595 ;----------------------------
598 plot_name = station(n)+"_ob"
599 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
600 res@tiMainString = title
602 wks = gsn_open_wks (plot_type,plot_name)
603 plot=new(nfield,graphic) ; create graphic array
606 plot_data(0,:) = (/data_ob (n,i,:)/)
607 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
608 plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot
611 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
613 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
614 "rm "+plot_name+"."+plot_type)
618 ;----------------------------
621 plot_name = station(n)+"_model_vs_ob"
622 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
623 res@tiMainString = title
625 wks = gsn_open_wks (plot_type,plot_name)
626 plot=new(nfield,graphic) ; create graphic array
629 plot_data(0,:) = (/data_ob (n,i,:)/)
630 plot_data(1,:) = (/data_mod(n,i,:)/)
631 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
632 plot(i)=gsn_csm_xy(wks,mon,plot_data,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)
644 ;###################################################################
645 ; for the following tables,
646 ; sort by latitude in decending order (N->S)
647 ; sort by lat in decending order (N->S)
649 isort = dim_pqsort(lat_ob,-1)
651 station_sort = station(isort)
652 lat_ob_sort = lat_ob(isort)
653 lon_ob_sort = lon_ob(isort)
654 year_ob_sort = year_ob(isort)
655 M_score_sort = M_score(isort,:)
659 ;###################################################################
660 ;*******************************************************************
661 ; html table of site: observed
662 ;*******************************************************************
663 output_html = "line_ob.html"
665 header = (/"<HTML>" \
667 ,"<TITLE>CLAMP metrics</TITLE>" \
669 ,"<H1>Energy at Site: Observation</H1>" \
674 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
676 ," <th bgcolor=DDDDDD >Site Name</th>" \
677 ," <th bgcolor=DDDDDD >Latitude</th>" \
678 ," <th bgcolor=DDDDDD >Longitude</th>" \
679 ," <th bgcolor=DDDDDD >Observed</th>" \
682 table_footer = "</table>"
686 lines = new(50000,string)
689 set_line(lines,nline,header)
690 set_line(lines,nline,table_header)
691 ;-----------------------------------------------
695 set_line(lines,nline,row_header)
697 txt0 = station_sort(n)
698 txt1 = sprintf("%5.2f", lat_ob_sort(n))
699 txt2 = sprintf("%5.2f", lon_ob_sort(n))
700 txt3 = year_ob_sort(n)
702 set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
703 set_line(lines,nline,"<th>"+txt1+"</th>")
704 set_line(lines,nline,"<th>"+txt2+"</th>")
705 set_line(lines,nline,"<th>"+txt3+"</th>")
707 set_line(lines,nline,row_footer)
709 ;-----------------------------------------------
710 set_line(lines,nline,table_footer)
711 set_line(lines,nline,footer)
713 ; Now write to an HTML file.
714 idx = ind(.not.ismissing(lines))
715 if(.not.any(ismissing(idx))) then
716 asciiwrite(output_html,lines(idx))
722 ;*******************************************************************
723 ; score and line table : model vs observed
724 ;*******************************************************************
725 output_html = "score+line_vs_ob.html"
727 header = (/"<HTML>" \
729 ,"<TITLE>CLAMP metrics</TITLE>" \
731 ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
735 delete (table_header)
737 "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
739 ," <th bgcolor=DDDDDD >Site Name</th>" \
740 ," <th bgcolor=DDDDDD >Latitude</th>" \
741 ," <th bgcolor=DDDDDD >Longitude</th>" \
742 ," <th bgcolor=DDDDDD >Observed</th>" \
743 ," <th bgcolor=DDDDDD >CO2 Flux</th>" \
744 ," <th bgcolor=DDDDDD >Net Radiation</th>" \
745 ," <th bgcolor=DDDDDD >Latent Heat</th>" \
746 ," <th bgcolor=DDDDDD >Sensible Heat</th>" \
747 ," <th bgcolor=DDDDDD >GPP Glux</th>" \
748 ," <th bgcolor=DDDDDD >Respiration</th>" \
749 ," <th bgcolor=DDDDDD >Average</th>" \
752 table_footer = "</table>"
756 lines = new(50000,string)
759 set_line(lines,nline,header)
760 set_line(lines,nline,table_header)
761 ;-----------------------------------------------
765 set_line(lines,nline,row_header)
767 txt0 = station_sort(n)
768 txt1 = sprintf("%5.2f", lat_ob_sort(n))
769 txt2 = sprintf("%5.2f", lon_ob_sort(n))
770 txt3 = year_ob_sort(n)
771 txt4 = sprintf("%5.2f", M_score_sort(n,0))
772 txt5 = sprintf("%5.2f", M_score_sort(n,1))
773 txt6 = sprintf("%5.2f", M_score_sort(n,2))
774 txt7 = sprintf("%5.2f", M_score_sort(n,3))
775 txt8 = sprintf("%5.2f", M_score_sort(n,4))
776 txt9 = sprintf("%5.2f", M_score_sort(n,5))
777 txt10 = sprintf("%5.2f", avg(M_score_sort(n,:)))
779 set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
780 set_line(lines,nline,"<th>"+txt1+"</th>")
781 set_line(lines,nline,"<th>"+txt2+"</th>")
782 set_line(lines,nline,"<th>"+txt3+"</th>")
783 set_line(lines,nline,"<th>"+txt4+"</th>")
784 set_line(lines,nline,"<th>"+txt5+"</th>")
785 set_line(lines,nline,"<th>"+txt6+"</th>")
786 set_line(lines,nline,"<th>"+txt7+"</th>")
787 set_line(lines,nline,"<th>"+txt8+"</th>")
788 set_line(lines,nline,"<th>"+txt9+"</th>")
789 set_line(lines,nline,"<th>"+txt10+"</th>")
791 set_line(lines,nline,row_footer)
795 set_line(lines,nline,row_header)
797 txt0 = "All_"+sprintf("%.0f", nstation)
809 set_line(lines,nline,"<th>"+txt0+"</th>")
810 set_line(lines,nline,"<th>"+txt1+"</th>")
811 set_line(lines,nline,"<th>"+txt2+"</th>")
812 set_line(lines,nline,"<th>"+txt3+"</th>")
813 set_line(lines,nline,"<th>"+txt4+"</th>")
814 set_line(lines,nline,"<th>"+txt5+"</th>")
815 set_line(lines,nline,"<th>"+txt6+"</th>")
816 set_line(lines,nline,"<th>"+txt7+"</th>")
817 set_line(lines,nline,"<th>"+txt8+"</th>")
818 set_line(lines,nline,"<th>"+txt9+"</th>")
819 set_line(lines,nline,"<th>"+txt10+"</th>")
821 set_line(lines,nline,row_footer)
822 ;-----------------------------------------------
823 set_line(lines,nline,table_footer)
824 set_line(lines,nline,footer)
826 ; Now write to an HTML file.
827 idx = ind(.not.ismissing(lines))
828 if(.not.any(ismissing(idx))) then
829 asciiwrite(output_html,lines(idx))
835 ;***************************************************************************
837 ;***************************************************************************
838 output_dir = model_name+"/ameriflux"
840 system("mv *.png *.html " + output_dir)
841 ;***************************************************************************