Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
1 ;*************************************************************
2 ; remove histogram plots.
4 ; required command line input parameters:
5 ; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl
7 ; histogram normalized by rain and compute correleration
8 ;**************************************************************
9 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
10 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
11 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
12 ;**************************************************************
13 procedure set_line(lines:string,nline:integer,newlines:string)
15 ; add line to ascci/html file
17 nnewlines = dimsizes(newlines)
18 if(nline+nnewlines-1.ge.dimsizes(lines))
19 print("set_line: bad index, not setting anything.")
22 lines(nline:nline+nnewlines-1) = newlines
23 ; print ("lines = " + lines(nline:nline+nnewlines-1))
24 nline = nline + nnewlines
27 ;**************************************************************
34 ;************************************************
36 ;************************************************
38 ;film = "b30.061n_1995-2004_MONS_climo_lnd.nc"
39 ;model_name = "b30.061n"
42 ;film = "newcn05_ncep_1i_MONS_climo_lnd.nc"
46 ;film = "i01.06cn_1798-2004_MONS_climo.nc"
50 ;film = "i01.06casa_1798-2004_MONS_climo.nc"
51 ;model_name = "06casa"
54 film = "i01.10cn_1948-2004_MONS_climo.nc"
58 ;film = "i01.10casa_1948-2004_MONS_climo.nc"
59 ;model_name = "10casa"
62 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
63 fm = addfile(dirm+film,"r")
67 ;************************************************
69 ;************************************************
71 ob_name = "MODIS MOD 15A2 2000-2005"
73 diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/"
74 filo1 = "land_class_"+model_grid+".nc"
75 filo2 = "LAI_2000-2005_MONS_"+model_grid+".nc"
77 fo1 = addfile(diro+filo1,"r")
78 fo2 = addfile(diro+filo2,"r")
80 classob = tofloat(fo1->LAND_CLASS)
83 ; input observed data has 20 land-type classes
86 ;************************************************
88 ;************************************************
89 resg = True ; Use plot options
90 resg@cnFillOn = True ; Turn on color fill
91 resg@gsnSpreadColors = True ; use full colormap
92 resg@cnLinesOn = False ; Turn off contourn lines
93 resg@mpFillOn = False ; Turn off map fill
94 resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals
96 ;************************************************
97 ; plot global land class: observed
98 ;************************************************
100 resg@cnMinLevelValF = 1. ; Min level
101 resg@cnMaxLevelValF = 19. ; Max level
102 resg@cnLevelSpacingF = 1. ; interval
105 classob@_FillValue = 1.e+36
106 classob = where(classob.eq.0,classob@_FillValue,classob)
108 plot_name = "global_class_ob"
110 resg@tiMainString = title
112 wks = gsn_open_wks (plot_type,plot_name) ; open workstation
113 gsn_define_colormap(wks,"gui_default") ; choose colormap
115 plot = gsn_csm_contour_map_ce(wks,classob,resg)
120 ;*******************************************************************
121 ; for html table : all 4 components (Mean, Max, Phase, Growth)
122 ;*******************************************************************
124 ; column (not including header column)
126 component = (/"Mean","Max","Phase","Growth"/)
127 col_head2 = (/"observed",model_name,"M_score" \
128 ,"observed",model_name,"M_score" \
129 ,"observed",model_name,"M_score" \
130 ,"observed",model_name,"M_score" \
133 n_comp = dimsizes(component)
134 ncol = dimsizes(col_head2)
136 ; row (not including header row)
137 row_head = (/"Evergreen Needleleaf Forests" \
138 ,"Evergreen Broadleaf Forests" \
139 ,"Deciduous Needleleaf Forest" \
140 ,"Deciduous Broadleaf Forests" \
142 ,"Closed Bushlands" \
144 ,"Woody Savannas (S. Hem.)" \
145 ,"Savannas (S. Hem.)" \
147 ,"Permanent Wetlands" \
149 ,"Cropland/Natural Vegetation Mosaic" \
150 ,"Barren or Sparsely Vegetated" \
151 ,"Woody Savannas (N. Hem.)" \
152 ,"Savannas (N. Hem.)" \
155 nrow = dimsizes(row_head)
157 ; arrays to be passed to table.
158 text4 = new ((/nrow, ncol/),string )
161 M_comp = (/"M_lai_mean","M_lai_max","M_lai_phase","M_lai_grow"/)
166 ;********************************************************************
167 ; use land-type class to bin the data in equally spaced ranges
168 ;********************************************************************
171 range = fspan(0,nclassn-1,nclassn)
174 ; Use this range information to grab all the values in a
175 ; particular range, and then take an average.
179 xvalues = new((/2,nx/),float)
180 xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
181 dx = xvalues(0,1) - xvalues(0,0) ; range width
182 dx4 = dx/4 ; 1/4 of the range
183 xvalues(1,:) = xvalues(0,:) - dx/5.
185 ;************************************************************************
186 ; go through all components
187 ;************************************************************************
197 data_ob = dim_avg_Wrap(laiob (lat|:,lon|:,time|:))
198 data_mod = dim_avg_Wrap(laimod(lat|:,lon|:,time|:))
206 data_ob = laiob(0,:,:)
208 data_ob@long_name = "Leaf Area Index Max"
210 dsizes_z = dimsizes(laiob)
217 data_ob(j,i) = max(s)
225 data_mod = laimod(0,:,:)
227 data_mod@long_name = "Leaf Area Index Max"
229 dsizes_z = dimsizes(laimod)
236 data_mod(j,i) = max(s)
249 data_ob = laiob(0,:,:)
251 data_ob@long_name = "Leaf Area Index Max Month"
253 dsizes_z = dimsizes(laiob)
260 data_ob(j,i) = maxind(s) + 1
268 data_mod = laimod(0,:,:)
270 data_mod@long_name = "Leaf Area Index Max Month"
272 dsizes_z = dimsizes(laimod)
279 data_mod(j,i) = maxind(s) + 1
291 day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/)
294 data_ob = laiob(0,:,:)
295 data_ob@long_name = "Days of Growing Season"
297 dsizes_z = dimsizes(laiob)
306 if (.not. ismissing(laiob(k,j,i)) .and. laiob(k,j,i) .gt. 1.0) then
307 nday = nday + day_of_data(k)
318 data_mod = laimod(0,:,:)
319 data_mod@long_name = "Days of Growing Season"
321 dsizes_z = dimsizes(laimod)
330 if (.not. ismissing(laimod(k,j,i)) .and. laimod(k,j,i) .gt. 1.0) then
331 nday = nday + day_of_data(k)
342 ;==============================
344 ;==============================
346 base_1D = ndtooned(classob)
347 data1_1D = ndtooned(data_ob)
348 data2_1D = ndtooned(data_mod)
350 ; output for data in bins
352 yvalues = new((/2,nx/),float)
353 count = new((/2,nx/),float)
359 ; See if we are doing data1 (nd=0) or data2 (nd=1).
369 ; Loop through each range, using base.
372 if (i.ne.(nr-2)) then
374 ; print("In range ["+range(i)+","+range(i+1)+")")
375 idx = ind((base.ge.range(i)).and.(base.lt.range(i+1)))
378 ; print("In range ["+range(i)+",)")
379 idx = ind(base.ge.range(i))
384 if(.not.any(ismissing(idx))) then
385 yvalues(nd,i) = avg(data(idx))
386 count(nd,i) = dimsizes(idx)
388 yvalues(nd,i) = yvalues@_FillValue
392 ;#############################################################
393 ; set the following 4 classes to _FillValue:
394 ; Water Bodies(0), Urban and Build-Up(13),
395 ; Permenant Snow and Ice(15), Unclassified(17)
397 if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then
398 yvalues(nd,i) = yvalues@_FillValue
401 ;#############################################################
403 ; print(nd + ": " + count(nd,i) + " points, avg = " + yvalues(nd,i))
405 ; Clean up for next time in loop.
418 ;=====================================
419 ; compute correlation coef and M score
420 ;=====================================
425 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
429 ; compute correlation coef
433 bias = avg(abs(vv-uu))
434 bias = where((bias.gt. 6.),12.-bias,bias)
435 Mscore = ((6. - bias)/6.)*5.
436 M_score = sprintf("%.2f", Mscore)
438 bias = sum(abs(vv-uu)/abs(vv+uu))
439 Mscore = (1.- (bias/dimsizes(uu)))*5.
440 M_score = sprintf("%.2f", Mscore)
445 M_total = M_total + Mscore
452 ;=======================
453 ; output to html table
454 ;=======================
459 text4(i,nn) = sprintf("%.2f",u(i))
460 text4(i,nn+1) = sprintf("%.2f",v(i))
463 text4(nrow-1,nn) = sprintf("%.2f",avg(u))
464 text4(nrow-1,nn+1) = sprintf("%.2f",avg(v))
465 text4(nrow-1,nn+2) = M_score
474 ;========================================
475 ; global res changes for each component
476 ;========================================
480 resg@cnMinLevelValF = 0.
481 resg@cnMaxLevelValF = 10.
482 resg@cnLevelSpacingF = 1.
484 data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
488 resg@cnMinLevelValF = 0.
489 resg@cnMaxLevelValF = 10.
490 resg@cnLevelSpacingF = 1.
492 data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
496 resg@cnMinLevelValF = 1.
497 resg@cnMaxLevelValF = 12.
498 resg@cnLevelSpacingF = 1.
500 data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
504 resg@cnMinLevelValF = 60.
505 resg@cnMaxLevelValF = 360.
506 resg@cnLevelSpacingF = 20.
508 data_ob@_FillValue = 1.e+36
509 data_ob = where(data_ob .lt. 10.,data_ob@_FillValue,data_ob)
511 data_mod@_FillValue = 1.e+36
512 data_mod = where(data_mod .lt. 10.,data_mod@_FillValue,data_mod)
515 ;=========================
516 ; global contour : ob
517 ;=========================
519 plot_name = "global_"+component(n)+"_ob"
521 resg@tiMainString = title
523 wks = gsn_open_wks (plot_type,plot_name) ; open workstation
524 gsn_define_colormap(wks,"gui_default") ; choose colormap
526 plot = gsn_csm_contour_map_ce(wks,data_ob,resg)
532 ;============================
533 ; global contour : model
534 ;============================
536 plot_name = "global_"+component(n)+"_model"
537 title = "Model " + model_name
538 resg@tiMainString = title
540 wks = gsn_open_wks (plot_type,plot_name)
541 gsn_define_colormap(wks,"gui_default")
543 plot = gsn_csm_contour_map_ce(wks,data_mod,resg)
549 ;================================
550 ; global contour: model vs ob
551 ;================================
553 plot_name = "global_"+component(n)+"_model_vs_ob"
555 wks = gsn_open_wks (plot_type,plot_name)
556 gsn_define_colormap(wks,"gui_default")
558 plot=new(3,graphic) ; create graphic array
560 resg@gsnFrame = False ; Do not draw plot
561 resg@gsnDraw = False ; Do not advance frame
563 ; plot correlation coef
566 gRes@txFontHeightF = 0.02
569 correlation_text = "(correlation coef = "+sprintf("%.2f", cc)+")"
571 gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes)
576 resg@tiMainString = title
578 plot(0) = gsn_csm_contour_map_ce(wks,data_ob,resg)
582 title = "Model "+ model_name
583 resg@tiMainString = title
585 plot(1) = gsn_csm_contour_map_ce(wks,data_mod,resg)
590 resg@cnMinLevelValF = -2.
591 resg@cnMaxLevelValF = 2.
592 resg@cnLevelSpacingF = 0.4
596 resg@cnMinLevelValF = -6.
597 resg@cnMaxLevelValF = 6.
598 resg@cnLevelSpacingF = 1.
602 resg@cnMinLevelValF = -6.
603 resg@cnMaxLevelValF = 6.
604 resg@cnLevelSpacingF = 1.
608 resg@cnMinLevelValF = -100.
609 resg@cnMaxLevelValF = 100.
610 resg@cnLevelSpacingF = 20.
614 zz = data_mod - data_ob
615 title = "Model_"+model_name+" - Observed"
616 resg@tiMainString = title
618 plot(2) = gsn_csm_contour_map_ce(wks,zz,resg)
622 pres = True ; panel plot mods desired
623 pres@gsnMaximize = True ; fill the page
625 gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot
631 ;**************************************************
633 ;**************************************************
634 output_html = "table_model_vs_ob.html"
636 header_text = "<H1>LAI: Model "+model_name+" vs Observed</H1>"
638 header = (/"<HTML>" \
640 ,"<TITLE>CLAMP metrics</TITLE>" \
647 "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
649 ," <th bgcolor=DDDDDD rowspan=2>Biome Class</th>" \
650 ," <th bgcolor=DDDDDD colspan=3>"+component(0)+"</th>" \
651 ," <th bgcolor=DDDDDD colspan=3>"+component(1)+"</th>" \
652 ," <th bgcolor=DDDDDD colspan=3>"+component(2)+"</th>" \
653 ," <th bgcolor=DDDDDD colspan=3>"+component(3)+"</th>" \
656 ," <th bgcolor=DDDDDD >observed</th>" \
657 ," <th bgcolor=DDDDDD >"+model_name+"</th>" \
658 ," <th bgcolor=DDDDDD >M_score</th>" \
659 ," <th bgcolor=DDDDDD >observed</th>" \
660 ," <th bgcolor=DDDDDD >"+model_name+"</th>" \
661 ," <th bgcolor=DDDDDD >M_score</th>" \
662 ," <th bgcolor=DDDDDD >observed</th>" \
663 ," <th bgcolor=DDDDDD >"+model_name+"</th>" \
664 ," <th bgcolor=DDDDDD >M_score</th>" \
665 ," <th bgcolor=DDDDDD >observed</th>" \
666 ," <th bgcolor=DDDDDD >"+model_name+"</th>" \
667 ," <th bgcolor=DDDDDD >M_score</th>" \
670 table_footer = "</table>"
674 lines = new(50000,string)
677 set_line(lines,nline,header)
678 set_line(lines,nline,table_header)
679 ;-----------------------------------------------
683 set_line(lines,nline,row_header)
699 set_line(lines,nline,"<th>"+txt1+"</th>")
700 set_line(lines,nline,"<th>"+txt2+"</th>")
701 set_line(lines,nline,"<th>"+txt3+"</th>")
702 set_line(lines,nline,"<th>"+txt4+"</th>")
703 set_line(lines,nline,"<th>"+txt5+"</th>")
704 set_line(lines,nline,"<th>"+txt6+"</th>")
705 set_line(lines,nline,"<th>"+txt7+"</th>")
706 set_line(lines,nline,"<th>"+txt8+"</th>")
707 set_line(lines,nline,"<th>"+txt9+"</th>")
708 set_line(lines,nline,"<th>"+txt10+"</th>")
709 set_line(lines,nline,"<th>"+txt11+"</th>")
710 set_line(lines,nline,"<th>"+txt12+"</th>")
711 set_line(lines,nline,"<th>"+txt13+"</th>")
713 set_line(lines,nline,row_footer)
715 ;-----------------------------------------------
716 set_line(lines,nline,table_footer)
717 set_line(lines,nline,footer)
719 ; Now write to an HTML file.
720 idx = ind(.not.ismissing(lines))
721 if(.not.any(ismissing(idx))) then
722 asciiwrite(output_html,lines(idx))
727 ;***************************************************************************
728 ; write total score to file
729 ;***************************************************************************
731 asciiwrite("M_save.lai", M_total)
733 ;***************************************************************************