npp/16.scatter_bias.ncl
author Forrest Hoffman <forrest@climatemodeling.org>
Mon, 26 Jan 2009 22:08:20 -0500
changeset 0 0c6405ab2ff4
permissions -rw-r--r--
Initial commit of C-LAMP Diagnostics from Jeff Lee
forrest@0
     1
; ***********************************************
forrest@0
     2
; combine all scatter
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
 dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/"
forrest@0
    26
 fil81 = "data.81.nc"
forrest@0
    27
 f81   = addfile (dir81+fil81,"r")
forrest@0
    28
forrest@0
    29
 id81   = f81->SITE_ID  
forrest@0
    30
 npp81  = f81->TNPP_C
forrest@0
    31
 rain81 = tofloat(f81->PREC_ANN)
forrest@0
    32
 x81    = f81->LONG_DD  
forrest@0
    33
 y81    = f81->LAT_DD
forrest@0
    34
forrest@0
    35
 id81@long_name  = "SITE_ID"
forrest@0
    36
 npp81@long_name = "NPP (gC/m2/year)"
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
 dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/"
forrest@0
    49
 fil933 = "data.933.nc"
forrest@0
    50
 f933   = addfile (dir933+fil933,"r")
forrest@0
    51
forrest@0
    52
 id933   = f933->SITE_ID  
forrest@0
    53
 npp933  = f933->TNPP_C
forrest@0
    54
 rain933 = f933->PREC
forrest@0
    55
 x933    = f933->LONG_DD  
forrest@0
    56
 y933    = f933->LAT_DD 
forrest@0
    57
forrest@0
    58
 id933@long_name  = "SITE_ID"
forrest@0
    59
 npp933@long_name = "NPP (gC/m2/year)"
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
; read in model data
forrest@0
    72
;************************************************
forrest@0
    73
 model_name = "b30.061n"
forrest@0
    74
forrest@0
    75
 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    76
 film = "b30.061n_1995-2004_ANN_climo_lnd.nc"
forrest@0
    77
 fm   = addfile (dirm+film,"r")
forrest@0
    78
  
forrest@0
    79
 nppmod  = fm->NPP
forrest@0
    80
 rainmod = fm->RAIN
forrest@0
    81
 xm      = fm->lon  
forrest@0
    82
 ym      = fm->lat
forrest@0
    83
forrest@0
    84
 nppmod81  =linint2_points(xm,ym,nppmod(0,:,:),True,x81,y81,0)
forrest@0
    85
forrest@0
    86
 nppmod933 =linint2_points(xm,ym,nppmod(0,:,:),True,x933,y933,0)
forrest@0
    87
forrest@0
    88
 rainmod81 =linint2_points(xm,ym,rainmod(0,:,:),True,x81,y81,0)
forrest@0
    89
forrest@0
    90
 rainmod933=linint2_points(xm,ym,rainmod(0,:,:),True,x933,y933,0)
forrest@0
    91
forrest@0
    92
;************************************************
forrest@0
    93
; Units for these four variables are:
forrest@0
    94
;
forrest@0
    95
; rain81  : mm/year
forrest@0
    96
; rainmod : mm/s
forrest@0
    97
; npp81   : g C/m^2/year
forrest@0
    98
; nppmod81: g C/m^2/s
forrest@0
    99
;
forrest@0
   100
; We want to convert these to "m/year" and "g C/m^2/year".
forrest@0
   101
;
forrest@0
   102
  nsec_per_year = 60*60*24*365                 
forrest@0
   103
forrest@0
   104
  rain81    = rain81 / 1000.
forrest@0
   105
  rainmod81 = (rainmod81/ 1000.) * nsec_per_year
forrest@0
   106
  nppmod81  = nppmod81 * nsec_per_year
forrest@0
   107
forrest@0
   108
  rain933    = rain933 / 1000.
forrest@0
   109
  rainmod933 = (rainmod933/ 1000.) * nsec_per_year
forrest@0
   110
  nppmod933  = nppmod933 * nsec_per_year
forrest@0
   111
forrest@0
   112
  npp81@units      = "gC/m^2/yr"
forrest@0
   113
  nppmod81@units   = "gC/m^2/yr"
forrest@0
   114
  npp933@units     = "gC/m^2/yr"
forrest@0
   115
  nppmod933@units  = "gC/m^2/yr"
forrest@0
   116
  rain81@units     = "m/yr"
forrest@0
   117
  rainmod81@units  = "m/yr"
forrest@0
   118
  rain933@units    = "m/yr"
forrest@0
   119
  rainmod933@units = "m/yr"
