fire/24.table+tseries.ncl
author Forrest Hoffman <forrest@climatemodeling.org>
Thu, 26 Mar 2009 14:02:21 -0400
changeset 1 4be95183fbcd
permissions -rw-r--r--
Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
forrest@0
     1
;********************************************************
forrest@0
     2
; landfrac applied to area only.
forrest@0
     3
; using model biome class
forrest@0
     4
;
forrest@0
     5
; required command line input parameters:
forrest@0
     6
;  ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl
forrest@0
     7
;
forrest@0
     8
; histogram normalized by rain and compute correleration
forrest@0
     9
;**************************************************************
forrest@0
    10
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
forrest@0
    11
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
forrest@0
    12
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
forrest@0
    13
;**************************************************************
forrest@0
    14
procedure set_line(lines:string,nline:integer,newlines:string) 
forrest@0
    15
begin
forrest@0
    16
; add line to ascci/html file
forrest@0
    17
    
forrest@0
    18
  nnewlines = dimsizes(newlines)
forrest@0
    19
  if(nline+nnewlines-1.ge.dimsizes(lines))
forrest@0
    20
    print("set_line: bad index, not setting anything.") 
forrest@0
    21
    return
forrest@0
    22
  end if 
forrest@0
    23
  lines(nline:nline+nnewlines-1) = newlines
forrest@0
    24
;  print ("lines = " + lines(nline:nline+nnewlines-1))
forrest@0
    25
  nline = nline + nnewlines
forrest@0
    26
  return 
forrest@0
    27
end
forrest@0
    28
;**************************************************************
forrest@0
    29
; Main code.
forrest@0
    30
begin
forrest@0
    31
 
forrest@0
    32
  plot_type     = "ps"
forrest@0
    33
  plot_type_new = "png"
forrest@0
    34
forrest@0
    35
;---------------------------------------------------
forrest@0
    36
; model name and grid       
forrest@0
    37
forrest@0
    38
  model_grid = "T42"
forrest@0
    39
forrest@0
    40
  model_name  = "cn"
forrest@0
    41
  model_name1 = "i01.06cn"
forrest@0
    42
  model_name2 = "i01.10cn"
forrest@0
    43
forrest@0
    44
;---------------------------------------------------
forrest@0
    45
; get biome data: model
forrest@0
    46
forrest@0
    47
  biome_name_mod = "Model PFT Class"
forrest@0
    48
forrest@0
    49
  dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    50
  film = "class_pft_"+model_grid+".nc"
forrest@0
    51
  fm   = addfile(dirm+film,"r")
forrest@0
    52
 
forrest@0
    53
  classmod = fm->CLASS_PFT
forrest@0
    54
forrest@0
    55
  delete (fm)
forrest@0
    56
forrest@0
    57
; model data has 17 land-type classes
forrest@0
    58
forrest@0
    59
  nclass_mod = 17
forrest@0
    60
forrest@0
    61
;--------------------------------------------------
forrest@0
    62
; get model data: landmask, landfrac and area
forrest@0
    63
forrest@0
    64
  dirm = "/fis/cgd/cseg/people/jeff/surface_data/" 
forrest@0
    65
  film = "lnd_T42.nc"
forrest@0
    66
  fm   = addfile (dirm+film,"r")
forrest@0
    67
  
forrest@0
    68
  landmask = fm->landmask
forrest@0
    69
  landfrac = fm->landfrac
forrest@0
    70
  area     = fm->area
forrest@0
    71
forrest@0
    72
  delete (fm)
forrest@0
    73
forrest@0
    74
; change area from km**2 to m**2
forrest@0
    75
  area = area * 1.e6
forrest@0
    76
             
forrest@0
    77
;---------------------------------------------------
forrest@0
    78
; take into account landfrac
forrest@0
    79
forrest@0
    80
  area     = area * landfrac
forrest@0
    81
forrest@0
    82
;----------------------------------------------------
forrest@0
    83
; read data: time series, model
forrest@0
    84
forrest@0
    85
 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    86
 film = model_name2 + "_Fire_C_1979-2004_monthly.nc"
forrest@0
    87
 fm   = addfile (dirm+film,"r")
forrest@0
    88
forrest@0
    89
 data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:)
forrest@0
    90
forrest@0
    91
 delete (fm)
forrest@0
    92
forrest@0
    93
; Units for these variables are:
forrest@0
    94
; g C/m^2/s
forrest@0
    95
forrest@0
    96
; change unit to g C/m^2/month
forrest@0
    97
