all/01.npp.ncl
author Forrest Hoffman <forrest@climatemodeling.org>
Thu, 26 Mar 2009 14:02:21 -0400
changeset 1 4be95183fbcd
parent 0 0c6405ab2ff4
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
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
forrest@0
     3
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
forrest@0
     4
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
forrest@0
     5
;****************************************************************************
forrest@0
     6
procedure set_line(lines:string,nline:integer,newlines:string) 
forrest@0
     7
begin
forrest@0
     8
; add line to ascci/html file
forrest@0
     9
    
forrest@0
    10
  nnewlines = dimsizes(newlines)
forrest@0
    11
  if(nline+nnewlines-1.ge.dimsizes(lines))
forrest@0
    12
    print("set_line: bad index, not setting anything.") 
forrest@0
    13
    return
forrest@0
    14
  end if 
forrest@0
    15
  lines(nline:nline+nnewlines-1) = newlines
forrest@0
    16
;  print ("lines = " + lines(nline:nline+nnewlines-1))
forrest@0
    17
  nline = nline + nnewlines
forrest@0
    18
  return 
forrest@0
    19
end
forrest@0
    20
;****************************************************************************
forrest@0
    21
procedure get_bin(RAIN1_1D[*]:numeric, NPP1_1D[*]:numeric \
forrest@0
    22
                 ,RAIN2_1D[*]:numeric, NPP2_1D[*]:numeric \
forrest@0
    23
                 ,xvalues[*][*]:numeric, yvalues[*][*]:numeric \
forrest@0
    24
                 ,mn_yvalues[*][*]:numeric, mx_yvalues[*][*]:numeric \
forrest@0
    25
                 ,dx4[1]:numeric \
forrest@0
    26
                  )
forrest@0
    27
begin
forrest@0
    28
; Calculaee "nice" bins for binning the data in equally spaced ranges.
forrest@0
    29
; input : RAIN1_1D, RAIN2_1D, NPP1_1D, NPP2_1D
forrest@0
    30
; output: xvalues, yvalues, mn_yvalues, mx_yvalues,dx4
forrest@0
    31
forrest@0
    32
  nbins       = 15     ; Number of bins to use.
forrest@0
    33
forrest@0
    34
  nicevals    = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True)
forrest@0
    35
  nvals       = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
forrest@0
    36
  range       = fspan(nicevals(0),nicevals(1),nvals)
forrest@0
    37
forrest@0
    38
; Use this range information to grab all the values in a
forrest@0
    39
; particular range, and then take an average.
forrest@0
    40
forrest@0
    41
  nr           = dimsizes(range)
forrest@0
    42
  nx           = nr-1
forrest@0
    43
; print (nx)
forrest@0
    44
forrest@0
    45
; xvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
    46
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
    47
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
    48
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
    49
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
    50
; yvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
    51
; mn_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
    52
; mx_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
    53
forrest@0
    54
  do nd=0,1
forrest@0
    55
forrest@0
    56
; See if we are doing model or observational data.
forrest@0
    57
forrest@0
    58
    if(nd.eq.0) then
forrest@0
    59
      data     = RAIN1_1D
forrest@0
    60
      npp_data = NPP1_1D
forrest@0
    61
    else
forrest@0
    62
      data     = RAIN2_1D
forrest@0
    63
      npp_data = NPP2_1D
forrest@0
    64
    end if
forrest@0
    65
forrest@0
    66
; Loop through each range and check for values.
forrest@0
    67
forrest@0
    68
    do i=0,nr-2
forrest@0
    69
      if (i.ne.(nr-2)) then
forrest@0
    70
;        print("")
forrest@0
    71
;        print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
    72
        idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
forrest@0
    73
      else
forrest@0
    74
;        print("")
forrest@0
    75
;        print("In range ["+range(i)+",)")
forrest@0
    76
        idx = ind(range(i).le.data)
forrest@0
    77
      end if
forrest@0
    78
forrest@0
    79
; Calculate average, and get min and max.
forrest@0
    80
forrest@0
    81
      if(.not.any(ismissing(idx))) then
forrest@0
    82
        yvalues(nd,i)    = avg(npp_data(idx))
forrest@0
    83
        mn_yvalues(nd,i) = min(npp_data(idx))
forrest@0
    84
        mx_yvalues(nd,i) = max(npp_data(idx))
forrest@0
    85
        count = dimsizes(idx)
forrest@0
    86
      else
forrest@0
    87
        count            = 0
forrest@0
    88
        yvalues(nd,i)    = yvalues@_FillValue
forrest@0
    89
        mn_yvalues(nd,i) = yvalues@_FillValue
forrest@0
    90
        mx_yvalues(nd,i) = yvalues@_FillValue
forrest@0
    91
      end if
forrest@0
    92
forrest@0
    93
; Print out information.
forrest@0
    94
;      print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i))
forrest@0
    95
;      print("Min/Max:  " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
forrest@0
    96
forrest@0
    97
; Clean up for next time in loop.
forrest@0
    98
forrest@0
    99
      delete(idx)
forrest@0
   100
    end do
forrest@0
   101
    delete(data)
forrest@0
   102
    delete(npp_data)
forrest@0
   103
  end do 
forrest@0
   104
end
forrest@0
   105
;****************************************************************************
forrest@0
   106
; Main code.
forrest@0
   107
;****************************************************************************
forrest@0
   108
begin
forrest@0
   109
forrest@0
   110
 plot_type     = "ps"
forrest@0
   111
 plot_type_new = "png"
forrest@0
   112
forrest@0
   113
;-----------------------------------------------------
forrest@0
   114
; edit table.html of current model for movel1_vs_model2
forrest@0
   115
forrest@0
   116
 if (isvar("compare")) then
forrest@0
   117
    html_name2 = compare+"/table.html"  
forrest@0
   118
    html_new2  = html_name2 +".new"
forrest@0
   119
 end if
forrest@0
   120
;------------------------------------------------------
forrest@0
   121
; edit table.html for current model
forrest@0
   122
forrest@0
   123
 html_name = model_name+"/table.html"  
forrest@0
   124
 html_new  = html_name +".new"
forrest@0
   125
forrest@0
   126
;------------------------------------------------------
forrest@0
   127
; read model data
forrest@0
   128
forrest@0
   129
 fm   = addfile (dirm+film1,"r")
forrest@0
   130
  
forrest@0
   131
 nppmod0  = fm->NPP
forrest@0
   132
 rainmod0 = fm->RAIN
forrest@0
   133
 xm       = fm->lon  
forrest@0
   134
 ym       = fm->lat
forrest@0
   135
forrest@0
   136
 delete (fm)
forrest@0
   137
forrest@0
   138
;----------------------------------------------------
forrest@0
   139
; read ob data
forrest@0
   140
forrest@0
   141
;(1) data at 81 sites
forrest@0
   142
forrest@0
   143
 dir81 = diro + "npp/"
forrest@0
   144
 fil81 = "data.81.nc"
forrest@0
   145
 f81   = addfile (dir81+fil81,"r")
forrest@0
   146
forrest@0
   147
 id81   = f81->SITE_ID  
forrest@0
   148
 npp81  = f81->TNPP_C
forrest@0
   149
 rain81 = tofloat(f81->PREC_ANN)
forrest@0
   150
 x81    = f81->LONG_DD  
forrest@0
   151
 y81    = f81->LAT_DD
forrest@0
   152
forrest@0
   153
 delete (f81)
forrest@0
   154
forrest@0
   155
 id81@long_name  = "SITE_ID"
forrest@0
   156
forrest@0
   157
;change longitude from (-180,180) to (0,360)
forrest@0
   158
;for model data interpolation
forrest@0
   159
forrest@0
   160
 do i= 0,dimsizes(x81)-1
forrest@0
   161
    if (x81(i) .lt. 0.) then
forrest@0
   162
        x81(i) = x81(i)+ 360.
forrest@0
   163
    end if
forrest@0
   164
 end do
forrest@0
   165
forrest@0
   166
;-------------------------------------
forrest@0
   167
;(2) data at 933 sites
forrest@0
   168
forrest@0
   169
 dir933 = diro + "npp/"
forrest@0
   170
 fil933 = "data.933.nc"
forrest@0
   171
 f933   = addfile (dir933+fil933,"r")
forrest@0
   172
forrest@0
   173
 id933   = f933->SITE_ID  
forrest@0
   174
 npp933  = f933->TNPP_C
forrest@0
   175
 rain933 = f933->PREC
forrest@0
   176
 x933    = f933->LONG_DD  
forrest@0
   177
 y933    = f933->LAT_DD 
forrest@0
   178
forrest@0
   179
 delete (f933)
forrest@0
   180
forrest@0
   181
 id933@long_name  = "SITE_ID"
forrest@0
   182
forrest@0
   183
;change longitude from (-180,180) to (0,360)
forrest@0
   184
;for model data interpolation
forrest@0
   185
forrest@0
   186
 do i= 0,dimsizes(x933)-1
forrest@0
   187
    if (x933(i) .lt. 0.) then
forrest@0
   188
        x933(i) = x933(i)+ 360.
forrest@0
   189
    end if
forrest@0
   190
 end do
forrest@0
   191
forrest@0
   192
;----------------------------------------
forrest@0
   193
;(3) global data, interpolated into model grid
forrest@0
   194
forrest@0
   195
 dirg = diro + "npp/"
forrest@1
   196
 ;filg = "Npp_"+model_grid+"_mean.nc"
forrest@1
   197
 filg = "npp_"+model_grid+"_mean_2000-2004.nc"
forrest@0
   198
 fglobe   = addfile (dirg+filg,"r")
forrest@0
   199
 
forrest@0
   200
 nppglobe0 = fglobe->NPP
forrest@0
   201
 nppglobe  = nppglobe0
forrest@0
   202
forrest@0
   203
 delete (fglobe)
forrest@0
   204
forrest@0
   205
;***********************************************************************
forrest@0
   206
; interpolate model data into ob sites
forrest@0
   207
;***********************************************************************
forrest@0
   208
forrest@0
   209
 nppmod   = nppmod0(0,:,:)
forrest@0
   210
 rainmod  = rainmod0(0,:,:)
forrest@0
   211
 delete (nppmod0)
forrest@0
   212
 delete (rainmod0)
forrest@0
   213
forrest@0
   214
 nppmod81  =linint2_points(xm,ym,nppmod,True,x81,y81,0)
forrest@0
   215
forrest@0
   216
 nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0)