forrest@0
   120
forrest@0
   121
  npp81@long_name      = "NPP (gC/m2/year)"
forrest@0
   122
  npp933@long_name     = "NPP (gC/m2/year)"
forrest@0
   123
  nppmod81@long_name   = "NPP (gC/m2/year)"
forrest@0
   124
  nppmod933@long_name  = "NPP (gC/m2/year)"
forrest@0
   125
  rain81@long_name     = "PREC (m/year)"
forrest@0
   126
  rain933@long_name    = "PREC (m/year)"
forrest@0
   127
  rainmod81@long_name  = "PREC (m/year)"
forrest@0
   128
  rainmod933@long_name = "PREC (m/year)"
forrest@0
   129
forrest@0
   130
;(A) plot scatter ob 81
forrest@0
   131
   
forrest@0
   132
 plot_name = "scatter_ob_81"
forrest@0
   133
 title     = "Observed 81 sites"
forrest@0
   134
forrest@0
   135
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   136
 res                   = True                  ; plot mods desired
forrest@0
   137
 res@tiMainString      = title                 ; add title
forrest@0
   138
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   139
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   140
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   141
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   142
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   143
forrest@0
   144
 plot  = gsn_csm_xy (wks,id81,npp81,res)       ; create plot
forrest@0
   145
 frame(wks)
forrest@0
   146
forrest@0
   147
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   148
 system("rm "+plot_name+"."+plot_type)
forrest@0
   149
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   150
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   151
forrest@0
   152
 clear (wks)
forrest@0
   153
 
forrest@0
   154
;(B) plot scatter ob 933
forrest@0
   155
forrest@0
   156
 plot_name = "scatter_ob_933"
forrest@0
   157
 title     = "Observed 933 sites"
forrest@0
   158
forrest@0
   159
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   160
 res                   = True                  ; plot mods desired
forrest@0
   161
 res@tiMainString      = title                 ; add title
forrest@0
   162
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   163
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   164
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   165
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   166
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   167
forrest@0
   168
 plot  = gsn_csm_xy (wks,id933,npp933,res)     ; create plot
forrest@0
   169
 frame(wks)
forrest@0
   170
forrest@0
   171
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   172
 system("rm "+plot_name+"."+plot_type)
forrest@0
   173
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   174
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   175
forrest@0
   176
 clear (wks)
forrest@0
   177
forrest@0
   178
;(C) plot scatter model 81
forrest@0
   179
  
forrest@0
   180
 plot_name = "scatter_model_81"
forrest@0
   181
 title     = "Model "+ model_name +" 81 sites"
forrest@0
   182
forrest@0
   183
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   184
 res                   = True                  ; plot mods desired
forrest@0
   185
 res@tiMainString      = title                 ; add title
forrest@0
   186
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   187
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   188
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   189
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   190
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   191
forrest@0
   192
 plot  = gsn_csm_xy (wks,id81,nppmod81,res)    ; create plot
forrest@0
   193
 frame(wks)
forrest@0
   194
forrest@0
   195
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   196
 system("rm "+plot_name+"."+plot_type)
forrest@0
   197
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   198
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   199
forrest@0
   200
 clear (wks)
forrest@0
   201
 
forrest@0
   202
;(D) plot scatter model 933
forrest@0
   203
forrest@0
   204
 plot_name = "scatter_model_933"
forrest@0
   205
 title     = "Model "+ model_name +" 933 sites"
forrest@0
   206
forrest@0
   207
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   208
 res                   = True                  ; plot mods desired
forrest@0
   209
 res@tiMainString      = title                 ; add title
forrest@0
   210
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   211
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   212
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   213
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   214
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   215
forrest@0
   216
 plot  = gsn_csm_xy (wks,id933,nppmod933,res)    ; create plot
forrest@0
   217
 frame(wks)
forrest@0
   218
forrest@0
   219
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   220
 system("rm "+plot_name+"."+plot_type)
forrest@0
   221
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   222
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   223
forrest@0
   224
 clear (wks)
forrest@0
   225
forrest@0
   226
;(E) scatter model vs ob 81
forrest@0
   227
  
forrest@0
   228
 plot_name = "scatter_model_vs_ob_81"
forrest@0
   229
 title     = model_name +" vs ob 81 sites"
forrest@0
   230
forrest@0
   231
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   232
 res                   = True                  ; plot mods desired
forrest@0
   233
 res@tiMainString      = title                 ; add title
forrest@0
   234
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   235
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   236
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   237
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   238
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   239
;-------------------------------
forrest@0
   240
;compute correlation coef. and M
forrest@0
   241
 ccr81 = esccr(nppmod81,npp81,0)
