beta/03.biome.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
; histogram normalized by rain and compute correleration
forrest@0
     3
;********************************************************
forrest@0
     4
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
forrest@0
     5
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
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
 nclass = 20
forrest@0
    20
forrest@0
    21
 plot_type     = "ps"
forrest@0
    22
 plot_type_new = "png"
forrest@0
    23
forrest@0
    24
;************************************************
forrest@0
    25
; read data: model       
forrest@0
    26
;************************************************
forrest@0
    27
 co2_i = 283.1878
forrest@0
    28
 co2_f = 364.1252
forrest@0
    29
forrest@0
    30
 model_grid = "T42"
forrest@0
    31
forrest@0
    32
;model_name_i = "i01.07cn"
forrest@0
    33
;model_name_f = "i01.10cn"
forrest@0
    34
forrest@0
    35
 model_name_i = "i01.07casa"
forrest@0
    36
 model_name_f = "i01.10casa"
forrest@0
    37
forrest@0
    38
 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    39
 film_i = model_name_i + "_1990-2004_ANN_climo.nc"
forrest@0
    40
 film_f = model_name_f + "_1990-2004_ANN_climo.nc"
forrest@0
    41
forrest@0
    42
 fm_i   = addfile (dirm+film_i,"r")
forrest@0
    43
 fm_f   = addfile (dirm+film_f,"r")
forrest@0
    44
  
forrest@0
    45
 npp_i  = fm_i->NPP
forrest@0
    46
 npp_f  = fm_f->NPP
forrest@0
    47
 
forrest@0
    48
;************************************************
forrest@0
    49
; read data: observed
forrest@0
    50
;************************************************
forrest@0
    51
forrest@0
    52
 ob_name = "MODIS MOD 15A2 2000-2005"
forrest@0
    53
forrest@0
    54
 diro  = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/"
forrest@0
    55
 filo  = "land_class_"+model_grid+".nc"
forrest@0
    56
forrest@0
    57
 fo = addfile(diro+filo,"r")
forrest@0
    58
 
forrest@0
    59
 classob    = tofloat(fo->LAND_CLASS)
forrest@0
    60
forrest@0
    61
 class_name = (/"Water Bodies" \
forrest@0
    62
               ,"Evergreen Needleleaf Forests" \
forrest@0
    63
               ,"Evergreen Broadleaf Forests" \
forrest@0
    64
               ,"Deciduous Needleleaf Forest" \
forrest@0
    65
               ,"Deciduous Broadleaf Forests" \
forrest@0
    66
               ,"Mixed Forests" \                      
forrest@0
    67
               ,"Closed Bushlands" \                   
forrest@0
    68
               ,"Open Bushlands" \                     
forrest@0
    69
               ,"Woody Savannas (S. Hem.)" \           
forrest@0
    70
               ,"Savannas (S. Hem.)" \                 
forrest@0
    71
               ,"Grasslands" \                         
forrest@0
    72
               ,"Permanent Wetlands" \                 
forrest@0
    73
               ,"Croplands" \                         
forrest@0
    74
               ,"Urban and Built-Up" \                 
forrest@0
    75
               ,"Cropland/Natural Vegetation Mosaic" \ 
forrest@0
    76
               ,"Permanent Snow and Ice" \             
forrest@0
    77
               ,"Barren or Sparsely Vegetated" \       
forrest@0
    78
               ,"Unclassified" \                       
forrest@0
    79
               ,"Woody Savannas (N. Hem.)" \           
forrest@0
    80
               ,"Savannas (N. Hem.)" \                
forrest@0
    81
               /)  
forrest@0
    82
               
forrest@0
    83
;*******************************************************************
forrest@0
    84
; Calculate "nice" bins for binning the data in equally spaced ranges
forrest@0
    85
;********************************************************************
forrest@0
    86
  nclassn     = nclass + 1
forrest@0
    87
  range       = fspan(0,nclassn-1,nclassn)
forrest@0
    88
; print (range)
forrest@0
    89
forrest@0
    90
; Use this range information to grab all the values in a
forrest@0
    91
; particular range, and then take an average.
forrest@0
    92
