lai/99.all.ncl.new
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
; remove histogram plots.
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.test"
forrest@0
    10
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
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
; read data: model       
forrest@0
    36
;************************************************
forrest@0
    37
forrest@0
    38
;film  = "b30.061n_1995-2004_MONS_climo_lnd.nc"
forrest@0
    39
;model_name = "b30.061n"
forrest@0
    40
;model_grid = "T31"
forrest@0
    41
forrest@0
    42
;film  = "newcn05_ncep_1i_MONS_climo_lnd.nc"
forrest@0
    43
;model_name = "newcn"
forrest@0
    44
;model_grid = "1.9"
forrest@0
    45
forrest@0
    46
;film  = "i01.06cn_1798-2004_MONS_climo.nc"
forrest@0
    47
;model_name = "06cn"
forrest@0
    48
;model_grid = "T42"
forrest@0
    49
forrest@0
    50
;film  = "i01.06casa_1798-2004_MONS_climo.nc"
forrest@0
    51
;model_name = "06casa"
forrest@0
    52
;model_grid = "T42"
forrest@0
    53
forrest@0
    54
 film  = "i01.10cn_1948-2004_MONS_climo.nc"
forrest@0
    55
 model_name = "10cn"
forrest@0
    56
 model_grid = "T42"
forrest@0
    57
forrest@0
    58
;film  = "i01.10casa_1948-2004_MONS_climo.nc"
forrest@0
    59
;model_name = "10casa"
forrest@0
    60
;model_grid = "T42"
forrest@0
    61
forrest@0
    62
 dirm  = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    63
 fm    = addfile(dirm+film,"r")
forrest@0
    64
      
forrest@0
    65
 laimod  = fm->TLAI
forrest@0
    66
      
forrest@0
    67
;************************************************
forrest@0
    68
; read data: observed
forrest@0
    69
;************************************************
forrest@0
    70
forrest@0
    71
  ob_name = "MODIS MOD 15A2 2000-2005"
forrest@0
    72
forrest@0
    73
  diro  = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/"
forrest@0
    74
  filo1  = "land_class_"+model_grid+".nc"
forrest@0
    75
  filo2  = "LAI_2000-2005_MONS_"+model_grid+".nc"
forrest@0
    76
forrest@0
    77
  fo1 = addfile(diro+filo1,"r")
forrest@0
    78
  fo2 = addfile(diro+filo2,"r")
forrest@0
    79
 
forrest@0
    80
  classob    = tofloat(fo1->LAND_CLASS)               
forrest@0
    81
  laiob      = fo2->LAI
forrest@0
    82
forrest@0
    83
; input observed data has 20 land-type classes
forrest@0
    84
  nclass = 20
forrest@0
    85
forrest@0
    86
;************************************************
forrest@0
    87
; global res
forrest@0
    88
;************************************************
forrest@0
    89
  resg                      = True             ; Use plot options
forrest@0
    90
  resg@cnFillOn             = True             ; Turn on color fill
forrest@0
    91
  resg@gsnSpreadColors      = True             ; use full colormap
forrest@0
    92
  resg@cnLinesOn            = False            ; Turn off contourn lines
forrest@0
    93
  resg@mpFillOn             = False            ; Turn off map fill
forrest@0
    94
  resg@cnLevelSelectionMode = "ManualLevels"   ; Manual contour invtervals
forrest@0
    95
forrest@0
    96
;************************************************
forrest@0
    97
; plot global land class: observed
forrest@0
    98
;************************************************
forrest@0
    99
forrest@0
   100
  resg@cnMinLevelValF       = 1.              ; Min level
forrest@0
   101
  resg@cnMaxLevelValF       = 19.             ; Max level
forrest@0
   102
  resg@cnLevelSpacingF      = 1.              ; interval
forrest@0
   103
forrest@0
   104
; global contour ob
forrest@0
   105
  classob@_FillValue = 1.e+36
forrest@0
   106
  classob = where(classob.eq.0,classob@_FillValue,classob)
forrest@0
   107
  
forrest@0
   108
  plot_name = "global_class_ob"
forrest@0
   109
  title     = ob_name
forrest@0
   110
  resg@tiMainString  = title
forrest@0
   111
forrest@0
   112
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
   113
  gsn_define_colormap(wks,"gui_default")     ; choose colormap
forrest@0
   114
forrest@0
   115
  plot = gsn_csm_contour_map_ce(wks,classob,resg)   
