Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
1 ;********************************************************
2 ; required command line input parameters:
3 ; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl
5 ; histogram normalized by rain and compute correleration
6 ;**************************************************************
7 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
8 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
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 ;**************************************************************
33 ;************************************************
35 ;************************************************
41 ;model_name_i = "i01.07cn"
42 ;model_name_f = "i01.10cn"
44 model_name_i = "i01.07casa"
45 model_name_f = "i01.10casa"
47 model_name = model_name_f
49 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
50 film_i = model_name_i + "_1990-2004_ANN_climo.nc"
51 film_f = model_name_f + "_1990-2004_ANN_climo.nc"
53 fm_i = addfile (dirm+film_i,"r")
54 fm_f = addfile (dirm+film_f,"r")
59 ;************************************************
61 ;************************************************
63 ob_name = "MODIS MOD 15A2 2000-2005"
65 diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/"
66 filo = "land_class_"+model_grid+".nc"
68 fo = addfile(diro+filo,"r")
70 classob = tofloat(fo->LAND_CLASS)
72 ;*******************************************************************
73 ; Calculate "nice" bins for binning the data in equally spaced ranges
74 ;********************************************************************
76 range = fspan(0,nclassn-1,nclassn)
79 ; Use this range information to grab all the values in a
80 ; particular range, and then take an average.
84 xvalues = new((/2,nx/),float)
85 xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
86 dx = xvalues(0,1) - xvalues(0,0) ; range width
87 dx4 = dx/4 ; 1/4 of the range
88 xvalues(1,:) = xvalues(0,:) - dx/5.
92 DATA11_1D = ndtooned(classob)
93 DATA12_1D = ndtooned(npp_i)
94 DATA22_1D = ndtooned(npp_f)
96 yvalues = new((/2,nx/),float)
97 mn_yvalues = new((/2,nx/),float)
98 mx_yvalues = new((/2,nx/),float)
102 ; See if we are doing model or observational data.
112 ; Loop through each range and check for values.
115 if (i.ne.(nr-2)) then
117 ; print("In range ["+range(i)+","+range(i+1)+")")
118 idx = ind((data_ob.ge.range(i)).and.(data_ob.lt.range(i+1)))
121 ; print("In range ["+range(i)+",)")
122 idx = ind(data_ob.ge.range(i))
125 ; Calculate average, and get min and max.
127 if(.not.any(ismissing(idx))) then
128 yvalues(nd,i) = avg(data_mod(idx))
129 mn_yvalues(nd,i) = min(data_mod(idx))
130 mx_yvalues(nd,i) = max(data_mod(idx))
131 count = dimsizes(idx)
134 yvalues(nd,i) = yvalues@_FillValue
135 mn_yvalues(nd,i) = yvalues@_FillValue
136 mx_yvalues(nd,i) = yvalues@_FillValue
139 ; print(nd + ": " + count + " points, avg = " + yvalues(nd,i))
140 ; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
142 ; Clean up for next time in loop.
149 ;============================
151 ;============================
153 nsec_per_year = 60*60*24*365
158 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
159 uu = u(good)* nsec_per_year
160 vv = v(good)* nsec_per_year
162 n_biome = dimsizes(uu)
164 beta_biome = new((/n_biome/),float)
166 beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i)
168 beta_biome_avg = avg(beta_biome)
170 print (beta_biome_avg)
171 ;*******************************************************************
173 ;*******************************************************************
175 ; column (not including header column)
177 col_head = (/"CO2_i","CO2_f","NPP_i","NPP_f","Beta"/)
179 ncol = dimsizes(col_head)
181 ; row (not including header row)
182 row_head = (/"Water Bodies" \
183 ,"Evergreen Needleleaf Forests" \
184 ,"Evergreen Broadleaf Forests" \
185 ,"Deciduous Needleleaf Forest" \
186 ,"Deciduous Broadleaf Forests" \
188 ,"Closed Bushlands" \
190 ,"Woody Savannas (S. Hem.)" \
191 ,"Savannas (S. Hem.)" \
193 ,"Permanent Wetlands" \
195 ,"Cropland/Natural Vegetation Mosaic" \
196 ,"Permanent Snow and Ice" \
197 ,"Barren or Sparsely Vegetated" \
198 ,"Woody Savannas (N. Hem.)" \
199 ,"Savannas (N. Hem.)" \
202 nrow = dimsizes(row_head)
204 ; arrays to be passed to table.
205 text4 = new ((/nrow, ncol/),string )
208 text4(i,0) = sprintf("%.2f",co2_i)
209 text4(i,1) = sprintf("%.2f",co2_f)
210 text4(i,2) = sprintf("%.2f",uu(i))
211 text4(i,3) = sprintf("%.2f",vv(i))
212 text4(i,4) = sprintf("%.2f",beta_biome(i))
214 text4(nrow-1,0) = "-"
215 text4(nrow-1,1) = "-"
216 text4(nrow-1,2) = "-"
217 text4(nrow-1,3) = "-"
218 text4(nrow-1,4) = sprintf("%.2f",beta_biome_avg)
220 ;**************************************************
222 ;**************************************************
223 output_html = "table_biome.html"
225 header_text = "<H1>Beta Factor: Model "+model_name+"</H1>"
227 header = (/"<HTML>" \
229 ,"<TITLE>CLAMP metrics</TITLE>" \
236 "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
238 ," <th bgcolor=DDDDDD >Biome Class</th>" \
239 ," <th bgcolor=DDDDDD >CO2_i</th>" \
240 ," <th bgcolor=DDDDDD >CO2_f</th>" \
241 ," <th bgcolor=DDDDDD >NPP_i</th>" \
242 ," <th bgcolor=DDDDDD >NPP_f</th>" \
243 ," <th bgcolor=DDDDDD >Beta</th>" \
246 table_footer = "</table>"
250 lines = new(50000,string)
253 set_line(lines,nline,header)
254 set_line(lines,nline,table_header)
255 ;-----------------------------------------------
259 set_line(lines,nline,row_header)
268 set_line(lines,nline,"<th>"+txt1+"</th>")
269 set_line(lines,nline,"<th>"+txt2+"</th>")
270 set_line(lines,nline,"<th>"+txt3+"</th>")
271 set_line(lines,nline,"<th>"+txt4+"</th>")
272 set_line(lines,nline,"<th>"+txt5+"</th>")
273 set_line(lines,nline,"<th>"+txt6+"</th>")
275 set_line(lines,nline,row_footer)
277 ;-----------------------------------------------
278 set_line(lines,nline,table_footer)
279 set_line(lines,nline,footer)
281 ; Now write to an HTML file.
282 idx = ind(.not.ismissing(lines))
283 if(.not.any(ismissing(idx))) then
284 asciiwrite(output_html,lines(idx))