forrest@0
    93
  nr           = dimsizes(range)
forrest@0
    94
  nx           = nr-1
forrest@0
    95
  xvalues      = new((/2,nx/),float)
forrest@0
    96
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
    97
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
    98
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
    99
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
   100
forrest@0
   101
; get data
forrest@0
   102
forrest@0
   103
  DATA11_1D = ndtooned(classob)
forrest@0
   104
  DATA12_1D = ndtooned(npp_i)
forrest@0
   105
  DATA22_1D = ndtooned(npp_f)
forrest@0
   106
forrest@0
   107
  yvalues      = new((/2,nx/),float)
forrest@0
   108
  mn_yvalues   = new((/2,nx/),float)
forrest@0
   109
  mx_yvalues   = new((/2,nx/),float)
forrest@0
   110
forrest@0
   111
  do nd=0,1
forrest@0
   112
forrest@0
   113
; See if we are doing model or observational data.
forrest@0
   114
forrest@0
   115
    if(nd.eq.0) then
forrest@0
   116
      data_ob  = DATA11_1D
forrest@0
   117
      data_mod = DATA12_1D
forrest@0
   118
    else
forrest@0
   119
      data_ob  = DATA11_1D
forrest@0
   120
      data_mod = DATA22_1D
forrest@0
   121
    end if
forrest@0
   122
forrest@0
   123
; Loop through each range and check for values.
forrest@0
   124
forrest@0
   125
    do i=0,nr-2
forrest@0
   126
      if (i.ne.(nr-2)) then
forrest@0
   127
;        print("")
forrest@0
   128
;        print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
   129
         idx = ind((data_ob.ge.range(i)).and.(data_ob.lt.range(i+1)))
forrest@0
   130
      else
forrest@0
   131
;        print("")
forrest@0
   132
;        print("In range ["+range(i)+",)")
forrest@0
   133
         idx = ind(data_ob.ge.range(i))
forrest@0
   134
      end if
forrest@0
   135
forrest@0
   136
; Calculate average, and get min and max.
forrest@0
   137
forrest@0
   138
      if(.not.any(ismissing(idx))) then
forrest@0
   139
        yvalues(nd,i)    = avg(data_mod(idx))
forrest@0
   140
        mn_yvalues(nd,i) = min(data_mod(idx))
forrest@0
   141
        mx_yvalues(nd,i) = max(data_mod(idx))
forrest@0
   142
        count = dimsizes(idx)
forrest@0
   143
      else
forrest@0
   144
        count            = 0
forrest@0
   145
        yvalues(nd,i)    = yvalues@_FillValue
forrest@0
   146
        mn_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   147
        mx_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   148
      end if
forrest@0
   149
forrest@0
   150
;     print(nd + ": " + count + " points, avg = " + yvalues(nd,i))
forrest@0
   151
;     print("Min/Max:  " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
forrest@0
   152
forrest@0
   153
; Clean up for next time in loop.
forrest@0
   154
forrest@0
   155
      delete(idx)
forrest@0
   156
    end do
forrest@0
   157
    delete(data_ob)
forrest@0
   158
    delete(data_mod)
forrest@0
   159
  end do
forrest@0
   160
forrest@0
   161
;============================
forrest@0
   162
;compute beta
forrest@0
   163
;============================
forrest@0
   164
forrest@0
   165
 u = yvalues(0,:)
forrest@0
   166
 v = yvalues(1,:)
forrest@0
   167
forrest@0
   168
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   169
 uu = u(good)
forrest@0
   170
 vv = v(good)
forrest@0
   171
 ww = class_name(good)
forrest@0
   172
forrest@0
   173
 n_biome = dimsizes(uu)
forrest@0
   174
forrest@0
   175
 beta_biome = new((/n_biome/),float)
forrest@0
   176
forrest@0
   177
 beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i)
forrest@0
   178
forrest@0
   179
 beta_biome_avg = avg(beta_biome)
forrest@0
   180
forrest@0
   181
 print("class/beta:  " + ww + "/" + beta_biome)
forrest@0
   182
 print (beta_biome_avg)
forrest@0
   183
forrest@0
   184
end
forrest@0
   185