forrest@0
   217
forrest@0
   218
 rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0)
forrest@0
   219
forrest@0
   220
 rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0)
forrest@0
   221
forrest@0
   222
;**********************************************************
forrest@0
   223
; unified units
forrest@0
   224
;**********************************************************
forrest@0
   225
; Units for these variables are:
forrest@0
   226
;
forrest@0
   227
; rain81  : mm/year
forrest@0
   228
; rainmod : mm/s
forrest@1
   229
; npp81   : gC/m^2/year
forrest@1
   230
; nppmod81: gC/m^2/s
forrest@1
   231
; nppglobe: gC/m^2/year
forrest@0
   232
;
forrest@1
   233
; We want to convert these to "m/year" and "gC/m^2/year".
forrest@0
   234
forrest@0
   235
  nsec_per_year = 60*60*24*365                 
forrest@0
   236
forrest@0
   237
  rain81    = rain81 / 1000.
forrest@0
   238
  rainmod81 = (rainmod81/ 1000.) * nsec_per_year
forrest@0
   239
  nppmod81  = nppmod81 * nsec_per_year
forrest@0
   240
forrest@0
   241
  rain933    = rain933 / 1000.
forrest@0
   242
  rainmod933 = (rainmod933/ 1000.) * nsec_per_year
forrest@0
   243
  nppmod933  = nppmod933 * nsec_per_year
forrest@0
   244
forrest@0
   245
  nppmod  = nppmod * nsec_per_year
forrest@0
   246
forrest@1
   247
  npp81@units      = "gC m~S~-2~N~ y~S~-1~N~"
forrest@1
   248
  nppmod81@units   = "gC m~S~-2~N~ y~S~-1~N~"
forrest@1
   249
  npp933@units     = "gC m~S~-2~N~ y~S~-1~N~"
forrest@1
   250
  nppmod933@units  = "gC m~S~-2~N~ y~S~-1~N~"
forrest@1
   251
  nppmod@units     = "gC m~S~-2~N~ y~S~-1~N~"
forrest@1
   252
  nppglobe@units   = "gC m~S~-2~N~ y~S~-1~N~"
forrest@1
   253
  rain81@units     = "m y~S~-1~N~"
forrest@1
   254
  rainmod81@units  = "m y~S~-1~N~"
forrest@1
   255
  rain933@units    = "m y~S~-1~N~"
forrest@1
   256
  rainmod933@units = "m y~S~-1~N~"
forrest@0
   257
forrest@1
   258
  npp81@long_name      = "Obs. NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@1
   259
  npp933@long_name     = "Obs. NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@1
   260
  nppmod81@long_name   = "Model NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@1
   261
  nppmod933@long_name  = "Model NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@1
   262
  nppmod@long_name     = "Model NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@1
   263
  nppglobe@long_name   = "NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@1
   264
  rain81@long_name     = "PREC (m y~S~-1~N~)"
forrest@1
   265
  rain933@long_name    = "PREC (m y~S~-1~N~)"
forrest@1
   266
  rainmod81@long_name  = "PREC (m y~S~-1~N~)"
forrest@1
   267
  rainmod933@long_name = "PREC (m y~S~-1~N~)"
forrest@0
   268
forrest@0
   269
; change longitude from 0-360 to -180-180
forrest@0
   270
  x81  = where(x81  .gt. 180., x81 -360., x81 )
forrest@0
   271
  x933 = where(x933 .gt. 180., x933-360., x933)
forrest@0
   272
forrest@0
   273
;*******************************************************************
forrest@0
   274
;(A)-1 html table of site81 -- observed
forrest@0
   275
;*******************************************************************
forrest@0
   276
forrest@0
   277
  output_html = "table_site81_ob.html"
forrest@0
   278
forrest@0
   279
  header = (/"<HTML>" \
forrest@0
   280
            ,"<HEAD>" \
forrest@0
   281
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   282
            ,"</HEAD>" \
forrest@0
   283
            ,"<H1>EMDI Observations Class A (81 sites)</H1>" \
forrest@0
   284
            /) 
forrest@0
   285
  footer = "</HTML>"
forrest@0
   286
forrest@0
   287
  table_header = (/ \
forrest@0
   288
        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
forrest@0
   289
       ,"<tr>" \
forrest@0
   290
       ,"   <th bgcolor=DDDDDD >Site ID</th>" \
forrest@0
   291
       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
forrest@0
   292
       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
forrest@1
   293
       ,"   <th bgcolor=DDDDDD >NPP (gC m<small><sup>-2</sup></small> y<small><sup>-1</sup></small>)</th>" \
forrest@1
   294
       ,"   <th bgcolor=DDDDDD >PPT (m y<small><sup>-1</sup></small>)</th>" \
forrest@0
   295
       ,"</tr>" \
forrest@0
   296
       /)
forrest@0
   297
  table_footer = "</table>"
forrest@0
   298
  row_header = "<tr>"
forrest@0
   299
  row_footer = "</tr>"
forrest@0
   300
forrest@0
   301
  lines = new(50000,string)
forrest@0
   302
  nline = 0
forrest@0
   303
forrest@0
   304
  set_line(lines,nline,header)
forrest@0
   305
  set_line(lines,nline,table_header)
forrest@0
   306
;-----------------------------------------------
forrest@0
   307
;row of table
forrest@0
   308
  
forrest@0
   309
  nrow = dimsizes(id81)
forrest@0
   310
  do n = 0,nrow-1
forrest@0
   311
     set_line(lines,nline,row_header)
forrest@0
   312
forrest@0
   313
     txt1 = sprintf("%5.0f", id81(n))
forrest@0
   314
     txt2 = sprintf("%5.2f", y81(n))  
forrest@0
   315
     txt3 = sprintf("%5.2f", x81(n))    
forrest@0
   316
     txt4 = sprintf("%5.2f", npp81(n))     
forrest@0
   317
     txt5 = sprintf("%5.2f", rain81(n)) 
forrest@0
   318
forrest@0
   319
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   320
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   321
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   322
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   323
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   324
forrest@0
   325
     set_line(lines,nline,row_footer)
forrest@0
   326
  end do
forrest@0
   327
;-----------------------------------------------
forrest@0
   328
  set_line(lines,nline,table_footer)
forrest@0
   329
  set_line(lines,nline,footer) 
forrest@0
   330
forrest@0
   331
; Now write to an HTML file.
forrest@0
   332
  idx = ind(.not.ismissing(lines))
forrest@0
   333
  if(.not.any(ismissing(idx))) then
forrest@0
   334
    asciiwrite(output_html,lines(idx))
forrest@0
   335
  else
forrest@0
   336
   print ("error?")
forrest@0
   337
  end if
forrest@0
   338
forrest@0
   339
;*******************************************************************
forrest@0
   340
;(A)-2 html table of site933 -- observed
forrest@0
   341
;*******************************************************************
forrest@0
   342
  output_html = "table_site933_ob.html"
forrest@0
   343
forrest@0
   344
  header = (/"<HTML>" \
forrest@0
   345
            ,"<HEAD>" \
forrest@0
   346
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   347
            ,"</HEAD>" \
forrest@0
   348
            ,"<H1>EMDI Observations Class B (933 sites)</H1>" \
forrest@0
   349
            /) 
forrest@0
   350
  footer = "</HTML>"
forrest@0
   351
forrest@0
   352
  table_header = (/ \
forrest@0
   353
        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
forrest@0
   354
       ,"<tr>" \
forrest@0
   355
       ,"   <th bgcolor=DDDDDD >Site ID</th>" \
forrest@0
   356
       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
forrest@0
   357
       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
forrest@1
   358
       ,"   <th bgcolor=DDDDDD >NPP (gC m<small><sup>-2</sup></small> y<small><sup>-1</sup></small>)</th>" \
forrest@1
   359
       ,"   <th bgcolor=DDDDDD >PPT (m y<small><sup>-1</sup></small>)</th>" \
forrest@0
   360
       ,"</tr>" \
forrest@0
   361
       /)