forrest@0
   116
  frame(wks)
forrest@0
   117
forrest@0
   118
  clear (wks)
forrest@0
   119
 
forrest@0
   120
;*******************************************************************
forrest@0
   121
; for html table : all 4 components (Mean, Max, Phase, Growth)
forrest@0
   122
;*******************************************************************
forrest@0
   123
forrest@0
   124
; column (not including header column)
forrest@0
   125
forrest@0
   126
  component = (/"Mean","Max","Phase","Growth"/)
forrest@0
   127
  col_head2 = (/"observed",model_name,"M_score" \
forrest@0
   128
               ,"observed",model_name,"M_score" \
forrest@0
   129
               ,"observed",model_name,"M_score" \
forrest@0
   130
               ,"observed",model_name,"M_score" \
forrest@0
   131
               /)
forrest@0
   132
  
forrest@0
   133
  n_comp = dimsizes(component) 
forrest@0
   134
  ncol   = dimsizes(col_head2)
forrest@0
   135
forrest@0
   136
; row (not including header row)
forrest@0
   137
  row_head  = (/"Evergreen Needleleaf Forests" \
forrest@0
   138
               ,"Evergreen Broadleaf Forests" \
forrest@0
   139
               ,"Deciduous Needleleaf Forest" \
forrest@0
   140
               ,"Deciduous Broadleaf Forests" \
forrest@0
   141
               ,"Mixed Forests" \                      
forrest@0
   142
               ,"Closed Bushlands" \                   
forrest@0
   143
               ,"Open Bushlands" \                     
forrest@0
   144
               ,"Woody Savannas (S. Hem.)" \           
forrest@0
   145
               ,"Savannas (S. Hem.)" \                 
forrest@0
   146
               ,"Grasslands" \                         
forrest@0
   147
               ,"Permanent Wetlands" \                 
forrest@0
   148
               ,"Croplands" \                                           
forrest@0
   149
               ,"Cropland/Natural Vegetation Mosaic" \             
forrest@0
   150
               ,"Barren or Sparsely Vegetated" \                             
forrest@0
   151
               ,"Woody Savannas (N. Hem.)" \           
forrest@0
   152
               ,"Savannas (N. Hem.)" \
forrest@0
   153
               ,"All Biome" \                
forrest@0
   154
               /)  
forrest@0
   155
  nrow = dimsizes(row_head)                  
forrest@0
   156
forrest@0
   157
; arrays to be passed to table. 
forrest@0
   158
  text4 = new ((/nrow, ncol/),string )
forrest@0
   159
forrest@0
   160
; M_comp
forrest@0
   161
  M_comp = (/"M_lai_mean","M_lai_max","M_lai_phase","M_lai_grow"/) 
forrest@0
   162
forrest@0
   163
; total M_score
forrest@0
   164
  M_total = 0.
forrest@0
   165
forrest@0
   166
;********************************************************************
forrest@0
   167
; use land-type class to bin the data in equally spaced ranges
forrest@0
   168
;********************************************************************
forrest@0
   169
forrest@0
   170
  nclassn     = nclass + 1
forrest@0
   171
  range       = fspan(0,nclassn-1,nclassn)
forrest@0
   172
; print (range)
forrest@0
   173
forrest@0
   174
; Use this range information to grab all the values in a
forrest@0
   175
; particular range, and then take an average.
forrest@0
   176
forrest@0
   177
  nr           = dimsizes(range)
forrest@0
   178
  nx           = nr-1
forrest@0
   179
  xvalues      = new((/2,nx/),float)
forrest@0
   180
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
   181
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
   182
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
   183
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
   184
forrest@0
   185
;************************************************************************
forrest@0
   186
; go through all components
forrest@0
   187
;************************************************************************
forrest@0
   188
forrest@0
   189
  do n = 0,n_comp-1
forrest@0
   190
forrest@0
   191
;===================
forrest@0
   192
; get data:
forrest@0
   193
;===================
forrest@0
   194
; (A) Mean
forrest@0
   195
 
forrest@0
   196
  if (n .eq. 0) then
forrest@0
   197
     data_ob  = dim_avg_Wrap(laiob (lat|:,lon|:,time|:))
forrest@0
   198
     data_mod = dim_avg_Wrap(laimod(lat|:,lon|:,time|:))
forrest@0
   199
  end if
forrest@0
   200
forrest@0
   201
; (B) Max
forrest@0
   202