forrest@0
    98
  nsec_per_month = 60*60*24*30
forrest@0
    99
 
forrest@0
   100
  data_mod = data_mod * nsec_per_month 
forrest@0
   101
forrest@0
   102
  data_mod@unit = "gC/m2/month"
forrest@0
   103
;----------------------------------------------------
forrest@0
   104
; read data: time series, observed
forrest@0
   105
forrest@0
   106
 dirm = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/"
forrest@0
   107
 film = "Fire_C_1997-2006_monthly_"+ model_grid+".nc"
forrest@0
   108
 fm   = addfile (dirm+film,"r")
forrest@0
   109
forrest@0
   110
 data_ob = fm->FIRE_C(0:7,:,:,:)
forrest@0
   111
forrest@0
   112
 delete (fm)
forrest@0
   113
forrest@0
   114
 ob_name = "GFEDv2"
forrest@0
   115
forrest@0
   116
; Units for these variables are:
forrest@0
   117
; g C/m^2/month
forrest@0
   118
forrest@0
   119
;-------------------------------------------------------------
forrest@0
   120
; html table1 data
forrest@0
   121
forrest@0
   122
; column (not including header column)
forrest@0
   123
forrest@0
   124
  col_head  = (/"Observed Fire_Flux (PgC/yr)" \
forrest@0
   125
               ,"Model Fire_Flux (PgC/yr)" \
forrest@0
   126
               ,"Correlation Coefficient" \
forrest@0
   127
               ,"Ratio model/observed" \
forrest@0
   128
               ,"M_score" \
forrest@0
   129
               ,"Timeseries plot" \
forrest@0
   130
               /)
forrest@0
   131
forrest@0
   132
  ncol = dimsizes(col_head)
forrest@0
   133
forrest@0
   134
; row (not including header row)                   
forrest@0
   135
forrest@0
   136
; using model biome class:  
forrest@0
   137
  row_head  = (/"Not Vegetated" \
forrest@0
   138
               ,"Needleleaf Evergreen Temperate Tree" \
forrest@0
   139
               ,"Needleleaf Evergreen Boreal Tree" \
forrest@0
   140
;              ,"Needleleaf Deciduous Boreal Tree" \
forrest@0
   141
               ,"Broadleaf Evergreen Tropical Tree" \
forrest@0
   142
               ,"Broadleaf Evergreen Temperate Tree" \
forrest@0
   143
               ,"Broadleaf Deciduous Tropical Tree" \
forrest@0
   144
               ,"Broadleaf Deciduous Temperate Tree" \
forrest@0
   145
;              ,"Broadleaf Deciduous Boreal Tree" \
forrest@0
   146
;              ,"Broadleaf Evergreen Shrub" \
forrest@0
   147
               ,"Broadleaf Deciduous Temperate Shrub" \
forrest@0
   148
               ,"Broadleaf Deciduous Boreal Shrub" \
forrest@0
   149
               ,"C3 Arctic Grass" \
forrest@0
   150
               ,"C3 Non-Arctic Grass" \
forrest@0
   151
               ,"C4 Grass" \
forrest@0
   152
               ,"Corn" \
forrest@0
   153
;              ,"Wheat" \                      
forrest@0
   154
               ,"All Biome" \                
forrest@0
   155
               /)  
forrest@0
   156
  nrow = dimsizes(row_head)                  
forrest@0
   157
forrest@0
   158
; arrays to be passed to table. 
forrest@0
   159
  text = new ((/nrow, ncol/),string ) 
forrest@0
   160
forrest@0
   161
;*****************************************************************
forrest@0
   162
; (A) get time-mean
forrest@0
   163
;*****************************************************************
forrest@0
   164
  
forrest@0
   165
  x          = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:))
forrest@0
   166
  data_mod_m = dim_avg_Wrap(       x(lat|:,lon|:,month|:))
forrest@0
   167
  delete (x)
forrest@0
   168
forrest@0
   169
  x          = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:))
forrest@0
   170
  data_ob_m  = dim_avg_Wrap(       x(lat|:,lon|:,month|:))
forrest@0
   171
  delete (x)
forrest@0
   172
forrest@0
   173
;----------------------------------------------------
forrest@0
   174
; compute correlation coef: space
forrest@0
   175
forrest@0
   176
  landmask_1d = ndtooned(landmask)
forrest@0
   177
  data_mod_1d = ndtooned(data_mod_m)
forrest@0
   178
  data_ob_1d  = ndtooned(data_ob_m )