forrest@0
   362
  table_footer = "</table>"
forrest@0
   363
  row_header = "<tr>"
forrest@0
   364
  row_footer = "</tr>"
forrest@0
   365
forrest@0
   366
  delete (lines)  
forrest@0
   367
  lines = new(50000,string)
forrest@0
   368
  nline = 0
forrest@0
   369
forrest@0
   370
  set_line(lines,nline,header)
forrest@0
   371
  set_line(lines,nline,table_header)
forrest@0
   372
;-----------------------------------------------
forrest@0
   373
;row of table
forrest@0
   374
  
forrest@0
   375
  nrow = dimsizes(id933)
forrest@0
   376
  do n = 0,nrow-1
forrest@0
   377
     set_line(lines,nline,row_header)
forrest@0
   378
forrest@0
   379
     txt1 = sprintf("%5.0f", id933(n))
forrest@0
   380
     txt2 = sprintf("%5.2f", y933(n))  
forrest@0
   381
     txt3 = sprintf("%5.2f", x933(n))    
forrest@0
   382
     txt4 = sprintf("%5.2f", npp933(n))     
forrest@0
   383
     txt5 = sprintf("%5.2f", rain933(n))
forrest@0
   384
forrest@0
   385
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   386
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   387
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   388
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   389
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   390
forrest@0
   391
     set_line(lines,nline,row_footer)
forrest@0
   392
  end do
forrest@0
   393
;-----------------------------------------------
forrest@0
   394
  set_line(lines,nline,table_footer)
forrest@0
   395
  set_line(lines,nline,footer) 
forrest@0
   396
forrest@0
   397
; Now write to an HTML file.
forrest@0
   398
  delete (idx)
forrest@0
   399
  idx = ind(.not.ismissing(lines))
forrest@0
   400
  if(.not.any(ismissing(idx))) then
forrest@0
   401
    asciiwrite(output_html,lines(idx))
forrest@0
   402
  else
forrest@0
   403
   print ("error?")
forrest@0
   404
  end if
forrest@0
   405
forrest@0
   406
;*******************************************************************
forrest@0
   407
;(A)-3 html table of site81 -- model vs ob
forrest@0
   408
;*******************************************************************
forrest@0
   409
  output_html = "table_site81_model_vs_ob.html"
forrest@0
   410
forrest@0
   411
  header_text = "<H1>Model "+model_name+" vs Class A Observations (81 sites)</H1>" 
forrest@0
   412
forrest@0
   413
  header = (/"<HTML>" \
forrest@0
   414
            ,"<HEAD>" \
forrest@0
   415
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   416
            ,"</HEAD>" \
forrest@0
   417
            ,header_text \
forrest@0
   418
            /) 
forrest@0
   419
  footer = "</HTML>"
forrest@0
   420
forrest@0
   421
  delete (table_header)
forrest@0
   422
  table_header_text = "   <th bgcolor=DDDDDD >"+model_name+"</th>"
forrest@0
   423
  table_header = (/ \
forrest@0
   424
        "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
forrest@0
   425
       ,"<tr>" \
forrest@0
   426
       ,"   <th bgcolor=DDDDDD rowspan=2>Site ID</th>" \
forrest@0
   427
       ,"   <th bgcolor=DDDDDD rowspan=2>Latitude</th>" \
forrest@0
   428
       ,"   <th bgcolor=DDDDDD rowspan=2>Longitude</th>" \
forrest@1
   429
       ,"   <th bgcolor=DDDDDD colspan=2>NPP (gC m<small><sup>-2</sup></small> y<small><sup>-1</sup></small>)</th>" \
forrest@1
   430
       ,"   <th bgcolor=DDDDDD colspan=2>RAIN (m y<small><sup>-1</sup></small>)</th>" \
forrest@0
   431
       ,"</tr>" \
forrest@0
   432
       ,"<tr>" \
forrest@0
   433
       ,"   <th bgcolor=DDDDDD >observed</th>" \
forrest@0
   434
       ,     table_header_text \
forrest@0
   435
       ,"   <th bgcolor=DDDDDD >observed</th>" \
forrest@0
   436
       ,     table_header_text \
forrest@0
   437
       ,"</tr>" \
forrest@0
   438
       /)
forrest@0
   439
  table_footer = "</table>"
forrest@0
   440
  row_header = "<tr>"
forrest@0
   441
  row_footer = "</tr>"
forrest@0
   442
forrest@0
   443
  delete (lines)
forrest@0
   444
  lines = new(50000,string)
forrest@0
   445
  nline = 0
forrest@0
   446
forrest@0
   447
  set_line(lines,nline,header)
forrest@0
   448
  set_line(lines,nline,table_header)
forrest@0
   449
;-----------------------------------------------
forrest@0
   450
;row of table
forrest@0
   451
  
forrest@0
   452
  nrow = dimsizes(id81)
forrest@0
   453
  do n = 0,nrow-1
forrest@0
   454
     set_line(lines,nline,row_header)
forrest@0
   455
forrest@0
   456
     txt1 = sprintf("%5.0f", id81(n))
forrest@0
   457
     txt2 = sprintf("%5.2f", y81(n))  
forrest@0
   458
     txt3 = sprintf("%5.2f", x81(n))    
forrest@0
   459
     txt4 = sprintf("%5.2f", npp81(n))
forrest@0
   460
     txt5 = sprintf("%5.2f", nppmod81(n))     
forrest@0
   461
     txt6 = sprintf("%5.2f", rain81(n))
forrest@0
   462
     txt7 = sprintf("%5.2f", rainmod81(n)) 
forrest@0
   463
forrest@0
   464
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   465
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   466
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   467
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   468
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   469
     set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   470
     set_line(lines,nline,"<th>"+txt7+"</th>")
forrest@0
   471
forrest@0
   472
     set_line(lines,nline,row_footer)
forrest@0
   473
  end do
forrest@0
   474
;-----------------------------------------------
forrest@0
   475
  set_line(lines,nline,table_footer)
forrest@0
   476
  set_line(lines,nline,footer) 
forrest@0
   477
forrest@0
   478
; Now write to an HTML file.
forrest@0
   479
  delete (idx)
forrest@0
   480
  idx = ind(.not.ismissing(lines))
forrest@0
   481
  if(.not.any(ismissing(idx))) then
forrest@0
   482
    asciiwrite(output_html,lines(idx))
forrest@0
   483
  else
forrest@0
   484
   print ("error?")
forrest@0
   485
  end if
forrest@0
   486
forrest@0
   487
;*******************************************************************
forrest@0
   488
;(A)-4 html table of site933 -- model vs ob
forrest@0
   489
;*******************************************************************
forrest@0
   490
  output_html = "table_site933_model_vs_ob.html"
forrest@0
   491
forrest@0
   492
  header_text = "<H1>Model "+model_name+" vs Class B Observations (933 sites)</H1>" 
forrest@0
   493
forrest@0
   494
  header = (/"<HTML>" \
forrest@0
   495
            ,"<HEAD>" \
forrest@0
   496
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   497
            ,"</HEAD>" \
forrest@0
   498
            ,header_text \
forrest@0
   499
            /) 
forrest@0
   500
  footer = "</HTML>"
forrest@0
   501
forrest@0
   502
  delete (table_header)
forrest@0
   503
  table_header_text = "   <th bgcolor=DDDDDD >"+model_name+"</th>"
forrest@0
   504
  table_header = (/ \
forrest@0
   505
        "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
forrest@0
   506
       ,"<tr>" \
forrest@0
   507
       ,"   <th bgcolor=DDDDDD rowspan=2>Site ID</th>" \
forrest@0
   508
       ,"   <th bgcolor=DDDDDD rowspan=2>Latitude</th>" \
forrest@0
   509
       ,"   <th bgcolor=DDDDDD rowspan=2>Longitude</th>" \
forrest@1
   510
       ,"   <th bgcolor=DDDDDD colspan=2>NPP (gC m<small><sup>-2</sup></small> y<small><sup>-1</sup></small>)</th>" \
forrest@1
   511
       ,"   <th bgcolor=DDDDDD colspan=2>RAIN (m y<small><sup>-1</sup></small>)</th>" \
forrest@0
   512
       ,"</tr>" \
forrest@0
   513
       ,"<tr>" \
forrest@0
   514
       ,"   <th bgcolor=DDDDDD >observed</th>" \
forrest@0
   515
       ,     table_header_text \
forrest@0
   516
       ,"   <th bgcolor=DDDDDD >observed</th>" \
forrest@0
   517
       ,     table_header_text \
forrest@0
   518
       ,"</tr>" \
forrest@0
   519
       /)
forrest@0
   520
  table_footer = "</table>"
forrest@0
   521
  row_header = "<tr>"
forrest@0
   522
  row_footer = "</tr>"
forrest@0
   523
forrest@0
   524
  delete (lines)
forrest@0
   525
  lines = new(50000,string)
forrest@0
   526
  nline = 0
forrest@0
   527
forrest@0
   528
  set_line(lines,nline,header)
