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