npp/18.scatter_bias.ncl
author Forrest Hoffman <forrest@climatemodeling.org>
Thu, 26 Mar 2009 14:02:21 -0400
changeset 1 4be95183fbcd
permissions -rw-r--r--
Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
forrest@0
     1
; ****************************************************
forrest@0
     2
; combine  scatter, histogram, global and zonal plots
forrest@0
     3
; ****************************************************
forrest@0
     4
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
forrest@0
     5
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
forrest@0
     6
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
forrest@0
     7
;************************************************
forrest@0
     8
procedure pminmax(data:numeric,name:string)
forrest@0
     9
begin
forrest@0
    10
  print ("min/max " + name + " = " + min(data) + "/" + max(data))
forrest@0
    11
  if(isatt(data,"units")) then
forrest@0
    12
    print (name + " units = " + data@units)
forrest@0
    13
  end if
forrest@0
    14
end
forrest@0
    15
forrest@0
    16
; Main code.
forrest@0
    17
begin
forrest@0
    18
forrest@0
    19
 plot_type     = "ps"
forrest@0
    20
 plot_type_new = "png"
forrest@0
    21
forrest@0
    22
;************************************************
forrest@0
    23
; read in ob data
forrest@0
    24
;************************************************
forrest@0
    25
;(1)
forrest@0
    26
 dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/"
forrest@0
    27
 fil81 = "data.81.nc"
forrest@0
    28
 f81   = addfile (dir81+fil81,"r")
forrest@0
    29
forrest@0
    30
 id81   = f81->SITE_ID  
forrest@0
    31
 npp81  = f81->TNPP_C
forrest@0
    32
 rain81 = tofloat(f81->PREC_ANN)
forrest@0
    33
 x81    = f81->LONG_DD  
forrest@0
    34
 y81    = f81->LAT_DD
forrest@0
    35
forrest@0
    36
 id81@long_name  = "SITE_ID"
forrest@0
    37
forrest@0
    38
;change longitude from (-180,180) to (0,360)
forrest@0
    39
;for model data interpolation
forrest@0
    40
forrest@0
    41
 do i= 0,dimsizes(x81)-1
forrest@0
    42
    if (x81(i) .lt. 0.) then
forrest@0
    43
        x81(i) = x81(i)+ 360.
forrest@0
    44
    end if
forrest@0
    45
 end do
forrest@0
    46
;print (x81)
forrest@0
    47
;-------------------------------------
forrest@0
    48
;(2)
forrest@0
    49
 dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/"
forrest@0
    50
 fil933 = "data.933.nc"
forrest@0
    51
 f933   = addfile (dir933+fil933,"r")
forrest@0
    52
forrest@0
    53
 id933   = f933->SITE_ID  
forrest@0
    54
 npp933  = f933->TNPP_C
forrest@0
    55
 rain933 = f933->PREC
forrest@0
    56
 x933    = f933->LONG_DD  
forrest@0
    57
 y933    = f933->LAT_DD 
forrest@0
    58
forrest@0
    59
 id933@long_name  = "SITE_ID"
forrest@0
    60
forrest@0
    61
;change longitude from (-180,180) to (0,360)
forrest@0
    62
;for model data interpolation
forrest@0
    63
forrest@0
    64
 do i= 0,dimsizes(x933)-1
forrest@0
    65
    if (x933(i) .lt. 0.) then
forrest@0
    66
        x933(i) = x933(i)+ 360.
forrest@0
    67
    end if
forrest@0
    68
 end do
forrest@0
    69
;print (x933)
forrest@0
    70
;----------------------------------------
forrest@0
    71
;(3)
forrest@0
    72
 dirglobe = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/"
forrest@0
    73
 filglobe = "Npp_T31_mean.nc"
forrest@0
    74
 fglobe   = addfile (dirglobe+filglobe,"r")
forrest@0
    75
 
forrest@0
    76
 nppglobe0 = fglobe->NPP
forrest@0
    77
 nppglobe  = nppglobe0
forrest@0
    78
;************************************************
forrest@0
    79
; read in model data
forrest@0
    80
;************************************************
forrest@0
    81
 model_name = "b30.061n"
forrest@0
    82
forrest@0
    83
 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    84
 film = "b30.061n_1995-2004_ANN_climo_lnd.nc"
forrest@0
    85
 fm   = addfile (dirm+film,"r")
forrest@0
    86
  
forrest@0
    87
 nppmod0  = fm->NPP
forrest@0
    88
 rainmod0 = fm->RAIN
forrest@0
    89
 xm       = fm->lon  
forrest@0
    90
 ym       = fm->lat
forrest@0
    91
forrest@0
    92
 nppmod   = nppmod0(0,:,:)
forrest@0
    93
 rainmod  = rainmod0(0,:,:)
forrest@0
    94
 delete (nppmod0)
forrest@0
    95
 delete (rainmod0)
forrest@0
    96
forrest@0
    97
 nppmod81  =linint2_points(xm,ym,nppmod,True,x81,y81,0)
forrest@0
    98
forrest@0
    99
 nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0)
forrest@0
   100
forrest@0
   101
 rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0)
forrest@0
   102
forrest@0
   103
 rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0)
forrest@0
   104
forrest@0
   105
;************************************************
forrest@0
   106
; Units for these variables are:
forrest@0
   107
;
forrest@0
   108
; rain81  : mm/year
forrest@0
   109
; rainmod : mm/s
forrest@0
   110
; npp81   : g C/m^2/year
forrest@0
   111
; nppmod81: g C/m^2/s
forrest@0
   112
; nppglobe: g C/m^2/year
forrest@0
   113
;
forrest@0
   114
; We want to convert these to "m/year" and "g C/m^2/year".
forrest@0
   115
;
forrest@0
   116
  nsec_per_year = 60*60*24*365                 
forrest@0
   117
forrest@0
   118
  rain81    = rain81 / 1000.
forrest@0
   119
  rainmod81 = (rainmod81/ 1000.) * nsec_per_year
forrest@0
   120
  nppmod81  = nppmod81 * nsec_per_year
forrest@0
   121
forrest@0
   122
  rain933    = rain933 / 1000.
forrest@0
   123
  rainmod933 = (rainmod933/ 1000.) * nsec_per_year
forrest@0
   124
  nppmod933  = nppmod933 * nsec_per_year