forrest@0
   203
  if (n .eq. 1) then
forrest@0
   204
forrest@0
   205
;    observed  
forrest@0
   206
     data_ob = laiob(0,:,:)
forrest@0
   207
     s       = laiob(:,0,0)
forrest@0
   208
     data_ob@long_name = "Leaf Area Index Max"
forrest@0
   209
 
forrest@0
   210
     dsizes_z = dimsizes(laiob)
forrest@0
   211
     nlat     = dsizes_z(1)
forrest@0
   212
     nlon     = dsizes_z(2)
forrest@0
   213
  
forrest@0
   214
     do j = 0,nlat-1
forrest@0
   215
     do i = 0,nlon-1
forrest@0
   216
        s = laiob(:,j,i) 
forrest@0
   217
        data_ob(j,i) = max(s)
forrest@0
   218
     end do
forrest@0
   219
     end do
forrest@0
   220
forrest@0
   221
     delete (s)
forrest@0
   222
     delete (dsizes_z)          
forrest@0
   223
forrest@0
   224
;    model  
forrest@0
   225
     data_mod = laimod(0,:,:)
forrest@0
   226
     s        = laimod(:,0,0)
forrest@0
   227
     data_mod@long_name = "Leaf Area Index Max"
forrest@0
   228
 
forrest@0
   229
     dsizes_z = dimsizes(laimod)
forrest@0
   230
     nlat     = dsizes_z(1)
forrest@0
   231
     nlon     = dsizes_z(2)
forrest@0
   232
  
forrest@0
   233
     do j = 0,nlat-1
forrest@0
   234
     do i = 0,nlon-1
forrest@0
   235
        s = laimod(:,j,i) 
forrest@0
   236
        data_mod(j,i) = max(s)
forrest@0
   237
     end do
forrest@0
   238
     end do
forrest@0
   239
forrest@0
   240
     delete (s)
forrest@0
   241
     delete (dsizes_z)          
forrest@0
   242
  end if
forrest@0
   243
forrest@0
   244
; (C) phase
forrest@0
   245
forrest@0
   246
  if (n .eq. 2) then  
forrest@0
   247
forrest@0
   248
;    observed
forrest@0
   249
     data_ob = laiob(0,:,:)
forrest@0
   250
     s       = laiob(:,0,0)
forrest@0
   251
     data_ob@long_name = "Leaf Area Index Max Month"
forrest@0
   252
 
forrest@0
   253
     dsizes_z = dimsizes(laiob)
forrest@0
   254
     nlat     = dsizes_z(1)
forrest@0
   255
     nlon     = dsizes_z(2)
forrest@0
   256
  
forrest@0
   257
     do j = 0,nlat-1
forrest@0
   258
     do i = 0,nlon-1
forrest@0
   259
        s = laiob(:,j,i) 
forrest@0
   260
        data_ob(j,i) = maxind(s) + 1
forrest@0
   261
     end do
forrest@0
   262
     end do
forrest@0
   263
forrest@0
   264
     delete (s)
forrest@0
   265
     delete (dsizes_z)          
forrest@0
   266
forrest@0
   267
;    model
forrest@0
   268
     data_mod = laimod(0,:,:)
forrest@0
   269
     s        = laimod(:,0,0)
forrest@0
   270
     data_mod@long_name = "Leaf Area Index Max Month"
forrest@0
   271
 
forrest@0
   272
     dsizes_z = dimsizes(laimod)
forrest@0
   273
     nlat     = dsizes_z(1)
forrest@0
   274
     nlon     = dsizes_z(2)
forrest@0
   275
  
forrest@0
   276
     do j = 0,nlat-1
forrest@0
   277
     do i = 0,nlon-1
forrest@0
   278
        s = laimod(:,j,i) 
forrest@0
   279
        data_mod(j,i) = maxind(s) + 1
forrest@0
   280
     end do
forrest@0
   281
     end do
forrest@0
   282
forrest@0
   283
     delete (s)
forrest@0
   284
     delete (dsizes_z)          
forrest@0
   285
  end if
forrest@0
   286
forrest@0
   287
; (D) grow day
forrest@0
   288
forrest@0
   289
  if (n .eq. 3) then   
forrest@0
   290
forrest@0
   291
     day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/)
forrest@0
   292
forrest@0
   293
;    observed
forrest@0
   294
     data_ob = laiob(0,:,:)
forrest@0
   295
     data_ob@long_name = "Days of Growing Season"
