Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
1 ;********************************************************
2 ; histogram normalized by rain and compute correleration
3 ;********************************************************
4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
5 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
8 procedure pminmax(data:numeric,name:string)
10 print ("min/max " + name + " = " + min(data) + "/" + max(data))
11 if(isatt(data,"units")) then
12 print (name + " units = " + data@units)
24 ;************************************************
25 ; read in data: observed
26 ;************************************************
27 diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/"
28 ;fili1 = "land_class_T42.nc"
29 fili1 = "land_class_T42_new.nc"
30 fili2 = "LAI_2000-2005_ensemble_T42.nc"
31 data_file_ob1 = addfile(diri1+fili1,"r")
32 data_file_ob2 = addfile(diri1+fili2,"r")
34 RAIN1 = tofloat(data_file_ob1->LAND_CLASS)
36 z = data_file_ob2->LAI
38 y@long_name = "Leaf Area Index Max Month"
41 dsizes_z = dimsizes(z)
49 y(j,i) = maxind(s) + 1
53 print (min(y)+"/"+max(y))
60 ;************************************************
62 ;************************************************
63 diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
64 ;fili3 = "i01.03cn_1545-1569_MONS_climo.nc"
65 fili3 = "i01.04casa_1605-1629_MONS_climo.nc"
66 data_file_model = addfile(diri2+fili3,"r")
68 z = data_file_model->TLAI
70 y@long_name = "Leaf Area Index Max Month"
73 dsizes_z = dimsizes(z)
81 y(j,i) = maxind(s) + 1
85 print (min(y)+"/"+max(y))
92 ;************************************************
93 ; print min/max and unit
94 ;************************************************
95 pminmax(RAIN1,"RAIN1")
99 RAIN1_1D = ndtooned(RAIN1)
100 NPP1_1D = ndtooned(NPP1)
101 NPP2_1D = ndtooned(NPP2)
103 ; Calculate some "nice" bins for binning the data in equally spaced
107 ; nbins = nclass + 1 ; Number of bins to use.
108 ; nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,False)
109 ; nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
110 ; range = fspan(nicevals(0),nicevals(1),nvals)
113 range = fspan(0,nclass-1,nclass)
121 ; Use this range information to grab all the values in a
122 ; particular range, and then take an average.
126 xvalues = new((/2,nx/),typeof(RAIN1_1D))
127 xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
128 dx = xvalues(0,1) - xvalues(0,0) ; range width
129 dx4 = dx/4 ; 1/4 of the range
130 xvalues(1,:) = xvalues(0,:) - dx/5.
131 yvalues = new((/2,nx/),typeof(RAIN1_1D))
132 mn_yvalues = new((/2,nx/),typeof(RAIN1_1D))
133 mx_yvalues = new((/2,nx/),typeof(RAIN1_1D))
137 ; See if we are doing model or observational data.
147 ; Loop through each range and check for values.
150 if (i.ne.(nr-2)) then
152 print("In range ["+range(i)+","+range(i+1)+")")
153 idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
156 print("In range ["+range(i)+",)")
157 idx = ind(range(i).le.data)
160 ; Calculate average, and get min and max.
162 if(.not.any(ismissing(idx))) then
163 yvalues(nd,i) = avg(npp_data(idx))
164 mn_yvalues(nd,i) = min(npp_data(idx))
165 mx_yvalues(nd,i) = max(npp_data(idx))
166 count = dimsizes(idx)
169 yvalues(nd,i) = yvalues@_FillValue
170 mn_yvalues(nd,i) = yvalues@_FillValue
171 mx_yvalues(nd,i) = yvalues@_FillValue
174 ; Print out information.
176 print(nd + ": " + count + " points, avg = " + yvalues(nd,i))
177 print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
180 ; Clean up for next time in loop.
189 ; Start the graphics.
191 wks = gsn_open_wks("ps","xy")
194 res@gsnMaximize = True
197 res@xyMarkLineMode = "Markers"
198 res@xyMarkerSizeF = 0.014
200 res@xyMarkerColors = (/"Brown","Blue"/)
201 ; res@trYMinF = min(mn_yvalues) - 10.
202 ; res@trYMaxF = max(mx_yvalues) + 10.
203 res@trYMinF = min(mn_yvalues) - 2
204 res@trYMaxF = max(mx_yvalues) + 4
206 ; res@tiMainString = "Observed vs i01.03cn"
207 res@tiMainString = "Observed vs i01.04casa"
209 res@tiYAxisString = "Max LAI (Leaf Area Index) Month"
210 res@tiXAxisString = "Land Cover Type"
212 ; Add a boxed legend using the more simple method, which won't have
213 ; vertical lines going through the markers.
215 res@pmLegendDisplayMode = "Always"
216 ; res@pmLegendWidthF = 0.1
217 res@pmLegendWidthF = 0.08
218 res@pmLegendHeightF = 0.05
219 res@pmLegendOrthogonalPosF = -1.17
220 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
221 ; res@pmLegendParallelPosF = 0.18
222 res@pmLegendParallelPosF = 0.23 ;(rightward)
224 ; res@lgPerimOn = False
225 res@lgLabelFontHeightF = 0.015
226 ; res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/)
227 res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/)
229 xy = gsn_csm_xy(wks,xvalues,yvalues,res)
231 max_bar = new((/2,nx/),graphic)
232 min_bar = new((/2,nx/),graphic)
233 max_cap = new((/2,nx/),graphic)
234 min_cap = new((/2,nx/),graphic)
238 line_colors = (/"brown","blue"/)
240 lnres@gsLineColor = line_colors(nd)
243 if(.not.ismissing(mn_yvalues(nd,i)).and. \
244 .not.ismissing(mx_yvalues(nd,i))) then
246 ; Attach the vertical bar, both above and below the marker.
250 y2 = mn_yvalues(nd,i)
251 min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
253 y2 = mx_yvalues(nd,i)
254 max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
256 ; Attach the horizontal cap line, both above and below the marker.
258 x1 = xvalues(nd,i) - dx4
259 x2 = xvalues(nd,i) + dx4
260 y1 = mn_yvalues(nd,i)
261 min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
263 y1 = mx_yvalues(nd,i)
264 max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
270 ; Here's how to do the legend by hand.
272 ; mkres = True ; Marker resources
273 ; txres = True ; Text resources
274 ; mkres@gsMarkerIndex = 16
275 ; mkres@gsMarkerSizeF = 0.02
276 ; txres@txFontHeightF = 0.02
277 ; txres@txJust = "CenterLeft"
279 ; Change these values if you want to move the marker legend location.
280 ; These values are in the same data space as the plot.
288 ; mkres@gsMarkerColor = "brown"
289 ; lnres@gsLineColor = "brown"
291 ; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres)
292 ; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \
293 ; (/ylg1_cen-60,ylg1_cen+60/),lnres)
294 ; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \
295 ; (/ylg1_cen-60,ylg1_cen-60/),lnres)
296 ; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \
297 ; (/ylg1_cen+60,ylg1_cen+60/),lnres)
299 ; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres)
301 ; mkres@gsMarkerColor = "blue"
302 ; lnres@gsLineColor = "blue"
304 ; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres)
305 ; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \
306 ; (/ylg2_cen-60,ylg2_cen+60/),lnres)
307 ; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \
308 ; (/ylg2_cen-60,ylg2_cen-60/),lnres)
309 ; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \
310 ; (/ylg2_cen+60,ylg2_cen+60/),lnres)
311 ; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres)
315 system("convert xy.ps xy.png")
320 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
330 ;bias = sum(((vv-uu)/uu)^2)
331 ;M = (1.- sqrt(bias/nz))*5.
334 bias = abs(avg(vv)-avg(uu))
335 bias = where((bias.gt. 6.),12.-bias,bias)
336 M = ((6. - bias)/6.)*5.