forrest@0
   125
forrest@0
   126
  nppmod  = nppmod * nsec_per_year
forrest@0
   127
forrest@0
   128
  npp81@units      = "gC/m^2/yr"
forrest@0
   129
  nppmod81@units   = "gC/m^2/yr"
forrest@0
   130
  npp933@units     = "gC/m^2/yr"
forrest@0
   131
  nppmod933@units  = "gC/m^2/yr"
forrest@0
   132
  nppmod@units     = "gC/m^2/yr"
forrest@0
   133
  nppglobe@units   = "gC/m^2/yr"
forrest@0
   134
  rain81@units     = "m/yr"
forrest@0
   135
  rainmod81@units  = "m/yr"
forrest@0
   136
  rain933@units    = "m/yr"
forrest@0
   137
  rainmod933@units = "m/yr"
forrest@0
   138
forrest@0
   139
  npp81@long_name      = "NPP (gC/m2/year)"
forrest@0
   140
  npp933@long_name     = "NPP (gC/m2/year)"
forrest@0
   141
  nppmod81@long_name   = "NPP (gC/m2/year)"
forrest@0
   142
  nppmod933@long_name  = "NPP (gC/m2/year)"
forrest@0
   143
  nppmod@long_name     = "NPP (gC/m2/year)"
forrest@0
   144
  nppglobe@long_name   = "NPP (gC/m2/year)"
forrest@0
   145
  rain81@long_name     = "PREC (m/year)"
forrest@0
   146
  rain933@long_name    = "PREC (m/year)"
forrest@0
   147
  rainmod81@long_name  = "PREC (m/year)"
forrest@0
   148
  rainmod933@long_name = "PREC (m/year)"
forrest@0
   149
forrest@0
   150
;(A) plot scatter ob 81
forrest@0
   151
   
forrest@0
   152
 plot_name = "scatter_ob_81"
forrest@0
   153
 title     = "Observed 81 sites"
forrest@0
   154
forrest@0
   155
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   156
 res                   = True                  ; plot mods desired
forrest@0
   157
 res@tiMainString      = title                 ; add title
forrest@0
   158
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   159
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   160
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   161
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   162
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   163
forrest@0
   164
 plot  = gsn_csm_xy (wks,id81,npp81,res)       ; create plot
forrest@0
   165
 frame(wks)
forrest@0
   166
forrest@0
   167
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   168
 system("rm "+plot_name+"."+plot_type)
forrest@0
   169
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   170
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   171
forrest@0
   172
 clear (wks)
forrest@0
   173
 
forrest@0
   174
;(B) plot scatter ob 933
forrest@0
   175
forrest@0
   176
 plot_name = "scatter_ob_933"
forrest@0
   177
 title     = "Observed 933 sites"
forrest@0
   178
forrest@0
   179
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   180
 res                   = True                  ; plot mods desired
forrest@0
   181
 res@tiMainString      = title                 ; add title
forrest@0
   182
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   183
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   184
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   185
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   186
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   187
forrest@0
   188
 plot  = gsn_csm_xy (wks,id933,npp933,res)     ; create plot
forrest@0
   189
 frame(wks)
forrest@0
   190
forrest@0
   191
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   192
 system("rm "+plot_name+"."+plot_type)
forrest@0
   193
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   194
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   195
forrest@0
   196
 clear (wks)
forrest@0
   197
forrest@0
   198
;(C) plot scatter model 81
forrest@0
   199
  
forrest@0
   200
 plot_name = "scatter_model_81"
forrest@0
   201
 title     = "Model "+ model_name +" 81 sites"
forrest@0
   202
forrest@0
   203
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   204
 res                   = True                  ; plot mods desired
forrest@0
   205
 res@tiMainString      = title                 ; add title
forrest@0
   206
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   207
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   208
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   209
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   210
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   211
forrest@0
   212
 plot  = gsn_csm_xy (wks,id81,nppmod81,res)    ; create plot
forrest@0
   213
 frame(wks)
forrest@0
   214
forrest@0
   215
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   216
 system("rm "+plot_name+"."+plot_type)
forrest@0
   217
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   218
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   219
forrest@0
   220
 clear (wks)
forrest@0
   221
 
forrest@0
   222
;(D) plot scatter model 933
forrest@0
   223
forrest@0
   224
 plot_name = "scatter_model_933"
forrest@0
   225
 title     = "Model "+ model_name +" 933 sites"
forrest@0
   226
forrest@0
   227
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   228
 res                   = True                  ; plot mods desired
forrest@0
   229
 res@tiMainString      = title                 ; add title
forrest@0
   230
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   231
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   232
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   233
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   234
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   235
forrest@0
   236
 plot  = gsn_csm_xy (wks,id933,nppmod933,res)    ; create plot
forrest@0
   237
 frame(wks)
forrest@0
   238
forrest@0
   239
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   240
 system("rm "+plot_name+"."+plot_type)
forrest@0
   241
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   242
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   243
forrest@0
   244
 clear (wks)
forrest@0
   245
forrest@0
   246
;(E) scatter model vs ob 81
forrest@0
   247
  
forrest@0
   248
 plot_name = "scatter_model_vs_ob_81"
forrest@0
   249
 title     = model_name +" vs ob 81 sites"
forrest@0
   250
forrest@0
   251
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   252
 res                   = True                  ; plot mods desired
forrest@0
   253
 res@tiMainString      = title                 ; add title
forrest@0
   254
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   255
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   256
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   257
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   258
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   259
;-------------------------------
forrest@0
   260
;compute correlation coef. and M
forrest@0
   261
 ccr81 = esccr(nppmod81,npp81,0)
forrest@0
   262
 print (ccr81)
forrest@0
   263
forrest@0
   264
;new eq
forrest@0
   265
 bias = sum(abs(nppmod81-npp81)/(nppmod81+npp81))
forrest@0
   266
 M81  = (1. - (bias/dimsizes(y81)))*5.
forrest@0
   267
 print (M81)
forrest@0
   268
forrest@0
   269
 tRes  = True
forrest@0
   270
 tRes@txFontHeightF = 0.025
forrest@0
   271
forrest@0
   272
 correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")"
forrest@0
   273
forrest@0
   274
 gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes)
forrest@0
   275
