1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/energy/99.all.ncl.0 Mon Jan 26 22:08:20 2009 -0500
1.3 @@ -0,0 +1,420 @@
1.4 +; ***********************************************
1.5 +; using gsn_table for all
1.6 +; output: line plot for each site (4 fields)
1.7 +; table for M_score
1.8 +; ***********************************************
1.9 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
1.10 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
1.11 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
1.12 +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
1.13 +;************************************************
1.14 +begin
1.15 +
1.16 + plot_type = "ps"
1.17 + plot_type_new = "png"
1.18 +
1.19 +;************************************************
1.20 +; read model data
1.21 +;************************************************
1.22 +; model_name = "06cn"
1.23 +; film = "i01.06cn_1798-2004_MONS_climo.nc"
1.24 +
1.25 +; model_name = "06casa"
1.26 +; film = "i01.06casa_1798-2004_MONS_climo.nc"
1.27 +
1.28 +; model_name = "10cn"
1.29 +; film = "i01.10cn_1948-2004_MONS_climo.nc"
1.30 +
1.31 + model_name = "10casa"
1.32 + film = "i01.10casa_1948-2004_MONS_climo.nc"
1.33 +;--------------------------------------------
1.34 + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
1.35 + fm = addfile(dirm+film,"r")
1.36 +
1.37 + xm = fm->lon
1.38 + ym = fm->lat
1.39 + nlat = dimsizes(ym)
1.40 + nlon = dimsizes(xm)
1.41 +
1.42 + nmon = 12
1.43 + nfield = 4
1.44 +
1.45 + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
1.46 +
1.47 +; change to unit of observed (u mol/m2/s)
1.48 +; Model_units [=] gC/m2/s
1.49 +; 12. = molecular weight of C
1.50 +; u mol = 1e-6 mol
1.51 + data = fm->NEE
1.52 +
1.53 + factor = 1e6 /12.
1.54 +
1.55 + data_mod0(0,:,:,:) = data(:,:,:) * factor
1.56 + delete (data)
1.57 +
1.58 + data = fm->NETRAD
1.59 + data_mod0(1,:,:,:) = data(:,:,:)
1.60 + delete (data)
1.61 +
1.62 + data = fm->LATENT
1.63 + data_mod0(2,:,:,:) = data(:,:,:)
1.64 + delete (data)
1.65 +
1.66 + data = fm->SENSIBLE
1.67 + data_mod0(3,:,:,:) = data(:,:,:)
1.68 + delete (data)
1.69 +
1.70 +; printVarSummary (data_mod0)
1.71 +;************************************************
1.72 +; read in data: observed
1.73 +;************************************************
1.74 + station = (/"BOREAS_NSA_OBS" \
1.75 + ,"CastelPorziano" \
1.76 + ,"Hyytiala" \
1.77 + ,"Kaamanen" \
1.78 + ,"LBA_Tapajos_KM67" \
1.79 + ,"Lethbridge" \
1.80 + ,"Tharandt" \
1.81 + ,"Vielsalm" \
1.82 + /)
1.83 +
1.84 + year_ob = (/"1994-2004" \
1.85 + ,"1997-2003" \
1.86 + ,"1996-2003" \
1.87 + ,"2000-2003" \
1.88 + ,"2002-2005" \
1.89 + ,"1999-2004" \
1.90 + ,"1996-2003" \
1.91 + ,"1998-2003" \
1.92 + /)
1.93 +
1.94 + field = (/"CO2 Flux" \
1.95 + ,"Net Radiation" \
1.96 + ,"Latent Heat" \
1.97 + ,"Sensible Heat" \
1.98 + /)
1.99 +
1.100 + nstation = dimsizes(station)
1.101 + nmon = 12
1.102 + nfield = dimsizes(field)
1.103 +
1.104 + data_ob = new ((/nstation, nfield, nmon/),float)
1.105 + lat_ob = new ((/nstation/),float)
1.106 + lon_ob = new ((/nstation/),float)
1.107 +
1.108 + diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
1.109 +
1.110 + do n = 0,nstation-1
1.111 + diri = diri_root + station(n)+"/"
1.112 + fili = station(n)+"_"+year_ob(n)+"_monthly.nc"
1.113 + g = addfile (diri+fili,"r")
1.114 +
1.115 + lon_ob(n) = g->lon
1.116 + lat_ob(n) = g->lat
1.117 +
1.118 + data = g->CO2_FLUX
1.119 + data_ob(n,0,:) = dim_avg(data(month|:,year|:))
1.120 + delete (data)
1.121 +
1.122 + data = g->RAD_FLUX
1.123 + data_ob(n,1,:) = dim_avg(data(month|:,year|:))
1.124 + delete (data)
1.125 +
1.126 + data = g->LH_FLUX
1.127 + data_ob(n,2,:) = dim_avg(data(month|:,year|:))
1.128 + delete (data)
1.129 +
1.130 + data = g->SH_FLUX
1.131 + data_ob(n,3,:) = dim_avg(data(month|:,year|:))
1.132 + delete (data)
1.133 +
1.134 + delete (g)
1.135 + end do
1.136 +
1.137 +;print (lat_ob)
1.138 +;print (lon_ob)
1.139 +;printVarSummary (data_ob)
1.140 +
1.141 +;************************************************************
1.142 +; interpolate model data into observed station
1.143 +; note: model is 0-360E, 90S-90N
1.144 +;************************************************************
1.145 +
1.146 +; to be able to handle observation at (-89.98,-24.80)
1.147 +; print (ym(0))
1.148 + ym(0) = -90.
1.149 +
1.150 + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
1.151 +
1.152 + delete (data_mod0)
1.153 + yy!0 = "field"
1.154 + data_mod = yy(pts|:,field|:,time|:)
1.155 +; printVarSummary (data_mod)
1.156 +
1.157 +;************************************************************
1.158 +; compute correlation coef and M score
1.159 +;************************************************************
1.160 +
1.161 + score_max = 5.
1.162 +
1.163 + ccr = new ((/nstation, nfield/),float)
1.164 + M_score = new ((/nstation, nfield/),float)
1.165 +
1.166 + do n=0,nstation-1
1.167 + do m=0,nfield-1
1.168 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
1.169 + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
1.170 + M_score(n,m) = (1. -(bias/nmon)) * score_max
1.171 + end do
1.172 + end do
1.173 +
1.174 +;*******************************************************************
1.175 +; for station line plot
1.176 +;*******************************************************************
1.177 +
1.178 +; for x-axis in xyplot
1.179 + mon = ispan(1,12,1)
1.180 + mon@long_name = "month"
1.181 +
1.182 + res = True ; plot mods desired
1.183 + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
1.184 + res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
1.185 +;-------------------------------------------------------------------------
1.186 +; Add a boxed legend using the more simple method
1.187 +
1.188 + res@pmLegendDisplayMode = "Always"
1.189 +; res@pmLegendWidthF = 0.1
1.190 + res@pmLegendWidthF = 0.08
1.191 + res@pmLegendHeightF = 0.06
1.192 +; res@pmLegendOrthogonalPosF = -1.17
1.193 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
1.194 + res@pmLegendOrthogonalPosF = -0.30 ;(downward)
1.195 +
1.196 +; res@pmLegendParallelPosF = 0.18
1.197 + res@pmLegendParallelPosF = 0.23 ;(rightward)
1.198 +
1.199 +; res@lgPerimOn = False
1.200 + res@lgLabelFontHeightF = 0.015
1.201 + res@xyExplicitLegendLabels = (/"observed",model_name/)
1.202 +;-------------------------------------------------------------------
1.203 +; for panel plot
1.204 + res@gsnFrame = False ; Do not draw plot
1.205 + res@gsnDraw = False ; Do not advance frame
1.206 +
1.207 + pres = True ; panel plot mods desired
1.208 + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
1.209 + ; indiv. plots in panel
1.210 + pres@gsnMaximize = True ; fill the page
1.211 +;-------------------------------------------------------------------
1.212 +
1.213 + plot_data = new((/2,12/),float)
1.214 + plot_data!0 = "case"
1.215 + plot_data!1 = "month"
1.216 +
1.217 + do n = 0,nstation-1
1.218 +;----------------------------
1.219 +; for observed
1.220 +
1.221 + plot_name = station(n)+"_ob"
1.222 + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
1.223 + res@tiMainString = title
1.224 +
1.225 + wks = gsn_open_wks (plot_type,plot_name)
1.226 + plot=new(4,graphic) ; create graphic array
1.227 +
1.228 + plot_data(0,:) = (/data_ob (n,0,:)/)
1.229 + plot_data@long_name = field(0)
1.230 + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1
1.231 +
1.232 + plot_data(0,:) = (/data_ob (n,1,:)/)
1.233 + plot_data@long_name = field(1)
1.234 + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2
1.235 +
1.236 + plot_data(0,:) = (/data_ob (n,2,:)/)
1.237 + plot_data@long_name = field(2)
1.238 + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3
1.239 +
1.240 + plot_data(0,:) = (/data_ob (n,3,:)/)
1.241 + plot_data@long_name = field(3)
1.242 + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4
1.243 +
1.244 + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
1.245 +
1.246 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.247 + system("rm "+plot_name+"."+plot_type)
1.248 + clear (wks)
1.249 + delete (plot)
1.250 +;----------------------------
1.251 +; for model_vs_ob
1.252 +
1.253 + plot_name = station(n)+"_model_vs_ob"
1.254 + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
1.255 + res@tiMainString = title
1.256 +
1.257 + wks = gsn_open_wks (plot_type,plot_name)
1.258 + plot=new(4,graphic) ; create graphic array
1.259 +
1.260 + plot_data(0,:) = (/data_ob (n,0,:)/)
1.261 + plot_data(1,:) = (/data_mod(n,0,:)/)
1.262 + plot_data@long_name = field(0)
1.263 + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1
1.264 +
1.265 + plot_data(0,:) = (/data_ob (n,1,:)/)
1.266 + plot_data(1,:) = (/data_mod(n,1,:)/)
1.267 + plot_data@long_name = field(1)
1.268 + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2
1.269 +
1.270 + plot_data(0,:) = (/data_ob (n,2,:)/)
1.271 + plot_data(1,:) = (/data_mod(n,2,:)/)
1.272 + plot_data@long_name = field(2)
1.273 + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3
1.274 +
1.275 + plot_data(0,:) = (/data_ob (n,3,:)/)
1.276 + plot_data(1,:) = (/data_mod(n,3,:)/)
1.277 + plot_data@long_name = field(3)
1.278 + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4
1.279 +
1.280 + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
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 + clear (wks)
1.285 + delete (plot)
1.286 + end do
1.287 +
1.288 +;*******************************************************************
1.289 +; for table of site score
1.290 +;*******************************************************************
1.291 +
1.292 + table_length = 0.8
1.293 +
1.294 +; table header name
1.295 + table_header_name = "Site"
1.296 +
1.297 +; column (not including header column)
1.298 + col_header = (/"Latitude","Longitude","observed" \
1.299 + ,"CO2 Flux","Net Radiation","Latent Heat" \
1.300 + ,"Sensible Heat","Average" \
1.301 + /)
1.302 + ncol = dimsizes(col_header)
1.303 +
1.304 +; row (not including header row)
1.305 + nrow = nstation + 1
1.306 + row_header = new ((/nrow/),string )
1.307 + row_header(0:nstation-1) = station(:)
1.308 + row_header(nrow-1) = "All Sites"
1.309 +
1.310 +; Table header
1.311 + ncr1 = (/1,1/) ; 1 row, 1 column
1.312 + x1 = (/0.005,0.15/) ; Start and end X
1.313 + y1 = (/0.800,0.895/) ; Start and end Y
1.314 + text1 = table_header_name
1.315 + res1 = True
1.316 + res1@txFontHeightF = 0.03
1.317 + res1@gsFillColor = "CornFlowerBlue"
1.318 +
1.319 +; Column header (equally space in x2)
1.320 + ncr2 = (/1,ncol/) ; 1 rows, ncol columns
1.321 + x2 = (/x1(1),0.995/) ; start from end of x1
1.322 + y2 = y1 ; same as y1
1.323 + text2 = col_header
1.324 + res2 = True
1.325 + res2@txFontHeightF = 0.010
1.326 + res2@gsFillColor = "Gray"
1.327 +
1.328 +; Row header (equally space in y2)
1.329 + ncr3 = (/nrow,1/) ; nrow rows, 1 columns
1.330 + x3 = x1 ; same as x1
1.331 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1
1.332 + text3 = row_header
1.333 + res3 = True
1.334 + res3@txFontHeightF = 0.010
1.335 + res3@gsFillColor = "Gray"
1.336 +
1.337 +; Main table body
1.338 + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns
1.339 + x4 = x2 ; Start and end x
1.340 + y4 = y3 ; Start and end Y
1.341 + text4 = new((/nrow,ncol/),string)
1.342 +
1.343 + color_fill4 = new((/nrow,ncol/),string)
1.344 + color_fill4 = "white"
1.345 + color_fill4(:,ncol-1) = "grey"
1.346 + color_fill4(nrow-1,:) = "green"
1.347 +
1.348 + res4 = True ; Set up resource list
1.349 +; res4@gsnDebug = True ; Useful to print NDC row,col values used.
1.350 + res4@txFontHeightF = 0.015
1.351 + res4@gsFillColor = color_fill4
1.352 +
1.353 + delete (color_fill4)
1.354 +;-------------------------------------------------------------------
1.355 +; for table value
1.356 +
1.357 + do n = 0,nrow-2
1.358 + text4(n,0) = sprintf("%5.2f", lat_ob(n))
1.359 + text4(n,1) = sprintf("%5.2f", lon_ob(n))
1.360 + text4(n,2) = year_ob(n)
1.361 + text4(n,3) = sprintf("%5.2f", M_score(n,0)) ; CO2 Flux
1.362 + text4(n,4) = sprintf("%5.2f", M_score(n,1)) ; Net Radiation
1.363 + text4(n,5) = sprintf("%5.2f", M_score(n,2)) ; Latent Heat
1.364 + text4(n,6) = sprintf("%5.2f", M_score(n,3)) ; Sensible Heat
1.365 + text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields
1.366 + end do
1.367 +
1.368 +; for the last row
1.369 +
1.370 + M_co2 = avg(M_score(:,0))
1.371 + M_rad = avg(M_score(:,1))
1.372 + M_lh = avg(M_score(:,2))
1.373 + M_sh = avg(M_score(:,3))
1.374 + M_all = M_co2+ M_rad +M_lh + M_sh
1.375 +
1.376 + text4(nrow-1,0) = "-"
1.377 + text4(nrow-1,1) = "-"
1.378 + text4(nrow-1,2) = "-"
1.379 + text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites
1.380 + text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites
1.381 + text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites
1.382 + text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites
1.383 + text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites
1.384 +
1.385 + print (M_co2)
1.386 + print (M_rad)
1.387 + print (M_lh )
1.388 + print (M_sh)
1.389 + print (M_all)
1.390 +;---------------------------------------------------------------------------
1.391 +
1.392 + plot_name = "table_site_score"
1.393 +
1.394 + wks = gsn_open_wks (plot_type,plot_name)
1.395 +;------------------------------------------
1.396 +; for table title
1.397 +
1.398 + gRes = True
1.399 + gRes@txFontHeightF = 0.02
1.400 +; gRes@txAngleF = 90
1.401 +
1.402 + title_text = "Model " + model_name + " M_Score"
1.403 +
1.404 + gsn_text_ndc(wks,title_text,0.50,0.95,gRes)
1.405 +;------------------------------------------
1.406 +
1.407 + gsn_table(wks,ncr1,x1,y1,text1,res1)
1.408 + gsn_table(wks,ncr2,x2,y2,text2,res2)
1.409 + gsn_table(wks,ncr3,x3,y3,text3,res3)
1.410 + gsn_table(wks,ncr4,x4,y4,text4,res4)
1.411 +
1.412 + frame(wks)
1.413 +
1.414 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.415 + system("rm "+plot_name+"."+plot_type)
1.416 +;-------------------------------------------------------------------
1.417 + temp_name = "temp." + model_name
1.418 + system("mkdir -p " + temp_name)
1.419 + system("mv *.png " + temp_name)
1.420 + system("tar cf "+ temp_name +".tar " + temp_name)
1.421 +;-------------------------------------------------------------------
1.422 +
1.423 +end