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