;--------------------------------
forrest@0
   276
 plot  = gsn_csm_xy (wks,npp81,nppmod81,res)       ; create plot
forrest@0
   277
 frame(wks)
forrest@0
   278
forrest@0
   279
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   280
 system("rm "+plot_name+"."+plot_type)
forrest@0
   281
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   282
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   283
forrest@0
   284
 clear (wks)
forrest@0
   285
 
forrest@0
   286
;(F) scatter model vs ob 933
forrest@0
   287
  
forrest@0
   288
 plot_name = "scatter_model_vs_ob_933"
forrest@0
   289
 title     = model_name +" vs ob 933 sites"
forrest@0
   290
forrest@0
   291
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   292
 res                   = True                  ; plot mods desired
forrest@0
   293
 res@tiMainString      = title                 ; add title
forrest@0
   294
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   295
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   296
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   297
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   298
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   299
;-------------------------------
forrest@0
   300
;compute correlation coef. and M
forrest@0
   301
 ccr933 = esccr(nppmod933,npp933,0)
forrest@0
   302
 print (ccr933)
forrest@0
   303
forrest@0
   304
;new eq
forrest@0
   305
 bias = sum(abs(nppmod933-npp933)/(nppmod933+npp933))
forrest@0
   306
 M933 = (1. - (bias/dimsizes(y933)))*5.
forrest@0
   307
 print (M933)
forrest@0
   308
forrest@0
   309
 tRes  = True
forrest@0
   310
 tRes@txFontHeightF = 0.025
forrest@0
   311
forrest@0
   312
 correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")"
forrest@0
   313
forrest@0
   314
 gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes)
forrest@0
   315
;--------------------------------
forrest@0
   316
 plot  = gsn_csm_xy (wks,npp933,nppmod933,res)    ; create plot
forrest@0
   317
 frame(wks)
forrest@0
   318
forrest@0
   319
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   320
 system("rm "+plot_name+"."+plot_type)
forrest@0
   321
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   322
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   323
forrest@0
   324
 clear (wks)
forrest@0
   325
;**************************************************************************
forrest@0
   326
;(G) histogram 81
forrest@0
   327
forrest@0
   328
;--------------------------------------------------------------------
forrest@0
   329
;get data
forrest@0
   330
forrest@0
   331
  RAIN1_1D = ndtooned(rain81)
forrest@0
   332
  RAIN2_1D = ndtooned(rainmod81)
forrest@0
   333
  NPP1_1D  = ndtooned(npp81)
forrest@0
   334
  NPP2_1D  = ndtooned(nppmod81)
forrest@0
   335
forrest@0
   336
; Calculaee "nice" bins for binning the data in equally spaced ranges.
forrest@0
   337
forrest@0
   338
  nbins       = 15     ; Number of bins to use.
forrest@0
   339
forrest@0
   340
  nicevals    = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True)
forrest@0
   341
  nvals       = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
forrest@0
   342
  range       = fspan(nicevals(0),nicevals(1),nvals)
forrest@0
   343
forrest@0
   344
; Use this range information to grab all the values in a
forrest@0
   345
; particular range, and then take an average.
forrest@0
   346
forrest@0
   347
  nr           = dimsizes(range)
forrest@0
   348
  nx           = nr-1
forrest@0
   349
  xvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   350
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
   351
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
   352
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
   353
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
   354
  yvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   355
  mn_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   356
  mx_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   357
forrest@0
   358
  do nd=0,1
forrest@0
   359
forrest@0
   360
; See if we are doing model or observational data.
forrest@0
   361
forrest@0
   362
    if(nd.eq.0) then
forrest@0
   363
      data     = RAIN1_1D
forrest@0
   364
      npp_data = NPP1_1D
forrest@0
   365
    else
forrest@0
   366
      data     = RAIN2_1D
forrest@0
   367
      npp_data = NPP2_1D
forrest@0
   368
    end if
forrest@0
   369
forrest@0
   370
; Loop through each range and check for values.
forrest@0
   371
forrest@0
   372
    do i=0,nr-2
forrest@0
   373
      if (i.ne.(nr-2)) then
forrest@0
   374
;        print("")
forrest@0
   375
;        print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
   376
        idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
forrest@0
   377
      else
forrest@0
   378
;        print("")
forrest@0
   379
;        print("In range ["+range(i)+",)")
forrest@0
   380
        idx = ind(range(i).le.data)
forrest@0
   381
      end if
forrest@0
   382
forrest@0
   383
; Calculate average, and get min and max.
forrest@0
   384
forrest@0
   385
      if(.not.any(ismissing(idx))) then
forrest@0
   386
        yvalues(nd,i)    = avg(npp_data(idx))
forrest@0
   387
        mn_yvalues(nd,i) = min(npp_data(idx))
forrest@0
   388
        mx_yvalues(nd,i) = max(npp_data(idx))
forrest@0
   389
        count = dimsizes(idx)
forrest@0
   390
      else
forrest@0
   391
        count            = 0
forrest@0
   392
        yvalues(nd,i)    = yvalues@_FillValue
forrest@0
   393
        mn_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   394
        mx_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   395
      end if
forrest@0
   396
forrest@0
   397
; Print out information.
forrest@0
   398
forrest@0
   399
;      print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i))
forrest@0
   400