forrest@0
   179
  area_1d     = ndtooned(area)
forrest@0
   180
  landfrac_1d = ndtooned(landfrac)
forrest@0
   181
forrest@0
   182
  good = ind(landmask_1d .gt. 0.)
forrest@0
   183
forrest@0
   184
  global_mod = sum(data_mod_1d(good)*area_1d(good)) * 1.e-15 * 12.
forrest@0
   185
  global_ob  = sum(data_ob_1d(good) *area_1d(good)) * 1.e-15 * 12.
forrest@0
   186
  print (global_mod)
forrest@0
   187
  print (global_ob)  
forrest@0
   188
forrest@0
   189
  global_area= sum(area_1d)
forrest@0
   190
  global_land= sum(area_1d(good))
forrest@0
   191
  print (global_area)
forrest@0
   192
  print (global_land)
forrest@0
   193
forrest@0
   194
  cc_space = esccr(data_mod_1d(good)*landfrac_1d(good),data_ob_1d(good)*landfrac_1d(good),0)
forrest@0
   195
forrest@0
   196
  delete (landmask_1d)
forrest@0
   197
  delete (landfrac_1d)
forrest@0
   198
; delete (area_1d)
forrest@0
   199
  delete (data_mod_1d)
forrest@0
   200
  delete (data_ob_1d)
forrest@0
   201
  delete (good)
forrest@0
   202
forrest@0
   203
;----------------------------------------------------
forrest@0
   204
; compute M_global
forrest@0
   205
forrest@0
   206
  score_max = 1.
forrest@0
   207
forrest@0
   208
  Mscore1 = cc_space * cc_space * score_max
forrest@0
   209
forrest@0
   210
  M_global = sprintf("%.2f", Mscore1)
forrest@0
   211
 
forrest@0
   212
;----------------------------------------------------
forrest@0
   213
; global res
forrest@0
   214
forrest@0
   215
  resg                      = True             ; Use plot options
forrest@0
   216
  resg@cnFillOn             = True             ; Turn on color fill
forrest@0
   217
  resg@gsnSpreadColors      = True             ; use full colormap
forrest@0
   218
  resg@cnLinesOn            = False            ; Turn off contourn lines
forrest@0
   219
  resg@mpFillOn             = False            ; Turn off map fill
forrest@0
   220
  resg@cnLevelSelectionMode = "ManualLevels"   ; Manual contour invtervals
forrest@0
   221
      
forrest@0
   222
;----------------------------------------------------
forrest@0
   223
; global contour: model vs ob
forrest@0
   224
forrest@0
   225
  plot_name = "global_model_vs_ob"
forrest@0
   226
forrest@0
   227
  wks = gsn_open_wks (plot_type,plot_name)   
forrest@0
   228
  gsn_define_colormap(wks,"gui_default")     
forrest@0
   229
forrest@0
   230
  plot=new(3,graphic)                        ; create graphic array
forrest@0
   231
forrest@0
   232
  resg@gsnFrame             = False          ; Do not draw plot 
forrest@0
   233
  resg@gsnDraw              = False          ; Do not advance frame
forrest@0
   234
forrest@0
   235
;----------------------
forrest@0
   236
; plot correlation coef
forrest@0
   237
forrest@0
   238
  gRes               = True
forrest@0
   239
  gRes@txFontHeightF = 0.02
forrest@0
   240
  gRes@txAngleF      = 90
forrest@0
   241
forrest@0
   242
  correlation_text = "(correlation coef = "+sprintf("%.2f", cc_space)+")"
forrest@0
   243
forrest@0
   244
  gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes)
forrest@0
   245
forrest@0
   246
;-----------------------  
forrest@0
   247
; plot ob
forrest@0
   248
forrest@0
   249
  data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue)
forrest@0
   250
forrest@0
   251
  title     = ob_name
forrest@0
   252
  resg@tiMainString  = title
forrest@0
   253
forrest@0
   254
  resg@cnMinLevelValF       = 1.             
forrest@0
   255
  resg@cnMaxLevelValF       = 10.             
forrest@0
   256
  resg@cnLevelSpacingF      = 1.
forrest@0
   257
forrest@0
   258
  plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg)       
forrest@0
   259
forrest@0
   260
;-----------------------
forrest@0
   261
; plot model
forrest@0
   262
forrest@0
   263
  data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue)
forrest@0
   264
forrest@0
   265
  title     = "Model "+ model_name