forrest@0
   242
 print (ccr81)
forrest@0
   243
forrest@0
   244
;new eq
forrest@0
   245
 bias = sum(abs(nppmod81-npp81)/(nppmod81+npp81))
forrest@0
   246
 M81  = (1. - (bias/dimsizes(y81)))*5.
forrest@0
   247
 print (M81)
forrest@0
   248
forrest@0
   249
 tRes  = True
forrest@0
   250
 tRes@txFontHeightF = 0.025
forrest@0
   251
forrest@0
   252
 correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")"
forrest@0
   253
forrest@0
   254
 gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes)
forrest@0
   255
;--------------------------------
forrest@0
   256
 plot  = gsn_csm_xy (wks,npp81,nppmod81,res)       ; create plot
forrest@0
   257
 frame(wks)
forrest@0
   258
forrest@0
   259
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   260
 system("rm "+plot_name+"."+plot_type)
forrest@0
   261
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   262
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   263
forrest@0
   264
 clear (wks)
forrest@0
   265
 
forrest@0
   266
;(F) scatter model vs ob 933
forrest@0
   267
  
forrest@0
   268
 plot_name = "scatter_model_vs_ob_933"
forrest@0
   269
 title     = model_name +" vs ob 933 sites"
forrest@0
   270
forrest@0
   271
 wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   272
 res                   = True                  ; plot mods desired
forrest@0
   273
 res@tiMainString      = title                 ; add title
forrest@0
   274
 res@xyMarkLineModes   = "Markers"             ; choose which have markers
forrest@0
   275
 res@xyMarkers         =  16                   ; choose type of marker  
forrest@0
   276
 res@xyMarkerColor     = "red"                 ; Marker color
forrest@0
   277
 res@xyMarkerSizeF     = 0.01                  ; Marker size (default 0.01)
forrest@0
   278
 res@tmLabelAutoStride = True                  ; nice tick mark labels
forrest@0
   279
;-------------------------------
forrest@0
   280
;compute correlation coef. and M
forrest@0
   281
 ccr933 = esccr(nppmod933,npp933,0)
forrest@0
   282
 print (ccr933)
forrest@0
   283
forrest@0
   284
;new eq
forrest@0
   285
 bias = sum(abs(nppmod933-npp933)/(nppmod933+npp933))
forrest@0
   286
 M933 = (1. - (bias/dimsizes(y933)))*5.
forrest@0
   287
 print (M933)
forrest@0
   288
forrest@0
   289
 tRes  = True
forrest@0
   290
 tRes@txFontHeightF = 0.025
forrest@0
   291
forrest@0
   292
 correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")"
forrest@0
   293
forrest@0
   294
 gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes)
forrest@0
   295
;--------------------------------
forrest@0
   296
 plot  = gsn_csm_xy (wks,npp933,nppmod933,res)    ; create plot
forrest@0
   297
 frame(wks)
forrest@0
   298
forrest@0
   299
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   300
 system("rm "+plot_name+"."+plot_type)
forrest@0
   301
 system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   302
 system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   303
forrest@0
   304
 clear (wks)
forrest@0
   305
;**************************************************************************
forrest@0
   306
;(G) histogram 81
forrest@0
   307
forrest@0
   308
;--------------------------------------------------------------------
forrest@0
   309
;get data
forrest@0
   310
forrest@0
   311
  RAIN1_1D = ndtooned(rain81)
forrest@0
   312
  RAIN2_1D = ndtooned(rainmod81)
forrest@0
   313
  NPP1_1D  = ndtooned(npp81)
forrest@0
   314
  NPP2_1D  = ndtooned(nppmod81)
forrest@0
   315
;
forrest@0
   316
; Calculate some "nice" bins for binning the data in equally spaced
forrest@0
   317
; ranges.
forrest@0
   318
;
forrest@0
   319
  nbins       = 15     ; Number of bins to use.
forrest@0
   320
forrest@0
   321
  nicevals    = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True)
forrest@0
   322
  nvals       = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
forrest@0
   323
  range       = fspan(nicevals(0),nicevals(1),nvals)
forrest@0
   324
;
forrest@0
   325
; Use this range information to grab all the values in a
forrest@0
   326
; particular range, and then take an average.
forrest@0
   327
;
forrest@0
   328
  nr           = dimsizes(range)
forrest@0
   329
  nx           = nr-1
forrest@0
   330
  xvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   331
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
   332
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
   333
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
   334
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
   335
  yvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   336
  mn_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   337
  mx_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   338
forrest@0
   339
  do nd=0,1