forrest@0
   296
 
forrest@0
   297
     dsizes_z = dimsizes(laiob)
forrest@0
   298
     ntime    = dsizes_z(0)
forrest@0
   299
     nlat     = dsizes_z(1)
forrest@0
   300
     nlon     = dsizes_z(2)
forrest@0
   301
  
forrest@0
   302
     do j = 0,nlat-1
forrest@0
   303
     do i = 0,nlon-1
forrest@0
   304
        nday = 0.
forrest@0
   305
        do k = 0,ntime-1
forrest@0
   306
           if (.not. ismissing(laiob(k,j,i)) .and. laiob(k,j,i) .gt. 1.0) then
forrest@0
   307
              nday = nday + day_of_data(k)
forrest@0
   308
           end if
forrest@0
   309
        end do
forrest@0
   310
forrest@0
   311
        data_ob(j,i) = nday
forrest@0
   312
     end do
forrest@0
   313
     end do
forrest@0
   314
forrest@0
   315
     delete (dsizes_z)     
forrest@0
   316
forrest@0
   317
;    model
forrest@0
   318
     data_mod = laimod(0,:,:)
forrest@0
   319
     data_mod@long_name = "Days of Growing Season"
forrest@0
   320
 
forrest@0
   321
     dsizes_z = dimsizes(laimod)
forrest@0
   322
     ntime    = dsizes_z(0)
forrest@0
   323
     nlat     = dsizes_z(1)
forrest@0
   324
     nlon     = dsizes_z(2)
forrest@0
   325
  
forrest@0
   326
     do j = 0,nlat-1
forrest@0
   327
     do i = 0,nlon-1
forrest@0
   328
        nday = 0.
forrest@0
   329
        do k = 0,ntime-1
forrest@0
   330
           if (.not. ismissing(laimod(k,j,i)) .and. laimod(k,j,i) .gt. 1.0) then
forrest@0
   331
              nday = nday + day_of_data(k)
forrest@0
   332
           end if
forrest@0
   333
        end do
forrest@0
   334
forrest@0
   335
        data_mod(j,i) = nday
forrest@0
   336
     end do
forrest@0
   337
     end do
forrest@0
   338
forrest@0
   339
     delete (dsizes_z)
forrest@0
   340
  end if
forrest@0
   341
forrest@0
   342
;==============================
forrest@0
   343
; put data into bins
forrest@0
   344
;==============================
forrest@0
   345
forrest@0
   346
  base_1D  = ndtooned(classob)
forrest@0
   347
  data1_1D = ndtooned(data_ob)
forrest@0
   348
  data2_1D = ndtooned(data_mod)
forrest@0
   349
forrest@0
   350
; output for data in bins
forrest@0
   351
forrest@0
   352
  yvalues = new((/2,nx/),float)
forrest@0
   353
  count   = new((/2,nx/),float)
forrest@0
   354
forrest@0
   355
; put data into bins
forrest@0
   356
forrest@0
   357
  do nd=0,1
forrest@0
   358
forrest@0
   359
;   See if we are doing data1 (nd=0) or data2 (nd=1).
forrest@0
   360
forrest@0
   361
    base = base_1D
forrest@0
   362
forrest@0
   363
    if(nd.eq.0) then
forrest@0
   364
      data = data1_1D
forrest@0
   365
    else
forrest@0
   366
      data = data2_1D
forrest@0
   367
    end if
forrest@0
   368
forrest@0
   369
;   Loop through each range, using base.
forrest@0
   370
forrest@0
   371
    do i=0,nr-2
forrest@0
   372
      if (i.ne.(nr-2)) then
forrest@0
   373
;        print("")
forrest@0
   374
;        print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
   375
         idx = ind((base.ge.range(i)).and.(base.lt.range(i+1)))
forrest@0
   376
      else
forrest@0
   377
;        print("")
forrest@0
   378
;        print("In range ["+range(i)+",)")
forrest@0
   379
         idx = ind(base.ge.range(i))
forrest@0
   380
      end if
forrest@0
   381
forrest@0
   382
;     Calculate average 
forrest@0
   383
forrest@0
   384
      if(.not.any(ismissing(idx))) then
forrest@0
   385
        yvalues(nd,i) = avg(data(idx))
forrest@0
   386
        count(nd,i)   = dimsizes(idx)
forrest@0
   387
      else
forrest@0
   388
        yvalues(nd,i) = yvalues@_FillValue