forrest@0
   266
  resg@tiMainString  = title
forrest@0
   267
forrest@0
   268
  resg@cnMinLevelValF       = 1.             
forrest@0
   269
  resg@cnMaxLevelValF       = 10.             
forrest@0
   270
  resg@cnLevelSpacingF      = 1.
forrest@0
   271
forrest@0
   272
  plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg) 
forrest@0
   273
forrest@0
   274
;-----------------------
forrest@0
   275
; plot model-ob
forrest@0
   276
forrest@0
   277
  resg@cnMinLevelValF  = -8.           
forrest@0
   278
  resg@cnMaxLevelValF  =  2.            
forrest@0
   279
  resg@cnLevelSpacingF =  1.
forrest@0
   280
forrest@0
   281
  zz = data_ob_m
forrest@0
   282
  zz = data_mod_m - data_ob_m
forrest@0
   283
  title = "Model_"+model_name+" - Observed"
forrest@0
   284
  resg@tiMainString    = title
forrest@0
   285
forrest@0
   286
  plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) 
forrest@0
   287
forrest@0
   288
; plot panel
forrest@0
   289
forrest@0
   290
  pres                            = True        ; panel plot mods desired
forrest@0
   291
  pres@gsnMaximize                = True        ; fill the page
forrest@0
   292
forrest@0
   293
  gsn_panel(wks,plot,(/3,1/),pres)              ; create panel plot
forrest@0
   294
forrest@0
   295
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   296
        "rm "+plot_name+"."+plot_type)
forrest@0
   297
forrest@0
   298
  clear (wks)
forrest@0
   299
  delete (plot)
forrest@0
   300
forrest@0
   301
  delete (data_ob_m)
forrest@0
   302
  delete (data_mod_m)
forrest@0
   303
  delete (zz)
forrest@0
   304
forrest@0
   305
  resg@gsnFrame             = True          ; Do advance frame 
forrest@0
   306
  resg@gsnDraw              = True          ; Do draw plot
forrest@0
   307
forrest@0
   308
;*******************************************************************
forrest@0
   309
; (B) Time series : per biome
forrest@0
   310
;*******************************************************************
forrest@0
   311
forrest@0
   312
 data_n = 2
forrest@0
   313
forrest@0
   314
 dsizes = dimsizes(data_mod)
forrest@0
   315
 nyear  = dsizes(0)
forrest@0
   316
 nmonth = dsizes(1)
forrest@0
   317
 ntime  = nyear * nmonth
forrest@0
   318
forrest@0
   319
 year_start = 1997
forrest@0
   320
 year_end   = 2004
forrest@0
   321
                
forrest@0
   322
;-------------------------------------------
forrest@0
   323
; Calculate "nice" bins for binning the data
forrest@0
   324
forrest@0
   325
; using model biome class
forrest@0
   326
  nclass = nclass_mod
forrest@0
   327
forrest@0
   328
  range  = fspan(0,nclass,nclass+1)
forrest@0
   329
forrest@0
   330
; Use this range information to grab all the values in a
forrest@0
   331
; particular range, and then take an average.
forrest@0
   332
forrest@0
   333
  nx = dimsizes(range) - 1
forrest@0
   334
forrest@0
   335
;-------------------------------------------
forrest@0
   336
; put data into bins
forrest@0
   337
forrest@0
   338
; using observed biome class
forrest@0
   339
; base  = ndtooned(classob)
forrest@0
   340
; using model biome class
forrest@0
   341
  base  = ndtooned(classmod)
forrest@0
   342
forrest@0
   343
; output
forrest@0
   344
forrest@0
   345
  area_bin = new((/nx/),float)
forrest@0
   346
  yvalues  = new((/ntime,data_n,nx/),float)
forrest@0
   347
forrest@0
   348
; Loop through each range, using base.
forrest@0
   349
forrest@0
   350
  do i=0,nx-1
forrest@0
   351
forrest@0
   352
     if (i.ne.(nx-1)) then
forrest@0
   353
        idx = ind((base.ge.range(i)).and.(base.lt.range(i+1)))
forrest@0
   354
     else
forrest@0
   355
        idx = ind(base.ge.range(i))
forrest@0
   356
     end if
forrest@0
   357
;---------------------
forrest@0
   358
;    for area  
forrest@0
   359
forrest@0
   360
     if (.not.any(ismissing(idx))) then 
forrest@0
   361
        area_bin(i) = sum(area_1d(idx))
forrest@0
   362
     else