forrest@0
   340
;
forrest@0
   341
; See if we are doing model or observational data.
forrest@0
   342
;
forrest@0
   343
    if(nd.eq.0) then
forrest@0
   344
      data     = RAIN1_1D
forrest@0
   345
      npp_data = NPP1_1D
forrest@0
   346
    else
forrest@0
   347
      data     = RAIN2_1D
forrest@0
   348
      npp_data = NPP2_1D
forrest@0
   349
    end if
forrest@0
   350
;
forrest@0
   351
; Loop through each range and check for values.
forrest@0
   352
;
forrest@0
   353
    do i=0,nr-2
forrest@0
   354
      if (i.ne.(nr-2)) then
forrest@0
   355
;        print("")
forrest@0
   356
;        print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
   357
        idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
forrest@0
   358
      else
forrest@0
   359
;        print("")
forrest@0
   360
;        print("In range ["+range(i)+",)")
forrest@0
   361
        idx = ind(range(i).le.data)
forrest@0
   362
      end if
forrest@0
   363
;
forrest@0
   364
; Calculate average, and get min and max.
forrest@0
   365
;
forrest@0
   366
      if(.not.any(ismissing(idx))) then
forrest@0
   367
        yvalues(nd,i)    = avg(npp_data(idx))
forrest@0
   368
        mn_yvalues(nd,i) = min(npp_data(idx))
forrest@0
   369
        mx_yvalues(nd,i) = max(npp_data(idx))
forrest@0
   370
        count = dimsizes(idx)
forrest@0
   371
      else
forrest@0
   372
        count            = 0
forrest@0
   373
        yvalues(nd,i)    = yvalues@_FillValue
forrest@0
   374
        mn_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   375
        mx_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   376
      end if
forrest@0
   377
;
forrest@0
   378
; Print out information.
forrest@0
   379
;
forrest@0
   380
;      print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i))
forrest@0
   381
;      print("Min/Max:  " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
forrest@0
   382
forrest@0
   383
;
forrest@0
   384
; Clean up for next time in loop.
forrest@0
   385
;
forrest@0
   386
      delete(idx)
forrest@0
   387
    end do
forrest@0
   388
    delete(data)
forrest@0
   389
    delete(npp_data)
forrest@0
   390
  end do
forrest@0
   391
;----------------------------------------
forrest@0
   392
;compute correlation coeff and M score 
forrest@0
   393
 u = yvalues(0,:)
forrest@0
   394
 v = yvalues(1,:)
forrest@0
   395
forrest@0
   396
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   397
 uu = u(good)
forrest@0
   398
 vv = v(good)
forrest@0
   399
forrest@0
   400
 ccr81h = esccr(uu,vv,0)
forrest@0
   401
 print (ccr81h)
forrest@0
   402
forrest@0
   403
;new eq
forrest@0
   404
 bias = sum(abs(vv-uu)/(vv+uu))
forrest@0
   405
 M81h = (1.- (bias/dimsizes(uu)))*5.
forrest@0
   406
 print (M81h)
forrest@0
   407
forrest@0
   408
 delete (u)
forrest@0
   409
 delete (v)
forrest@0
   410
 delete (uu)
forrest@0
   411
 delete (vv)
forrest@0
   412
;----------------------------------------------------------------------
forrest@0
   413
; histogram res
forrest@0
   414
forrest@0
   415
  res                = True
forrest@0
   416
  res@gsnMaximize    = True
forrest@0
   417
  res@gsnDraw        = False
forrest@0
   418
  res@gsnFrame       = False
forrest@0
   419
  res@xyMarkLineMode = "Markers"
forrest@0
   420
  res@xyMarkerSizeF  = 0.014
forrest@0
   421
  res@xyMarker       = 16
forrest@0
   422
  res@xyMarkerColors = (/"Brown","Blue"/)
forrest@0
   423
  res@trYMinF        = min(mn_yvalues) - 10.
forrest@0
   424
  res@trYMaxF        = max(mx_yvalues) + 10.
forrest@0
   425
forrest@0
   426
  res@tiYAxisString  = "NPP (g C/m2/year)"
forrest@0
   427
  res@tiXAxisString  = "Precipitation (m/year)"
forrest@0
   428
forrest@0
   429
  max_bar = new((/2,nx/),graphic)
forrest@0
   430
  min_bar = new((/2,nx/),graphic)
forrest@0
   431
  max_cap = new((/2,nx/),graphic)
forrest@0
   432
  min_cap = new((/2,nx/),graphic)
forrest@0
   433
forrest@0
   434
  lnres = True
forrest@0
   435
  line_colors = (/"brown","blue"/)
forrest@0
   436
;=================================================================
forrest@0
   437
; histogram ob 81 site only
forrest@0
   438
;
forrest@0
   439
  plot_name = "histogram_ob_81"
forrest@0
   440
  title     = "Observed 81 site"
forrest@0
   441
  res@tiMainString  = title
forrest@0
   442
forrest@0
   443
  wks   = gsn_open_wks (plot_type,plot_name)    
forrest@0
   444
forrest@0
   445
  xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res)