forrest@0
   389
        count(nd,i)   = 0
forrest@0
   390
      end if
forrest@0
   391
forrest@0
   392
;#############################################################
forrest@0
   393
;     set the following 4 classes to _FillValue:
forrest@0
   394
;     Water Bodies(0), Urban and Build-Up(13),
forrest@0
   395
;     Permenant Snow and Ice(15), Unclassified(17)
forrest@0
   396
forrest@0
   397
      if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then
forrest@0
   398
         yvalues(nd,i) = yvalues@_FillValue
forrest@0
   399
         count(nd,i)   = 0
forrest@0
   400
      end if
forrest@0
   401
;############################################################# 
forrest@0
   402
forrest@0
   403
;     print(nd + ": " + count(nd,i) + " points, avg = " + yvalues(nd,i))
forrest@0
   404
forrest@0
   405
;     Clean up for next time in loop.
forrest@0
   406
forrest@0
   407
      delete(idx)
forrest@0
   408
    end do
forrest@0
   409
forrest@0
   410
    delete(data)
forrest@0
   411
  end do
forrest@0
   412
forrest@0
   413
  delete (base)
forrest@0
   414
  delete (base_1D)
forrest@0
   415
  delete (data1_1D)
forrest@0
   416
  delete (data2_1D)
forrest@0
   417
forrest@0
   418
;=====================================
forrest@0
   419
; compute correlation coef and M score 
forrest@0
   420
;=====================================
forrest@0
   421
forrest@0
   422
  u = yvalues(0,:)
forrest@0
   423
  v = yvalues(1,:)
forrest@0
   424
forrest@0
   425
  good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   426
  uu = u(good)
forrest@0
   427
  vv = v(good)
forrest@0
   428
forrest@0
   429
; compute correlation coef
forrest@0
   430
  cc = esccr(uu,vv,0)
forrest@0
   431
forrest@0
   432
  if (n .eq. 2) then
forrest@0
   433
     bias   = avg(abs(vv-uu))
forrest@0
   434
     bias   = where((bias.gt. 6.),12.-bias,bias)
forrest@0
   435
     Mscore = ((6. - bias)/6.)*5.
forrest@0
   436
     M_score = sprintf("%.2f", Mscore)
forrest@0
   437
  else
forrest@0
   438
     bias  = sum(abs(vv-uu)/abs(vv+uu))
forrest@0
   439
     Mscore = (1.- (bias/dimsizes(uu)))*5.
forrest@0
   440
     M_score = sprintf("%.2f", Mscore)
forrest@0
   441
  end if
forrest@0
   442
forrest@0
   443
; compute M_total
forrest@0
   444
  
forrest@0
   445
  M_total = M_total + Mscore
forrest@0
   446
forrest@0
   447
;==================
forrest@0
   448
; output M_score
forrest@0
   449
;==================
forrest@0
   450
forrest@0
   451
  print (Mscore)
forrest@0
   452
;=======================
forrest@0
   453
; output to html table
forrest@0
   454
;=======================
forrest@0
   455
forrest@0
   456
  nn = n*3
forrest@0
   457
forrest@0
   458
  do i=0,nrow-2
forrest@0
   459
     text4(i,nn)   = sprintf("%.2f",u(i))
forrest@0
   460
     text4(i,nn+1) = sprintf("%.2f",v(i))
forrest@0
   461
     text4(i,nn+2) = "-"
forrest@0
   462
  end do
forrest@0
   463
  text4(nrow-1,nn)   = sprintf("%.2f",avg(u))
forrest@0
   464
  text4(nrow-1,nn+1) = sprintf("%.2f",avg(v))
forrest@0
   465
  text4(nrow-1,nn+2) = M_score
forrest@0
   466
forrest@0
   467
  delete (u)
forrest@0
   468
  delete (v)
forrest@0
   469
  delete (uu)
forrest@0
   470
  delete (vv)
forrest@0
   471
  delete (yvalues)
forrest@0
   472
  delete (good)
forrest@0
   473
forrest@0
   474
;======================================== 
forrest@0
   475
; global res changes for each component
forrest@0
   476
;========================================
forrest@0
   477
  delta = 0.00001  
forrest@0
   478
forrest@0
   479
  if (n .eq. 0) then
forrest@0
   480
     resg@cnMinLevelValF       = 0.             
forrest@0
   481
     resg@cnMaxLevelValF       = 10.             