;      print("Min/Max:  " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
forrest@0
   401
forrest@0
   402
forrest@0
   403
; Clean up for next time in loop.
forrest@0
   404
forrest@0
   405
      delete(idx)
forrest@0
   406
    end do
forrest@0
   407
    delete(data)
forrest@0
   408
    delete(npp_data)
forrest@0
   409
  end do
forrest@0
   410
;----------------------------------------
forrest@0
   411
;compute correlation coeff and M score
forrest@0
   412
 
forrest@0
   413
 u = yvalues(0,:)
forrest@0
   414
 v = yvalues(1,:)
forrest@0
   415
forrest@0
   416
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   417
 uu = u(good)
forrest@0
   418
 vv = v(good)
forrest@0
   419
forrest@0
   420
 ccr81h = esccr(uu,vv,0)
forrest@0
   421
 print (ccr81h)
forrest@0
   422
forrest@0
   423
;new eq
forrest@0
   424
 bias = sum(abs(vv-uu)/(vv+uu))
forrest@0
   425
 M81h = (1.- (bias/dimsizes(uu)))*5.
forrest@0
   426
 print (M81h)
forrest@0
   427
forrest@0
   428
 delete (u)
forrest@0
   429
 delete (v)
forrest@0
   430
 delete (uu)
forrest@0
   431
 delete (vv)
forrest@0
   432
;----------------------------------------------------------------------
forrest@0
   433
; histogram res
forrest@0
   434
forrest@0
   435
  resh                = True
forrest@0
   436
  resh@gsnMaximize    = True
forrest@0
   437
  resh@gsnDraw        = False
forrest@0
   438
  resh@gsnFrame       = False
forrest@0
   439
  resh@xyMarkLineMode = "Markers"
forrest@0
   440
  resh@xyMarkerSizeF  = 0.014
forrest@0
   441
  resh@xyMarker       = 16
forrest@0
   442
  resh@xyMarkerColors = (/"Brown","Blue"/)
forrest@0
   443
  resh@trYMinF        = min(mn_yvalues) - 10.
forrest@0
   444
  resh@trYMaxF        = max(mx_yvalues) + 10.
forrest@0
   445
forrest@0
   446
  resh@tiYAxisString  = "NPP (g C/m2/year)"
forrest@0
   447
  resh@tiXAxisString  = "Precipitation (m/year)"
forrest@0
   448
forrest@0
   449
  max_bar = new((/2,nx/),graphic)
forrest@0
   450
  min_bar = new((/2,nx/),graphic)
forrest@0
   451
  max_cap = new((/2,nx/),graphic)
forrest@0
   452
  min_cap = new((/2,nx/),graphic)
forrest@0
   453
forrest@0
   454
  lnres = True
forrest@0
   455
  line_colors = (/"brown","blue"/)
forrest@0
   456
;=================================================================
forrest@0
   457
; histogram ob 81 site only
forrest@0
   458
;
forrest@0
   459
  plot_name = "histogram_ob_81"
forrest@0
   460
  title     = "Observed 81 site"
forrest@0
   461
  resh@tiMainString  = title
forrest@0
   462
forrest@0
   463
  wks   = gsn_open_wks (plot_type,plot_name)    
forrest@0
   464
forrest@0
   465
  xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh)
forrest@0
   466
forrest@0
   467
;-------------------------------
forrest@0
   468
;Attach the vertical bar and the horizontal cap line 
forrest@0
   469
forrest@0
   470
  do nd=0,0
forrest@0
   471
    lnres@gsLineColor = line_colors(nd)
forrest@0
   472
    do i=0,nx-1
forrest@0
   473
     
forrest@0
   474
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   475
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   476
;
forrest@0
   477
; Attach the vertical bar, both above and below the marker.
forrest@0
   478
;
forrest@0
   479
        x1 = xvalues(nd,i)
forrest@0
   480
        y1 = yvalues(nd,i)
forrest@0
   481
        y2 = mn_yvalues(nd,i)
forrest@0
   482
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   483
forrest@0
   484
        y2 = mx_yvalues(nd,i)
forrest@0
   485
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   486
;
forrest@0
   487
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   488
;
forrest@0
   489
        x1 = xvalues(nd,i) - dx4
forrest@0
   490
        x2 = xvalues(nd,i) + dx4
forrest@0
   491
        y1 = mn_yvalues(nd,i)
forrest@0
   492
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   493
forrest@0
   494
        y1 = mx_yvalues(nd,i)
forrest@0
   495
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   496
      end if
forrest@0
   497
    end do
forrest@0
   498
  end do
forrest@0
   499
forrest@0
   500
  draw(xy)
forrest@0
   501
  frame(wks)
forrest@0
   502
forrest@0
   503
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   504
  system("rm "+plot_name+"."+plot_type)
forrest@0
   505
; system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   506
; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   507
forrest@0
   508
  clear (wks)
forrest@0
   509
;===========================================================================
forrest@0
   510
; histogram model vs ob 81 site 
forrest@0
   511
forrest@0
   512
  plot_name = "histogram_mod-ob_81"
forrest@0
   513
  title     = model_name+ " vs Observed 81 site"
forrest@0
   514
  resh@tiMainString  = title
forrest@0
   515
forrest@0
   516
  wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   517
forrest@0
   518
;-----------------------------
forrest@0
   519
; Add a boxed legend using the more simple method, which won't have
forrest@0
   520
; vertical lines going through the markers.
forrest@0
   521
forrest@0
   522
  resh@pmLegendDisplayMode    = "Always"
forrest@0
   523
; resh@pmLegendWidthF         = 0.1
forrest@0
   524
  resh@pmLegendWidthF         = 0.08
forrest@0
   525
  resh@pmLegendHeightF        = 0.05
forrest@0
   526
  resh@pmLegendOrthogonalPosF = -1.17
forrest@0
   527
; resh@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   528
; resh@pmLegendParallelPosF   =  0.18
forrest@0
   529
  resh@pmLegendParallelPosF   =  0.88  ;(rightward)
forrest@0
   530
forrest@0
   531
; resh@lgPerimOn              = False
forrest@0
   532
  resh@lgLabelFontHeightF     = 0.015
forrest@0
   533
  resh@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
   534
;-----------------------------
forrest@0
   535
  tRes  = True
forrest@0
   536
  tRes@txFontHeightF = 0.025
forrest@0
   537
forrest@0
   538
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")"
forrest@0
   539
forrest@0
   540
  gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes)
forrest@0
   541
forrest@0
   542
  xy = gsn_csm_xy(wks,xvalues,yvalues,resh)
forrest@0
   543
;-------------------------------
forrest@0
   544
;Attach the vertical bar and the horizontal cap line 
forrest@0
   545
forrest@0
   546
  do nd=0,1
forrest@0
   547
    lnres@gsLineColor = line_colors(nd)
forrest@0
   548
    do i=0,nx-1
forrest@0
   549
     
forrest@0
   550
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   551
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   552
;
forrest@0
   553
; Attach the vertical bar, both above and below the marker.
forrest@0
   554
;
forrest@0
   555
        x1 = xvalues(nd,i)
forrest@0
   556
        y1 = yvalues(nd,i)
forrest@0
   557
        y2 = mn_yvalues(nd,i)
forrest@0
   558
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   559
forrest@0
   560
        y2 = mx_yvalues(nd,i)