forrest@0
   446
forrest@0
   447
;-------------------------------
forrest@0
   448
;Attach the vertical bar and the horizontal cap line 
forrest@0
   449
forrest@0
   450
  do nd=0,0
forrest@0
   451
    lnres@gsLineColor = line_colors(nd)
forrest@0
   452
    do i=0,nx-1
forrest@0
   453
     
forrest@0
   454
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   455
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   456
;
forrest@0
   457
; Attach the vertical bar, both above and below the marker.
forrest@0
   458
;
forrest@0
   459
        x1 = xvalues(nd,i)
forrest@0
   460
        y1 = yvalues(nd,i)
forrest@0
   461
        y2 = mn_yvalues(nd,i)
forrest@0
   462
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   463
forrest@0
   464
        y2 = mx_yvalues(nd,i)
forrest@0
   465
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   466
;
forrest@0
   467
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   468
;
forrest@0
   469
        x1 = xvalues(nd,i) - dx4
forrest@0
   470
        x2 = xvalues(nd,i) + dx4
forrest@0
   471
        y1 = mn_yvalues(nd,i)
forrest@0
   472
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   473
forrest@0
   474
        y1 = mx_yvalues(nd,i)
forrest@0
   475
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   476
      end if
forrest@0
   477
    end do
forrest@0
   478
  end do
forrest@0
   479
forrest@0
   480
  draw(xy)
forrest@0
   481
  frame(wks)
forrest@0
   482
forrest@0
   483
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   484
; system("rm "+plot_name+"."+plot_type)
forrest@0
   485
; system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   486
; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   487
forrest@0
   488
  clear (wks)
forrest@0
   489
;===========================================================================
forrest@0
   490
; histogram model vs ob 81 site 
forrest@0
   491
forrest@0
   492
  plot_name = "histogram_mod-ob_81"
forrest@0
   493
  title     = model_name+ " vs Observed 81 site"
forrest@0
   494
  res@tiMainString  = title
forrest@0
   495
forrest@0
   496
  wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   497
forrest@0
   498
;-----------------------------
forrest@0
   499
; Add a boxed legend using the more simple method, which won't have
forrest@0
   500
; vertical lines going through the markers.
forrest@0
   501
forrest@0
   502
  res@pmLegendDisplayMode    = "Always"
forrest@0
   503
; res@pmLegendWidthF         = 0.1
forrest@0
   504
  res@pmLegendWidthF         = 0.08
forrest@0
   505
  res@pmLegendHeightF        = 0.05
forrest@0
   506
  res@pmLegendOrthogonalPosF = -1.17
forrest@0
   507
; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   508
; res@pmLegendParallelPosF   =  0.18
forrest@0
   509
  res@pmLegendParallelPosF   =  0.23  ;(rightward)
forrest@0
   510
forrest@0
   511
; res@lgPerimOn              = False
forrest@0
   512
  res@lgLabelFontHeightF     = 0.015
forrest@0
   513
  res@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
   514
;-----------------------------
forrest@0
   515
  tRes  = True
forrest@0
   516
  tRes@txFontHeightF = 0.025
forrest@0
   517
forrest@0
   518
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")"
forrest@0
   519
forrest@0
   520
  gsn_text_ndc(wks,correlation_text,0.5,0.8,tRes)
forrest@0
   521
forrest@0
   522
  xy = gsn_csm_xy(wks,xvalues,yvalues,res)
forrest@0
   523
;-------------------------------
forrest@0
   524
;Attach the vertical bar and the horizontal cap line 
forrest@0
   525
forrest@0
   526
  do nd=0,1
forrest@0
   527
    lnres@gsLineColor = line_colors(nd)
forrest@0
   528
    do i=0,nx-1
forrest@0
   529
     
forrest@0
   530
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   531
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   532
;
forrest@0
   533
; Attach the vertical bar, both above and below the marker.
forrest@0
   534
;
forrest@0
   535
        x1 = xvalues(nd,i)
forrest@0
   536
        y1 = yvalues(nd,i)
forrest@0
   537
        y2 = mn_yvalues(nd,i)