forrest@0
   363
        area_bin(i) = area_bin@_FillValue
forrest@0
   364
     end if
forrest@0
   365
forrest@0
   366
;#############################################################
forrest@0
   367
; using model biome class:
forrest@0
   368
;     set the following 4 classes to _FillValue:
forrest@0
   369
;     (3)Needleleaf Deciduous Boreal Tree,
forrest@0
   370
;     (8)Broadleaf Deciduous Boreal Tree,
forrest@0
   371
;     (9)Broadleaf Evergreen Shrub,
forrest@0
   372
;     (16)Wheat
forrest@0
   373
forrest@0
   374
     if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then
forrest@0
   375
        area_bin(i) = area_bin@_FillValue
forrest@0
   376
     end if
forrest@0
   377
;#############################################################  
forrest@0
   378
forrest@0
   379
;---------------------
forrest@0
   380
; for data_mod and data_ob
forrest@0
   381
forrest@0
   382
  do n = 0,data_n-1
forrest@0
   383
forrest@0
   384
     t = -1
forrest@0
   385
     do m = 0,nyear-1
forrest@0
   386
     do k = 0,nmonth-1
forrest@0
   387
    
forrest@0
   388
        t = t + 1 
forrest@0
   389
forrest@0
   390
        if (n.eq.0) then
forrest@0
   391
           data = ndtooned(data_ob(m,k,:,:))
forrest@0
   392
        end if
forrest@0
   393
forrest@0
   394
        if (n.eq.1) then
forrest@0
   395
           data = ndtooned(data_mod(m,k,:,:))
forrest@0
   396
        end if
forrest@0
   397
forrest@0
   398
;       Calculate average
forrest@0
   399
 
forrest@0
   400
        if (.not.any(ismissing(idx))) then 
forrest@0
   401
           yvalues(t,n,i) = sum(data(idx)*area_1d(idx))
forrest@0
   402
        else
forrest@0
   403
           yvalues(t,n,i) = yvalues@_FillValue
forrest@0
   404
        end if
forrest@0
   405
forrest@0
   406
;#############################################################
forrest@0
   407
; using model biome class:
forrest@0
   408
;     set the following 4 classes to _FillValue:
forrest@0
   409
;     (3)Needleleaf Deciduous Boreal Tree,
forrest@0
   410
;     (8)Broadleaf Deciduous Boreal Tree,
forrest@0
   411
;     (9)Broadleaf Evergreen Shrub,
forrest@0
   412
;     (16)Wheat
forrest@0
   413
forrest@0
   414
        if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then
forrest@0
   415
           yvalues(t,n,i) = yvalues@_FillValue
forrest@0
   416
        end if
forrest@0
   417
;#############################################################  
forrest@0
   418
forrest@0
   419
     end do
forrest@0
   420
     end do
forrest@0
   421
forrest@0
   422
     delete(data)
forrest@0
   423
  end do 
forrest@0
   424
forrest@0
   425
    delete(idx)
forrest@0
   426
  end do
forrest@0
   427
forrest@0
   428
  delete (base)
forrest@0
   429
  delete (data_mod)
forrest@0
   430
  delete (data_ob)
forrest@0
   431
forrest@0
   432
  global_bin = sum(area_bin)
forrest@0
   433
  print (global_bin)
forrest@0
   434
forrest@0
   435
;----------------------------------------------------------------
forrest@0
   436
; get area_good
forrest@0
   437
forrest@0
   438
  good = ind(.not.ismissing(area_bin))
forrest@0
   439
forrest@0
   440
  area_g = area_bin(good)  
forrest@0
   441
forrest@0
   442
  n_biome = dimsizes(good)
forrest@0
   443
forrest@0
   444
  global_good = sum(area_g)
forrest@0
   445
  print (global_good)
forrest@0
   446
forrest@0
   447
;----------------------------------------------------------------
forrest@0
   448
; data for tseries plot
forrest@0
   449
forrest@0
   450
  yvalues_g = new((/ntime,data_n,n_biome/),float)
forrest@0
   451
forrest@0
   452
  yvalues_g@units = "TgC/month"
forrest@0
   453
forrest@0
   454
; change unit to Tg C/month
forrest@0
   455
; change unit from g to Tg (Tera gram)
forrest@0
   456
  factor_unit = 1.e-12
forrest@0
   457
forrest@0
   458
  yvalues_g = yvalues(:,:,good) * factor_unit
forrest@0
   459
forrest@0
   460
  delete (good)