forrest@0
   561
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   562
;
forrest@0
   563
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   564
;
forrest@0
   565
        x1 = xvalues(nd,i) - dx4
forrest@0
   566
        x2 = xvalues(nd,i) + dx4
forrest@0
   567
        y1 = mn_yvalues(nd,i)
forrest@0
   568
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   569
forrest@0
   570
        y1 = mx_yvalues(nd,i)
forrest@0
   571
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   572
      end if
forrest@0
   573
    end do
forrest@0
   574
  end do
forrest@0
   575
  draw(xy)
forrest@0
   576
  frame(wks)
forrest@0
   577
forrest@0
   578
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   579
  system("rm "+plot_name+"."+plot_type)
forrest@0
   580
; system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   581
; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   582
forrest@0
   583
 clear (wks)
forrest@0
   584
forrest@0
   585
 delete (RAIN1_1D)
forrest@0
   586
 delete (RAIN2_1D)
forrest@0
   587
 delete (NPP1_1D)
forrest@0
   588
 delete (NPP2_1D)
forrest@0
   589
 delete (range)
forrest@0
   590
 delete (xvalues) 
forrest@0
   591
 delete (yvalues)
forrest@0
   592
 delete (mn_yvalues)
forrest@0
   593
 delete (mx_yvalues)
forrest@0
   594
 delete (good)
forrest@0
   595
 delete (max_bar)
forrest@0
   596
 delete (min_bar)
forrest@0
   597
 delete (max_cap)
forrest@0
   598
 delete (min_cap)   
forrest@0
   599
;**************************************************************************
forrest@0
   600
;(H) histogram 933
forrest@0
   601
forrest@0
   602
;--------------------------------------------------------------------
forrest@0
   603
;get data
forrest@0
   604
forrest@0
   605
  RAIN1_1D = ndtooned(rain933)
forrest@0
   606
  RAIN2_1D = ndtooned(rainmod933)
forrest@0
   607
  NPP1_1D  = ndtooned(npp933)
forrest@0
   608
  NPP2_1D  = ndtooned(nppmod933)
forrest@0
   609
 
forrest@0
   610
; Calculate "nice" bins for binning the data in equally spaced ranges.
forrest@0
   611
 
forrest@0
   612
  nbins       = 15     ; Number of bins to use.
forrest@0
   613
forrest@0
   614
  nicevals    = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True)
forrest@0
   615
  nvals       = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
forrest@0
   616
  range       = fspan(nicevals(0),nicevals(1),nvals)
forrest@0
   617
 
forrest@0
   618
; Use this range information to grab all the values in a
forrest@0
   619
; particular range, and then take an average.
forrest@0
   620
 
forrest@0
   621
  nr           = dimsizes(range)
forrest@0
   622
  nx           = nr-1
forrest@0
   623
  xvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   624
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
   625
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
   626
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
   627
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
   628
  yvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   629
  mn_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   630
  mx_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   631
forrest@0
   632
  do nd=0,1
forrest@0
   633
 
forrest@0
   634
; See if we are doing model or observational data.
forrest@0
   635
forrest@0
   636
    if(nd.eq.0) then
forrest@0
   637
      data     = RAIN1_1D
forrest@0
   638
      npp_data = NPP1_1D
forrest@0
   639
    else
forrest@0
   640
      data     = RAIN2_1D
forrest@0
   641
      npp_data = NPP2_1D
forrest@0
   642
    end if
forrest@0
   643
forrest@0
   644
; Loop through each range and check for values.
forrest@0
   645
forrest@0
   646
    do i=0,nr-2
forrest@0
   647
      if (i.ne.(nr-2)) then
forrest@0
   648
;        print("")
forrest@0
   649
;        print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
   650
        idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
forrest@0
   651
      else
forrest@0
   652
;        print("")
forrest@0
   653
;        print("In range ["+range(i)+",)")
forrest@0
   654
        idx = ind(range(i).le.data)
forrest@0
   655
      end if
forrest@0
   656
 
forrest@0
   657
; Calculate average, and get min and max.
forrest@0
   658
forrest@0
   659
      if(.not.any(ismissing(idx))) then
forrest@0
   660
        yvalues(nd,i)    = avg(npp_data(idx))
forrest@0
   661
        mn_yvalues(nd,i) = min(npp_data(idx))
forrest@0
   662
        mx_yvalues(nd,i) = max(npp_data(idx))
forrest@0
   663
        count = dimsizes(idx)
forrest@0
   664
      else
forrest@0
   665
        count            = 0
forrest@0
   666
        yvalues(nd,i)    = yvalues@_FillValue
forrest@0
   667
        mn_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   668
        mx_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   669
      end if
forrest@0
   670
forrest@0
   671
; Print out information.
forrest@0
   672
forrest@0
   673
;      print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i))
forrest@0
   674
