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