forrest@0
   529
  set_line(lines,nline,table_header)
forrest@0
   530
;-----------------------------------------------
forrest@0
   531
;row of table
forrest@0
   532
  
forrest@0
   533
  nrow = dimsizes(id933)
forrest@0
   534
  do n = 0,nrow-1
forrest@0
   535
     set_line(lines,nline,row_header)
forrest@0
   536
forrest@0
   537
     txt1 = sprintf("%5.0f", id933(n))
forrest@0
   538
     txt2 = sprintf("%5.2f", y933(n))  
forrest@0
   539
     txt3 = sprintf("%5.2f", x933(n))    
forrest@0
   540
     txt4 = sprintf("%5.2f", npp933(n))
forrest@0
   541
     txt5 = sprintf("%5.2f", nppmod933(n))     
forrest@0
   542
     txt6 = sprintf("%5.2f", rain933(n))
forrest@0
   543
     txt7 = sprintf("%5.2f", rainmod933(n)) 
forrest@0
   544
forrest@0
   545
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   546
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   547
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   548
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   549
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   550
     set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   551
     set_line(lines,nline,"<th>"+txt7+"</th>")
forrest@0
   552
forrest@0
   553
     set_line(lines,nline,row_footer)
forrest@0
   554
  end do
forrest@0
   555
;-----------------------------------------------
forrest@0
   556
  set_line(lines,nline,table_footer)
forrest@0
   557
  set_line(lines,nline,footer) 
forrest@0
   558
forrest@0
   559
; Now write to an HTML file.
forrest@0
   560
  delete (idx)
forrest@0
   561
  idx = ind(.not.ismissing(lines))
forrest@0
   562
  if(.not.any(ismissing(idx))) then
forrest@0
   563
    asciiwrite(output_html,lines(idx))
forrest@0
   564
  else
forrest@0
   565
   print ("error?")
forrest@0
   566
  end if
forrest@0
   567
forrest@0
   568
;***************************************************************************
forrest@0
   569
;(A)-5 scatter plot, model vs ob 81
forrest@0
   570
;***************************************************************************
forrest@0
   571
  
forrest@0
   572
 plot_name = "scatter_model_vs_ob_81"
forrest@1
   573
 ;title     = model_name +" vs Class A observations (81 sites)"
forrest@1
   574
 title     = model_name +" (1975-2000) vs Class A observations (81 sites)"
forrest@0
   575
forrest@0
   576
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   577
 res                   = True                  ; plot mods desired
forrest@0
   578
 res@tiMainString      = title                 ; add title
forrest@0
   579
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   580
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   581
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   582
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   583
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   584
forrest@0
   585
 res@gsnDraw           = False
forrest@0
   586
 res@gsnFrame          = False                 ; don't advance frame yet
forrest@0
   587
;-------------------------------
forrest@0
   588
;compute correlation coef. and M
forrest@0
   589
 ccr81 = esccr(nppmod81,npp81,0)
forrest@0
   590
;print (ccr81)
forrest@0
   591
forrest@1
   592
 score_max = 1.0
forrest@0
   593
forrest@0
   594
 bias = sum(abs(nppmod81-npp81)/(abs(nppmod81)+abs(npp81))) 
forrest@0
   595
 M81s = (1. - (bias/dimsizes(y81)))*score_max
forrest@0
   596
 M_npp_S81  = sprintf("%.2f", M81s)
forrest@0
   597
forrest@0
   598
 if (isvar("compare")) then
forrest@0
   599
    system("sed -e '1,/M_npp_S81/s/M_npp_S81/"+M_npp_S81+"/' "+html_name2+" > "+html_new2+";"+ \
forrest@0
   600
           "mv -f "+html_new2+" "+html_name2)
forrest@0
   601
 end if
forrest@0
   602
forrest@0
   603
 system("sed s#M_npp_S81#"+M_npp_S81+"# "+html_name+" > "+html_new+";"+ \
forrest@0
   604
        "mv -f "+html_new+" "+html_name)
forrest@0
   605
 
forrest@0
   606
 tRes  = True
forrest@0
   607
 tRes@txFontHeightF = 0.025
forrest@0
   608
forrest@0
   609
 correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")"
forrest@0
   610
forrest@0
   611
 gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes)
forrest@0
   612
;--------------------------------
forrest@0
   613
 plot  = gsn_csm_xy (wks,npp81,nppmod81,res)       ; create plot
forrest@0
   614
;-------------------------------
forrest@0
   615
; add polyline
forrest@0
   616
forrest@0
   617
 dum=gsn_add_polyline(wks,plot,(/0,1200/),(/0,1200/),False)
forrest@0
   618
;-------------------------------
forrest@0
   619
 draw (plot)
forrest@0
   620
 delete (wks)
forrest@0
   621
 delete (dum)
forrest@0
   622
forrest@1
   623
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   624
        "rm "+plot_name+"."+plot_type)
forrest@1
   625
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   626
forrest@0
   627
;***************************************************************************
forrest@0
   628
;(A)-6 scatter plot, model vs ob 933
forrest@0
   629
;***************************************************************************
forrest@0
   630
  
forrest@0
   631
 plot_name = "scatter_model_vs_ob_933"
forrest@1
   632
 title     = model_name +" (1975-2000) vs Class B Observations (933 sites)"
forrest@0
   633
forrest@0
   634
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   635
 res                   = True                  ; plot mods desired
forrest@0
   636
 res@tiMainString      = title                 ; add title
forrest@0
   637
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   638
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   639
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   640
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   641
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   642
forrest@0
   643
 res@gsnDraw           = False
forrest@0
   644
 res@gsnFrame          = False                 ; don't advance frame yet
forrest@0
   645
;-------------------------------
forrest@0
   646
;compute correlation coef. and M
forrest@0
   647
forrest@0
   648
 ccr933 = esccr(nppmod933,npp933,0)
forrest@0
   649
forrest@1
   650
 score_max = 1.0
forrest@0
   651
forrest@0
   652
 bias  = sum(abs(nppmod933-npp933)/(abs(nppmod933)+abs(npp933)))
forrest@0
   653
 M933s = (1. - (bias/dimsizes(y933)))*score_max
forrest@0
   654
 M_npp_S933  = sprintf("%.2f", M933s)
forrest@0
   655
forrest@0
   656
 if (isvar("compare")) then
forrest@0
   657
    system("sed -e '1,/M_npp_S933/s/M_npp_S933/"+M_npp_S933+"/' "+html_name2+" > "+html_new2+";"+ \
forrest@0
   658
           "mv -f "+html_new2+" "+html_name2)
forrest@0
   659
 end if
forrest@0
   660
forrest@0
   661
 system("sed s#M_npp_S933#"+M_npp_S933+"# "+html_name+" > "+html_new+";"+ \
forrest@0
   662
        "mv -f "+html_new+" "+html_name)
forrest@0
   663
forrest@0
   664
 tRes  = True
forrest@0
   665
 tRes@txFontHeightF = 0.025
forrest@0
   666
forrest@0
   667
 correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")"
forrest@0
   668
forrest@0
   669
 gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes)
forrest@0
   670
;--------------------------------
forrest@0
   671
 plot  = gsn_csm_xy (wks,npp933,nppmod933,res)    ; create plot
forrest@0
   672
;-------------------------------
forrest@0
   673
; add polyline
forrest@0
   674
forrest@0
   675
 dum=gsn_add_polyline(wks,plot,(/0,1500/),(/0,1500/),False)
forrest@0
   676
;-------------------------------
forrest@0
   677
 draw (plot)
forrest@0
   678
 delete (wks)
forrest@0
   679
 delete (dum)
forrest@0
   680
forrest@1
   681
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   682
        "rm "+plot_name+"."+plot_type)
forrest@1
   683
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   684
forrest@0
   685
;**************************************************************************
forrest@0
   686
;(B) histogram 81
forrest@0
   687
;**************************************************************************
forrest@0
   688
;get data
forrest@0
   689
  RAIN1_1D = ndtooned(rain81)
forrest@0
   690
  RAIN2_1D = ndtooned(rainmod81)
forrest@0
   691
  NPP1_1D  = ndtooned(npp81)
forrest@0
   692
  NPP2_1D  = ndtooned(nppmod81)
forrest@0
   693
forrest@0
   694
; number of bin
forrest@0
   695
  nx = 8
forrest@0
   696
forrest@0
   697
  xvalues      = new((/2,nx/),float)
forrest@0
   698
  yvalues      = new((/2,nx/),float)
forrest@0
   699
  mn_yvalues   = new((/2,nx/),float)
forrest@0
   700
  mx_yvalues   = new((/2,nx/),float)
forrest@0
   701
  dx4          = new((/1/),float)
forrest@0
   702
forrest@0
   703
  get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \
forrest@0
   704
         ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4)
forrest@0
   705
forrest@0
   706
;----------------------------------------
forrest@0
   707
;compute correlation coeff and M score
forrest@0
   708
 
forrest@0
   709
 u = yvalues(0,:)
forrest@0
   710
 v = yvalues(1,:)
forrest@0
   711
forrest@0
   712
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   713
 uu = u(good)
forrest@0
   714
 vv = v(good)