forrest@0
   482
     resg@cnLevelSpacingF      = 1.
forrest@0
   483
forrest@0
   484
     data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
forrest@0
   485
  end if
forrest@0
   486
forrest@0
   487
  if (n .eq. 1) then
forrest@0
   488
     resg@cnMinLevelValF       = 0.             
forrest@0
   489
     resg@cnMaxLevelValF       = 10.             
forrest@0
   490
     resg@cnLevelSpacingF      = 1.
forrest@0
   491
forrest@0
   492
     data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
forrest@0
   493
  end if
forrest@0
   494
forrest@0
   495
  if (n .eq. 2) then
forrest@0
   496
     resg@cnMinLevelValF       = 1.             
forrest@0
   497
     resg@cnMaxLevelValF       = 12.             
forrest@0
   498
     resg@cnLevelSpacingF      = 1.
forrest@0
   499
forrest@0
   500
     data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
forrest@0
   501
  end if
forrest@0
   502
forrest@0
   503
  if (n .eq. 3) then
forrest@0
   504
     resg@cnMinLevelValF       = 60.             
forrest@0
   505
     resg@cnMaxLevelValF       = 360.             
forrest@0
   506
     resg@cnLevelSpacingF      = 20.
forrest@0
   507
forrest@0
   508
     data_ob@_FillValue = 1.e+36
forrest@0
   509
     data_ob = where(data_ob .lt. 10.,data_ob@_FillValue,data_ob)
forrest@0
   510
forrest@0
   511
     data_mod@_FillValue = 1.e+36
forrest@0
   512
     data_mod = where(data_mod .lt. 10.,data_mod@_FillValue,data_mod)        
forrest@0
   513
  end if                                                        
forrest@0
   514
forrest@0
   515
;=========================
forrest@0
   516
; global contour : ob
forrest@0
   517
;=========================
forrest@0
   518
  
forrest@0
   519
  plot_name = "global_"+component(n)+"_ob"
forrest@0
   520
  title     = ob_name
forrest@0
   521
  resg@tiMainString  = title
forrest@0
   522
forrest@0
   523
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
   524
  gsn_define_colormap(wks,"gui_default")     ; choose colormap
forrest@0
   525
forrest@0
   526
  plot = gsn_csm_contour_map_ce(wks,data_ob,resg)   
forrest@0
   527
  frame(wks)
forrest@0
   528
forrest@0
   529
  clear (wks)
forrest@0
   530
  delete (plot)
forrest@0
   531
forrest@0
   532
;============================
forrest@0
   533
; global contour : model
forrest@0
   534
;============================
forrest@0
   535
forrest@0
   536
  plot_name = "global_"+component(n)+"_model"  
forrest@0
   537
  title     = "Model " + model_name
forrest@0
   538
  resg@tiMainString  = title
forrest@0
   539
forrest@0
   540
  wks = gsn_open_wks (plot_type,plot_name)
forrest@0
   541
  gsn_define_colormap(wks,"gui_default")     
forrest@0
   542
forrest@0
   543
  plot = gsn_csm_contour_map_ce(wks,data_mod,resg)   
forrest@0
   544
  frame(wks)
forrest@0
   545
forrest@0
   546
  clear (wks)
forrest@0
   547
  delete (plot)
forrest@0
   548
forrest@0
   549
;================================
forrest@0
   550
; global contour: model vs ob
forrest@0
   551
;================================
forrest@0
   552
forrest@0
   553
  plot_name = "global_"+component(n)+"_model_vs_ob"
forrest@0
   554
forrest@0
   555
  wks = gsn_open_wks (plot_type,plot_name)   
forrest@0
   556
  gsn_define_colormap(wks,"gui_default")     
forrest@0
   557
forrest@0
   558
  plot=new(3,graphic)                        ; create graphic array
forrest@0
   559
forrest@0
   560
  resg@gsnFrame             = False          ; Do not draw plot 
forrest@0
   561
  resg@gsnDraw              = False          ; Do not advance frame
forrest@0
   562
forrest@0
   563
; plot correlation coef
forrest@0
   564
forrest@0
   565
  gRes               = True
forrest@0
   566
  gRes@txFontHeightF = 0.02
forrest@0
   567
  gRes@txAngleF      = 90
forrest@0
   568
forrest@0
   569
  correlation_text = "(correlation coef = "+sprintf("%.2f", cc)+")"
forrest@0
   570
forrest@0
   571
  gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes)
