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