forrest@0
   715
forrest@0
   716
 ccr81h = esccr(uu,vv,0)
forrest@0
   717
forrest@1
   718
 score_max = 2.0
forrest@0
   719
forrest@0
   720
 bias = sum(abs(vv-uu)/(abs(vv)+abs(uu)))
forrest@0
   721
 M81h = (1.- (bias/dimsizes(uu)))*score_max
forrest@0
   722
 M_npp_H81  = sprintf("%.2f", M81h)
forrest@0
   723
forrest@0
   724
 if (isvar("compare")) then
forrest@0
   725
    system("sed -e '1,/M_npp_H81/s/M_npp_H81/"+M_npp_H81+"/' "+html_name2+" > "+html_new2+";"+ \
forrest@0
   726
           "mv -f "+html_new2+" "+html_name2)
forrest@0
   727
 end if
forrest@0
   728
forrest@0
   729
 system("sed s#M_npp_H81#"+M_npp_H81+"# "+html_name+" > "+html_new+";"+ \
forrest@0
   730
        "mv -f "+html_new+" "+html_name)
forrest@0
   731
 
forrest@0
   732
 delete (u)
forrest@0
   733
 delete (v)
forrest@0
   734
 delete (uu)
forrest@0
   735
 delete (vv)
forrest@0
   736
;----------------------------------------------------------------------
forrest@0
   737
; histogram res
forrest@0
   738
  resh                = True
forrest@0
   739
  resh@gsnMaximize    = True
forrest@0
   740
  resh@gsnDraw        = False
forrest@0
   741
  resh@gsnFrame       = False
forrest@0
   742
  resh@xyMarkLineMode = "Markers"
forrest@0
   743
  resh@xyMarkerSizeF  = 0.014
forrest@0
   744
  resh@xyMarker       = 16
forrest@0
   745
  resh@xyMarkerColors = (/"Brown","Blue"/)
forrest@0
   746
  resh@trYMinF        = min(mn_yvalues) - 10.
forrest@0
   747
  resh@trYMaxF        = max(mx_yvalues) + 10.
forrest@0
   748
forrest@1
   749
  resh@tiYAxisString  = "NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@1
   750
  resh@tiXAxisString  = "Precipitation (m y~S~-1~N~)"
forrest@0
   751
forrest@0
   752
  max_bar = new((/2,nx/),graphic)
forrest@0
   753
  min_bar = new((/2,nx/),graphic)
forrest@0
   754
  max_cap = new((/2,nx/),graphic)
forrest@0
   755
  min_cap = new((/2,nx/),graphic)
forrest@0
   756
forrest@0
   757
  lnres = True
forrest@0
   758
  line_colors = (/"brown","blue"/)
forrest@0
   759
forrest@0
   760
;**************************************************************************
forrest@0
   761
;(B)-1 histogram plot, ob 81 site 
forrest@0
   762
;**************************************************************************
forrest@0
   763
forrest@0
   764
  plot_name = "histogram_ob_81"
forrest@0
   765
  title     = "Class A Observations (81 sites)"
forrest@0
   766
  resh@tiMainString  = title
forrest@0
   767
forrest@0
   768
  wks   = gsn_open_wks (plot_type,plot_name)    
forrest@0
   769
forrest@0
   770
  xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh)
forrest@0
   771
forrest@1
   772
  ; Added by Forrest Hoffman to print out values on Wed Feb  4 14:36:00 EST 2009
forrest@1
   773
  print("Observations: " + xvalues(0,:) + " " + yvalues(0,:))
forrest@1
   774
forrest@0
   775
;-------------------------------
forrest@0
   776
;Attach the vertical bar and the horizontal cap line 
forrest@0
   777
forrest@0
   778
  do nd=0,0
forrest@0
   779
    lnres@gsLineColor = line_colors(nd)
forrest@0
   780
    do i=0,nx-1
forrest@0
   781
     
forrest@0
   782
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   783
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   784
;
forrest@0
   785
; Attach the vertical bar, both above and below the marker.
forrest@0
   786
;
forrest@0
   787
        x1 = xvalues(nd,i)
forrest@0
   788
        y1 = yvalues(nd,i)
forrest@0
   789
        y2 = mn_yvalues(nd,i)
forrest@0
   790
        plx = (/x1,x1/)
forrest@0
   791
        ply = (/y1,y2/)
forrest@0
   792
        min_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres)
forrest@0
   793
forrest@0
   794
        y2 = mx_yvalues(nd,i)
forrest@0
   795
        plx = (/x1,x1/)
forrest@0
   796
        ply = (/y1,y2/)
forrest@0
   797
        max_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres)
forrest@0
   798
;
forrest@0
   799
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   800
;
forrest@0
   801
        x1 = xvalues(nd,i) - dx4
forrest@0
   802
        x2 = xvalues(nd,i) + dx4
forrest@0
   803
        y1 = mn_yvalues(nd,i)
forrest@0
   804
        plx = (/x1,x2/)
forrest@0
   805
        ply = (/y1,y1/)
forrest@0
   806
        min_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres)
forrest@0
   807
forrest@0
   808
        y1 = mx_yvalues(nd,i)
forrest@0
   809
        plx = (/x1,x2/)
forrest@0
   810
        ply = (/y1,y1/)
forrest@0
   811
        max_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres)
forrest@0
   812
      end if
forrest@0
   813
    end do
forrest@0
   814
  end do
forrest@0
   815
forrest@0
   816
  draw(xy)
forrest@0
   817
  delete (wks)
forrest@0
   818
forrest@1
   819
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   820
        "rm "+plot_name+"."+plot_type)
forrest@1
   821
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   822
forrest@0
   823
;****************************************************************************
forrest@0
   824
;(B)-2 histogram plot, model vs ob 81 site 
forrest@0
   825
;****************************************************************************
forrest@0
   826
forrest@0
   827
  plot_name = "histogram_model_vs_ob_81"
forrest@1
   828
  title     = model_name+ " (1975-2000) vs Class A Observations (81 sites)"
forrest@0
   829
  resh@tiMainString  = title
forrest@0
   830
forrest@0
   831
  wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   832
forrest@0
   833
;-----------------------------
forrest@0
   834
; Add a boxed legend using the more simple method, which won't have
forrest@0
   835
; vertical lines going through the markers.
forrest@0
   836
forrest@0
   837
  resh@pmLegendDisplayMode    = "Always"
forrest@0
   838
; resh@pmLegendWidthF         = 0.1
forrest@0
   839
  resh@pmLegendWidthF         = 0.08
forrest@0
   840
  resh@pmLegendHeightF        = 0.05
forrest@0
   841
  resh@pmLegendOrthogonalPosF = -1.17
forrest@0
   842
; resh@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   843
; resh@pmLegendParallelPosF   =  0.18
forrest@0
   844
  resh@pmLegendParallelPosF   =  0.88  ;(rightward)
forrest@0
   845
forrest@0
   846
; resh@lgPerimOn              = False
forrest@0
   847
  resh@lgLabelFontHeightF     = 0.015
forrest@0
   848
  resh@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
   849
;-----------------------------
forrest@0
   850
  tRes  = True
forrest@0
   851
  tRes@txFontHeightF = 0.025
forrest@0
   852
forrest@0
   853
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")"
forrest@0
   854
forrest@0
   855
  gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes)
forrest@0
   856
forrest@0
   857
  xy = gsn_csm_xy(wks,xvalues,yvalues,resh)
forrest@1
   858
forrest@1
   859
  ; Added by Forrest Hoffman to print out values on Wed Feb  4 14:36:00 EST 2009
forrest@1
   860
  print(model_name + ": " + xvalues(1,:) + " " + yvalues(1,:))
forrest@1
   861
  ;print("All: " + xvalues(:,:) + " " + yvalues(:,:))
forrest@0
   862
;-------------------------------
forrest@0
   863
;Attach the vertical bar and the horizontal cap line 
forrest@0
   864
forrest@0
   865
  do nd=0,1
forrest@0
   866
    lnres@gsLineColor = line_colors(nd)
forrest@0
   867
    do i=0,nx-1
forrest@0
   868
     
forrest@0
   869
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   870
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   871
;
forrest@0
   872
; Attach the vertical bar, both above and below the marker.
forrest@0
   873
;
forrest@0
   874
        x1 = xvalues(nd,i)
forrest@0
   875
        y1 = yvalues(nd,i)
forrest@0
   876
        y2 = mn_yvalues(nd,i)
forrest@0
   877
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   878
forrest@0
   879
        y2 = mx_yvalues(nd,i)
forrest@0
   880
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   881
;
forrest@0
   882
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   883
;
forrest@0
   884
        x1 = xvalues(nd,i) - dx4
forrest@0
   885
        x2 = xvalues(nd,i) + dx4
forrest@0
   886
        y1 = mn_yvalues(nd,i)
forrest@0
   887
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   888
forrest@0
   889
        y1 = mx_yvalues(nd,i)
forrest@0
   890
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   891
      end if
forrest@0
   892
    end do
forrest@0
   893
  end do
forrest@0
   894
forrest@0
   895
  draw(xy)
forrest@0
   896
  delete(wks)
forrest@0
   897