forrest@0
   461
forrest@0
   462
;-------------------------------------------------------------------
forrest@0
   463
; general settings for line plot
forrest@0
   464
forrest@0
   465
  res                   = True               
forrest@0
   466
  res@xyDashPatterns    = (/0,0/)          ; make lines solid
forrest@0
   467
  res@xyLineThicknesses = (/2.0,2.0/)      ; make lines thicker
forrest@0
   468
  res@xyLineColors      = (/"blue","red"/) ; line color
forrest@0
   469
forrest@0
   470
  res@trXMinF   = year_start
forrest@0
   471
  res@trXMaxF   = year_end + 1
forrest@0
   472
forrest@0
   473
  res@vpHeightF = 0.4                 ; change aspect ratio of plot
forrest@0
   474
; res@vpWidthF  = 0.8
forrest@0
   475
  res@vpWidthF  = 0.75   
forrest@0
   476
forrest@0
   477
  res@tiMainFontHeightF = 0.025       ; size of title 
forrest@0
   478
forrest@0
   479
  res@tmXBFormat  = "f"               ; not to add trailing zeros
forrest@0
   480
forrest@0
   481
; res@gsnMaximize = True
forrest@0
   482
forrest@0
   483
;----------------------------------------------
forrest@0
   484
; Add a boxed legend using the simple method
forrest@0
   485
forrest@0
   486
  res@pmLegendDisplayMode    = "Always"
forrest@0
   487
; res@pmLegendWidthF         = 0.1
forrest@0
   488
  res@pmLegendWidthF         = 0.08
forrest@0
   489
  res@pmLegendHeightF        = 0.06
forrest@0
   490
  res@pmLegendOrthogonalPosF = -1.17
forrest@0
   491
; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   492
; res@pmLegendOrthogonalPosF = -0.30  ;(downward)
forrest@0
   493
forrest@0
   494
; res@pmLegendParallelPosF   =  0.18
forrest@0
   495
  res@pmLegendParallelPosF   =  0.23  ;(rightward)
forrest@0
   496
  res@pmLegendParallelPosF   =  0.73  ;(rightward)
forrest@0
   497
  res@pmLegendParallelPosF   =  0.83  ;(rightward)
forrest@0
   498
forrest@0
   499
; res@lgPerimOn             = False
forrest@0
   500
  res@lgLabelFontHeightF     = 0.015
forrest@0
   501
  res@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
   502
forrest@0
   503
;*******************************************************************
forrest@0
   504
; (A) time series plot: monthly ( 2 lines per plot)
forrest@0
   505
;*******************************************************************
forrest@0
   506
forrest@0
   507
; x-axis in time series plot
forrest@0
   508
forrest@0
   509
  timeI = new((/ntime/),integer)
forrest@0
   510
  timeF = new((/ntime/),float)
forrest@0
   511
  timeI = ispan(1,ntime,1)
forrest@0
   512
  timeF = year_start + (timeI-1)/12.
forrest@0
   513
  timeF@long_name = "year" 
forrest@0
   514
forrest@0
   515
  plot_data = new((/2,ntime/),float)
forrest@0
   516
  plot_data@long_name = "TgC/month"
forrest@0
   517
forrest@0
   518
;----------------------------------------------
forrest@0
   519
; time series plot : per biome
forrest@0
   520
 
forrest@0
   521
  do m = 0, n_biome-1
forrest@0
   522
forrest@0
   523
     plot_name = "monthly_biome_"+ m
forrest@0
   524
forrest@0
   525
     wks = gsn_open_wks (plot_type,plot_name)   
forrest@0
   526
forrest@0
   527
     title = "Fire : "+ row_head(m)
forrest@0
   528
     res@tiMainString = title
forrest@0
   529
forrest@0
   530
     plot_data(0,:) = yvalues_g(:,0,m)
forrest@0
   531
     plot_data(1,:) = yvalues_g(:,1,m)
forrest@0
   532
                                  
forrest@0
   533
     plot = gsn_csm_xy(wks,timeF,plot_data,res)
forrest@0
   534
forrest@0
   535
     system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   536
            "rm "+plot_name+"."+plot_type)
forrest@0
   537
forrest@0
   538
     clear (wks)  
forrest@0
   539
     delete (plot)
forrest@0
   540
   
forrest@0
   541
  end do
forrest@0
   542
forrest@0
   543
;------------------------------------------
forrest@0
   544
; data for table : per biome
forrest@0
   545
forrest@0
   546