forrest@0
   538
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   539
forrest@0
   540
        y2 = mx_yvalues(nd,i)
forrest@0
   541
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   542
;
forrest@0
   543
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   544
;
forrest@0
   545
        x1 = xvalues(nd,i) - dx4
forrest@0
   546
        x2 = xvalues(nd,i) + dx4
forrest@0
   547
        y1 = mn_yvalues(nd,i)
forrest@0
   548
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   549
forrest@0
   550
        y1 = mx_yvalues(nd,i)
forrest@0
   551
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   552
      end if
forrest@0
   553
    end do
forrest@0
   554
  end do
forrest@0
   555
  draw(xy)
forrest@0
   556
  frame(wks)
forrest@0
   557
forrest@0
   558
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   559
;system("rm "+plot_name+"."+plot_type)
forrest@0
   560
;system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   561
;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   562
forrest@0
   563
 clear (wks)
forrest@0
   564
forrest@0
   565
 delete (RAIN1_1D)
forrest@0
   566
 delete (RAIN2_1D)
forrest@0
   567
 delete (NPP1_1D)
forrest@0
   568
 delete (NPP2_1D)
forrest@0
   569
 delete (range)
forrest@0
   570
 delete (xvalues) 
forrest@0
   571
 delete (yvalues)
forrest@0
   572
 delete (mn_yvalues)
forrest@0
   573
 delete (mx_yvalues)
forrest@0
   574
 delete (good)
forrest@0
   575
 delete (max_bar)
forrest@0
   576
 delete (min_bar)
forrest@0
   577
 delete (max_cap)
forrest@0
   578
 delete (min_cap)   
forrest@0
   579
;**************************************************************************
forrest@0
   580
;(H) histogram 933
forrest@0
   581
forrest@0
   582
;--------------------------------------------------------------------
forrest@0
   583
;get data
forrest@0
   584
forrest@0
   585
  RAIN1_1D = ndtooned(rain933)
forrest@0
   586
  RAIN2_1D = ndtooned(rainmod933)
forrest@0
   587
  NPP1_1D  = ndtooned(npp933)
forrest@0
   588
  NPP2_1D  = ndtooned(nppmod933)
forrest@0
   589
;
forrest@0
   590
; Calculate some "nice" bins for binning the data in equally spaced
forrest@0
   591
; ranges.
forrest@0
   592
;
forrest@0
   593
  nbins       = 15     ; Number of bins to use.
forrest@0
   594
forrest@0
   595
  nicevals    = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True)
forrest@0
   596
  nvals       = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
forrest@0
   597
  range       = fspan(nicevals(0),nicevals(1),nvals)
forrest@0
   598
;
forrest@0
   599
; Use this range information to grab all the values in a
forrest@0
   600
; particular range, and then take an average.
forrest@0
   601
;
forrest@0
   602
  nr           = dimsizes(range)
forrest@0
   603
  nx           = nr-1
forrest@0
   604
  xvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   605
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
   606
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
   607
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
   608
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
   609
  yvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   610
  mn_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   611
  mx_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
   612
forrest@0
   613
  do nd=0,1
forrest@0
   614
;
forrest@0
   615
; See if we are doing model or observational data.
forrest@0
   616
;
forrest@0
   617
    if(nd.eq.0) then
forrest@0
   618
      data     = RAIN1_1D
forrest@0
   619
      npp_data = NPP1_1D
forrest@0
   620
    else
forrest@0
   621
      data     = RAIN2_1D
forrest@0
   622
      npp_data = NPP2_1D
forrest@0
   623
    end if
forrest@0
   624
;
forrest@0
   625
; Loop through each range and check for values.
forrest@0
   626
;
forrest@0
   627
    do i=0,nr-2
forrest@0
   628
      if (i.ne.(nr-2)) then
forrest@0
   629
;        print("")
forrest@0
   630
;        print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
   631
        idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
forrest@0
   632
      else
forrest@0
   633
;        print("")
forrest@0
   634
;        print("In range ["+range(i)+",)")
forrest@0
   635
        idx = ind(range(i).le.data)
forrest@0
   636
      end if
forrest@0
   637
;
forrest@0
   638
; Calculate average, and get min and max.
forrest@0
   639
;
forrest@0
   640
      if(.not.any(ismissing(idx))) then
forrest@0
   641
        yvalues(nd,i)    = avg(npp_data(idx))
forrest@0
   642
        mn_yvalues(nd,i) = min(npp_data(idx))
forrest@0
   643
        mx_yvalues(nd,i) = max(npp_data(idx))
forrest@0
   644
        count = dimsizes(idx)