forrest@1
   898
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   899
        "rm "+plot_name+"."+plot_type)
forrest@1
   900
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   901
forrest@0
   902
 delete (RAIN1_1D)
forrest@0
   903
 delete (RAIN2_1D)
forrest@0
   904
 delete (NPP1_1D)
forrest@0
   905
 delete (NPP2_1D)
forrest@0
   906
;delete (range)
forrest@0
   907
 delete (xvalues) 
forrest@0
   908
 delete (yvalues)
forrest@0
   909
 delete (mn_yvalues)
forrest@0
   910
 delete (mx_yvalues)
forrest@0
   911
 delete (good)
forrest@0
   912
 delete (max_bar)
forrest@0
   913
 delete (min_bar)
forrest@0
   914
 delete (max_cap)
forrest@0
   915
 delete (min_cap)
forrest@0
   916
   
forrest@0
   917
;**************************************************************************
forrest@0
   918
;(B) histogram 933
forrest@0
   919
;**************************************************************************
forrest@0
   920
forrest@0
   921
; get data
forrest@0
   922
  RAIN1_1D = ndtooned(rain933)
forrest@0
   923
  RAIN2_1D = ndtooned(rainmod933)
forrest@0
   924
  NPP1_1D  = ndtooned(npp933)
forrest@0
   925
  NPP2_1D  = ndtooned(nppmod933)
forrest@0
   926
forrest@0
   927
; number of bin
forrest@0
   928
  nx = 10
forrest@0
   929
forrest@0
   930
  xvalues      = new((/2,nx/),float)
forrest@0
   931
  yvalues      = new((/2,nx/),float)
forrest@0
   932
  mn_yvalues   = new((/2,nx/),float)
forrest@0
   933
  mx_yvalues   = new((/2,nx/),float)
forrest@0
   934
  dx4          = new((/1/),float)
forrest@0
   935
forrest@0
   936
  get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \
forrest@0
   937
         ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4)
forrest@0
   938
 
forrest@0
   939
;----------------------------------------
forrest@0
   940
;compute correlation coeff and M score
forrest@0
   941
 
forrest@0
   942
 u = yvalues(0,:)
forrest@0
   943
 v = yvalues(1,:)
forrest@0
   944
forrest@0
   945
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   946
 uu = u(good)
forrest@0
   947
 vv = v(good)
forrest@0
   948
forrest@0
   949
 ccr933h = esccr(uu,vv,0)
forrest@0
   950
forrest@1
   951
 score_max = 2.0
forrest@0
   952
forrest@0
   953
 bias  = sum(abs(vv-uu)/(abs(vv)+abs(uu)))
forrest@0
   954
 M933h = (1.- (bias/dimsizes(uu)))*score_max
forrest@0
   955
 M_npp_H933 = sprintf("%.2f", M933h)
forrest@0
   956
forrest@0
   957
 if (isvar("compare")) then
forrest@0
   958
    system("sed -e '1,/M_npp_H933/s/M_npp_H933/"+M_npp_H933+"/' "+html_name2+" > "+html_new2+";"+ \
forrest@0
   959
           "mv -f "+html_new2+" "+html_name2)
forrest@0
   960
 end if
forrest@0
   961
forrest@0
   962
 system("sed s#M_npp_H933#"+M_npp_H933+"# "+html_name+" > "+html_new+";"+ \
forrest@0
   963
        "mv -f "+html_new+" "+html_name)
forrest@0
   964
forrest@0
   965
 delete (u)
forrest@0
   966
 delete (v)
forrest@0
   967
 delete (uu)
forrest@0
   968
 delete (vv)
forrest@0
   969
;----------------------------------------------------------------------
forrest@0
   970
; histogram res
forrest@0
   971
  delete (resh)
forrest@0
   972
  resh                = True
forrest@0
   973
  resh@gsnMaximize    = True
forrest@0
   974
  resh@gsnDraw        = False
forrest@0
   975
  resh@gsnFrame       = False
forrest@0
   976
  resh@xyMarkLineMode = "Markers"
forrest@0
   977
  resh@xyMarkerSizeF  = 0.014
forrest@0
   978
  resh@xyMarker       = 16
forrest@0
   979
  resh@xyMarkerColors = (/"Brown","Blue"/)
forrest@0
   980
  resh@trYMinF        = min(mn_yvalues) - 10.
forrest@0
   981
  resh@trYMaxF        = max(mx_yvalues) + 10.
forrest@0
   982
forrest@1
   983
  resh@tiYAxisString  = "NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@1
   984
  resh@tiXAxisString  = "Precipitation (m y~S~-1~N~)"
forrest@0
   985
forrest@0
   986
  max_bar = new((/2,nx/),graphic)
forrest@0
   987
  min_bar = new((/2,nx/),graphic)
forrest@0
   988
  max_cap = new((/2,nx/),graphic)
forrest@0
   989
  min_cap = new((/2,nx/),graphic)
forrest@0
   990
forrest@0
   991
  lnres = True
forrest@0
   992
  line_colors = (/"brown","blue"/)
forrest@0
   993
forrest@0
   994
;**************************************************************************
forrest@0
   995
;(B)-3 histogram plot, ob 933 site 
forrest@0
   996
;**************************************************************************
forrest@0
   997
forrest@0
   998
  plot_name = "histogram_ob_933"
forrest@0
   999
  title     = "Class B Observations (933 sites)"
forrest@0
  1000
  resh@tiMainString  = title
forrest@0
  1001
forrest@0
  1002
  wks   = gsn_open_wks (plot_type,plot_name)    
forrest@0
  1003
forrest@0
  1004
  xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh)
forrest@0
  1005
forrest@1
  1006
  ; Added by Forrest Hoffman to print out values on Wed Feb  4 14:36:00 EST 2009
forrest@1
  1007
  print("Observations: " + xvalues(0,:) + " " + yvalues(0,:))
forrest@1
  1008
forrest@0
  1009
;-------------------------------
forrest@0
  1010
;Attach the vertical bar and the horizontal cap line 
forrest@0
  1011
forrest@0
  1012
  do nd=0,0
forrest@0
  1013
    lnres@gsLineColor = line_colors(nd)
forrest@0
  1014
    do i=0,nx-1
forrest@0
  1015
     
forrest@0
  1016
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
  1017
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
  1018
forrest@0
  1019
; Attach the vertical bar, both above and below the marker.
forrest@0
  1020
forrest@0
  1021
        x1 = xvalues(nd,i)
forrest@0
  1022
        y1 = yvalues(nd,i)
forrest@0
  1023
        y2 = mn_yvalues(nd,i)
forrest@0
  1024
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
  1025
forrest@0
  1026
        y2 = mx_yvalues(nd,i)
forrest@0
  1027
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
  1028
forrest@0
  1029
; Attach the horizontal cap line, both above and below the marker.
forrest@0
  1030
forrest@0
  1031
        x1 = xvalues(nd,i) - dx4
forrest@0
  1032
        x2 = xvalues(nd,i) + dx4
forrest@0
  1033
        y1 = mn_yvalues(nd,i)
forrest@0
  1034
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
  1035
forrest@0
  1036
        y1 = mx_yvalues(nd,i)
forrest@0
  1037
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
  1038
      end if
forrest@0
  1039
    end do
forrest@0
  1040
  end do
forrest@0
  1041
forrest@0
  1042
  draw(xy)
forrest@0
  1043
  delete (xy)
forrest@0
  1044
  delete (wks)
forrest@0
  1045
forrest@1
  1046
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
  1047
        "rm "+plot_name+"."+plot_type)
forrest@1
  1048
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
  1049
forrest@0
  1050
;****************************************************************************
forrest@0
  1051
;(B)-4 histogram plot, model vs ob 933 site
forrest@0
  1052
;**************************************************************************** 
forrest@0
  1053
forrest@0
  1054
  plot_name = "histogram_model_vs_ob_933"
forrest@1
  1055
  title     = model_name+ " (1975-2000) vs Class B Observations (933 sites)"
forrest@0
  1056
  resh@tiMainString  = title
forrest@0
  1057
forrest@0
  1058
  wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
  1059
forrest@0
  1060
;-----------------------------
forrest@0
  1061
; Add a boxed legend using the more simple method, which won't have
forrest@0
  1062
; vertical lines going through the markers.
forrest@0
  1063
forrest@0
  1064
  resh@pmLegendDisplayMode    = "Always"
forrest@0
  1065
; resh@pmLegendWidthF         = 0.1
forrest@0
  1066
  resh@pmLegendWidthF         = 0.08
forrest@0
  1067
  resh@pmLegendHeightF        = 0.05
forrest@0
  1068
  resh@pmLegendOrthogonalPosF = -1.17
forrest@0
  1069
; resh@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
  1070
; resh@pmLegendParallelPosF   =  0.18
forrest@0
  1071
  resh@pmLegendParallelPosF   =  0.88  ;(rightward)
forrest@0
  1072
forrest@0
  1073
; resh@lgPerimOn              = False
forrest@0
  1074
  resh@lgLabelFontHeightF     = 0.015
forrest@0
  1075
  resh@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
  1076
;-----------------------------
forrest@0
  1077
  tRes  = True
