1 ;************************************************************
2 ; change data name to timeseries_L4_m.nc
7 ; sort by latitude in decending order (N->S)
9 ; add year_ob_i and year_ob_f
11 ;************************************************************
12 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
13 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
14 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
15 ;************************************************************
16 procedure set_line(lines:string,nline:integer,newlines:string)
18 ; add line to ascci/html file
20 nnewlines = dimsizes(newlines)
21 if(nline+nnewlines-1.ge.dimsizes(lines))
22 print("set_line: bad index, not setting anything.")
25 lines(nline:nline+nnewlines-1) = newlines
26 ; print ("lines = " + lines(nline:nline+nnewlines-1))
27 nline = nline + nnewlines
30 ;*************************************************************
36 ;************************************************
38 ;************************************************
42 model_name = "i01.10" + model
48 ;************************************************
50 ;************************************************
52 station = (/"ARM_Oklahoma" \
53 ,"ARM_Oklahoma_burn" \
54 ,"ARM_Oklahoma_control" \
62 ,"Duke_Forest_Hardwoods" \
63 ,"Duke_Forest_Open_Field" \
67 ,"Flagstaff_Managed" \
68 ,"Flagstaff_Unmanaged" \
69 ,"Flagstaff_Wildfire" \
71 ,"FreemanRanch_mesquite" \
74 ,"HarvardForestHemlock" \
75 ,"HowlandForestMain" \
76 ,"HowlandForestWest" \
78 ,"KendallGrasslands" \
79 ,"KennedySpaceCenterPine" \
80 ,"KennedySpaceCenterScrub" \
84 ,"Mead-irrigated-rotation" \
86 ,"Metolius_2nd_YoungPonderosaPine" \
88 ,"MetoliusIntermediatePine" \
89 ,"MetoliusOldPonderosaPine" \
100 ,"SkyOaks_PostFire" \
102 ,"SylvaniaWilderness" \
128 field = (/"NEE Flux" \
136 field_unit = (/"u mol/m2/s" \
144 nstation = dimsizes(station)
145 nfield = dimsizes(field)
147 ;========================================================================
148 ; get observed info: number of year, first/last year, lat, lon
151 dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/"
153 year_station = new ((/nstation/),integer) ; number of year
154 year_ob = new ((/nstation/),string) ; observed year
155 year_ob_i = new ((/nstation/),integer) ; first year
156 year_ob_f = new ((/nstation/),integer) ; last year
157 lat_ob = new ((/nstation/),float) ; latitude
158 lon_ob = new ((/nstation/),float) ; longitude
160 data_ob_ann = new ((/nfield, nmonth, nstation/),float)
164 diro = dir_root + station(n)+"/"
165 filo = "timeseries_L4_m.nc"
166 fo = addfile (diro+filo,"r")
173 year_station(n) = dimsizes(year)
174 year_ob_i(n) = year(0)
175 year_ob_f(n) = year(year_station(n)-1)
176 year_ob(n) = year_ob_i(n) + "-" + year_ob_f(n)
180 data = fo->NEE_or_fMDS
181 data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:))
184 data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:))
187 data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:))
190 data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:))
192 data = fo->GPP_or_MDS
193 data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:))
196 data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:))
205 ;--------------------------------------------------------------
206 ; find (# of year observed) >=4 and year_ob_i <= 2001
208 i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001)
210 station_long = station(i_long_ob)
211 lat_ob_long = lat_ob(i_long_ob)
212 lon_ob_long = lat_ob(i_long_ob)
213 year_ob_long = year_ob(i_long_ob)
214 year_ob_i_long = year_ob_i(i_long_ob)
215 year_ob_f_long = year_ob_f(i_long_ob)
216 year_station_long = year_station(i_long_ob)
218 nstation_long = dimsizes(station_long)
221 ; print (nstation_long)
222 ; print (station_long)
223 ; print (year_ob_i(i_long_ob))
225 ;=========================================================
226 ; get model data at observed lat-lon
228 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
229 film = model_name+"_ameriflux_1990-2004_monthly.nc"
230 fm = addfile (dirm+film,"r")
236 date_dim = dimsizes(date)
239 data_mod = new ((/nfield,nyear,nmonth,nstation/),float)
240 data_mod_ann = new ((/nfield,nmonth,nstation/),float)
241 data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float)
243 ; change to unit of observed (u mol/m2/s)
244 ; Model_units [=] gC/m2/s
245 ; 12. = molecular weight of C
250 ;------------------------------------------------------------
251 ; interpolate model data into observed station
252 ; note: model is 0-360E, 90S-90N
254 ; to be able to handle observation at (-89.98,-24.80)
256 ;------------------------------------------------------------
258 if (ENERGY .eq. "old") then
261 data_mod(0,:,:,:) = data(:,:,:) * factor
267 data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
272 ; data = fm->SENSIBLE
274 data_mod(3,:,:,:) = data(:,:,:)
279 data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:)
286 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
287 data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
288 data_mod(0,:,:,:) = yy(:,:,:) * factor
290 ; printVarSummary(yy)
293 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
294 data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:))
295 data_mod(1,:,:,:) = yy(:,:,:)
298 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
299 data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:))
300 data_mod(2,:,:,:) = yy(:,:,:)
302 ; data = fm->SENSIBLE
304 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
305 data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:))
306 data_mod(3,:,:,:) = yy(:,:,:)
311 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
312 data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
313 data_mod(4,:,:,:) = yy(:,:,:) * factor
315 if (model .eq. "cn") then
326 yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
327 data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
328 data_mod(5,:,:,:) = yy(:,:,:) * factor
330 data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob)
337 ;*******************************************************************
338 ; for station line plot
339 ;*******************************************************************
341 ; for x-axis in xyplot
343 mon@long_name = "month"
345 res = True ; plot mods desired
346 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
347 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
349 res@tmXBFormat = "f" ; not to add trailing zeros
351 ;-------------------------------------------------------------------------
352 ; Add a boxed legend using the more simple method
354 res@pmLegendDisplayMode = "Always"
355 ; res@pmLegendWidthF = 0.1
356 res@pmLegendWidthF = 0.08
357 res@pmLegendHeightF = 0.06
358 ; res@pmLegendOrthogonalPosF = -1.17
359 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
360 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
362 ; res@pmLegendParallelPosF = 0.18
363 res@pmLegendParallelPosF = 0.23 ;(rightward)
365 ; res@lgPerimOn = False
366 res@lgLabelFontHeightF = 0.015
367 res@xyExplicitLegendLabels = (/"observed",model_name/)
368 ;-------------------------------------------------------------------
370 res@gsnFrame = False ; Do not draw plot
371 res@gsnDraw = False ; Do not advance frame
373 pres = True ; panel plot mods desired
374 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
375 ; indiv. plots in panel
376 pres@gsnMaximize = True ; fill the page
377 ;-------------------------------------------------------------------
379 ;==============================================================
380 ; get ob data at each site with long observation
382 dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
384 do n = 0,nstation_long-1
389 nyear = year_station_long(n)
391 if (year_ob_f_long(n).eq. 2006) then
392 year_setback = 2006 -2004
394 if (year_ob_f_long(n).eq. 2005) then
395 year_setback = 2005 -2004
398 ntime = (nyear - year_setback) * nmonth
400 data_ob = new ((/nfield, nyear, nmonth/),float)
402 diro = dir_root + station_long(n)+"/"
403 filo = year_ob_long(n)+"_L4_m.nc"
404 fo = addfile (diro+filo,"r")
409 data_ob(0,:,:) = fo->NEE_or_fMDS
410 data_ob(1,:,:) = fo->Rg_f
411 data_ob(2,:,:) = fo->LE_f
412 data_ob(3,:,:) = fo->H_f
413 data_ob(4,:,:) = fo->GPP_or_MDS
414 data_ob(5,:,:) = fo->Reco_or
418 timeI = new((/ntime/),integer)
419 timeF = new((/ntime/),float)
420 timeI = ispan(1,ntime,1)
421 timeF = year_ob_i_long(n) + (timeI-1)/12.
422 timeF@long_name = "year"
424 plot_data = new((/2,ntime/),float)
426 ;----------------------------
429 plot_name = station_long(n)+"_tseries_vs_ob"
430 title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")"
431 res@tiMainString = title
433 wks = gsn_open_wks (plot_type,plot_name)
434 plot=new(nfield,graphic) ; create graphic array
436 i_year_mod_i = year_ob_i_long(n) - 1990
437 i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback
439 i_year_ob_f = nyear - year_setback - 1
442 ; print (i_year_ob_f)
443 ; print (i_year_mod_i)
444 ; print (i_year_mod_f)
447 plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:))
448 plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n))
449 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
450 plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot
453 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
455 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
456 "rm "+plot_name+"."+plot_type)
468 ;###################################################################
469 ; for the following tables,
470 ; sort by latitude in decending order (N->S)
472 isort = dim_pqsort(lat_ob_long,-1)
474 station_sort = station_long(isort)
475 year_ob_sort = year_ob_long(isort)
476 lat_ob_sort = lat_ob_long(isort)
477 lon_ob_sort = lon_ob_long(isort)
482 ;*******************************************************************
483 ; html table of site: observed
484 ;*******************************************************************
485 output_html = "tseries_vs_ob.html"
487 header = (/"<HTML>" \
489 ,"<TITLE>CLAMP metrics</TITLE>" \
491 ,"<H1>Timeseries at Site: "+model_name+" vs Observation</H1>" \
496 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
498 ," <th bgcolor=DDDDDD >Site Name</th>" \
499 ," <th bgcolor=DDDDDD >Latitude</th>" \
500 ," <th bgcolor=DDDDDD >Longitude</th>" \
501 ," <th bgcolor=DDDDDD >Observed</th>" \
504 table_footer = "</table>"
508 lines = new(50000,string)
511 set_line(lines,nline,header)
512 set_line(lines,nline,table_header)
513 ;-----------------------------------------------
516 do n = 0,nstation_long-1
518 set_line(lines,nline,row_header)
520 txt0 = station_sort(n)
521 txt1 = sprintf("%5.2f", lat_ob_sort(n))
522 txt2 = sprintf("%5.2f", lon_ob_sort(n))
523 txt3 = year_ob_sort(n)
525 set_line(lines,nline,"<th><a href="+txt0+"_tseries_vs_ob.png>"+txt0+"</a></th>")
526 set_line(lines,nline,"<th>"+txt1+"</th>")
527 set_line(lines,nline,"<th>"+txt2+"</th>")
528 set_line(lines,nline,"<th>"+txt3+"</th>")
530 set_line(lines,nline,row_footer)
532 ;-----------------------------------------------
533 set_line(lines,nline,table_footer)
534 set_line(lines,nline,footer)
536 ; Now write to an HTML file.
537 idx = ind(.not.ismissing(lines))
538 if(.not.any(ismissing(idx))) then
539 asciiwrite(output_html,lines(idx))
546 delete (station_sort)
547 delete (year_ob_sort)
551 ;************************************************************
552 ; compute annual cycle correlation coef and M score
553 ;************************************************************
557 ccr = new ((/nstation, nfield/),float)
558 M_score = new ((/nstation, nfield/),float)
562 ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0)
563 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))))
564 M_score(n,m) = (1. -(bias/nmonth)) * score_max
568 M_co2 = avg(M_score(:,0))
569 M_rad = avg(M_score(:,1))
570 M_lh = avg(M_score(:,2))
571 M_sh = avg(M_score(:,3))
572 M_gpp = avg(M_score(:,4))
573 M_er = avg(M_score(:,5))
574 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
576 M_energy_co2 = sprintf("%.2f", M_co2)
577 M_energy_rad = sprintf("%.2f", M_rad)
578 M_energy_lh = sprintf("%.2f", M_lh )
579 M_energy_sh = sprintf("%.2f", M_sh )
580 M_energy_gpp = sprintf("%.2f", M_gpp)
581 M_energy_er = sprintf("%.2f", M_er )
582 M_energy_all = sprintf("%.2f", M_all)
584 ;*******************************************************************
585 ; for station line plot
586 ;*******************************************************************
588 ; for x-axis in xyplot
590 mon@long_name = "month"
592 ;-------------------------------------------------------------------
594 plot_data = new((/2,nmonth/),float)
596 plot_data!1 = "month"
599 ;----------------------------
602 plot_name = station(n)+"_ob"
603 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
604 res@tiMainString = title
606 wks = gsn_open_wks (plot_type,plot_name)
607 plot=new(nfield,graphic) ; create graphic array
610 plot_data(0,:) = (/data_ob_ann(i,:,n)/)
611 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
612 plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot
615 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
617 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
618 "rm "+plot_name+"."+plot_type)
622 ;----------------------------
625 plot_name = station(n)+"_model_vs_ob"
626 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
627 res@tiMainString = title
629 wks = gsn_open_wks (plot_type,plot_name)
630 plot=new(nfield,graphic) ; create graphic array
633 plot_data(0,:) = (/data_ob_ann(i,:,n)/)
634 plot_data(1,:) = (/data_mod_ann(i,:,n)/)
635 plot_data@long_name = field(i)+" ("+field_unit(i)+")"
636 plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot
639 gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
641 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
642 "rm "+plot_name+"."+plot_type)
648 ;###################################################################
649 ; for the following tables,
650 ; sort by latitude in decending order (N->S)
651 ; sort by lat in decending order (N->S)
653 isort = dim_pqsort(lat_ob,-1)
655 station_sort = station(isort)
656 year_ob_sort = year_ob(isort)
657 lat_ob_sort = lat_ob(isort)
658 lon_ob_sort = lon_ob(isort)
659 M_score_sort = M_score(isort,:)
663 ;###################################################################
664 ;*******************************************************************
665 ; html table of site: observed
666 ;*******************************************************************
667 output_html = "line_ob.html"
669 header = (/"<HTML>" \
671 ,"<TITLE>CLAMP metrics</TITLE>" \
673 ,"<H1>Energy at Site: Observation</H1>" \
678 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
680 ," <th bgcolor=DDDDDD >Site Name</th>" \
681 ," <th bgcolor=DDDDDD >Latitude</th>" \
682 ," <th bgcolor=DDDDDD >Longitude</th>" \
683 ," <th bgcolor=DDDDDD >Observed</th>" \
686 table_footer = "</table>"
690 lines = new(50000,string)
693 set_line(lines,nline,header)
694 set_line(lines,nline,table_header)
695 ;-----------------------------------------------
699 set_line(lines,nline,row_header)
701 txt0 = station_sort(n)
702 txt1 = sprintf("%5.2f", lat_ob_sort(n))
703 txt2 = sprintf("%5.2f", lon_ob_sort(n))
704 txt3 = year_ob_sort(n)
706 set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
707 set_line(lines,nline,"<th>"+txt1+"</th>")
708 set_line(lines,nline,"<th>"+txt2+"</th>")
709 set_line(lines,nline,"<th>"+txt3+"</th>")
711 set_line(lines,nline,row_footer)
713 ;-----------------------------------------------
714 set_line(lines,nline,table_footer)
715 set_line(lines,nline,footer)
717 ; Now write to an HTML file.
718 idx = ind(.not.ismissing(lines))
719 if(.not.any(ismissing(idx))) then
720 asciiwrite(output_html,lines(idx))
726 ;*******************************************************************
727 ; score and line table : model vs observed
728 ;*******************************************************************
729 output_html = "score+line_vs_ob.html"
731 header = (/"<HTML>" \
733 ,"<TITLE>CLAMP metrics</TITLE>" \
735 ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
739 delete (table_header)
741 "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
743 ," <th bgcolor=DDDDDD >Site Name</th>" \
744 ," <th bgcolor=DDDDDD >Latitude</th>" \
745 ," <th bgcolor=DDDDDD >Longitude</th>" \
746 ," <th bgcolor=DDDDDD >Observed</th>" \
747 ," <th bgcolor=DDDDDD >CO2 Flux</th>" \
748 ," <th bgcolor=DDDDDD >Net Radiation</th>" \
749 ," <th bgcolor=DDDDDD >Latent Heat</th>" \
750 ," <th bgcolor=DDDDDD >Sensible Heat</th>" \
751 ," <th bgcolor=DDDDDD >GPP Glux</th>" \
752 ," <th bgcolor=DDDDDD >Respiration</th>" \
753 ," <th bgcolor=DDDDDD >Average</th>" \
756 table_footer = "</table>"
760 lines = new(50000,string)
763 set_line(lines,nline,header)
764 set_line(lines,nline,table_header)
765 ;-----------------------------------------------
769 set_line(lines,nline,row_header)
771 txt0 = station_sort(n)
772 txt1 = sprintf("%5.2f", lat_ob_sort(n))
773 txt2 = sprintf("%5.2f", lon_ob_sort(n))
774 txt3 = year_ob_sort(n)
775 txt4 = sprintf("%5.2f", M_score_sort(n,0))
776 txt5 = sprintf("%5.2f", M_score_sort(n,1))
777 txt6 = sprintf("%5.2f", M_score_sort(n,2))
778 txt7 = sprintf("%5.2f", M_score_sort(n,3))
779 txt8 = sprintf("%5.2f", M_score_sort(n,4))
780 txt9 = sprintf("%5.2f", M_score_sort(n,5))
781 txt10 = sprintf("%5.2f", avg(M_score_sort(n,:)))
783 set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
784 set_line(lines,nline,"<th>"+txt1+"</th>")
785 set_line(lines,nline,"<th>"+txt2+"</th>")
786 set_line(lines,nline,"<th>"+txt3+"</th>")
787 set_line(lines,nline,"<th>"+txt4+"</th>")
788 set_line(lines,nline,"<th>"+txt5+"</th>")
789 set_line(lines,nline,"<th>"+txt6+"</th>")
790 set_line(lines,nline,"<th>"+txt7+"</th>")
791 set_line(lines,nline,"<th>"+txt8+"</th>")
792 set_line(lines,nline,"<th>"+txt9+"</th>")
793 set_line(lines,nline,"<th>"+txt10+"</th>")
795 set_line(lines,nline,row_footer)
799 set_line(lines,nline,row_header)
801 txt0 = "All_"+sprintf("%.0f", nstation)
813 set_line(lines,nline,"<th>"+txt0+"</th>")
814 set_line(lines,nline,"<th>"+txt1+"</th>")
815 set_line(lines,nline,"<th>"+txt2+"</th>")
816 set_line(lines,nline,"<th>"+txt3+"</th>")
817 set_line(lines,nline,"<th>"+txt4+"</th>")
818 set_line(lines,nline,"<th>"+txt5+"</th>")
819 set_line(lines,nline,"<th>"+txt6+"</th>")
820 set_line(lines,nline,"<th>"+txt7+"</th>")
821 set_line(lines,nline,"<th>"+txt8+"</th>")
822 set_line(lines,nline,"<th>"+txt9+"</th>")
823 set_line(lines,nline,"<th>"+txt10+"</th>")
825 set_line(lines,nline,row_footer)
826 ;-----------------------------------------------
827 set_line(lines,nline,table_footer)
828 set_line(lines,nline,footer)
830 ; Now write to an HTML file.
831 idx = ind(.not.ismissing(lines))
832 if(.not.any(ismissing(idx))) then
833 asciiwrite(output_html,lines(idx))
839 ;***************************************************************************
841 ;***************************************************************************
842 output_dir = model_name+"/ameriflux"
844 system("mv *.png *.html " + output_dir)
845 ;***************************************************************************