forrest@0
   572
  
forrest@0
   573
; plot ob
forrest@0
   574
forrest@0
   575
  title     = ob_name
forrest@0
   576
  resg@tiMainString  = title
forrest@0
   577
forrest@0
   578
  plot(0) = gsn_csm_contour_map_ce(wks,data_ob,resg)       
forrest@0
   579
forrest@0
   580
; plot model
forrest@0
   581
forrest@0
   582
  title     = "Model "+ model_name
forrest@0
   583
  resg@tiMainString  = title
forrest@0
   584
forrest@0
   585
  plot(1) = gsn_csm_contour_map_ce(wks,data_mod,resg) 
forrest@0
   586
forrest@0
   587
; plot model-ob
forrest@0
   588
forrest@0
   589
  if (n .eq. 0) then
forrest@0
   590
     resg@cnMinLevelValF  = -2.           
forrest@0
   591
     resg@cnMaxLevelValF  =  2.            
forrest@0
   592
     resg@cnLevelSpacingF =  0.4
forrest@0
   593
  end if
forrest@0
   594
forrest@0
   595
  if (n .eq. 1) then
forrest@0
   596
     resg@cnMinLevelValF  = -6.           
forrest@0
   597
     resg@cnMaxLevelValF  =  6.            
forrest@0
   598
     resg@cnLevelSpacingF =  1.
forrest@0
   599
  end if
forrest@0
   600
forrest@0
   601
  if (n .eq. 2) then
forrest@0
   602
     resg@cnMinLevelValF  = -6.           
forrest@0
   603
     resg@cnMaxLevelValF  =  6.            
forrest@0
   604
     resg@cnLevelSpacingF =  1.
forrest@0
   605
  end if
forrest@0
   606
forrest@0
   607
  if (n .eq. 3) then
forrest@0
   608
     resg@cnMinLevelValF  = -100.           
forrest@0
   609
     resg@cnMaxLevelValF  =  100.            
forrest@0
   610
     resg@cnLevelSpacingF =  20.
forrest@0
   611
  end if            
forrest@0
   612
forrest@0
   613
  zz = data_mod
forrest@0
   614
  zz = data_mod - data_ob
forrest@0
   615
  title = "Model_"+model_name+" - Observed"
forrest@0
   616
  resg@tiMainString    = title
forrest@0
   617
forrest@0
   618
  plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) 
forrest@0
   619
forrest@0
   620
; plot panel
forrest@0
   621
forrest@0
   622
  pres                            = True        ; panel plot mods desired
forrest@0
   623
  pres@gsnMaximize                = True        ; fill the page
forrest@0
   624
forrest@0
   625
  gsn_panel(wks,plot,(/3,1/),pres)              ; create panel plot
forrest@0
   626
forrest@0
   627
  clear (wks)
forrest@0
   628
  delete (plot)
forrest@0
   629
forrest@0
   630
  end do
forrest@0
   631
;**************************************************
forrest@0
   632
; html table
forrest@0
   633
;**************************************************
forrest@0
   634
  output_html = "table_model_vs_ob.html"
forrest@0
   635
forrest@0
   636
  header_text = "<H1>LAI: Model "+model_name+" vs Observed</H1>" 
forrest@0
   637
forrest@0
   638
  header = (/"<HTML>" \
forrest@0
   639
            ,"<HEAD>" \
forrest@0
   640
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   641
            ,"</HEAD>" \
forrest@0
   642
            ,header_text \
forrest@0
   643
            /) 
forrest@0
   644
  footer = "</HTML>"
forrest@0
   645
