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_mean_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)
35 NPP1 = data_file_ob2->LAI
36 ;************************************************
38 ;************************************************
39 diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
40 ;fili3 = "i01.03cn_1545-1569_ANN_climo.nc"
41 fili3 = "i01.04casa_1605-1629_ANN_climo.nc"
42 data_file_model = addfile(diri2+fili3,"r")
44 NPP2 = data_file_model->TLAI
45 ;************************************************
46 ; print min/max and unit
47 ;************************************************
48 pminmax(RAIN1,"RAIN1")
52 RAIN1_1D = ndtooned(RAIN1)
53 NPP1_1D = ndtooned(NPP1)
54 NPP2_1D = ndtooned(NPP2)
56 ; Calculate some "nice" bins for binning the data in equally spaced
60 ; nbins = nclass + 1 ; Number of bins to use.
61 ; nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,False)
62 ; nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
63 ; range = fspan(nicevals(0),nicevals(1),nvals)
66 range = fspan(0,nclassn-1,nclassn)
74 ; Use this range information to grab all the values in a
75 ; particular range, and then take an average.
79 xvalues = new((/2,nx/),typeof(RAIN1_1D))
80 xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
81 dx = xvalues(0,1) - xvalues(0,0) ; range width
82 dx4 = dx/4 ; 1/4 of the range
83 xvalues(1,:) = xvalues(0,:) - dx/5.
84 yvalues = new((/2,nx/),typeof(RAIN1_1D))
85 mn_yvalues = new((/2,nx/),typeof(RAIN1_1D))
86 mx_yvalues = new((/2,nx/),typeof(RAIN1_1D))
90 ; See if we are doing model or observational data.
100 ; Loop through each range and check for values.
103 if (i.ne.(nr-2)) then
105 print("In range ["+range(i)+","+range(i+1)+")")
106 idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
109 print("In range ["+range(i)+",)")
110 idx = ind(range(i).le.data)
113 ; Calculate average, and get min and max.
115 if(.not.any(ismissing(idx))) then
116 yvalues(nd,i) = avg(npp_data(idx))
117 mn_yvalues(nd,i) = min(npp_data(idx))
118 mx_yvalues(nd,i) = max(npp_data(idx))
119 count = dimsizes(idx)
122 yvalues(nd,i) = yvalues@_FillValue
123 mn_yvalues(nd,i) = yvalues@_FillValue
124 mx_yvalues(nd,i) = yvalues@_FillValue
127 ; Print out information.
129 print(nd + ": " + count + " points, avg = " + yvalues(nd,i))
130 print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
133 ; Clean up for next time in loop.
142 ; Start the graphics.
144 wks = gsn_open_wks("ps","xy")
147 res@gsnMaximize = True
150 res@xyMarkLineMode = "Markers"
151 res@xyMarkerSizeF = 0.014
153 res@xyMarkerColors = (/"Brown","Blue"/)
154 ; res@trYMinF = min(mn_yvalues) - 10.
155 ; res@trYMaxF = max(mx_yvalues) + 10.
156 res@trYMinF = min(mn_yvalues) - 2
157 res@trYMaxF = max(mx_yvalues) + 4
159 ; res@tiMainString = "Observed vs i01.03cn"
160 res@tiMainString = "Observed vs i01.04casa"
162 res@tiYAxisString = "Mean LAI (Leaf Area Index)"
163 res@tiXAxisString = "Land Cover Type"
165 ; Add a boxed legend using the more simple method, which won't have
166 ; vertical lines going through the markers.
168 res@pmLegendDisplayMode = "Always"
169 ; res@pmLegendWidthF = 0.1
170 res@pmLegendWidthF = 0.08
171 res@pmLegendHeightF = 0.05
172 res@pmLegendOrthogonalPosF = -1.17
173 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
174 ; res@pmLegendParallelPosF = 0.18
175 res@pmLegendParallelPosF = 0.23 ;(rightward)
177 ; res@lgPerimOn = False
178 res@lgLabelFontHeightF = 0.015
179 ; res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/)
180 res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/)
182 xy = gsn_csm_xy(wks,xvalues,yvalues,res)
184 max_bar = new((/2,nx/),graphic)
185 min_bar = new((/2,nx/),graphic)
186 max_cap = new((/2,nx/),graphic)
187 min_cap = new((/2,nx/),graphic)
191 line_colors = (/"brown","blue"/)
193 lnres@gsLineColor = line_colors(nd)
196 if(.not.ismissing(mn_yvalues(nd,i)).and. \
197 .not.ismissing(mx_yvalues(nd,i))) then
199 ; Attach the vertical bar, both above and below the marker.
203 y2 = mn_yvalues(nd,i)
204 min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
206 y2 = mx_yvalues(nd,i)
207 max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
209 ; Attach the horizontal cap line, both above and below the marker.
211 x1 = xvalues(nd,i) - dx4
212 x2 = xvalues(nd,i) + dx4
213 y1 = mn_yvalues(nd,i)
214 min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
216 y1 = mx_yvalues(nd,i)
217 max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
223 ; Here's how to do the legend by hand.
225 ; mkres = True ; Marker resources
226 ; txres = True ; Text resources
227 ; mkres@gsMarkerIndex = 16
228 ; mkres@gsMarkerSizeF = 0.02
229 ; txres@txFontHeightF = 0.02
230 ; txres@txJust = "CenterLeft"
232 ; Change these values if you want to move the marker legend location.
233 ; These values are in the same data space as the plot.
241 ; mkres@gsMarkerColor = "brown"
242 ; lnres@gsLineColor = "brown"
244 ; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres)
245 ; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \
246 ; (/ylg1_cen-60,ylg1_cen+60/),lnres)
247 ; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \
248 ; (/ylg1_cen-60,ylg1_cen-60/),lnres)
249 ; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \
250 ; (/ylg1_cen+60,ylg1_cen+60/),lnres)
252 ; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres)
254 ; mkres@gsMarkerColor = "blue"
255 ; lnres@gsLineColor = "blue"
257 ; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres)
258 ; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \
259 ; (/ylg2_cen-60,ylg2_cen+60/),lnres)
260 ; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \
261 ; (/ylg2_cen-60,ylg2_cen-60/),lnres)
262 ; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \
263 ; (/ylg2_cen+60,ylg2_cen+60/),lnres)
264 ; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres)
268 system("convert xy.ps xy.png")
273 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
283 ;bias = sum(((vv-uu)/uu)^2)
284 ;M = (1.- sqrt(bias/nz))*5.
287 bias = sum(abs(vv-uu)/(vv+uu))
288 M = (1.- (bias/nz))*5.