;      print("Min/Max:  " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
forrest@0
   675
forrest@0
   676
; Clean up for next time in loop.
forrest@0
   677
forrest@0
   678
      delete(idx)
forrest@0
   679
    end do
forrest@0
   680
    delete(data)
forrest@0
   681
    delete(npp_data)
forrest@0
   682
  end do
forrest@0
   683
;----------------------------------------
forrest@0
   684
;compute correlation coeff and M score
forrest@0
   685
 
forrest@0
   686
 u = yvalues(0,:)
forrest@0
   687
 v = yvalues(1,:)
forrest@0
   688
forrest@0
   689
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   690
 uu = u(good)
forrest@0
   691
 vv = v(good)
forrest@0
   692
forrest@0
   693
 ccr933h = esccr(uu,vv,0)
forrest@0
   694
 print (ccr933h)
forrest@0
   695
forrest@0
   696
;new eq
forrest@0
   697
 bias  = sum(abs(vv-uu)/(vv+uu))
forrest@0
   698
 M933h = (1.- (bias/dimsizes(uu)))*5.
forrest@0
   699
 print (M933h)
forrest@0
   700
forrest@0
   701
 delete (u)
forrest@0
   702
 delete (v)
forrest@0
   703
 delete (uu)
forrest@0
   704
 delete (vv)
forrest@0
   705
;----------------------------------------------------------------------
forrest@0
   706
; histogram res
forrest@0
   707
forrest@0
   708
  delete (resh)
forrest@0
   709
  resh                = True
forrest@0
   710
  resh@gsnMaximize    = True
forrest@0
   711
  resh@gsnDraw        = False
forrest@0
   712
  resh@gsnFrame       = False
forrest@0
   713
  resh@xyMarkLineMode = "Markers"
forrest@0
   714
  resh@xyMarkerSizeF  = 0.014
forrest@0
   715
  resh@xyMarker       = 16
forrest@0
   716
  resh@xyMarkerColors = (/"Brown","Blue"/)
forrest@0
   717
  resh@trYMinF        = min(mn_yvalues) - 10.
forrest@0
   718
  resh@trYMaxF        = max(mx_yvalues) + 10.
forrest@0
   719
forrest@0
   720
  resh@tiYAxisString  = "NPP (g C/m2/year)"
forrest@0
   721
  resh@tiXAxisString  = "Precipitation (m/year)"
forrest@0
   722
forrest@0
   723
  max_bar = new((/2,nx/),graphic)
forrest@0
   724
  min_bar = new((/2,nx/),graphic)
forrest@0
   725
  max_cap = new((/2,nx/),graphic)
forrest@0
   726
  min_cap = new((/2,nx/),graphic)
forrest@0
   727
forrest@0
   728
  lnres = True
forrest@0
   729
  line_colors = (/"brown","blue"/)
forrest@0
   730
;=================================================================
forrest@0
   731
; histogram ob 933 site only
forrest@0
   732
 
forrest@0
   733
  plot_name = "histogram_ob_933"
forrest@0
   734
  title     = "Observed 933 site"
forrest@0
   735
  resh@tiMainString  = title
forrest@0
   736
forrest@0
   737
  wks   = gsn_open_wks (plot_type,plot_name)    
forrest@0
   738
forrest@0
   739
  xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh)
forrest@0
   740
forrest@0
   741
;-------------------------------
forrest@0
   742
;Attach the vertical bar and the horizontal cap line 
forrest@0
   743
forrest@0
   744
  do nd=0,0
forrest@0
   745
    lnres@gsLineColor = line_colors(nd)
forrest@0
   746
    do i=0,nx-1
forrest@0
   747
     
forrest@0
   748
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   749
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   750
forrest@0
   751
; Attach the vertical bar, both above and below the marker.
forrest@0
   752
forrest@0
   753
        x1 = xvalues(nd,i)
forrest@0
   754
        y1 = yvalues(nd,i)
forrest@0
   755
        y2 = mn_yvalues(nd,i)
forrest@0
   756
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   757
forrest@0
   758
        y2 = mx_yvalues(nd,i)
forrest@0
   759
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   760
forrest@0
   761
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   762
forrest@0
   763
        x1 = xvalues(nd,i) - dx4
forrest@0
   764
        x2 = xvalues(nd,i) + dx4
forrest@0
   765
        y1 = mn_yvalues(nd,i)
forrest@0
   766
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   767
forrest@0
   768
        y1 = mx_yvalues(nd,i)
forrest@0
   769
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   770
      end if
forrest@0
   771
    end do
forrest@0
   772
  end do
forrest@0
   773
forrest@0
   774
  draw(xy)
forrest@0
   775
  frame(wks)
forrest@0
   776
forrest@0
   777
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   778
  system("rm "+plot_name+"."+plot_type)
forrest@0
   779
; system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   780
; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   781
forrest@0
   782
  delete (xy)
forrest@0
   783
  clear (wks)
forrest@0
   784
forrest@0
   785
;===========================================================================
forrest@0
   786
; histogram model vs ob 933 site 
forrest@0
   787
forrest@0
   788
  plot_name = "histogram_mod-ob_933"
forrest@0
   789
  title     = model_name+ " vs Observed 933 site"
forrest@0
   790
  resh@tiMainString  = title
forrest@0
   791
forrest@0
   792
  wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   793
forrest@0
   794
;-----------------------------
forrest@0
   795
; Add a boxed legend using the more simple method, which won't have
forrest@0
   796
; vertical lines going through the markers.
forrest@0
   797
forrest@0
   798
  resh@pmLegendDisplayMode    = "Always"
forrest@0
   799
; resh@pmLegendWidthF         = 0.1
forrest@0
   800
  resh@pmLegendWidthF         = 0.08
forrest@0
   801
  resh@pmLegendHeightF        = 0.05
forrest@0
   802
  resh@pmLegendOrthogonalPosF = -1.17
forrest@0
   803
; resh@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   804
; resh@pmLegendParallelPosF   =  0.18
forrest@0
   805
  resh@pmLegendParallelPosF   =  0.88  ;(rightward)
forrest@0
   806
forrest@0
   807
; resh@lgPerimOn              = False
forrest@0
   808
  resh@lgLabelFontHeightF     = 0.015
forrest@0
   809
  resh@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
   810
;-----------------------------
forrest@0
   811
  tRes  = True
forrest@0
   812
  tRes@txFontHeightF = 0.025
forrest@0
   813
forrest@0
   814
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")"
forrest@0
   815
forrest@0
   816
  gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes)
forrest@0
   817
forrest@0
   818
  xy = gsn_csm_xy(wks,xvalues,yvalues,resh)
forrest@0
   819
;-------------------------------
forrest@0
   820
;Attach the vertical bar and the horizontal cap line 
forrest@0
   821
forrest@0
   822
  do nd=0,1
forrest@0
   823
    lnres@gsLineColor = line_colors(nd)
forrest@0
   824
    do i=0,nx-1
forrest@0
   825
     
forrest@0
   826
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   827
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   828
;
forrest@0
   829
; Attach the vertical bar, both above and below the marker.
forrest@0
   830
;
forrest@0
   831
        x1 = xvalues(nd,i)
forrest@0
   832
        y1 = yvalues(nd,i)
forrest@0
   833
        y2 = mn_yvalues(nd,i)
forrest@0
   834
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   835
forrest@0
   836
        y2 = mx_yvalues(nd,i)
forrest@0
   837
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   838
;
forrest@0
   839
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   840
;
forrest@0
   841
        x1 = xvalues(nd,i) - dx4
forrest@0
   842
        x2 = xvalues(nd,i) + dx4
forrest@0
   843
        y1 = mn_yvalues(nd,i)
forrest@0
   844
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   845
forrest@0
   846
        y1 = mx_yvalues(nd,i)
