1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/npp/17.scatter_bias.ncl Mon Jan 26 22:08:20 2009 -0500
1.3 @@ -0,0 +1,972 @@
1.4 +; ***********************************************
1.5 +; combine all scatter and all histogram
1.6 +; ***********************************************
1.7 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
1.8 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
1.9 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
1.10 +;************************************************
1.11 +procedure pminmax(data:numeric,name:string)
1.12 +begin
1.13 + print ("min/max " + name + " = " + min(data) + "/" + max(data))
1.14 + if(isatt(data,"units")) then
1.15 + print (name + " units = " + data@units)
1.16 + end if
1.17 +end
1.18 +
1.19 +; Main code.
1.20 +begin
1.21 +
1.22 + plot_type = "ps"
1.23 + plot_type_new = "png"
1.24 +
1.25 +;************************************************
1.26 +; read in ob data
1.27 +;************************************************
1.28 +;(1)
1.29 + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/"
1.30 + fil81 = "data.81.nc"
1.31 + f81 = addfile (dir81+fil81,"r")
1.32 +
1.33 + id81 = f81->SITE_ID
1.34 + npp81 = f81->TNPP_C
1.35 + rain81 = tofloat(f81->PREC_ANN)
1.36 + x81 = f81->LONG_DD
1.37 + y81 = f81->LAT_DD
1.38 +
1.39 + id81@long_name = "SITE_ID"
1.40 +
1.41 +;change longitude from (-180,180) to (0,360)
1.42 +;for model data interpolation
1.43 +
1.44 + do i= 0,dimsizes(x81)-1
1.45 + if (x81(i) .lt. 0.) then
1.46 + x81(i) = x81(i)+ 360.
1.47 + end if
1.48 + end do
1.49 +;print (x81)
1.50 +;-------------------------------------
1.51 +;(2)
1.52 + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/"
1.53 + fil933 = "data.933.nc"
1.54 + f933 = addfile (dir933+fil933,"r")
1.55 +
1.56 + id933 = f933->SITE_ID
1.57 + npp933 = f933->TNPP_C
1.58 + rain933 = f933->PREC
1.59 + x933 = f933->LONG_DD
1.60 + y933 = f933->LAT_DD
1.61 +
1.62 + id933@long_name = "SITE_ID"
1.63 +
1.64 +;change longitude from (-180,180) to (0,360)
1.65 +;for model data interpolation
1.66 +
1.67 + do i= 0,dimsizes(x933)-1
1.68 + if (x933(i) .lt. 0.) then
1.69 + x933(i) = x933(i)+ 360.
1.70 + end if
1.71 + end do
1.72 +;print (x933)
1.73 +;----------------------------------------
1.74 +;(3)
1.75 + dirglobe = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/"
1.76 + filglobe = "Npp_T31_mean.nc"
1.77 + fglobe = addfile (dirglobe+filglobe,"r")
1.78 +
1.79 + nppglobe = fglobe->NPP
1.80 +
1.81 +;************************************************
1.82 +; read in model data
1.83 +;************************************************
1.84 + model_name = "b30.061n"
1.85 +
1.86 + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
1.87 + film = "b30.061n_1995-2004_ANN_climo_lnd.nc"
1.88 + fm = addfile (dirm+film,"r")
1.89 +
1.90 + nppmod0 = fm->NPP
1.91 + rainmod0 = fm->RAIN
1.92 + xm = fm->lon
1.93 + ym = fm->lat
1.94 +
1.95 + nppmod = nppmod0(0,:,:)
1.96 + rainmod = rainmod0(0,:,:)
1.97 + delete (nppmod0)
1.98 + delete (rainmod0)
1.99 +
1.100 + nppmod81 =linint2_points(xm,ym,nppmod,True,x81,y81,0)
1.101 +
1.102 + nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0)
1.103 +
1.104 + rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0)
1.105 +
1.106 + rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0)
1.107 +
1.108 +;************************************************
1.109 +; Units for these variables are:
1.110 +;
1.111 +; rain81 : mm/year
1.112 +; rainmod : mm/s
1.113 +; npp81 : g C/m^2/year
1.114 +; nppmod81: g C/m^2/s
1.115 +; nppglobe: g C/m^2/year
1.116 +;
1.117 +; We want to convert these to "m/year" and "g C/m^2/year".
1.118 +;
1.119 + nsec_per_year = 60*60*24*365
1.120 +
1.121 + rain81 = rain81 / 1000.
1.122 + rainmod81 = (rainmod81/ 1000.) * nsec_per_year
1.123 + nppmod81 = nppmod81 * nsec_per_year
1.124 +
1.125 + rain933 = rain933 / 1000.
1.126 + rainmod933 = (rainmod933/ 1000.) * nsec_per_year
1.127 + nppmod933 = nppmod933 * nsec_per_year
1.128 +
1.129 + nppmod = nppmod * nsec_per_year
1.130 +
1.131 + npp81@units = "gC/m^2/yr"
1.132 + nppmod81@units = "gC/m^2/yr"
1.133 + npp933@units = "gC/m^2/yr"
1.134 + nppmod933@units = "gC/m^2/yr"
1.135 + nppmod@units = "gC/m^2/yr"
1.136 + nppglobe@units = "gC/m^2/yr"
1.137 + rain81@units = "m/yr"
1.138 + rainmod81@units = "m/yr"
1.139 + rain933@units = "m/yr"
1.140 + rainmod933@units = "m/yr"
1.141 +
1.142 + npp81@long_name = "NPP (gC/m2/year)"
1.143 + npp933@long_name = "NPP (gC/m2/year)"
1.144 + nppmod81@long_name = "NPP (gC/m2/year)"
1.145 + nppmod933@long_name = "NPP (gC/m2/year)"
1.146 + nppmod@long_name = "NPP (gC/m2/year)"
1.147 + nppglobe@long_name = "NPP (gC/m2/year)"
1.148 + rain81@long_name = "PREC (m/year)"
1.149 + rain933@long_name = "PREC (m/year)"
1.150 + rainmod81@long_name = "PREC (m/year)"
1.151 + rainmod933@long_name = "PREC (m/year)"
1.152 +
1.153 +;(A) plot scatter ob 81
1.154 +
1.155 + plot_name = "scatter_ob_81"
1.156 + title = "Observed 81 sites"
1.157 +
1.158 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.159 + res = True ; plot mods desired
1.160 + res@tiMainString = title ; add title
1.161 + res@xyMarkLineModes = "Markers" ; choose which have markers
1.162 + res@xyMarkers = 16 ; choose type of marker
1.163 + res@xyMarkerColor = "red" ; Marker color
1.164 + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
1.165 + res@tmLabelAutoStride = True ; nice tick mark labels
1.166 +
1.167 + plot = gsn_csm_xy (wks,id81,npp81,res) ; create plot
1.168 + frame(wks)
1.169 +
1.170 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.171 + system("rm "+plot_name+"."+plot_type)
1.172 + system("rm "+plot_name+"-1."+plot_type_new)
1.173 + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.174 +
1.175 + clear (wks)
1.176 +
1.177 +;(B) plot scatter ob 933
1.178 +
1.179 + plot_name = "scatter_ob_933"
1.180 + title = "Observed 933 sites"
1.181 +
1.182 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.183 + res = True ; plot mods desired
1.184 + res@tiMainString = title ; add title
1.185 + res@xyMarkLineModes = "Markers" ; choose which have markers
1.186 + res@xyMarkers = 16 ; choose type of marker
1.187 + res@xyMarkerColor = "red" ; Marker color
1.188 + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
1.189 + res@tmLabelAutoStride = True ; nice tick mark labels
1.190 +
1.191 + plot = gsn_csm_xy (wks,id933,npp933,res) ; create plot
1.192 + frame(wks)
1.193 +
1.194 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.195 + system("rm "+plot_name+"."+plot_type)
1.196 + system("rm "+plot_name+"-1."+plot_type_new)
1.197 + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.198 +
1.199 + clear (wks)
1.200 +
1.201 +;(C) plot scatter model 81
1.202 +
1.203 + plot_name = "scatter_model_81"
1.204 + title = "Model "+ model_name +" 81 sites"
1.205 +
1.206 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.207 + res = True ; plot mods desired
1.208 + res@tiMainString = title ; add title
1.209 + res@xyMarkLineModes = "Markers" ; choose which have markers
1.210 + res@xyMarkers = 16 ; choose type of marker
1.211 + res@xyMarkerColor = "red" ; Marker color
1.212 + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
1.213 + res@tmLabelAutoStride = True ; nice tick mark labels
1.214 +
1.215 + plot = gsn_csm_xy (wks,id81,nppmod81,res) ; create plot
1.216 + frame(wks)
1.217 +
1.218 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.219 + system("rm "+plot_name+"."+plot_type)
1.220 + system("rm "+plot_name+"-1."+plot_type_new)
1.221 + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.222 +
1.223 + clear (wks)
1.224 +
1.225 +;(D) plot scatter model 933
1.226 +
1.227 + plot_name = "scatter_model_933"
1.228 + title = "Model "+ model_name +" 933 sites"
1.229 +
1.230 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.231 + res = True ; plot mods desired
1.232 + res@tiMainString = title ; add title
1.233 + res@xyMarkLineModes = "Markers" ; choose which have markers
1.234 + res@xyMarkers = 16 ; choose type of marker
1.235 + res@xyMarkerColor = "red" ; Marker color
1.236 + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
1.237 + res@tmLabelAutoStride = True ; nice tick mark labels
1.238 +
1.239 + plot = gsn_csm_xy (wks,id933,nppmod933,res) ; create plot
1.240 + frame(wks)
1.241 +
1.242 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.243 + system("rm "+plot_name+"."+plot_type)
1.244 + system("rm "+plot_name+"-1."+plot_type_new)
1.245 + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.246 +
1.247 + clear (wks)
1.248 +
1.249 +;(E) scatter model vs ob 81
1.250 +
1.251 + plot_name = "scatter_model_vs_ob_81"
1.252 + title = model_name +" vs ob 81 sites"
1.253 +
1.254 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.255 + res = True ; plot mods desired
1.256 + res@tiMainString = title ; add title
1.257 + res@xyMarkLineModes = "Markers" ; choose which have markers
1.258 + res@xyMarkers = 16 ; choose type of marker
1.259 + res@xyMarkerColor = "red" ; Marker color
1.260 + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
1.261 + res@tmLabelAutoStride = True ; nice tick mark labels
1.262 +;-------------------------------
1.263 +;compute correlation coef. and M
1.264 + ccr81 = esccr(nppmod81,npp81,0)
1.265 + print (ccr81)
1.266 +
1.267 +;new eq
1.268 + bias = sum(abs(nppmod81-npp81)/(nppmod81+npp81))
1.269 + M81 = (1. - (bias/dimsizes(y81)))*5.
1.270 + print (M81)
1.271 +
1.272 + tRes = True
1.273 + tRes@txFontHeightF = 0.025
1.274 +
1.275 + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")"
1.276 +
1.277 + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes)
1.278 +;--------------------------------
1.279 + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot
1.280 + frame(wks)
1.281 +
1.282 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.283 + system("rm "+plot_name+"."+plot_type)
1.284 + system("rm "+plot_name+"-1."+plot_type_new)
1.285 + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.286 +
1.287 + clear (wks)
1.288 +
1.289 +;(F) scatter model vs ob 933
1.290 +
1.291 + plot_name = "scatter_model_vs_ob_933"
1.292 + title = model_name +" vs ob 933 sites"
1.293 +
1.294 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.295 + res = True ; plot mods desired
1.296 + res@tiMainString = title ; add title
1.297 + res@xyMarkLineModes = "Markers" ; choose which have markers
1.298 + res@xyMarkers = 16 ; choose type of marker
1.299 + res@xyMarkerColor = "red" ; Marker color
1.300 + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
1.301 + res@tmLabelAutoStride = True ; nice tick mark labels
1.302 +;-------------------------------
1.303 +;compute correlation coef. and M
1.304 + ccr933 = esccr(nppmod933,npp933,0)
1.305 + print (ccr933)
1.306 +
1.307 +;new eq
1.308 + bias = sum(abs(nppmod933-npp933)/(nppmod933+npp933))
1.309 + M933 = (1. - (bias/dimsizes(y933)))*5.
1.310 + print (M933)
1.311 +
1.312 + tRes = True
1.313 + tRes@txFontHeightF = 0.025
1.314 +
1.315 + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")"
1.316 +
1.317 + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes)
1.318 +;--------------------------------
1.319 + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot
1.320 + frame(wks)
1.321 +
1.322 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.323 + system("rm "+plot_name+"."+plot_type)
1.324 + system("rm "+plot_name+"-1."+plot_type_new)
1.325 + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.326 +
1.327 + clear (wks)
1.328 +;**************************************************************************
1.329 +;(G) histogram 81
1.330 +
1.331 +;--------------------------------------------------------------------
1.332 +;get data
1.333 +
1.334 + RAIN1_1D = ndtooned(rain81)
1.335 + RAIN2_1D = ndtooned(rainmod81)
1.336 + NPP1_1D = ndtooned(npp81)
1.337 + NPP2_1D = ndtooned(nppmod81)
1.338 +;
1.339 +; Calculate some "nice" bins for binning the data in equally spaced
1.340 +; ranges.
1.341 +;
1.342 + nbins = 15 ; Number of bins to use.
1.343 +
1.344 + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True)
1.345 + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
1.346 + range = fspan(nicevals(0),nicevals(1),nvals)
1.347 +;
1.348 +; Use this range information to grab all the values in a
1.349 +; particular range, and then take an average.
1.350 +;
1.351 + nr = dimsizes(range)
1.352 + nx = nr-1
1.353 + xvalues = new((/2,nx/),typeof(RAIN1_1D))
1.354 + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
1.355 + dx = xvalues(0,1) - xvalues(0,0) ; range width
1.356 + dx4 = dx/4 ; 1/4 of the range
1.357 + xvalues(1,:) = xvalues(0,:) - dx/5.
1.358 + yvalues = new((/2,nx/),typeof(RAIN1_1D))
1.359 + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D))
1.360 + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D))
1.361 +
1.362 + do nd=0,1
1.363 +;
1.364 +; See if we are doing model or observational data.
1.365 +;
1.366 + if(nd.eq.0) then
1.367 + data = RAIN1_1D
1.368 + npp_data = NPP1_1D
1.369 + else
1.370 + data = RAIN2_1D
1.371 + npp_data = NPP2_1D
1.372 + end if
1.373 +;
1.374 +; Loop through each range and check for values.
1.375 +;
1.376 + do i=0,nr-2
1.377 + if (i.ne.(nr-2)) then
1.378 +; print("")
1.379 +; print("In range ["+range(i)+","+range(i+1)+")")
1.380 + idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
1.381 + else
1.382 +; print("")
1.383 +; print("In range ["+range(i)+",)")
1.384 + idx = ind(range(i).le.data)
1.385 + end if
1.386 +;
1.387 +; Calculate average, and get min and max.
1.388 +;
1.389 + if(.not.any(ismissing(idx))) then
1.390 + yvalues(nd,i) = avg(npp_data(idx))
1.391 + mn_yvalues(nd,i) = min(npp_data(idx))
1.392 + mx_yvalues(nd,i) = max(npp_data(idx))
1.393 + count = dimsizes(idx)
1.394 + else
1.395 + count = 0
1.396 + yvalues(nd,i) = yvalues@_FillValue
1.397 + mn_yvalues(nd,i) = yvalues@_FillValue
1.398 + mx_yvalues(nd,i) = yvalues@_FillValue
1.399 + end if
1.400 +;
1.401 +; Print out information.
1.402 +;
1.403 +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i))
1.404 +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
1.405 +
1.406 +;
1.407 +; Clean up for next time in loop.
1.408 +;
1.409 + delete(idx)
1.410 + end do
1.411 + delete(data)
1.412 + delete(npp_data)
1.413 + end do
1.414 +;----------------------------------------
1.415 +;compute correlation coeff and M score
1.416 + u = yvalues(0,:)
1.417 + v = yvalues(1,:)
1.418 +
1.419 + good = ind(.not.ismissing(u) .and. .not.ismissing(v))
1.420 + uu = u(good)
1.421 + vv = v(good)
1.422 +
1.423 + ccr81h = esccr(uu,vv,0)
1.424 + print (ccr81h)
1.425 +
1.426 +;new eq
1.427 + bias = sum(abs(vv-uu)/(vv+uu))
1.428 + M81h = (1.- (bias/dimsizes(uu)))*5.
1.429 + print (M81h)
1.430 +
1.431 + delete (u)
1.432 + delete (v)
1.433 + delete (uu)
1.434 + delete (vv)
1.435 +;----------------------------------------------------------------------
1.436 +; histogram res
1.437 +
1.438 + res = True
1.439 + res@gsnMaximize = True
1.440 + res@gsnDraw = False
1.441 + res@gsnFrame = False
1.442 + res@xyMarkLineMode = "Markers"
1.443 + res@xyMarkerSizeF = 0.014
1.444 + res@xyMarker = 16
1.445 + res@xyMarkerColors = (/"Brown","Blue"/)
1.446 + res@trYMinF = min(mn_yvalues) - 10.
1.447 + res@trYMaxF = max(mx_yvalues) + 10.
1.448 +
1.449 + res@tiYAxisString = "NPP (g C/m2/year)"
1.450 + res@tiXAxisString = "Precipitation (m/year)"
1.451 +
1.452 + max_bar = new((/2,nx/),graphic)
1.453 + min_bar = new((/2,nx/),graphic)
1.454 + max_cap = new((/2,nx/),graphic)
1.455 + min_cap = new((/2,nx/),graphic)
1.456 +
1.457 + lnres = True
1.458 + line_colors = (/"brown","blue"/)
1.459 +;=================================================================
1.460 +; histogram ob 81 site only
1.461 +;
1.462 + plot_name = "histogram_ob_81"
1.463 + title = "Observed 81 site"
1.464 + res@tiMainString = title
1.465 +
1.466 + wks = gsn_open_wks (plot_type,plot_name)
1.467 +
1.468 + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res)
1.469 +
1.470 +;-------------------------------
1.471 +;Attach the vertical bar and the horizontal cap line
1.472 +
1.473 + do nd=0,0
1.474 + lnres@gsLineColor = line_colors(nd)
1.475 + do i=0,nx-1
1.476 +
1.477 + if(.not.ismissing(mn_yvalues(nd,i)).and. \
1.478 + .not.ismissing(mx_yvalues(nd,i))) then
1.479 +;
1.480 +; Attach the vertical bar, both above and below the marker.
1.481 +;
1.482 + x1 = xvalues(nd,i)
1.483 + y1 = yvalues(nd,i)
1.484 + y2 = mn_yvalues(nd,i)
1.485 + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
1.486 +
1.487 + y2 = mx_yvalues(nd,i)
1.488 + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
1.489 +;
1.490 +; Attach the horizontal cap line, both above and below the marker.
1.491 +;
1.492 + x1 = xvalues(nd,i) - dx4
1.493 + x2 = xvalues(nd,i) + dx4
1.494 + y1 = mn_yvalues(nd,i)
1.495 + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
1.496 +
1.497 + y1 = mx_yvalues(nd,i)
1.498 + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
1.499 + end if
1.500 + end do
1.501 + end do
1.502 +
1.503 + draw(xy)
1.504 + frame(wks)
1.505 +
1.506 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.507 +; system("rm "+plot_name+"."+plot_type)
1.508 +; system("rm "+plot_name+"-1."+plot_type_new)
1.509 +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.510 +
1.511 + clear (wks)
1.512 +;===========================================================================
1.513 +; histogram model vs ob 81 site
1.514 +
1.515 + plot_name = "histogram_mod-ob_81"
1.516 + title = model_name+ " vs Observed 81 site"
1.517 + res@tiMainString = title
1.518 +
1.519 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.520 +
1.521 +;-----------------------------
1.522 +; Add a boxed legend using the more simple method, which won't have
1.523 +; vertical lines going through the markers.
1.524 +
1.525 + res@pmLegendDisplayMode = "Always"
1.526 +; res@pmLegendWidthF = 0.1
1.527 + res@pmLegendWidthF = 0.08
1.528 + res@pmLegendHeightF = 0.05
1.529 + res@pmLegendOrthogonalPosF = -1.17
1.530 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
1.531 +; res@pmLegendParallelPosF = 0.18
1.532 + res@pmLegendParallelPosF = 0.23 ;(rightward)
1.533 +
1.534 +; res@lgPerimOn = False
1.535 + res@lgLabelFontHeightF = 0.015
1.536 + res@xyExplicitLegendLabels = (/"observed",model_name/)
1.537 +;-----------------------------
1.538 + tRes = True
1.539 + tRes@txFontHeightF = 0.025
1.540 +
1.541 + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")"
1.542 +
1.543 + gsn_text_ndc(wks,correlation_text,0.5,0.8,tRes)
1.544 +
1.545 + xy = gsn_csm_xy(wks,xvalues,yvalues,res)
1.546 +;-------------------------------
1.547 +;Attach the vertical bar and the horizontal cap line
1.548 +
1.549 + do nd=0,1
1.550 + lnres@gsLineColor = line_colors(nd)
1.551 + do i=0,nx-1
1.552 +
1.553 + if(.not.ismissing(mn_yvalues(nd,i)).and. \
1.554 + .not.ismissing(mx_yvalues(nd,i))) then
1.555 +;
1.556 +; Attach the vertical bar, both above and below the marker.
1.557 +;
1.558 + x1 = xvalues(nd,i)
1.559 + y1 = yvalues(nd,i)
1.560 + y2 = mn_yvalues(nd,i)
1.561 + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
1.562 +
1.563 + y2 = mx_yvalues(nd,i)
1.564 + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
1.565 +;
1.566 +; Attach the horizontal cap line, both above and below the marker.
1.567 +;
1.568 + x1 = xvalues(nd,i) - dx4
1.569 + x2 = xvalues(nd,i) + dx4
1.570 + y1 = mn_yvalues(nd,i)
1.571 + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
1.572 +
1.573 + y1 = mx_yvalues(nd,i)
1.574 + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
1.575 + end if
1.576 + end do
1.577 + end do
1.578 + draw(xy)
1.579 + frame(wks)
1.580 +
1.581 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.582 +;system("rm "+plot_name+"."+plot_type)
1.583 +;system("rm "+plot_name+"-1."+plot_type_new)
1.584 +;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.585 +
1.586 + clear (wks)
1.587 +
1.588 + delete (RAIN1_1D)
1.589 + delete (RAIN2_1D)
1.590 + delete (NPP1_1D)
1.591 + delete (NPP2_1D)
1.592 + delete (range)
1.593 + delete (xvalues)
1.594 + delete (yvalues)
1.595 + delete (mn_yvalues)
1.596 + delete (mx_yvalues)
1.597 + delete (good)
1.598 + delete (max_bar)
1.599 + delete (min_bar)
1.600 + delete (max_cap)
1.601 + delete (min_cap)
1.602 +;**************************************************************************
1.603 +;(H) histogram 933
1.604 +
1.605 +;--------------------------------------------------------------------
1.606 +;get data
1.607 +
1.608 + RAIN1_1D = ndtooned(rain933)
1.609 + RAIN2_1D = ndtooned(rainmod933)
1.610 + NPP1_1D = ndtooned(npp933)
1.611 + NPP2_1D = ndtooned(nppmod933)
1.612 +;
1.613 +; Calculate some "nice" bins for binning the data in equally spaced
1.614 +; ranges.
1.615 +;
1.616 + nbins = 15 ; Number of bins to use.
1.617 +
1.618 + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True)
1.619 + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
1.620 + range = fspan(nicevals(0),nicevals(1),nvals)
1.621 +;
1.622 +; Use this range information to grab all the values in a
1.623 +; particular range, and then take an average.
1.624 +;
1.625 + nr = dimsizes(range)
1.626 + nx = nr-1
1.627 + xvalues = new((/2,nx/),typeof(RAIN1_1D))
1.628 + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
1.629 + dx = xvalues(0,1) - xvalues(0,0) ; range width
1.630 + dx4 = dx/4 ; 1/4 of the range
1.631 + xvalues(1,:) = xvalues(0,:) - dx/5.
1.632 + yvalues = new((/2,nx/),typeof(RAIN1_1D))
1.633 + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D))
1.634 + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D))
1.635 +
1.636 + do nd=0,1
1.637 +;
1.638 +; See if we are doing model or observational data.
1.639 +;
1.640 + if(nd.eq.0) then
1.641 + data = RAIN1_1D
1.642 + npp_data = NPP1_1D
1.643 + else
1.644 + data = RAIN2_1D
1.645 + npp_data = NPP2_1D
1.646 + end if
1.647 +;
1.648 +; Loop through each range and check for values.
1.649 +;
1.650 + do i=0,nr-2
1.651 + if (i.ne.(nr-2)) then
1.652 +; print("")
1.653 +; print("In range ["+range(i)+","+range(i+1)+")")
1.654 + idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
1.655 + else
1.656 +; print("")
1.657 +; print("In range ["+range(i)+",)")
1.658 + idx = ind(range(i).le.data)
1.659 + end if
1.660 +;
1.661 +; Calculate average, and get min and max.
1.662 +;
1.663 + if(.not.any(ismissing(idx))) then
1.664 + yvalues(nd,i) = avg(npp_data(idx))
1.665 + mn_yvalues(nd,i) = min(npp_data(idx))
1.666 + mx_yvalues(nd,i) = max(npp_data(idx))
1.667 + count = dimsizes(idx)
1.668 + else
1.669 + count = 0
1.670 + yvalues(nd,i) = yvalues@_FillValue
1.671 + mn_yvalues(nd,i) = yvalues@_FillValue
1.672 + mx_yvalues(nd,i) = yvalues@_FillValue
1.673 + end if
1.674 +;
1.675 +; Print out information.
1.676 +;
1.677 +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i))
1.678 +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
1.679 +
1.680 +;
1.681 +; Clean up for next time in loop.
1.682 +;
1.683 + delete(idx)
1.684 + end do
1.685 + delete(data)
1.686 + delete(npp_data)
1.687 + end do
1.688 +;----------------------------------------
1.689 +;compute correlation coeff and M score
1.690 + u = yvalues(0,:)
1.691 + v = yvalues(1,:)
1.692 +
1.693 + good = ind(.not.ismissing(u) .and. .not.ismissing(v))
1.694 + uu = u(good)
1.695 + vv = v(good)
1.696 +
1.697 + ccr933h = esccr(uu,vv,0)
1.698 + print (ccr933h)
1.699 +
1.700 +;new eq
1.701 + bias = sum(abs(vv-uu)/(vv+uu))
1.702 + M933h = (1.- (bias/dimsizes(uu)))*5.
1.703 + print (M933h)
1.704 +
1.705 + delete (u)
1.706 + delete (v)
1.707 + delete (uu)
1.708 + delete (vv)
1.709 +;----------------------------------------------------------------------
1.710 +; histogram res
1.711 +
1.712 + res = True
1.713 + res@gsnMaximize = True
1.714 + res@gsnDraw = False
1.715 + res@gsnFrame = False
1.716 + res@xyMarkLineMode = "Markers"
1.717 + res@xyMarkerSizeF = 0.014
1.718 + res@xyMarker = 16
1.719 + res@xyMarkerColors = (/"Brown","Blue"/)
1.720 + res@trYMinF = min(mn_yvalues) - 10.
1.721 + res@trYMaxF = max(mx_yvalues) + 10.
1.722 +
1.723 + res@tiYAxisString = "NPP (g C/m2/year)"
1.724 + res@tiXAxisString = "Precipitation (m/year)"
1.725 +
1.726 + max_bar = new((/2,nx/),graphic)
1.727 + min_bar = new((/2,nx/),graphic)
1.728 + max_cap = new((/2,nx/),graphic)
1.729 + min_cap = new((/2,nx/),graphic)
1.730 +
1.731 + lnres = True
1.732 + line_colors = (/"brown","blue"/)
1.733 +;=================================================================
1.734 +; histogram ob 933 site only
1.735 +;
1.736 + plot_name = "histogram_ob_933"
1.737 + title = "Observed 933 site"
1.738 + res@tiMainString = title
1.739 +
1.740 + wks = gsn_open_wks (plot_type,plot_name)
1.741 +
1.742 + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res)
1.743 +
1.744 +;-------------------------------
1.745 +;Attach the vertical bar and the horizontal cap line
1.746 +
1.747 + do nd=0,0
1.748 + lnres@gsLineColor = line_colors(nd)
1.749 + do i=0,nx-1
1.750 +
1.751 + if(.not.ismissing(mn_yvalues(nd,i)).and. \
1.752 + .not.ismissing(mx_yvalues(nd,i))) then
1.753 +;
1.754 +; Attach the vertical bar, both above and below the marker.
1.755 +;
1.756 + x1 = xvalues(nd,i)
1.757 + y1 = yvalues(nd,i)
1.758 + y2 = mn_yvalues(nd,i)
1.759 + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
1.760 +
1.761 + y2 = mx_yvalues(nd,i)
1.762 + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
1.763 +;
1.764 +; Attach the horizontal cap line, both above and below the marker.
1.765 +;
1.766 + x1 = xvalues(nd,i) - dx4
1.767 + x2 = xvalues(nd,i) + dx4
1.768 + y1 = mn_yvalues(nd,i)
1.769 + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
1.770 +
1.771 + y1 = mx_yvalues(nd,i)
1.772 + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
1.773 + end if
1.774 + end do
1.775 + end do
1.776 +
1.777 + draw(xy)
1.778 + frame(wks)
1.779 +
1.780 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.781 +; system("rm "+plot_name+"."+plot_type)
1.782 +; system("rm "+plot_name+"-1."+plot_type_new)
1.783 +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.784 +
1.785 + clear (wks)
1.786 +;===========================================================================
1.787 +; histogram model vs ob 933 site
1.788 +
1.789 + plot_name = "histogram_mod-ob_933"
1.790 + title = model_name+ " vs Observed 933 site"
1.791 + res@tiMainString = title
1.792 +
1.793 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.794 +
1.795 +;-----------------------------
1.796 +; Add a boxed legend using the more simple method, which won't have
1.797 +; vertical lines going through the markers.
1.798 +
1.799 + res@pmLegendDisplayMode = "Always"
1.800 +; res@pmLegendWidthF = 0.1
1.801 + res@pmLegendWidthF = 0.08
1.802 + res@pmLegendHeightF = 0.05
1.803 + res@pmLegendOrthogonalPosF = -1.17
1.804 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
1.805 +; res@pmLegendParallelPosF = 0.18
1.806 + res@pmLegendParallelPosF = 0.23 ;(rightward)
1.807 +
1.808 +; res@lgPerimOn = False
1.809 + res@lgLabelFontHeightF = 0.015
1.810 + res@xyExplicitLegendLabels = (/"observed",model_name/)
1.811 +;-----------------------------
1.812 + tRes = True
1.813 + tRes@txFontHeightF = 0.025
1.814 +
1.815 + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")"
1.816 +
1.817 + gsn_text_ndc(wks,correlation_text,0.5,0.8,tRes)
1.818 +
1.819 + xy = gsn_csm_xy(wks,xvalues,yvalues,res)
1.820 +;-------------------------------
1.821 +;Attach the vertical bar and the horizontal cap line
1.822 +
1.823 + do nd=0,1
1.824 + lnres@gsLineColor = line_colors(nd)
1.825 + do i=0,nx-1
1.826 +
1.827 + if(.not.ismissing(mn_yvalues(nd,i)).and. \
1.828 + .not.ismissing(mx_yvalues(nd,i))) then
1.829 +;
1.830 +; Attach the vertical bar, both above and below the marker.
1.831 +;
1.832 + x1 = xvalues(nd,i)
1.833 + y1 = yvalues(nd,i)
1.834 + y2 = mn_yvalues(nd,i)
1.835 + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
1.836 +
1.837 + y2 = mx_yvalues(nd,i)
1.838 + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
1.839 +;
1.840 +; Attach the horizontal cap line, both above and below the marker.
1.841 +;
1.842 + x1 = xvalues(nd,i) - dx4
1.843 + x2 = xvalues(nd,i) + dx4
1.844 + y1 = mn_yvalues(nd,i)
1.845 + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
1.846 +
1.847 + y1 = mx_yvalues(nd,i)
1.848 + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
1.849 + end if
1.850 + end do
1.851 + end do
1.852 + draw(xy)
1.853 + frame(wks)
1.854 +
1.855 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.856 +; system("rm "+plot_name+"."+plot_type)
1.857 +; system("rm "+plot_name+"-1."+plot_type_new)
1.858 +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.859 +
1.860 + clear (wks)
1.861 +;------------------------------------------------------------------------
1.862 +;global contour
1.863 +
1.864 +;res
1.865 + resw = True ; Use plot options
1.866 + resw@cnFillOn = True ; Turn on color fill
1.867 + resw@gsnSpreadColors = True ; use full colormap
1.868 +; resw@cnFillMode = "RasterFill" ; Turn on raster color
1.869 +; resw@lbLabelAutoStride = True
1.870 + resw@cnLinesOn = False ; Turn off contourn lines
1.871 + resw@mpFillOn = False ; Turn off map fill
1.872 +
1.873 + resw@gsnSpreadColors = True ; use full colormap
1.874 + resw@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals
1.875 + resw@cnMinLevelValF = 0. ; Min level
1.876 + resw@cnMaxLevelValF = 2200. ; Max level
1.877 + resw@cnLevelSpacingF = 200. ; interval
1.878 +;------------------------------------------------------------------------
1.879 +;global contour ob
1.880 +
1.881 + delta = 0.00000000001
1.882 + nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe)
1.883 +
1.884 + plot_name = "global_ob"
1.885 + title = "Observed MODIS MOD 17"
1.886 + resw@tiMainString = title
1.887 +
1.888 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.889 + gsn_define_colormap(wks,"gui_default") ; choose colormap
1.890 +
1.891 +
1.892 + plot = gsn_csm_contour_map_ce(wks,nppglobe,resw)
1.893 + frame(wks)
1.894 +
1.895 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.896 + system("rm "+plot_name+"."+plot_type)
1.897 + system("rm "+plot_name+"-1."+plot_type_new)
1.898 + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.899 +
1.900 + clear (wks)
1.901 +;------------------------------------------------------------------------
1.902 +;global contour model
1.903 +
1.904 + plot_name = "global_model"
1.905 + title = "Model "+ model_name
1.906 + resw@tiMainString = title
1.907 +
1.908 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.909 + gsn_define_colormap(wks,"gui_default") ; choose colormap
1.910 +
1.911 + plot = gsn_csm_contour_map_ce(wks,nppmod,resw)
1.912 + frame(wks)
1.913 +
1.914 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.915 + system("rm "+plot_name+"."+plot_type)
1.916 + system("rm "+plot_name+"-1."+plot_type_new)
1.917 + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.918 +
1.919 + clear (wks)
1.920 +;------------------------------------------------------------------------
1.921 +;global contour model vs ob
1.922 +
1.923 + plot_name = "global_model_vs_ob"
1.924 +
1.925 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.926 + gsn_define_colormap(wks,"gui_default") ; choose colormap
1.927 +
1.928 + delete (plot)
1.929 + plot=new(3,graphic) ; create graphic array
1.930 +
1.931 + resw@gsnFrame = False ; Do not draw plot
1.932 + resw@gsnDraw = False ; Do not advance frame
1.933 +
1.934 +;(a) ob
1.935 +
1.936 + title = "Observed MODIS MOD 17"
1.937 + resw@tiMainString = title
1.938 +
1.939 + plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resw) ; for observed
1.940 +
1.941 +;(b) model
1.942 +
1.943 + title = "Model "+ model_name
1.944 + resw@tiMainString = title
1.945 +
1.946 + plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resw) ; for model
1.947 +
1.948 +;(c) model-ob
1.949 +
1.950 + zz = nppmod
1.951 + zz = nppmod - nppglobe
1.952 + title = "Model_"+model_name+" - Observed"
1.953 +
1.954 + resw@cnMinLevelValF = -500 ; Min level
1.955 + resw@cnMaxLevelValF = 500. ; Max level
1.956 + resw@cnLevelSpacingF = 50. ; interval
1.957 + resw@tiMainString = title
1.958 +
1.959 + plot(2) = gsn_csm_contour_map_ce(wks,zz,resw)
1.960 +
1.961 + pres = True ; panel plot mods desired
1.962 + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
1.963 + ; indiv. plots in panel
1.964 + pres@gsnMaximize = True ; fill the page
1.965 +
1.966 + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot
1.967 +
1.968 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.969 + system("rm "+plot_name+"."+plot_type)
1.970 +; system("rm "+plot_name+"-1."+plot_type_new)
1.971 +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
1.972 +
1.973 + frame (wks)
1.974 + clear (wks)
1.975 +end