; unit change from TgC/month to PgC/month
forrest@0
   547
  unit_factor = 1.e-3
forrest@0
   548
forrest@0
   549
  score_max = 1.
forrest@0
   550
forrest@0
   551
  tmp_ob    = new((/ntime/),float)
forrest@0
   552
  tmp_mod   = new((/ntime/),float)
forrest@0
   553
forrest@0
   554
  total_ob  = new((/n_biome/),float)
forrest@0
   555
  total_mod = new((/n_biome/),float)
forrest@0
   556
  Mscore2   = new((/n_biome/),float)
forrest@0
   557
forrest@0
   558
  do m = 0, n_biome-1
forrest@0
   559
forrest@0
   560
     tmp_ob  = yvalues_g(:,0,m) 
forrest@0
   561
     tmp_mod = yvalues_g(:,1,m) 
forrest@0
   562
forrest@0
   563
     total_ob(m)  = avg(month_to_annual(tmp_ob, 0)) * unit_factor 
forrest@0
   564
     total_mod(m) = avg(month_to_annual(tmp_mod,0)) * unit_factor
forrest@0
   565
     
forrest@0
   566
     cc_time = esccr(tmp_mod,tmp_ob,0)
forrest@0
   567
forrest@0
   568
     ratio = total_mod(m)/total_ob(m)
forrest@0
   569
forrest@0
   570
     good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.)
forrest@0
   571
forrest@0
   572
     bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) )
forrest@0
   573
     Mscore2(m) = (1.- (bias/dimsizes(good)))*score_max
forrest@0
   574
forrest@0
   575
     delete (good)
forrest@0
   576
     
forrest@0
   577
     text(m,0) = sprintf("%.2f",total_ob(m))
forrest@0
   578
     text(m,1) = sprintf("%.2f",total_mod(m))
forrest@0
   579
     text(m,2) = sprintf("%.2f",cc_time)
forrest@0
   580
     text(m,3) = sprintf("%.2f",ratio)
forrest@0
   581
     text(m,4) = sprintf("%.2f",Mscore2(m))
forrest@0
   582
     text(m,5) = "<a href=./monthly_biome_"+m+".png>model_vs_ob</a>" 
forrest@0
   583
  end do
forrest@0
   584
 
forrest@0
   585
  delete (tmp_ob)
forrest@0
   586
  delete (tmp_mod)
forrest@0
   587
forrest@0
   588
;--------------------------------------------
forrest@0
   589
; time series plot: all biome
forrest@0
   590
forrest@0
   591
     plot_name = "monthly_global"
forrest@0
   592
forrest@0
   593
     wks = gsn_open_wks (plot_type,plot_name)   
forrest@0
   594
forrest@0
   595
     title = "Fire : "+ row_head(n_biome)
forrest@0
   596
     res@tiMainString = title
forrest@0
   597
forrest@0
   598
     do k = 0,ntime-1
forrest@0
   599
        plot_data(0,k) = sum(yvalues_g(k,0,:))
forrest@0
   600
        plot_data(1,k) = sum(yvalues_g(k,1,:))
forrest@0
   601
     end do
forrest@0
   602
                                  
forrest@0
   603
     plot = gsn_csm_xy(wks,timeF,plot_data,res)
forrest@0
   604
forrest@0
   605
     system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   606
            "rm "+plot_name+"."+plot_type)
forrest@0
   607
forrest@0
   608
     clear (wks)  
forrest@0
   609
     delete (plot)
forrest@0
   610
forrest@0
   611
;------------------------------------------
forrest@0
   612
; data for table : global
forrest@0
   613
forrest@0
   614
  score_max = 1.
forrest@0
   615
forrest@0
   616
  tmp_ob  = ndtooned(yvalues_g(:,0,:))
forrest@0
   617
  tmp_mod = ndtooned(yvalues_g(:,1,:))
forrest@0
   618
forrest@0
   619
  cc_time = esccr(tmp_mod,tmp_ob,0)
forrest@0
   620
forrest@0
   621
  ratio = sum(total_mod)/sum(total_ob) 
forrest@0
   622
forrest@0
   623
  good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.)
forrest@0
   624
forrest@0
   625
  bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) )
forrest@0
   626
  Mscore3 = (1.- (bias/dimsizes(good)))*score_max
forrest@0
   627
forrest@0
   628
  print (Mscore3)
forrest@0
   629
forrest@0
   630
  delete (good) 
forrest@0
   631
