1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/all/10.fire.ncl Mon Jan 26 22:08:20 2009 -0500
1.3 @@ -0,0 +1,744 @@
1.4 +;**************************************************************
1.5 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
1.6 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
1.7 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
1.8 +;**************************************************************
1.9 +procedure set_line(lines:string,nline:integer,newlines:string)
1.10 +begin
1.11 +; add line to ascci/html file
1.12 +
1.13 + nnewlines = dimsizes(newlines)
1.14 + if(nline+nnewlines-1.ge.dimsizes(lines))
1.15 + print("set_line: bad index, not setting anything.")
1.16 + return
1.17 + end if
1.18 + lines(nline:nline+nnewlines-1) = newlines
1.19 +; print ("lines = " + lines(nline:nline+nnewlines-1))
1.20 + nline = nline + nnewlines
1.21 + return
1.22 +end
1.23 +;**************************************************************
1.24 +; Main code.
1.25 +begin
1.26 +
1.27 + plot_type = "ps"
1.28 + plot_type_new = "png"
1.29 +
1.30 +;------------------------------------------------------
1.31 +; edit table.html of current model for movel1_vs_model2
1.32 +
1.33 + if (isvar("compare")) then
1.34 + html_name2 = compare+"/table.html"
1.35 + html_new2 = html_name2 +".new"
1.36 + end if
1.37 +
1.38 +;------------------------------------------------------
1.39 +; edit table.html for current model
1.40 +
1.41 + html_name = model_name+"/table.html"
1.42 + html_new = html_name +".new"
1.43 +
1.44 +;------------------------------------------------------
1.45 +; get biome data: model
1.46 +
1.47 + biome_name_mod = "Model PFT Class"
1.48 +
1.49 + film_c = "class_pft_"+ model_grid +".nc"
1.50 + fm_c = addfile (dirs+film_c,"r")
1.51 + classmod = fm_c->CLASS_PFT
1.52 +
1.53 + delete (fm_c)
1.54 +
1.55 +; model data has 17 land-type classes
1.56 + nclass_mod = 17
1.57 +
1.58 +;--------------------------------
1.59 +; get model data: landmask, landfrac and area
1.60 +
1.61 + film_l = "lnd_"+ model_grid +".nc"
1.62 + fm_l = addfile (dirs+film_l,"r")
1.63 + landmask = fm_l->landmask
1.64 + landfrac = fm_l->landfrac
1.65 + area = fm_l->area
1.66 +
1.67 + delete (fm_l)
1.68 +
1.69 +; change area from km**2 to m**2
1.70 + area = area * 1.e6
1.71 +
1.72 +; take into account landfrac
1.73 + area = area * landfrac
1.74 +
1.75 +;--------------------------------
1.76 +; read data: time series, model
1.77 +
1.78 + fm = addfile (dirm+film7,"r")
1.79 +
1.80 + data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:)
1.81 +
1.82 + delete (fm)
1.83 +
1.84 +; Units for these variables are:
1.85 +; g C/m^2/s
1.86 +
1.87 +; change unit to gC/m2/month
1.88 +
1.89 + nsec_per_month = 60*60*24*30
1.90 +
1.91 + data_mod = data_mod * nsec_per_month
1.92 +
1.93 + data_mod@units = "gC/m2/month"
1.94 +
1.95 +;----------------------------------------------------
1.96 +; read data: time series, observed
1.97 +
1.98 + dir_f = diro + "fire/"
1.99 + fil_f = "Fire_C_1997-2006_monthly_"+ model_grid+".nc"
1.100 + fm = addfile (dir_f+fil_f,"r")
1.101 + data_ob = fm->FIRE_C(0:7,:,:,:)
1.102 +
1.103 + delete (fm)
1.104 +
1.105 + ob_name = "GFEDv2"
1.106 +
1.107 +; Units for these variables are: gC/m2/month
1.108 +
1.109 + data_ob@units = "gC/m2/month"
1.110 +
1.111 +;-------------------------------------------------------------
1.112 +; html table1 data
1.113 +
1.114 +; column (not including header column)
1.115 +
1.116 + col_head = (/"Observed Fire_Flux (PgC/yr)" \
1.117 + ,"Model Fire_Flux (PgC/yr)" \
1.118 + ,"Correlation Coefficient" \
1.119 + ,"Ratio model/observed" \
1.120 + ,"M_score" \
1.121 + ,"Timeseries plot" \
1.122 + /)
1.123 +
1.124 + ncol = dimsizes(col_head)
1.125 +
1.126 +; row (not including header row)
1.127 +
1.128 +; using model biome class:
1.129 + row_head = (/"Not Vegetated" \
1.130 + ,"Needleleaf Evergreen Temperate Tree" \
1.131 + ,"Needleleaf Evergreen Boreal Tree" \
1.132 +; ,"Needleleaf Deciduous Boreal Tree" \
1.133 + ,"Broadleaf Evergreen Tropical Tree" \
1.134 + ,"Broadleaf Evergreen Temperate Tree" \
1.135 + ,"Broadleaf Deciduous Tropical Tree" \
1.136 + ,"Broadleaf Deciduous Temperate Tree" \
1.137 +; ,"Broadleaf Deciduous Boreal Tree" \
1.138 +; ,"Broadleaf Evergreen Shrub" \
1.139 + ,"Broadleaf Deciduous Temperate Shrub" \
1.140 + ,"Broadleaf Deciduous Boreal Shrub" \
1.141 + ,"C3 Arctic Grass" \
1.142 + ,"C3 Non-Arctic Grass" \
1.143 + ,"C4 Grass" \
1.144 + ,"Corn" \
1.145 +; ,"Wheat" \
1.146 + ,"All Biomes" \
1.147 + /)
1.148 + nrow = dimsizes(row_head)
1.149 +
1.150 +; arrays to be passed to table.
1.151 + text = new ((/nrow, ncol/),string )
1.152 +
1.153 +;*****************************************************************
1.154 +; (A) get time-mean
1.155 +;*****************************************************************
1.156 +
1.157 + x = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:))
1.158 + data_mod_m = dim_avg_Wrap( x(lat|:,lon|:,month|:))
1.159 + delete (x)
1.160 +
1.161 + x = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:))
1.162 + data_ob_m = dim_avg_Wrap( x(lat|:,lon|:,month|:))
1.163 + delete (x)
1.164 +
1.165 +;----------------------------------------------------
1.166 +; compute correlation coef: space
1.167 +
1.168 + landmask_1d = ndtooned(landmask)
1.169 + data_mod_1d = ndtooned(data_mod_m)
1.170 + data_ob_1d = ndtooned(data_ob_m )
1.171 + area_1d = ndtooned(area)
1.172 + landfrac_1d = ndtooned(landfrac)
1.173 +
1.174 + good = ind(landmask_1d .gt. 0.)
1.175 +
1.176 + global_mod = sum(data_mod_1d(good)*area_1d(good)) * 1.e-15 * 12.
1.177 + global_ob = sum(data_ob_1d(good) *area_1d(good)) * 1.e-15 * 12.
1.178 +; print (global_mod)
1.179 +; print (global_ob)
1.180 +
1.181 + global_area= sum(area_1d)
1.182 + global_land= sum(area_1d(good))
1.183 +; print (global_area)
1.184 +; print (global_land)
1.185 +
1.186 + cc_space = esccr(data_mod_1d(good)*landfrac_1d(good),data_ob_1d(good)*landfrac_1d(good),0)
1.187 +
1.188 + delete (landmask_1d)
1.189 + delete (landfrac_1d)
1.190 +; delete (area_1d)
1.191 + delete (data_mod_1d)
1.192 + delete (data_ob_1d)
1.193 + delete (good)
1.194 +
1.195 +;----------------------------------------------------
1.196 +; compute M_global
1.197 +
1.198 + score_max = 1.
1.199 +
1.200 + Mscore1 = cc_space * cc_space * score_max
1.201 +
1.202 + M_global = sprintf("%.2f", Mscore1)
1.203 +
1.204 +;----------------------------------------------------
1.205 +; global res
1.206 +
1.207 + resg = True ; Use plot options
1.208 + resg@cnFillOn = True ; Turn on color fill
1.209 + resg@gsnSpreadColors = True ; use full colormap
1.210 + resg@cnLinesOn = False ; Turn off contourn lines
1.211 + resg@mpFillOn = False ; Turn off map fill
1.212 + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals
1.213 +
1.214 +;----------------------------------------------------
1.215 +; global contour: model vs ob
1.216 +
1.217 + plot_name = "global_model_vs_ob"
1.218 +
1.219 + wks = gsn_open_wks (plot_type,plot_name)
1.220 + gsn_define_colormap(wks,"gui_default")
1.221 +
1.222 + plot=new(3,graphic) ; create graphic array
1.223 +
1.224 + resg@gsnFrame = False ; Do not draw plot
1.225 + resg@gsnDraw = False ; Do not advance frame
1.226 +
1.227 +;----------------------
1.228 +; plot correlation coef
1.229 +
1.230 + gRes = True
1.231 + gRes@txFontHeightF = 0.02
1.232 + gRes@txAngleF = 90
1.233 +
1.234 + correlation_text = "(correlation coef = "+sprintf("%.2f", cc_space)+")"
1.235 +
1.236 + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes)
1.237 +
1.238 +;-----------------------
1.239 +; plot ob
1.240 +; change from gC/m2/month to gC/m2/yr
1.241 + month_to_year = 12.
1.242 +
1.243 + data_ob_m@units = "gC/m2/yr"
1.244 + data_mod_m@units = "gC/m2/yr"
1.245 +
1.246 + data_ob_m = data_ob_m * month_to_year
1.247 + data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue)
1.248 +
1.249 + title = ob_name
1.250 + resg@tiMainString = title
1.251 +
1.252 + resg@cnMinLevelValF = 10.
1.253 + resg@cnMaxLevelValF = 100.
1.254 + resg@cnLevelSpacingF = 10.
1.255 +
1.256 + plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg)
1.257 +
1.258 +;-----------------------
1.259 +; plot model
1.260 +
1.261 + data_mod_m = data_mod_m * month_to_year
1.262 +
1.263 + data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue)
1.264 +
1.265 + title = "Model "+ model_name
1.266 + resg@tiMainString = title
1.267 +
1.268 + resg@cnMinLevelValF = 10.
1.269 + resg@cnMaxLevelValF = 100.
1.270 + resg@cnLevelSpacingF = 10.
1.271 +
1.272 + plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg)
1.273 +
1.274 +;-----------------------
1.275 +; plot model-ob
1.276 +
1.277 + resg@cnMinLevelValF = -80.
1.278 + resg@cnMaxLevelValF = 20.
1.279 + resg@cnLevelSpacingF = 10.
1.280 +
1.281 + zz = data_ob_m
1.282 + zz = data_mod_m - data_ob_m
1.283 + title = "Model_"+model_name+" - Observed"
1.284 + resg@tiMainString = title
1.285 +
1.286 + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg)
1.287 +
1.288 +; plot panel
1.289 +
1.290 + pres = True ; panel plot mods desired
1.291 + pres@gsnMaximize = True ; fill the page
1.292 +
1.293 + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot
1.294 +
1.295 + delete (wks)
1.296 + delete (plot)
1.297 +
1.298 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
1.299 + "rm "+plot_name+"."+plot_type)
1.300 +
1.301 + delete (data_ob_m)
1.302 + delete (data_mod_m)
1.303 + delete (zz)
1.304 +
1.305 + resg@gsnFrame = True ; Do advance frame
1.306 + resg@gsnDraw = True ; Do draw plot
1.307 +
1.308 +;*******************************************************************
1.309 +; (B) Time series : per biome
1.310 +;*******************************************************************
1.311 +
1.312 + data_n = 2
1.313 +
1.314 + dsizes = dimsizes(data_mod)
1.315 + nyear = dsizes(0)
1.316 + nmonth = dsizes(1)
1.317 + ntime = nyear * nmonth
1.318 +
1.319 + year_start = 1997
1.320 + year_end = 2004
1.321 +
1.322 +;-------------------------------------------
1.323 +; Calculate "nice" bins for binning the data
1.324 +
1.325 +; using model biome class
1.326 + nclass = nclass_mod
1.327 +
1.328 + range = fspan(0,nclass,nclass+1)
1.329 +
1.330 +; Use this range information to grab all the values in a
1.331 +; particular range, and then take an average.
1.332 +
1.333 + nx = dimsizes(range) - 1
1.334 +
1.335 +;-------------------------------------------
1.336 +; put data into bins
1.337 +
1.338 +; using observed biome class
1.339 +; base = ndtooned(classob)
1.340 +; using model biome class
1.341 + base = ndtooned(classmod)
1.342 +
1.343 +; output
1.344 +
1.345 + area_bin = new((/nx/),float)
1.346 + yvalues = new((/ntime,data_n,nx/),float)
1.347 +
1.348 +; Loop through each range, using base.
1.349 +
1.350 + do i=0,nx-1
1.351 +
1.352 + if (i.ne.(nx-1)) then
1.353 + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1)))
1.354 + else
1.355 + idx = ind(base.ge.range(i))
1.356 + end if
1.357 +;---------------------
1.358 +; for area
1.359 +
1.360 + if (.not.any(ismissing(idx))) then
1.361 + area_bin(i) = sum(area_1d(idx))
1.362 + else
1.363 + area_bin(i) = area_bin@_FillValue
1.364 + end if
1.365 +
1.366 +;#############################################################
1.367 +; using model biome class:
1.368 +; set the following 4 classes to _FillValue:
1.369 +; (3)Needleleaf Deciduous Boreal Tree,
1.370 +; (8)Broadleaf Deciduous Boreal Tree,
1.371 +; (9)Broadleaf Evergreen Shrub,
1.372 +; (16)Wheat
1.373 +
1.374 + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then
1.375 + area_bin(i) = area_bin@_FillValue
1.376 + end if
1.377 +;#############################################################
1.378 +
1.379 +;---------------------
1.380 +; for data_mod and data_ob
1.381 +
1.382 + do n = 0,data_n-1
1.383 +
1.384 + t = -1
1.385 + do m = 0,nyear-1
1.386 + do k = 0,nmonth-1
1.387 +
1.388 + t = t + 1
1.389 +
1.390 + if (n.eq.0) then
1.391 + data = ndtooned(data_ob(m,k,:,:))
1.392 + end if
1.393 +
1.394 + if (n.eq.1) then
1.395 + data = ndtooned(data_mod(m,k,:,:))
1.396 + end if
1.397 +
1.398 +; Calculate average
1.399 +
1.400 + if (.not.any(ismissing(idx))) then
1.401 + yvalues(t,n,i) = sum(data(idx)*area_1d(idx))
1.402 + else
1.403 + yvalues(t,n,i) = yvalues@_FillValue
1.404 + end if
1.405 +
1.406 +;#############################################################
1.407 +; using model biome class:
1.408 +; set the following 4 classes to _FillValue:
1.409 +; (3)Needleleaf Deciduous Boreal Tree,
1.410 +; (8)Broadleaf Deciduous Boreal Tree,
1.411 +; (9)Broadleaf Evergreen Shrub,
1.412 +; (16)Wheat
1.413 +
1.414 + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then
1.415 + yvalues(t,n,i) = yvalues@_FillValue
1.416 + end if
1.417 +;#############################################################
1.418 +
1.419 + end do
1.420 + end do
1.421 +
1.422 + delete(data)
1.423 + end do
1.424 +
1.425 + delete(idx)
1.426 + end do
1.427 +
1.428 + delete (base)
1.429 + delete (data_mod)
1.430 + delete (data_ob)
1.431 +
1.432 + global_bin = sum(area_bin)
1.433 +; print (global_bin)
1.434 +
1.435 +;----------------------------------------------------------------
1.436 +; get area_good
1.437 +
1.438 + good = ind(.not.ismissing(area_bin))
1.439 +
1.440 + area_g = area_bin(good)
1.441 +
1.442 + n_biome = dimsizes(good)
1.443 +
1.444 + global_good = sum(area_g)
1.445 +; print (global_good)
1.446 +
1.447 +;----------------------------------------------------------------
1.448 +; data for tseries plot
1.449 +
1.450 + yvalues_g = new((/ntime,data_n,n_biome/),float)
1.451 +
1.452 + yvalues_g@units = "TgC/month"
1.453 +
1.454 +; change unit to Tg C/month
1.455 +; change unit from g to Tg (Tera gram)
1.456 + factor_unit = 1.e-12
1.457 +
1.458 + yvalues_g = yvalues(:,:,good) * factor_unit
1.459 +
1.460 + delete (good)
1.461 +
1.462 +;-------------------------------------------------------------------
1.463 +; general settings for line plot
1.464 +
1.465 + res = True
1.466 + res@xyDashPatterns = (/0,0/) ; make lines solid
1.467 + res@xyLineThicknesses = (/2.0,2.0/) ; make lines thicker
1.468 + res@xyLineColors = (/"blue","red"/) ; line color
1.469 +
1.470 + res@trXMinF = year_start
1.471 + res@trXMaxF = year_end + 1
1.472 +
1.473 + res@vpHeightF = 0.4 ; change aspect ratio of plot
1.474 +; res@vpWidthF = 0.8
1.475 + res@vpWidthF = 0.75
1.476 +
1.477 + res@tiMainFontHeightF = 0.025 ; size of title
1.478 +
1.479 + res@tmXBFormat = "f" ; not to add trailing zeros
1.480 +
1.481 +; res@gsnMaximize = True
1.482 +
1.483 +;----------------------------------------------
1.484 +; Add a boxed legend using the simple method
1.485 +
1.486 + res@pmLegendDisplayMode = "Always"
1.487 +; res@pmLegendWidthF = 0.1
1.488 + res@pmLegendWidthF = 0.08
1.489 + res@pmLegendHeightF = 0.06
1.490 + res@pmLegendOrthogonalPosF = -1.17
1.491 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
1.492 +; res@pmLegendOrthogonalPosF = -0.30 ;(downward)
1.493 +
1.494 +; res@pmLegendParallelPosF = 0.18
1.495 + res@pmLegendParallelPosF = 0.23 ;(rightward)
1.496 + res@pmLegendParallelPosF = 0.73 ;(rightward)
1.497 + res@pmLegendParallelPosF = 0.83 ;(rightward)
1.498 +
1.499 +; res@lgPerimOn = False
1.500 + res@lgLabelFontHeightF = 0.015
1.501 + res@xyExplicitLegendLabels = (/"observed",model_name/)
1.502 +
1.503 +;*******************************************************************
1.504 +; (A) time series plot: monthly ( 2 lines per plot)
1.505 +;*******************************************************************
1.506 +
1.507 +; x-axis in time series plot
1.508 +
1.509 + timeI = new((/ntime/),integer)
1.510 + timeF = new((/ntime/),float)
1.511 + timeI = ispan(1,ntime,1)
1.512 + timeF = year_start + (timeI-1)/12.
1.513 + timeF@long_name = "year"
1.514 +
1.515 + plot_data = new((/2,ntime/),float)
1.516 + plot_data@long_name = "TgC/month"
1.517 +
1.518 +;----------------------------------------------
1.519 +; time series plot : per biome
1.520 +
1.521 + do m = 0, n_biome-1
1.522 +
1.523 + plot_name = "monthly_biome_"+ m
1.524 +
1.525 + wks = gsn_open_wks (plot_type,plot_name)
1.526 +
1.527 + title = "Fire : "+ row_head(m)
1.528 + res@tiMainString = title
1.529 +
1.530 + plot_data(0,:) = yvalues_g(:,0,m)
1.531 + plot_data(1,:) = yvalues_g(:,1,m)
1.532 +
1.533 + plot = gsn_csm_xy(wks,timeF,plot_data,res)
1.534 +
1.535 + delete (wks)
1.536 + delete (plot)
1.537 +
1.538 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
1.539 + "rm "+plot_name+"."+plot_type)
1.540 + end do
1.541 +
1.542 +;------------------------------------------
1.543 +; data for table : per biome
1.544 +
1.545 +; unit change from TgC/month to PgC/month
1.546 + unit_factor = 1.e-3
1.547 +
1.548 + score_max = 1.
1.549 +
1.550 + tmp_ob = new((/ntime/),float)
1.551 + tmp_mod = new((/ntime/),float)
1.552 +
1.553 + total_ob = new((/n_biome/),float)
1.554 + total_mod = new((/n_biome/),float)
1.555 + Mscore2 = new((/n_biome/),float)
1.556 +
1.557 + do m = 0, n_biome-1
1.558 +
1.559 + tmp_ob = yvalues_g(:,0,m)
1.560 + tmp_mod = yvalues_g(:,1,m)
1.561 +
1.562 + total_ob(m) = avg(month_to_annual(tmp_ob, 0)) * unit_factor
1.563 + total_mod(m) = avg(month_to_annual(tmp_mod,0)) * unit_factor
1.564 +
1.565 + cc_time = esccr(tmp_mod,tmp_ob,0)
1.566 +
1.567 + ratio = total_mod(m)/total_ob(m)
1.568 +
1.569 + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.)
1.570 +
1.571 + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) )
1.572 + Mscore2(m) = (1.- (bias/dimsizes(good)))*score_max
1.573 +
1.574 + delete (good)
1.575 +
1.576 + text(m,0) = sprintf("%.2f",total_ob(m))
1.577 + text(m,1) = sprintf("%.2f",total_mod(m))
1.578 + text(m,2) = sprintf("%.2f",cc_time)
1.579 + text(m,3) = sprintf("%.2f",ratio)
1.580 + text(m,4) = sprintf("%.2f",Mscore2(m))
1.581 + text(m,5) = "<a href=./monthly_biome_"+m+".png>model_vs_ob</a>"
1.582 + end do
1.583 +
1.584 + delete (tmp_ob)
1.585 + delete (tmp_mod)
1.586 +
1.587 +;--------------------------------------------
1.588 +; time series plot: all biome
1.589 +
1.590 + plot_name = "monthly_global"
1.591 +
1.592 + wks = gsn_open_wks (plot_type,plot_name)
1.593 +
1.594 + title = "Fire : "+ row_head(n_biome)
1.595 + res@tiMainString = title
1.596 +
1.597 + do k = 0,ntime-1
1.598 + plot_data(0,k) = sum(yvalues_g(k,0,:))
1.599 + plot_data(1,k) = sum(yvalues_g(k,1,:))
1.600 + end do
1.601 +
1.602 + plot = gsn_csm_xy(wks,timeF,plot_data,res)
1.603 +
1.604 + delete (wks)
1.605 + delete (plot)
1.606 +
1.607 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
1.608 + "rm "+plot_name+"."+plot_type)
1.609 +
1.610 +;------------------------------------------
1.611 +; data for table : global
1.612 +
1.613 + score_max = 1.
1.614 +
1.615 + tmp_ob = ndtooned(yvalues_g(:,0,:))
1.616 + tmp_mod = ndtooned(yvalues_g(:,1,:))
1.617 +
1.618 + cc_time = esccr(tmp_mod,tmp_ob,0)
1.619 +
1.620 + ratio = sum(total_mod)/sum(total_ob)
1.621 +
1.622 + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.)
1.623 +
1.624 + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) )
1.625 + Mscore3 = (1.- (bias/dimsizes(good)))*score_max
1.626 +
1.627 +; print (Mscore3)
1.628 +
1.629 + delete (good)
1.630 +
1.631 + text(nrow-1,0) = sprintf("%.2f",sum(total_ob))
1.632 + text(nrow-1,1) = sprintf("%.2f",sum(total_mod))
1.633 + text(nrow-1,2) = sprintf("%.2f",cc_time)
1.634 + text(nrow-1,3) = sprintf("%.2f",ratio)
1.635 +; text(nrow-1,4) = sprintf("%.2f",avg(Mscore2))
1.636 + text(nrow-1,4) = sprintf("%.2f", Mscore3)
1.637 + text(nrow-1,5) = "<a href=./monthly_global.png>model_vs_ob</a>"
1.638 +
1.639 +;**************************************************
1.640 +; create html table
1.641 +;**************************************************
1.642 +
1.643 + header_text = "<H1>Fire Emissions from GFEDv2 (1997-2004) vs "+model_name+"</H1>"
1.644 +
1.645 + header = (/"<HTML>" \
1.646 + ,"<HEAD>" \
1.647 + ,"<TITLE>CLAMP metrics</TITLE>" \
1.648 + ,"</HEAD>" \
1.649 + ,header_text \
1.650 + /)
1.651 + footer = "</HTML>"
1.652 +
1.653 + table_header = (/ \
1.654 + "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
1.655 + ,"<tr>" \
1.656 + ," <th bgcolor=DDDDDD >Biome Type</th>" \
1.657 + ," <th bgcolor=DDDDDD >"+col_head(0)+"</th>" \
1.658 + ," <th bgcolor=DDDDDD >"+col_head(1)+"</th>" \
1.659 + ," <th bgcolor=DDDDDD >"+col_head(2)+"</th>" \
1.660 + ," <th bgcolor=DDDDDD >"+col_head(3)+"</th>" \
1.661 + ," <th bgcolor=DDDDDD >"+col_head(4)+"</th>" \
1.662 + ," <th bgcolor=DDDDDD >"+col_head(5)+"</th>" \
1.663 + ,"</tr>" \
1.664 + /)
1.665 + table_footer = "</table>"
1.666 + row_header = "<tr>"
1.667 + row_footer = "</tr>"
1.668 +
1.669 + lines = new(50000,string)
1.670 + nline = 0
1.671 +
1.672 + set_line(lines,nline,header)
1.673 + set_line(lines,nline,table_header)
1.674 +;-----------------------------------------------
1.675 +;row of table
1.676 +
1.677 + do n = 0,nrow-1
1.678 + set_line(lines,nline,row_header)
1.679 +
1.680 + txt0 = row_head(n)
1.681 + txt1 = text(n,0)
1.682 + txt2 = text(n,1)
1.683 + txt3 = text(n,2)
1.684 + txt4 = text(n,3)
1.685 + txt5 = text(n,4)
1.686 + txt6 = text(n,5)
1.687 +
1.688 + set_line(lines,nline,"<th>"+txt0+"</th>")
1.689 + set_line(lines,nline,"<th>"+txt1+"</th>")
1.690 + set_line(lines,nline,"<th>"+txt2+"</th>")
1.691 + set_line(lines,nline,"<th>"+txt3+"</th>")
1.692 + set_line(lines,nline,"<th>"+txt4+"</th>")
1.693 + set_line(lines,nline,"<th>"+txt5+"</th>")
1.694 + set_line(lines,nline,"<th>"+txt6+"</th>")
1.695 +
1.696 + set_line(lines,nline,row_footer)
1.697 + end do
1.698 +;-----------------------------------------------
1.699 + set_line(lines,nline,table_footer)
1.700 + set_line(lines,nline,footer)
1.701 +
1.702 +; Now write to an HTML file.
1.703 +
1.704 + output_html = "table_fire.html"
1.705 +
1.706 + idx = ind(.not.ismissing(lines))
1.707 + if(.not.any(ismissing(idx))) then
1.708 + asciiwrite(output_html,lines(idx))
1.709 + else
1.710 + print ("error?")
1.711 + end if
1.712 +
1.713 + delete (idx)
1.714 +
1.715 +;**************************************************************************************
1.716 +; update score
1.717 +;**************************************************************************************
1.718 +
1.719 + M_all = Mscore1 + Mscore3
1.720 + M_fire = sprintf("%.2f", M_all)
1.721 +
1.722 + if (isvar("compare")) then
1.723 + system("sed -e '1,/M_fire/s/M_fire/"+M_fire+"/' "+html_name2+" > "+html_new2+";"+ \
1.724 + "mv -f "+html_new2+" "+html_name2)
1.725 + end if
1.726 +
1.727 + system("sed s#M_fire#"+M_fire+"# "+html_name+" > "+html_new+";"+ \
1.728 + "mv -f "+html_new+" "+html_name)
1.729 +
1.730 +;***************************************************************************
1.731 +; get total score and write to file
1.732 +;***************************************************************************
1.733 +
1.734 + asciiwrite("M_save.fire", M_fire)
1.735 +
1.736 + delete (M_fire)
1.737 +
1.738 +;***************************************************************************
1.739 +; output plot and html
1.740 +;***************************************************************************
1.741 + output_dir = model_name+"/fire"
1.742 +
1.743 + system("mv *.png *.html " + output_dir)
1.744 +;***************************************************************************
1.745 +
1.746 +end
1.747 +