forrest@0
   847
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   848
      end if
forrest@0
   849
    end do
forrest@0
   850
  end do
forrest@0
   851
  draw(xy)
forrest@0
   852
  frame(wks)
forrest@0
   853
forrest@0
   854
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   855
  system("rm "+plot_name+"."+plot_type)
forrest@0
   856
; system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   857
; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   858
forrest@0
   859
  delete (xy)
forrest@0
   860
  clear (wks)
forrest@0
   861
;------------------------------------------------------------------------
forrest@0
   862
; global contour 
forrest@0
   863
forrest@0
   864
;res
forrest@0
   865
  resg                     = True             ; Use plot options
forrest@0
   866
  resg@cnFillOn            = True             ; Turn on color fill
forrest@0
   867
  resg@gsnSpreadColors     = True             ; use full colormap
forrest@0
   868
; resg@cnFillMode          = "RasterFill"     ; Turn on raster color
forrest@0
   869
; resg@lbLabelAutoStride   = True
forrest@0
   870
  resg@cnLinesOn           = False            ; Turn off contourn lines
forrest@0
   871
  resg@mpFillOn            = False            ; Turn off map fill
forrest@0
   872
forrest@0
   873
  resg@gsnSpreadColors      = True            ; use full colormap
forrest@0
   874
  resg@cnLevelSelectionMode = "ManualLevels"  ; Manual contour invtervals
forrest@0
   875
  resg@cnMinLevelValF       = 0.              ; Min level
forrest@0
   876
  resg@cnMaxLevelValF       = 2200.           ; Max level
forrest@0
   877
  resg@cnLevelSpacingF      = 200.            ; interval
forrest@0
   878
;------------------------------------------------------------------------
forrest@0
   879
;global contour ob
forrest@0
   880
forrest@0
   881
  delta = 0.00000000001
forrest@0
   882
  nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe)
forrest@0
   883
  
forrest@0
   884
  plot_name = "global_ob"
forrest@0
   885
  title     = "Observed MODIS MOD 17"
forrest@0
   886
  resg@tiMainString  = title
forrest@0
   887
forrest@0
   888
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
   889
  gsn_define_colormap(wks,"gui_default")     ; choose colormap
forrest@0
   890
forrest@0
   891
  plot = gsn_csm_contour_map_ce(wks,nppglobe,resg)   
forrest@0
   892
  frame(wks)
forrest@0
   893
forrest@0
   894
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   895
  system("rm "+plot_name+"."+plot_type)
forrest@0
   896
  system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   897
  system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   898
forrest@0
   899
  clear (wks)
forrest@0
   900
;------------------------------------------------------------------------
forrest@0
   901
;global contour model
forrest@0
   902
forrest@0
   903
  plot_name = "global_model"
forrest@0
   904
  title     = "Model "+ model_name
forrest@0
   905
  resg@tiMainString  = title
forrest@0
   906
forrest@0
   907
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
   908
  gsn_define_colormap(wks,"gui_default")     ; choose colormap
forrest@0
   909
forrest@0
   910
  plot = gsn_csm_contour_map_ce(wks,nppmod,resg)   
forrest@0
   911
  frame(wks)
forrest@0
   912
forrest@0
   913
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   914
  system("rm "+plot_name+"."+plot_type)
forrest@0
   915
  system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   916
  system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   917
forrest@0
   918
  clear (wks)
forrest@0
   919
;------------------------------------------------------------------------
forrest@0
   920
;global contour model vs ob
forrest@0
   921
forrest@0
   922
  plot_name = "global_model_vs_ob"
forrest@0
   923
forrest@0
   924
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
   925
  gsn_define_colormap(wks,"gui_default")     ; choose colormap
forrest@0
   926
forrest@0
   927
  delete (plot)
forrest@0
   928
  plot=new(3,graphic)                        ; create graphic array
forrest@0
   929
forrest@0
   930
  resg@gsnFrame             = False          ; Do not draw plot 
forrest@0
   931
  resg@gsnDraw              = False          ; Do not advance frame
forrest@0
   932
forrest@0
   933
;(d) compute correlation coef and M score
forrest@0
   934
forrest@0
   935
  uu1 = ndtooned(nppmod)
forrest@0
   936
  vv1 = ndtooned(nppglobe)
forrest@0
   937
forrest@0
   938
  delete (good) 
forrest@0
   939
  good = ind(.not.ismissing(uu1) .and. .not.ismissing(vv1))
forrest@0
   940
forrest@0
   941
  ug = uu1(good)
forrest@0
   942
  vg = vv1(good)
forrest@0
   943
forrest@0
   944
  ccrG = esccr(ug,vg,0)
forrest@0
   945
  print (ccrG)
forrest@0
   946
forrest@0
   947
  MG   = (ccrG*ccrG)* 5.0
forrest@0
   948
  print (MG)
forrest@0
   949
forrest@0
   950
; plot correlation coef
forrest@0
   951
forrest@0
   952
  gRes  = True
forrest@0
   953
  gRes@txFontHeightF = 0.02
forrest@0
   954
  gRes@txAngleF = 90
forrest@0
   955
forrest@0
   956
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")"
forrest@0
   957
forrest@0
   958
  gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes)
forrest@0
   959
;--------------------------------------------------------------------
forrest@0
   960
  
forrest@0
   961
;(a) ob
forrest@0
   962
forrest@0
   963
  title     = "Observed MODIS MOD 17"
forrest@0
   964
  resg@tiMainString  = title
forrest@0
   965
forrest@0
   966
  plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resg)       
forrest@0
   967
forrest@0
   968
;(b) model
forrest@0
   969
forrest@0
   970
  title     = "Model "+ model_name
forrest@0
   971
  resg@tiMainString  = title
forrest@0
   972
forrest@0
   973
  plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resg) 
forrest@0
   974
forrest@0
   975
;(c) model-ob
forrest@0
   976
forrest@0
   977
  zz = nppmod
forrest@0
   978
  zz = nppmod - nppglobe
forrest@0
   979
  title = "Model_"+model_name+" - Observed"
forrest@0
   980
forrest@0
   981
  resg@cnMinLevelValF  = -500           ; Min level
forrest@0
   982
  resg@cnMaxLevelValF  =  500.          ; Max level