forrest@0
  1078
  tRes@txFontHeightF = 0.025
forrest@0
  1079
forrest@0
  1080
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")"
forrest@0
  1081
forrest@0
  1082
  gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes)
forrest@0
  1083
forrest@0
  1084
  xy = gsn_csm_xy(wks,xvalues,yvalues,resh)
forrest@1
  1085
forrest@1
  1086
  ; Added by Forrest Hoffman to print out values on Wed Feb  4 14:36:00 EST 2009
forrest@1
  1087
  print("Observations: " + xvalues(1,:) + " " + yvalues(1,:))
forrest@0
  1088
;-------------------------------
forrest@0
  1089
;Attach the vertical bar and the horizontal cap line 
forrest@0
  1090
forrest@0
  1091
  do nd=0,1
forrest@0
  1092
    lnres@gsLineColor = line_colors(nd)
forrest@0
  1093
    do i=0,nx-1
forrest@0
  1094
     
forrest@0
  1095
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
  1096
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
  1097
;
forrest@0
  1098
; Attach the vertical bar, both above and below the marker.
forrest@0
  1099
;
forrest@0
  1100
        x1 = xvalues(nd,i)
forrest@0
  1101
        y1 = yvalues(nd,i)
forrest@0
  1102
        y2 = mn_yvalues(nd,i)
forrest@0
  1103
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
  1104
forrest@0
  1105
        y2 = mx_yvalues(nd,i)
forrest@0
  1106
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
  1107
;
forrest@0
  1108
; Attach the horizontal cap line, both above and below the marker.
forrest@0
  1109
;
forrest@0
  1110
        x1 = xvalues(nd,i) - dx4
forrest@0
  1111
        x2 = xvalues(nd,i) + dx4
forrest@0
  1112
        y1 = mn_yvalues(nd,i)
forrest@0
  1113
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
  1114
forrest@0
  1115
        y1 = mx_yvalues(nd,i)
forrest@0
  1116
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
  1117
      end if
forrest@0
  1118
    end do
forrest@0
  1119
  end do
forrest@0
  1120
forrest@0
  1121
  draw(xy)
forrest@0
  1122
  delete(xy)
forrest@0
  1123
  delete(wks)
forrest@0
  1124
forrest@1
  1125
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
  1126
        "rm "+plot_name+"."+plot_type)
forrest@1
  1127
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@1
  1128
forrest@1
  1129
;***************************************************************************
forrest@1
  1130
; Read 2000-2004 dataset for MODIS comparison
forrest@1
  1131
;***************************************************************************
forrest@1
  1132
forrest@1
  1133
;------------------------------------------------------
forrest@1
  1134
; read model data
forrest@1
  1135
forrest@1
  1136
 fm   = addfile (dirm+film9,"r")
forrest@1
  1137
  
forrest@1
  1138
 nppmod0  = fm->NPP
forrest@1
  1139
 xm       = fm->lon  
forrest@1
  1140
 ym       = fm->lat
forrest@1
  1141
forrest@1
  1142
 delete (fm)
forrest@1
  1143
forrest@1
  1144
 nppmod   = nppmod0(0,:,:)
forrest@1
  1145
 delete (nppmod0)
forrest@1
  1146
 nppmod  = nppmod * nsec_per_year
forrest@1
  1147
 nppmod@units     = "gC m~S~-2~N~ y~S~-1~N~"
forrest@1
  1148
 nppmod@long_name     = "Model NPP (gC m~S~-2~N~ y~S~-1~N~)"
forrest@0
  1149
forrest@0
  1150
;***************************************************************************
forrest@0
  1151
;(C) global contour 
forrest@0
  1152
;***************************************************************************
forrest@0
  1153
forrest@0
  1154
;res
forrest@0
  1155
  resg                     = True             ; Use plot options
forrest@0
  1156
  resg@cnFillOn            = True             ; Turn on color fill
forrest@0
  1157
  resg@gsnSpreadColors     = True             ; use full colormap
forrest@0
  1158
; resg@cnFillMode          = "RasterFill"     ; Turn on raster color
forrest@0
  1159
; resg@lbLabelAutoStride   = True
forrest@0
  1160
  resg@cnLinesOn           = False            ; Turn off contourn lines
forrest@0
  1161
  resg@mpFillOn            = False            ; Turn off map fill
forrest@0
  1162
forrest@0
  1163
  resg@gsnSpreadColors      = True            ; use full colormap
forrest@0
  1164
  resg@cnLevelSelectionMode = "ManualLevels"  ; Manual contour invtervals
forrest@0
  1165
  resg@cnMinLevelValF       = 0.              ; Min level
forrest@0
  1166
  resg@cnMaxLevelValF       = 2200.           ; Max level
forrest@0
  1167
  resg@cnLevelSpacingF      = 200.            ; interval
forrest@0
  1168
forrest@0
  1169
;****************************************************************************
forrest@0
  1170
;(C)-1 global contour plot, ob
forrest@0
  1171
;****************************************************************************
forrest@0
  1172
forrest@0
  1173
  delta = 0.00000000001
forrest@0
  1174
  nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe)
forrest@0
  1175
  
forrest@0
  1176
  plot_name = "global_ob"
forrest@1
  1177
  title     = "MODIS MOD17A3 (2000-2004)"
forrest@0
  1178
  resg@tiMainString  = title
forrest@0
  1179
forrest@0
  1180
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
  1181
  gsn_define_colormap(wks,"gui_default")     ; choose colormap
forrest@0
  1182
forrest@0
  1183
  plot = gsn_csm_contour_map_ce(wks,nppglobe,resg)
forrest@0
  1184
   
forrest@0
  1185
  delete (wks)
forrest@0
  1186
forrest@1
  1187
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
  1188
        "rm "+plot_name+"."+plot_type)
forrest@1
  1189
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
  1190
;****************************************************************************
forrest@0
  1191
;(C)-2 global contour plot, model
forrest@0
  1192
;****************************************************************************
forrest@0
  1193
forrest@0
  1194
  plot_name = "global_model"
forrest@1
  1195
  title     = "Model "+ model_name + " (2000-2004)"
forrest@0
  1196
  resg@tiMainString  = title
forrest@0
  1197
forrest@0
  1198
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
  1199
  gsn_define_colormap(wks,"gui_default")     ; choose colormap
forrest@0
  1200
forrest@0
  1201
  plot = gsn_csm_contour_map_ce(wks,nppmod,resg)
forrest@0
  1202
   
forrest@0
  1203
  delete (wks)
forrest@0
  1204
forrest@1
  1205
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
  1206
        "rm "+plot_name+"."+plot_type)
forrest@1
  1207
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
  1208
forrest@0
  1209
;****************************************************************************
forrest@0
  1210
;(C)-3 global contour plot, model vs ob
forrest@0
  1211
;****************************************************************************
forrest@0
  1212
forrest@0
  1213
  plot_name = "global_model_vs_ob"
forrest@0
  1214
forrest@0
  1215
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
  1216
  gsn_define_colormap(wks,"gui_default")     ; choose colormap
forrest@0
  1217
forrest@0
  1218
  delete (plot)
forrest@0
  1219
  plot=new(3,graphic)                        ; create graphic array
forrest@0
  1220
forrest@0
  1221
  resg@gsnFrame             = False          ; Do not draw plot 
forrest@0
  1222
  resg@gsnDraw              = False          ; Do not advance frame
forrest@0
  1223
forrest@0
  1224
; compute correlation coef and M score
forrest@0
  1225
forrest@0
  1226
  uu1 = ndtooned(nppmod)
forrest@0
  1227
  vv1 = ndtooned(nppglobe)
forrest@0
  1228
forrest@0
  1229
  delete (good) 
forrest@0
  1230
  good = ind(.not.ismissing(uu1) .and. .not.ismissing(vv1))
forrest@0
  1231
forrest@0
  1232
  ug = uu1(good)
forrest@0
  1233
  vg = vv1(good)
forrest@0
  1234
forrest@0
  1235
  ccrG = esccr(ug,vg,0)
forrest@0
  1236
forrest@1
  1237
  score_max = 2.0
forrest@0
  1238
forrest@0
  1239
  MG   = (ccrG*ccrG)* score_max
forrest@0
  1240
  M_npp_G = sprintf("%.2f", MG)
forrest@0
  1241
forrest@0
  1242
 if (isvar("compare")) then
forrest@0
  1243
    system("sed -e '1,/M_npp_G/s/M_npp_G/"+M_npp_G+"/' "+html_name2+" > "+html_new2+";"+ \
forrest@0
  1244
           "mv -f "+html_new2+" "+html_name2)
forrest@0
  1245
 end if
forrest@0
  1246
forrest@0
  1247
  system("sed s#M_npp_G#"+M_npp_G+"# "+html_name+" > "+html_new+";"+ \
forrest@0
  1248
         "mv -f "+html_new+" "+html_name)
forrest@0
  1249
forrest@0
  1250
; plot correlation coef
forrest@0
  1251
forrest@0
  1252
  gRes  = True
forrest@0
  1253
  gRes@txFontHeightF = 0.02
forrest@0
  1254
  gRes@txAngleF = 90