forrest@0
   646
  table_header = (/ \
forrest@0
   647
        "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
forrest@0
   648
       ,"<tr>" \
forrest@0
   649
       ,"   <th bgcolor=DDDDDD rowspan=2>Biome Class</th>" \
forrest@0
   650
       ,"   <th bgcolor=DDDDDD colspan=3>"+component(0)+"</th>" \
forrest@0
   651
       ,"   <th bgcolor=DDDDDD colspan=3>"+component(1)+"</th>" \
forrest@0
   652
       ,"   <th bgcolor=DDDDDD colspan=3>"+component(2)+"</th>" \
forrest@0
   653
       ,"   <th bgcolor=DDDDDD colspan=3>"+component(3)+"</th>" \
forrest@0
   654
       ,"</tr>" \
forrest@0
   655
       ,"<tr>" \
forrest@0
   656
       ,"   <th bgcolor=DDDDDD >observed</th>" \
forrest@0
   657
       ,"   <th bgcolor=DDDDDD >"+model_name+"</th>" \
forrest@0
   658
       ,"   <th bgcolor=DDDDDD >M_score</th>" \
forrest@0
   659
       ,"   <th bgcolor=DDDDDD >observed</th>" \
forrest@0
   660
       ,"   <th bgcolor=DDDDDD >"+model_name+"</th>" \
forrest@0
   661
       ,"   <th bgcolor=DDDDDD >M_score</th>" \
forrest@0
   662
       ,"   <th bgcolor=DDDDDD >observed</th>" \
forrest@0
   663
       ,"   <th bgcolor=DDDDDD >"+model_name+"</th>" \
forrest@0
   664
       ,"   <th bgcolor=DDDDDD >M_score</th>" \
forrest@0
   665
       ,"   <th bgcolor=DDDDDD >observed</th>" \
forrest@0
   666
       ,"   <th bgcolor=DDDDDD >"+model_name+"</th>" \
forrest@0
   667
       ,"   <th bgcolor=DDDDDD >M_score</th>" \
forrest@0
   668
       ,"</tr>" \
forrest@0
   669
       /)
forrest@0
   670
  table_footer = "</table>"
forrest@0
   671
  row_header = "<tr>"
forrest@0
   672
  row_footer = "</tr>"
forrest@0
   673
forrest@0
   674
  lines = new(50000,string)
forrest@0
   675
  nline = 0
forrest@0
   676
forrest@0
   677
  set_line(lines,nline,header)
forrest@0
   678
  set_line(lines,nline,table_header)
forrest@0
   679
;-----------------------------------------------
forrest@0
   680
;row of table
forrest@0
   681
forrest@0
   682
  do n = 0,nrow-1
forrest@0
   683
     set_line(lines,nline,row_header)
forrest@0
   684
forrest@0
   685
     txt1  = row_head(n)
forrest@0
   686
     txt2  = text4(n,0)
forrest@0
   687
     txt3  = text4(n,1)
forrest@0
   688
     txt4  = text4(n,2)
forrest@0
   689
     txt5  = text4(n,3)
forrest@0
   690
     txt6  = text4(n,4)
forrest@0
   691
     txt7  = text4(n,5)
forrest@0
   692
     txt8  = text4(n,6)
forrest@0
   693
     txt9  = text4(n,7)
forrest@0
   694
     txt10 = text4(n,8)
forrest@0
   695
     txt11 = text4(n,9)
forrest@0
   696
     txt12 = text4(n,10)
forrest@0
   697
     txt13 = text4(n,11) 
forrest@0
   698
forrest@0
   699
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   700
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   701
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   702
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   703
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   704
     set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   705
     set_line(lines,nline,"<th>"+txt7+"</th>")
forrest@0
   706
     set_line(lines,nline,"<th>"+txt8+"</th>")
forrest@0
   707
     set_line(lines,nline,"<th>"+txt9+"</th>")
forrest@0
   708
     set_line(lines,nline,"<th>"+txt10+"</th>")
forrest@0
   709
     set_line(lines,nline,"<th>"+txt11+"</th>")
forrest@0
   710
     set_line(lines,nline,"<th>"+txt12+"</th>")
forrest@0
   711
     set_line(lines,nline,"<th>"+txt13+"</th>")
forrest@0
   712
forrest@0
   713
     set_line(lines,nline,row_footer)
forrest@0
   714
  end do
forrest@0
   715
;-----------------------------------------------
forrest@0
   716
  set_line(lines,nline,table_footer)
forrest@0
   717
  set_line(lines,nline,footer) 
forrest@0
   718
forrest@0
   719
; Now write to an HTML file.
forrest@0
   720
  idx = ind(.not.ismissing(lines))
forrest@0
   721
  if(.not.any(ismissing(idx))) then
forrest@0
   722
    asciiwrite(output_html,lines(idx))
forrest@0
   723
  else
forrest@0
   724
   print ("error?")
forrest@0
   725
  end if
forrest@0
   726
forrest@0
   727
;***************************************************************************
forrest@0
   728
; write total score to file
forrest@0
   729
;***************************************************************************
forrest@0
   730
forrest@0
   731
  asciiwrite("M_save.lai", M_total)
forrest@0
   732
forrest@0
   733
;***************************************************************************
forrest@0
   734
end
forrest@0
   735