forrest@0
   983
  resg@cnLevelSpacingF =  50.           ; interval
forrest@0
   984
  resg@tiMainString    = title
forrest@0
   985
forrest@0
   986
  plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) 
forrest@0
   987
forrest@0
   988
  pres                            = True        ; panel plot mods desired
forrest@0
   989
  pres@gsnPanelYWhiteSpacePercent = 5           ; increase white space around
forrest@0
   990
                                                ; indiv. plots in panel
forrest@0
   991
  pres@gsnMaximize                = True        ; fill the page
forrest@0
   992
forrest@0
   993
  gsn_panel(wks,plot,(/3,1/),pres)              ; create panel plot
forrest@0
   994
forrest@0
   995
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   996
; system("rm "+plot_name+"."+plot_type)
forrest@0
   997
; system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   998
; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   999
forrest@0
  1000
  frame (wks)
forrest@0
  1001
  clear (wks)
forrest@0
  1002
forrest@0
  1003
  delete (plot)
forrest@0
  1004
;---------------------------------------------------------------------
forrest@0
  1005
; zonal line plot ob
forrest@0
  1006
forrest@0
  1007
  resz = True
forrest@0
  1008
  
forrest@0
  1009
  vv     = zonalAve(nppglobe)
forrest@0
  1010
  vv@long_name = nppglobe@long_name
forrest@0
  1011
forrest@0
  1012
  plot_name = "zonal_ob"
forrest@0
  1013
  title     = "Observed MODIS MOD 17"
forrest@0
  1014
  resz@tiMainString  = title
forrest@0
  1015
forrest@0
  1016
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
  1017
forrest@0
  1018
  plot  = gsn_csm_xy (wks,ym,vv,resz)   
forrest@0
  1019
  frame(wks)
forrest@0
  1020
forrest@0
  1021
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
  1022
  system("rm "+plot_name+"."+plot_type)
forrest@0
  1023
  system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
  1024
  system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
  1025
forrest@0
  1026
  clear (wks)
forrest@0
  1027
;---------------------------------------------------------------------
forrest@0
  1028
; zonal line plot model vs ob
forrest@0
  1029
forrest@0
  1030
  s  = new ((/2,dimsizes(ym)/), float)  
forrest@0
  1031
forrest@0
  1032
  s(0,:) = zonalAve(nppglobe) 
forrest@0
  1033
  s(1,:) = zonalAve(nppmod)
forrest@0
  1034
forrest@0
  1035
  s@long_name = nppglobe@long_name
forrest@0
  1036
;-------------------------------------------
forrest@0
  1037
;(d) compute correlation coef and M score
forrest@0
  1038
forrest@0
  1039
  ccrZ = esccr(s(1,:), s(0,:),0)
forrest@0
  1040
  print (ccrZ)
forrest@0
  1041
forrest@0
  1042
  MZ   = (ccrZ*ccrZ)* 5.0
forrest@0
  1043
  print (MZ)
forrest@0
  1044
;-------------------------------------------
forrest@0
  1045
  plot_name = "zonal_model_vs_ob"
forrest@0
  1046
  title     = "Zonal Average"
forrest@0
  1047
  resz@tiMainString  = title
forrest@0
  1048
forrest@0
  1049
  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
  1050
forrest@0
  1051
; resz@vpHeightF          = 0.4               ; change aspect ratio of plot
forrest@0
  1052
; resz@vpWidthF           = 0.7
forrest@0
  1053
forrest@0
  1054
  resz@xyMonoLineColor    = "False"           ; want colored lines
forrest@0
  1055
  resz@xyLineColors       = (/"black","red"/) ; colors chosen
forrest@0
  1056
; resz@xyLineThicknesses  = (/3.,3./)      ; line thicknesses
forrest@0
  1057
  resz@xyLineThicknesses  = (/2.,2./)      ; line thicknesses
forrest@0
  1058
  resz@xyDashPatterns     = (/0.,0./)      ; make all lines solid
forrest@0
  1059
forrest@0
  1060
  resz@tiYAxisString      = s@long_name      ; add a axis title    
forrest@0
  1061
  resz@txFontHeightF      = 0.0195            ; change title font heights
forrest@0
  1062
forrest@0
  1063
; Legent
forrest@0
  1064
  resz@pmLegendDisplayMode    = "Always"            ; turn on legend
forrest@0
  1065
  resz@pmLegendSide           = "Top"               ; Change location of 
forrest@0
  1066
; resz@pmLegendParallelPosF   = .45                 ; move units right
forrest@0
  1067
  resz@pmLegendParallelPosF   = .82                 ; move units right
forrest@0
  1068
  resz@pmLegendOrthogonalPosF = -0.4                ; move units down
forrest@0
  1069
forrest@0
  1070
  resz@pmLegendWidthF         = 0.10                ; Change width and
forrest@0
  1071
  resz@pmLegendHeightF        = 0.10                ; height of legend.
forrest@0
  1072
  resz@lgLabelFontHeightF     = .02                 ; change font height
forrest@0
  1073
; resz@lgTitleOn              = True                ; turn on legend title
forrest@0
  1074
; resz@lgTitleString          = "Example"           ; create legend title
forrest@0
  1075
; resz@lgTitleFontHeightF     = .025                ; font of legend title
forrest@0
  1076
  resz@xyExplicitLegendLabels = (/"Observed",model_name/) ; explicit labels
forrest@0
  1077
;--------------------------------------------------------------------
forrest@0
  1078
  zRes  = True
forrest@0
  1079
  zRes@txFontHeightF = 0.025
forrest@0
  1080
forrest@0
  1081
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrZ)+")"
forrest@0
  1082
forrest@0
  1083
  gsn_text_ndc(wks,correlation_text,0.50,0.77,zRes)
forrest@0
  1084
;--------------------------------------------------------------------
forrest@0
  1085
  
forrest@0
  1086
  plot  = gsn_csm_xy (wks,ym,s,resz)       ; create plot
forrest@0
  1087
forrest@0
  1088
  frame(wks)                                            ; advance frame
forrest@0
  1089
forrest@0
  1090
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
  1091
  system("rm "+plot_name+"."+plot_type)
forrest@0
  1092
  system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
  1093
  system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
  1094
forrest@0
  1095
  clear (wks)
forrest@0
  1096
end