forrest@0
  1255
forrest@0
  1256
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")"
forrest@0
  1257
forrest@0
  1258
  gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes)
forrest@0
  1259
;--------------------------------------------------------------------  
forrest@0
  1260
;(a) ob
forrest@0
  1261
forrest@1
  1262
  title     = "MODIS MOD17A3 (2000-2004)"
forrest@0
  1263
  resg@tiMainString  = title
forrest@0
  1264
forrest@0
  1265
  plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resg)       
forrest@0
  1266
forrest@0
  1267
;(b) model
forrest@0
  1268
forrest@1
  1269
  title     = "Model "+ model_name + " (2000-2004)"
forrest@0
  1270
  resg@tiMainString  = title
forrest@0
  1271
forrest@0
  1272
  plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resg) 
forrest@0
  1273
forrest@0
  1274
;(c) model-ob
forrest@0
  1275
forrest@0
  1276
  zz = nppmod
forrest@0
  1277
  zz = nppmod - nppglobe
forrest@1
  1278
  title = "Model "+model_name+" - MODIS MOD17A3"
forrest@0
  1279
forrest@0
  1280
  resg@cnMinLevelValF  = -500           ; Min level
forrest@0
  1281
  resg@cnMaxLevelValF  =  500.          ; Max level
forrest@0
  1282
  resg@cnLevelSpacingF =  50.           ; interval
forrest@0
  1283
  resg@tiMainString    = title
forrest@0
  1284
forrest@0
  1285
  plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) 
forrest@0
  1286
forrest@0
  1287
  pres                            = True        ; panel plot mods desired
forrest@0
  1288
; pres@gsnPanelYWhiteSpacePercent = 5           ; increase white space around
forrest@0
  1289
                                                ; indiv. plots in panel
forrest@0
  1290
  pres@gsnMaximize                = True        ; fill the page
forrest@0
  1291
forrest@0
  1292
  gsn_panel(wks,plot,(/3,1/),pres)              ; create panel plot
forrest@0
  1293
forrest@0
  1294
  delete (wks)
forrest@0
  1295
  delete (plot)
forrest@0
  1296
forrest@1
  1297
 system("convert -trim -density 150 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
  1298
        "rm "+plot_name+"."+plot_type)
forrest@1
  1299
 ;system("convert -trim -density 150 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
  1300
forrest@0
  1301
;***************************************************************************
forrest@0
  1302
;(D)-1 zonal line plot, ob
forrest@0
  1303
;***************************************************************************
forrest@0
  1304
 
forrest@0
  1305
  vv     = zonalAve(nppglobe)
forrest@0
  1306
  vv@long_name = nppglobe@long_name
forrest@0
  1307
forrest@0
  1308
  plot_name = "zonal_ob"
forrest@1
  1309
  title     = "MODIS MOD17A3 (2000-2004)"
forrest@0
  1310
forrest@0
  1311
  resz = True
forrest@0
  1312
  resz@tiMainString  = title
forrest@0
  1313
forrest@0
  1314
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
  1315
forrest@0
  1316
  plot  = gsn_csm_xy (wks,ym,vv,resz)
forrest@0
  1317
   
forrest@0
  1318
  delete (wks)
forrest@0
  1319
forrest@1
  1320
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
  1321
        "rm "+plot_name+"."+plot_type)
forrest@1
  1322
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
  1323
forrest@0
  1324
;****************************************************************************
forrest@0
  1325
;(D)-2 zonal line plot, model vs ob
forrest@0
  1326
;****************************************************************************
forrest@0
  1327
forrest@0
  1328
  s  = new ((/2,dimsizes(ym)/), float)  
forrest@0
  1329
forrest@0
  1330
  s(0,:) = zonalAve(nppglobe) 
forrest@0
  1331
  s(1,:) = zonalAve(nppmod)
forrest@0
  1332
forrest@0
  1333
  s@long_name = nppglobe@long_name
forrest@0
  1334
;-------------------------------------------
forrest@0
  1335
; compute correlation coef and M score
forrest@0
  1336
forrest@1
  1337
  score_max = 2.0
forrest@0
  1338
forrest@0
  1339
  ccrZ = esccr(s(1,:), s(0,:),0)
forrest@0
  1340
  MZ   = (ccrZ*ccrZ)* score_max
forrest@0
  1341
  M_npp_Z = sprintf("%.2f", MZ)
forrest@0
  1342
forrest@0
  1343
  if (isvar("compare")) then
forrest@0
  1344
     system("sed -e '1,/M_npp_Z/s/M_npp_Z/"+M_npp_Z+"/' "+html_name2+" > "+html_new2+";"+ \
forrest@0
  1345
            "mv -f "+html_new2+" "+html_name2)
forrest@0
  1346
  end if
forrest@0
  1347
forrest@0
  1348
  system("sed s#M_npp_Z#"+M_npp_Z+"# "+html_name+" > "+html_new+";"+ \
forrest@0
  1349
         "mv -f "+html_new+" "+html_name)
forrest@0
  1350
;-------------------------------------------
forrest@0
  1351
  plot_name = "zonal_model_vs_ob"
forrest@1
  1352
  title     = "Zonal Average (2000-2004)"
forrest@0
  1353
  resz@tiMainString  = title
forrest@0
  1354
forrest@0
  1355
  wks = gsn_open_wks (plot_type,plot_name)   
forrest@0
  1356
forrest@0
  1357
; resz@vpHeightF          = 0.4               ; change aspect ratio of plot
forrest@0
  1358
; resz@vpWidthF           = 0.7
forrest@0
  1359
forrest@0
  1360
  resz@xyMonoLineColor    = "False"           ; want colored lines
forrest@0
  1361
  resz@xyLineColors       = (/"black","red"/) ; colors chosen
forrest@0
  1362
; resz@xyLineThicknesses  = (/3.,3./)         ; line thicknesses
forrest@0
  1363
  resz@xyLineThicknesses  = (/2.,2./)         ; line thicknesses
forrest@0
  1364
  resz@xyDashPatterns     = (/0.,0./)         ; make all lines solid
forrest@0
  1365
forrest@0
  1366
  resz@tiYAxisString      = s@long_name       ; add a axis title    
forrest@0
  1367
  resz@txFontHeightF      = 0.0195            ; change title font heights
forrest@0
  1368
forrest@0
  1369
; Legent
forrest@0
  1370
  resz@pmLegendDisplayMode    = "Always"      ; turn on legend
forrest@0
  1371
  resz@pmLegendSide           = "Top"         ; Change location of 
forrest@0
  1372
; resz@pmLegendParallelPosF   = .45           ; move units right
forrest@1
  1373
  resz@pmLegendParallelPosF   = .75           ; move units right
forrest@0
  1374
  resz@pmLegendOrthogonalPosF = -0.4          ; move units down
forrest@0
  1375
forrest@0
  1376
  resz@pmLegendWidthF         = 0.10          ; Change width and
forrest@0
  1377
  resz@pmLegendHeightF        = 0.10          ; height of legend.
forrest@1
  1378
  resz@lgLabelFontHeightF     = .015          ; change font height
forrest@0
  1379
; resz@lgTitleOn              = True          ; turn on legend title
forrest@0
  1380
; resz@lgTitleString          = "Example"     ; create legend title
forrest@0
  1381
; resz@lgTitleFontHeightF     = .025          ; font of legend title
forrest@1
  1382
  resz@xyExplicitLegendLabels = (/"MODIS MOD17A3",model_name/) ; explicit labels
forrest@0
  1383
;--------------------------------------------------------------------
forrest@0
  1384
  zRes  = True
forrest@0
  1385
  zRes@txFontHeightF = 0.025
forrest@0
  1386
forrest@0
  1387
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrZ)+")"
forrest@0
  1388
forrest@0
  1389
  gsn_text_ndc(wks,correlation_text,0.50,0.77,zRes)
forrest@0
  1390
;--------------------------------------------------------------------
forrest@0
  1391
  
forrest@0
  1392
  plot  = gsn_csm_xy (wks,ym,s,resz)      
forrest@0
  1393
                                           
forrest@0
  1394
  delete (wks)
forrest@0
  1395
forrest@1
  1396
 system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
  1397
        "rm "+plot_name+"."+plot_type)
forrest@1
  1398
 ;system("convert -trim -density 100 "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
  1399
forrest@0
  1400
;***************************************************************************
forrest@0
  1401
; add total score and write to file
forrest@0
  1402
;***************************************************************************
forrest@0
  1403
  M_total = M81s + M81h + M933s + M933h + MG + MZ
forrest@0
  1404
forrest@0
  1405
  asciiwrite("M_save.npp", M_total)
forrest@0
  1406
forrest@0
  1407
;***************************************************************************
forrest@0
  1408
; output plots
forrest@0
  1409
;***************************************************************************
forrest@0
  1410
  output_dir = model_name+"/npp"
forrest@0
  1411
forrest@0
  1412
  system("mv table_*.html " + output_dir +";"+ \ 
forrest@0
  1413
         "mv *.png " + output_dir)
forrest@0
  1414
 
forrest@0
  1415
;***************************************************************************
forrest@0
  1416
end
forrest@0
  1417