forrest@0
   632
  text(nrow-1,0) = sprintf("%.2f",sum(total_ob))
forrest@0
   633
  text(nrow-1,1) = sprintf("%.2f",sum(total_mod))
forrest@0
   634
  text(nrow-1,2) = sprintf("%.2f",cc_time)
forrest@0
   635
  text(nrow-1,3) = sprintf("%.2f",ratio)
forrest@0
   636
; text(nrow-1,4) = sprintf("%.2f",avg(Mscore2))
forrest@0
   637
  text(nrow-1,4) = sprintf("%.2f",    Mscore3)
forrest@0
   638
  text(nrow-1,5) = "<a href=./monthly_global.png>model_vs_ob</a>"
forrest@0
   639
forrest@0
   640
;**************************************************
forrest@0
   641
; create html table
forrest@0
   642
;**************************************************
forrest@0
   643
forrest@0
   644
  header_text = "<H1>Fire Emission (1997-2004):  Model "+model_name+"</H1>" 
forrest@0
   645
forrest@0
   646
  header = (/"<HTML>" \
forrest@0
   647
            ,"<HEAD>" \
forrest@0
   648
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   649
            ,"</HEAD>" \
forrest@0
   650
            ,header_text \
forrest@0
   651
            /) 
forrest@0
   652
  footer = "</HTML>"
forrest@0
   653
forrest@0
   654
  table_header = (/ \
forrest@0
   655
        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
forrest@0
   656
       ,"<tr>" \
forrest@0
   657
       ,"   <th bgcolor=DDDDDD >Biome Type</th>" \
forrest@0
   658
       ,"   <th bgcolor=DDDDDD >"+col_head(0)+"</th>" \
forrest@0
   659
       ,"   <th bgcolor=DDDDDD >"+col_head(1)+"</th>" \
forrest@0
   660
       ,"   <th bgcolor=DDDDDD >"+col_head(2)+"</th>" \
forrest@0
   661
       ,"   <th bgcolor=DDDDDD >"+col_head(3)+"</th>" \
forrest@0
   662
       ,"   <th bgcolor=DDDDDD >"+col_head(4)+"</th>" \
forrest@0
   663
       ,"   <th bgcolor=DDDDDD >"+col_head(5)+"</th>" \
forrest@0
   664
       ,"</tr>" \
forrest@0
   665
       /)
forrest@0
   666
  table_footer = "</table>"
forrest@0
   667
  row_header = "<tr>"
forrest@0
   668
  row_footer = "</tr>"
forrest@0
   669
forrest@0
   670
  lines = new(50000,string)
forrest@0
   671
  nline = 0
forrest@0
   672
forrest@0
   673
  set_line(lines,nline,header)
forrest@0
   674
  set_line(lines,nline,table_header)
forrest@0
   675
;-----------------------------------------------
forrest@0
   676
;row of table
forrest@0
   677
forrest@0
   678
  do n = 0,nrow-1
forrest@0
   679
     set_line(lines,nline,row_header)
forrest@0
   680
forrest@0
   681
     txt0  = row_head(n)
forrest@0
   682
     txt1  = text(n,0)
forrest@0
   683
     txt2  = text(n,1)
forrest@0
   684
     txt3  = text(n,2)
forrest@0
   685
     txt4  = text(n,3)
forrest@0
   686
     txt5  = text(n,4)
forrest@0
   687
     txt6  = text(n,5)
forrest@0
   688
forrest@0
   689
     set_line(lines,nline,"<th>"+txt0+"</th>")
forrest@0
   690
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   691
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   692
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   693
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   694
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   695
     set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   696
forrest@0
   697
     set_line(lines,nline,row_footer)
forrest@0
   698
  end do
forrest@0
   699
;-----------------------------------------------
forrest@0
   700
  set_line(lines,nline,table_footer)
forrest@0
   701
  set_line(lines,nline,footer) 
forrest@0
   702
forrest@0
   703
; Now write to an HTML file.
forrest@0
   704
forrest@0
   705
  output_html = "table_fire.html"
forrest@0
   706
forrest@0
   707
  idx = ind(.not.ismissing(lines))
forrest@0
   708
  if(.not.any(ismissing(idx))) then
forrest@0
   709
    asciiwrite(output_html,lines(idx))
forrest@0
   710
  else
forrest@0
   711
   print ("error?")
forrest@0
   712
  end if
forrest@0
   713
forrest@0
   714
  delete (idx)
forrest@0
   715
forrest@0
   716
end
forrest@0
   717