1 ;************************************************************
6 ; sort by latitude in decending order (N->S)
8 ; add year_ob_i and year_ob_f
10 ;************************************************************
11 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
12 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
13 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
14 ;************************************************************
15 procedure set_line(lines:string,nline:integer,newlines:string)
17 ; add line to ascci/html file
19 nnewlines = dimsizes(newlines)
20 if(nline+nnewlines-1.ge.dimsizes(lines))
21 print("set_line: bad index, not setting anything.")
24 lines(nline:nline+nnewlines-1) = newlines
25 ; print ("lines = " + lines(nline:nline+nnewlines-1))
26 nline = nline + nnewlines
29 ;*************************************************************
35 ;************************************************
37 ;************************************************
41 model_name = "i01.10" + model
47 ;************************************************
49 ;************************************************
51 station = (/"ARM_Oklahoma" \
52 ,"ARM_Oklahoma_burn" \
53 ,"ARM_Oklahoma_control" \
61 ,"Duke_Forest_Hardwoods" \
62 ,"Duke_Forest_Open_Field" \
66 ,"Flagstaff_Managed" \
67 ,"Flagstaff_Unmanaged" \
68 ,"Flagstaff_Wildfire" \
70 ,"FreemanRanch_mesquite" \
73 ,"HarvardForestHemlock" \
74 ,"HowlandForestMain" \
75 ,"HowlandForestWest" \
77 ,"KendallGrasslands" \
78 ,"KennedySpaceCenterPine" \
79 ,"KennedySpaceCenterScrub" \
83 ,"Mead-irrigated-rotation" \
85 ,"Metolius_2nd_YoungPonderosaPine" \
87 ,"MetoliusIntermediatePine" \
88 ,"MetoliusOldPonderosaPine" \
101 ,"SylvaniaWilderness" \
127 year_ob = (/"2003-2006" \
203 field = (/"NEE Flux" \
211 field_unit = (/"u mol/m2/s" \
219 nstation = dimsizes(station)
220 nfield = dimsizes(field)
222 ;========================================================================
223 ; get observed info: number of year, first/last year, lat, lon
226 dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/"
228 year_station = new ((/nstation/),integer) ; number of year
229 year_ob_i = new ((/nstation/),integer) ; first year
230 year_ob_f = new ((/nstation/),integer) ; last year
231 lat_ob = new ((/nstation/),float) ; latitude
232 lon_ob = new ((/nstation/),float) ; longitude
234 data_ob_ann = new ((/nfield, nmonth, nstation/),float)
238 diro = dir_root + station(n)+"/"
239 filo = year_ob(n)+"_L4_m.nc"
240 fo = addfile (diro+filo,"r")
247 year_station(n) = dimsizes(year)
248 year_ob_i(n) = year(0)
249 year_ob_f(n) = year(year_station(n)-1)
253 data = fo->NEE_or_fMDS
254 data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:))
257 data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:))
260 data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:))
263 data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:))
265 data = fo->GPP_or_MDS
266 data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:))
269 data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:))
278 ;--------------------------------------------------------------
279 ; find (# of year observed) >=4 and year_ob_i <= 2001
281 i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001)
283 station_long = station(i_long_ob)
284 lat_ob_long = lat_ob(i_long_ob)
285 lon_ob_long = lat_ob(i_long_ob)
286 year_ob_long = year_ob(i_long_ob)
287 year_ob_i_long = year_ob_i(i_long_ob)
288 year_ob_f_long = year_ob_f(i_long_ob)
289 year_station_long = year_station(i_long_ob)
291 nstation_long = dimsizes(station_long)
294 ; print (nstation_long)
295 ; print (station_long)
296 ; print (year_ob_i(i_long_ob))
298 ;=========================================================
299 ; get model data at observed lat-lon
301 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
302 film = model_name+"_ameriflux_1990-2004_monthly.nc"
303 fm = addfile (dirm+film,"r")
309 date_dim = dimsizes(date)
312 data_mod = new ((/nfield,nyear,nmonth,nstation/),float)
313 data_mod_ann = new ((/nfield,nmonth,nstation/),float)
314 data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float)
316 ; change to unit of observed (u mol/m2/s)
317 ; Model_units [=] gC/m2/s
318 ; 12. = molecular weight of C
323 ;------------------------------------------------------------
324 ; interpolate model data into observed station
325 ; note: model is 0-360E, 90S-90N
327 ; to be able to handle observation at (-89.98,-24.80)
329 ;------------------------------------------------------------
331 if (ENERGY .eq. "old") then
334 data_mod(0,:,:,:) = data(:,:,:) * factor
340 data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
345 ; data = fm->SENSIBLE
347 data_mod(3,:,:,:) = data(:,:,:)
352 data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:)
359 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
360 data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
361 data_mod(0,:,:,:) = yy(:,:,:) * factor
363 ; printVarSummary(yy)
366 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
367 data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:))
368 data_mod(1,:,:,:) = yy(:,:,:)
371 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
372 data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:))
373 data_mod(2,:,:,:) = yy(:,:,:)
375 ; data = fm->SENSIBLE
377 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
378 data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:))
379 data_mod(3,:,:,:) = yy(:,:,:)
384 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
385 data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
386 data_mod(4,:,:,:) = yy(:,:,:) * factor
388 if (model .eq. "cn") then
399 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
400 data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
401 data_mod(5,:,:,:) = yy(:,:,:) * factor
403 data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob)
410 ;*******************************************************************
411 ; for station line plot
412 ;*******************************************************************
414 ; for x-axis in xyplot
416 mon@long_name = "month"
418 res = True ; plot mods desired
419 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
420 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
422 res@tmXBFormat = "f" ; not to add trailing zeros
424 ;-------------------------------------------------------------------------
425 ; Add a boxed legend using the more simple method
427 res@pmLegendDisplayMode = "Always"
428 ; res@pmLegendWidthF = 0.1
429 res@pmLegendWidthF = 0.08
430 res@pmLegendHeightF = 0.06
431 ; res@pmLegendOrthogonalPosF = -1.17
432 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
433 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
435 ; res@pmLegendParallelPosF = 0.18
436 res@pmLegendParallelPosF = 0.23 ;(rightward)
438 ; res@lgPerimOn = False
439 res@lgLabelFontHeightF = 0.015
440 res@xyExplicitLegendLabels = (/"observed",model_name/)
441 ;-------------------------------------------------------------------
443 res@gsnFrame = False ; Do not draw plot
444 res@gsnDraw = False ; Do not advance frame
446 pres = True ; panel plot mods desired
447 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
448 ; indiv. plots in panel
449 pres@gsnMaximize = True ; fill the page
450 ;-------------------------------------------------------------------
452 ;==============================================================
453 ; get ob data at each site with long observation
455 dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
457 do n = 0,nstation_long-1
462 nyear = year_station_long(n)
464 if (year_ob_f_long(n).eq. 2006) then
465 year_setback = 2006 -2004
467 if (year_ob_f_long(n).eq. 2005) then
468 year_setback = 2005 -2004
471 ntime = (nyear - year_setback) * nmonth
473 data_ob = new ((/nfield, nyear, nmonth/),float)
475 diro = dir_root + station_long(n)+"/"
476 filo = year_ob_long(n)+"_L4_m.nc"
477 fo = addfile (diro+filo,"r")
482 data_ob(0,:,:) = fo->NEE_or_fMDS
483 data_ob(1,:,:) = fo->Rg_f
484 data_ob(2,:,:) = fo->LE_f
485 data_ob(3,:,:) = fo->H_f
486 data_ob(4,:,:) = fo->GPP_or_MDS
487 data_ob(5,:,:) = fo->Reco_or
491 timeI = new((/ntime/),integer)
492 timeF = new((/ntime/),float)
493 timeI = ispan(1,ntime,1)
494 timeF = year_ob_i_long(n) + (timeI-1)/12.
495 timeF@long_name = "year"
497 plot_data = new((/2,ntime/),float)
499 ;----------------------------
502 plot_name = station_long(n)+"_tseries_vs_ob"
503 title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")"
504 res@tiMainString = title
506 wks = gsn_open_wks (plot_type,plot_name)
507 plot=new(nfield,graphic) ; create graphic array
509 i_year_mod_i = year_ob_i_long(n) - 1990
510 i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback
512 i_year_ob_f = nyear - year_setback - 1
515 ; print (i_year_ob_f)
516 ; print (i_year_mod_i)
517 ; print (i_year_mod_f)
520 plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:))
521 plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n))
522 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
523 plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot
526 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
528 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
529 "rm "+plot_name+"."+plot_type)
541 ;###################################################################
542 ; for the following tables,
543 ; sort by latitude in decending order (N->S)
545 isort = dim_pqsort(lat_ob_long,-1)
547 station_sort = station_long(isort)
548 year_ob_sort = year_ob_long(isort)
549 lat_ob_sort = lat_ob_long(isort)
550 lon_ob_sort = lon_ob_long(isort)
555 ;*******************************************************************
556 ; html table of site: observed
557 ;*******************************************************************
558 output_html = "tseries_vs_ob.html"
560 header = (/"<HTML>" \
562 ,"<TITLE>CLAMP metrics</TITLE>" \
564 ,"<H1>Timeseries at Site: "+model_name+" vs Observation</H1>" \
569 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
571 ," <th bgcolor=DDDDDD >Site Name</th>" \
572 ," <th bgcolor=DDDDDD >Latitude</th>" \
573 ," <th bgcolor=DDDDDD >Longitude</th>" \
574 ," <th bgcolor=DDDDDD >Observed</th>" \
577 table_footer = "</table>"
581 lines = new(50000,string)
584 set_line(lines,nline,header)
585 set_line(lines,nline,table_header)
586 ;-----------------------------------------------
589 do n = 0,nstation_long-1
591 set_line(lines,nline,row_header)
593 txt0 = station_sort(n)
594 txt1 = sprintf("%5.2f", lat_ob_sort(n))
595 txt2 = sprintf("%5.2f", lon_ob_sort(n))
596 txt3 = year_ob_sort(n)
598 set_line(lines,nline,"<th><a href="+txt0+"_tseries_vs_ob.png>"+txt0+"</a></th>")
599 set_line(lines,nline,"<th>"+txt1+"</th>")
600 set_line(lines,nline,"<th>"+txt2+"</th>")
601 set_line(lines,nline,"<th>"+txt3+"</th>")
603 set_line(lines,nline,row_footer)
605 ;-----------------------------------------------
606 set_line(lines,nline,table_footer)
607 set_line(lines,nline,footer)
609 ; Now write to an HTML file.
610 idx = ind(.not.ismissing(lines))
611 if(.not.any(ismissing(idx))) then
612 asciiwrite(output_html,lines(idx))
619 delete (station_sort)
620 delete (year_ob_sort)
624 ;************************************************************
625 ; compute annual cycle correlation coef and M score
626 ;************************************************************
630 ccr = new ((/nstation, nfield/),float)
631 M_score = new ((/nstation, nfield/),float)
635 ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0)
636 bias = sum(abs(data_mod_ann(m,:,n)-data_ob_ann(m,:,n))/(abs(data_mod_ann(m,:,n))+abs(data_ob_ann(m,:,n))))
637 M_score(n,m) = (1. -(bias/nmonth)) * score_max
641 M_co2 = avg(M_score(:,0))
642 M_rad = avg(M_score(:,1))
643 M_lh = avg(M_score(:,2))
644 M_sh = avg(M_score(:,3))
645 M_gpp = avg(M_score(:,4))
646 M_er = avg(M_score(:,5))
647 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
649 M_energy_co2 = sprintf("%.2f", M_co2)
650 M_energy_rad = sprintf("%.2f", M_rad)
651 M_energy_lh = sprintf("%.2f", M_lh )
652 M_energy_sh = sprintf("%.2f", M_sh )
653 M_energy_gpp = sprintf("%.2f", M_gpp)
654 M_energy_er = sprintf("%.2f", M_er )
655 M_energy_all = sprintf("%.2f", M_all)
657 ;*******************************************************************
658 ; for station line plot
659 ;*******************************************************************
661 ; for x-axis in xyplot
663 mon@long_name = "month"
665 ;-------------------------------------------------------------------
667 plot_data = new((/2,nmonth/),float)
669 plot_data!1 = "month"
672 ;----------------------------
675 plot_name = station(n)+"_ob"
676 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
677 res@tiMainString = title
679 wks = gsn_open_wks (plot_type,plot_name)
680 plot=new(nfield,graphic) ; create graphic array
683 plot_data(0,:) = (/data_ob_ann(i,:,n)/)
684 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
685 plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot
688 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
690 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
691 "rm "+plot_name+"."+plot_type)
695 ;----------------------------
698 plot_name = station(n)+"_model_vs_ob"
699 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
700 res@tiMainString = title
702 wks = gsn_open_wks (plot_type,plot_name)
703 plot=new(nfield,graphic) ; create graphic array
706 plot_data(0,:) = (/data_ob_ann(i,:,n)/)
707 plot_data(1,:) = (/data_mod_ann(i,:,n)/)
708 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
709 plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot
712 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
714 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
715 "rm "+plot_name+"."+plot_type)
721 ;###################################################################
722 ; for the following tables,
723 ; sort by latitude in decending order (N->S)
724 ; sort by lat in decending order (N->S)
726 isort = dim_pqsort(lat_ob,-1)
728 station_sort = station(isort)
729 year_ob_sort = year_ob(isort)
730 lat_ob_sort = lat_ob(isort)
731 lon_ob_sort = lon_ob(isort)
732 M_score_sort = M_score(isort,:)
736 ;###################################################################
737 ;*******************************************************************
738 ; html table of site: observed
739 ;*******************************************************************
740 output_html = "line_ob.html"
742 header = (/"<HTML>" \
744 ,"<TITLE>CLAMP metrics</TITLE>" \
746 ,"<H1>Energy at Site: Observation</H1>" \
751 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
753 ," <th bgcolor=DDDDDD >Site Name</th>" \
754 ," <th bgcolor=DDDDDD >Latitude</th>" \
755 ," <th bgcolor=DDDDDD >Longitude</th>" \
756 ," <th bgcolor=DDDDDD >Observed</th>" \
759 table_footer = "</table>"
763 lines = new(50000,string)
766 set_line(lines,nline,header)
767 set_line(lines,nline,table_header)
768 ;-----------------------------------------------
772 set_line(lines,nline,row_header)
774 txt0 = station_sort(n)
775 txt1 = sprintf("%5.2f", lat_ob_sort(n))
776 txt2 = sprintf("%5.2f", lon_ob_sort(n))
777 txt3 = year_ob_sort(n)
779 set_line(lines,nline,"<th><a href="+txt0+"_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>")
784 set_line(lines,nline,row_footer)
786 ;-----------------------------------------------
787 set_line(lines,nline,table_footer)
788 set_line(lines,nline,footer)
790 ; Now write to an HTML file.
791 idx = ind(.not.ismissing(lines))
792 if(.not.any(ismissing(idx))) then
793 asciiwrite(output_html,lines(idx))
799 ;*******************************************************************
800 ; score and line table : model vs observed
801 ;*******************************************************************
802 output_html = "score+line_vs_ob.html"
804 header = (/"<HTML>" \
806 ,"<TITLE>CLAMP metrics</TITLE>" \
808 ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
812 delete (table_header)
814 "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
816 ," <th bgcolor=DDDDDD >Site Name</th>" \
817 ," <th bgcolor=DDDDDD >Latitude</th>" \
818 ," <th bgcolor=DDDDDD >Longitude</th>" \
819 ," <th bgcolor=DDDDDD >Observed</th>" \
820 ," <th bgcolor=DDDDDD >CO2 Flux</th>" \
821 ," <th bgcolor=DDDDDD >Net Radiation</th>" \
822 ," <th bgcolor=DDDDDD >Latent Heat</th>" \
823 ," <th bgcolor=DDDDDD >Sensible Heat</th>" \
824 ," <th bgcolor=DDDDDD >GPP Glux</th>" \
825 ," <th bgcolor=DDDDDD >Respiration</th>" \
826 ," <th bgcolor=DDDDDD >Average</th>" \
829 table_footer = "</table>"
833 lines = new(50000,string)
836 set_line(lines,nline,header)
837 set_line(lines,nline,table_header)
838 ;-----------------------------------------------
842 set_line(lines,nline,row_header)
844 txt0 = station_sort(n)
845 txt1 = sprintf("%5.2f", lat_ob_sort(n))
846 txt2 = sprintf("%5.2f", lon_ob_sort(n))
847 txt3 = year_ob_sort(n)
848 txt4 = sprintf("%5.2f", M_score_sort(n,0))
849 txt5 = sprintf("%5.2f", M_score_sort(n,1))
850 txt6 = sprintf("%5.2f", M_score_sort(n,2))
851 txt7 = sprintf("%5.2f", M_score_sort(n,3))
852 txt8 = sprintf("%5.2f", M_score_sort(n,4))
853 txt9 = sprintf("%5.2f", M_score_sort(n,5))
854 txt10 = sprintf("%5.2f", avg(M_score_sort(n,:)))
856 set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
857 set_line(lines,nline,"<th>"+txt1+"</th>")
858 set_line(lines,nline,"<th>"+txt2+"</th>")
859 set_line(lines,nline,"<th>"+txt3+"</th>")
860 set_line(lines,nline,"<th>"+txt4+"</th>")
861 set_line(lines,nline,"<th>"+txt5+"</th>")
862 set_line(lines,nline,"<th>"+txt6+"</th>")
863 set_line(lines,nline,"<th>"+txt7+"</th>")
864 set_line(lines,nline,"<th>"+txt8+"</th>")
865 set_line(lines,nline,"<th>"+txt9+"</th>")
866 set_line(lines,nline,"<th>"+txt10+"</th>")
868 set_line(lines,nline,row_footer)
872 set_line(lines,nline,row_header)
874 txt0 = "All_"+sprintf("%.0f", nstation)
886 set_line(lines,nline,"<th>"+txt0+"</th>")
887 set_line(lines,nline,"<th>"+txt1+"</th>")
888 set_line(lines,nline,"<th>"+txt2+"</th>")
889 set_line(lines,nline,"<th>"+txt3+"</th>")
890 set_line(lines,nline,"<th>"+txt4+"</th>")
891 set_line(lines,nline,"<th>"+txt5+"</th>")
892 set_line(lines,nline,"<th>"+txt6+"</th>")
893 set_line(lines,nline,"<th>"+txt7+"</th>")
894 set_line(lines,nline,"<th>"+txt8+"</th>")
895 set_line(lines,nline,"<th>"+txt9+"</th>")
896 set_line(lines,nline,"<th>"+txt10+"</th>")
898 set_line(lines,nline,row_footer)
899 ;-----------------------------------------------
900 set_line(lines,nline,table_footer)
901 set_line(lines,nline,footer)
903 ; Now write to an HTML file.
904 idx = ind(.not.ismissing(lines))
905 if(.not.any(ismissing(idx))) then
906 asciiwrite(output_html,lines(idx))
912 ;***************************************************************************
914 ;***************************************************************************
915 output_dir = model_name+"/ameriflux"
917 system("mv *.png *.html " + output_dir)
918 ;***************************************************************************