forrest@0
   645
      else
forrest@0
   646
        count            = 0
forrest@0
   647
        yvalues(nd,i)    = yvalues@_FillValue
forrest@0
   648
        mn_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   649
        mx_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   650
      end if
forrest@0
   651
;
forrest@0
   652
; Print out information.
forrest@0
   653
;
forrest@0
   654
;      print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i))
forrest@0
   655
;      print("Min/Max:  " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
forrest@0
   656
forrest@0
   657
;
forrest@0
   658
; Clean up for next time in loop.
forrest@0
   659
;
forrest@0
   660
      delete(idx)
forrest@0
   661
    end do
forrest@0
   662
    delete(data)
forrest@0
   663
    delete(npp_data)
forrest@0
   664
  end do
forrest@0
   665
;----------------------------------------
forrest@0
   666
;compute correlation coeff and M score 
forrest@0
   667
 u = yvalues(0,:)
forrest@0
   668
 v = yvalues(1,:)
forrest@0
   669
forrest@0
   670
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   671
 uu = u(good)
forrest@0
   672
 vv = v(good)
forrest@0
   673
forrest@0
   674
 ccr933h = esccr(uu,vv,0)
forrest@0
   675
 print (ccr933h)
forrest@0
   676
forrest@0
   677
;new eq
forrest@0
   678
 bias  = sum(abs(vv-uu)/(vv+uu))
forrest@0
   679
 M933h = (1.- (bias/dimsizes(uu)))*5.
forrest@0
   680
 print (M933h)
forrest@0
   681
forrest@0
   682
 delete (u)
forrest@0
   683
 delete (v)
forrest@0
   684
 delete (uu)
forrest@0
   685
 delete (vv)
forrest@0
   686
;----------------------------------------------------------------------
forrest@0
   687
; histogram res
forrest@0
   688
forrest@0
   689
  res                = True
forrest@0
   690
  res@gsnMaximize    = True
forrest@0
   691
  res@gsnDraw        = False
forrest@0
   692
  res@gsnFrame       = False
forrest@0
   693
  res@xyMarkLineMode = "Markers"
forrest@0
   694
  res@xyMarkerSizeF  = 0.014
forrest@0
   695
  res@xyMarker       = 16
forrest@0
   696
  res@xyMarkerColors = (/"Brown","Blue"/)
forrest@0
   697
  res@trYMinF        = min(mn_yvalues) - 10.
forrest@0
   698
  res@trYMaxF        = max(mx_yvalues) + 10.
forrest@0
   699
forrest@0
   700
  res@tiYAxisString  = "NPP (g C/m2/year)"
forrest@0
   701
  res@tiXAxisString  = "Precipitation (m/year)"
forrest@0
   702
forrest@0
   703
  max_bar = new((/2,nx/),graphic)
forrest@0
   704
  min_bar = new((/2,nx/),graphic)
forrest@0
   705
  max_cap = new((/2,nx/),graphic)
forrest@0
   706
  min_cap = new((/2,nx/),graphic)
forrest@0
   707
forrest@0
   708
  lnres = True
forrest@0
   709
  line_colors = (/"brown","blue"/)
forrest@0
   710
;=================================================================
forrest@0
   711
; histogram ob 933 site only
forrest@0
   712
;
forrest@0
   713
  plot_name = "histogram_ob_933"
forrest@0
   714
  title     = "Observed 933 site"
forrest@0
   715
  res@tiMainString  = title
forrest@0
   716
forrest@0
   717
  wks   = gsn_open_wks (plot_type,plot_name)    
forrest@0
   718
forrest@0
   719
  xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res)
forrest@0
   720
forrest@0
   721
;-------------------------------
forrest@0
   722
;Attach the vertical bar and the horizontal cap line 
forrest@0
   723
forrest@0
   724
  do nd=0,0
forrest@0
   725
    lnres@gsLineColor = line_colors(nd)
forrest@0
   726
    do i=0,nx-1
forrest@0
   727
     
forrest@0
   728
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   729
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   730
;
forrest@0
   731
; Attach the vertical bar, both above and below the marker.
forrest@0
   732
;
forrest@0
   733
        x1 = xvalues(nd,i)
forrest@0
   734
        y1 = yvalues(nd,i)
forrest@0
   735
        y2 = mn_yvalues(nd,i)
forrest@0
   736
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   737
forrest@0
   738
        y2 = mx_yvalues(nd,i)
forrest@0
   739
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   740
;
forrest@0
   741
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   742
;
forrest@0
   743
        x1 = xvalues(nd,i) - dx4
forrest@0
   744
        x2 = xvalues(nd,i) + dx4
forrest@0
   745
        y1 = mn_yvalues(nd,i)
forrest@0
   746
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   747
forrest@0
   748
        y1 = mx_yvalues(nd,i)
forrest@0
   749
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   750
      end if
forrest@0
   751
    end do
forrest@0
   752
  end do
forrest@0
   753
forrest@0
   754
  draw(xy)
forrest@0
   755
  frame(wks)
forrest@0
   756
forrest@0
   757
  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   758
; system("rm "+plot_name+"."+plot_type)
forrest@0
   759
; system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   760
; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   761
forrest@0
   762
  clear (wks)
forrest@0
   763
;===========================================================================
forrest@0
   764
; histogram model vs ob 933 site 
forrest@0
   765
forrest@0
   766
  plot_name = "histogram_mod-ob_933"
forrest@0
   767
  title     = model_name+ " vs Observed 933 site"
forrest@0
   768
  res@tiMainString  = title
forrest@0
   769
forrest@0
   770
  wks   = gsn_open_wks (plot_type,plot_name)    ; open workstation
forrest@0
   771
forrest@0
   772
;-----------------------------
forrest@0
   773
; Add a boxed legend using the more simple method, which won't have
forrest@0
   774
; vertical lines going through the markers.
forrest@0
   775
forrest@0
   776
  res@pmLegendDisplayMode    = "Always"
forrest@0
   777
; res@pmLegendWidthF         = 0.1
forrest@0
   778
  res@pmLegendWidthF         = 0.08
forrest@0
   779
  res@pmLegendHeightF        = 0.05
forrest@0
   780
  res@pmLegendOrthogonalPosF = -1.17
forrest@0
   781
; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   782
; res@pmLegendParallelPosF   =  0.18
forrest@0
   783
  res@pmLegendParallelPosF   =  0.23  ;(rightward)
forrest@0
   784
forrest@0
   785
; res@lgPerimOn              = False
forrest@0
   786
  res@lgLabelFontHeightF     = 0.015
forrest@0
   787
  res@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
   788
;-----------------------------
forrest@0
   789
  tRes  = True
forrest@0
   790
  tRes@txFontHeightF = 0.025
forrest@0
   791
forrest@0
   792
  correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")"
forrest@0
   793
forrest@0
   794
  gsn_text_ndc(wks,correlation_text,0.5,0.8,tRes)
forrest@0
   795
forrest@0
   796
  xy = gsn_csm_xy(wks,xvalues,yvalues,res)
forrest@0
   797
;-------------------------------
forrest@0
   798
;Attach the vertical bar and the horizontal cap line 
forrest@0
   799
forrest@0
   800
  do nd=0,1
forrest@0
   801
    lnres@gsLineColor = line_colors(nd)
forrest@0
   802
    do i=0,nx-1
forrest@0
   803
     
forrest@0
   804
      if(.not.ismissing(mn_yvalues(nd,i)).and. \
forrest@0
   805
         .not.ismissing(mx_yvalues(nd,i))) then
forrest@0
   806
;
forrest@0
   807
; Attach the vertical bar, both above and below the marker.
forrest@0
   808
;
forrest@0
   809
        x1 = xvalues(nd,i)
forrest@0
   810
        y1 = yvalues(nd,i)
forrest@0
   811
        y2 = mn_yvalues(nd,i)
forrest@0
   812
        min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   813
forrest@0
   814
        y2 = mx_yvalues(nd,i)
forrest@0
   815
        max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres)
forrest@0
   816
;
forrest@0
   817
; Attach the horizontal cap line, both above and below the marker.
forrest@0
   818
;
forrest@0
   819
        x1 = xvalues(nd,i) - dx4
forrest@0
   820
        x2 = xvalues(nd,i) + dx4
forrest@0
   821
        y1 = mn_yvalues(nd,i)
forrest@0
   822
        min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   823
forrest@0
   824
        y1 = mx_yvalues(nd,i)
forrest@0
   825
        max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres)
forrest@0
   826
      end if
forrest@0
   827
    end do
forrest@0
   828
  end do
forrest@0
   829
  draw(xy)
forrest@0
   830
  frame(wks)
forrest@0
   831
forrest@0
   832
 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   833
;system("rm "+plot_name+"."+plot_type)
forrest@0
   834
;system("rm "+plot_name+"-1."+plot_type_new)
forrest@0
   835
;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
forrest@0
   836
forrest@0
   837
 clear (wks)
forrest@0
   838
;------------------------------------------------------------------------
forrest@0
   839
forrest@0
   840
end