lai/41.table_mean.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
; histogram normalized by rain and compute correleration
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
;
forrest@0
    17
; Main code.
forrest@0
    18
;
forrest@0
    19
begin
forrest@0
    20
 
forrest@0
    21
;nclass = 18
forrest@0
    22
 nclass = 20
forrest@0
    23
 
forrest@0
    24
;************************************************
forrest@0
    25
; read in data: observed
forrest@0
    26
;************************************************
forrest@0
    27
 diri1  = "/fis/cgd/cseg/people/jeff/clamp_data/lai/"
forrest@0
    28
;fili1  = "land_class_T42.nc"
forrest@0
    29
 fili1  = "land_class_T42_new.nc"
forrest@0
    30
 fili2  = "LAI_2000-2005_mean_T42.nc"
forrest@0
    31
 data_file_ob1 = addfile(diri1+fili1,"r")
forrest@0
    32
 data_file_ob2 = addfile(diri1+fili2,"r")
forrest@0
    33
 
forrest@0
    34
 RAIN1 = tofloat(data_file_ob1->LAND_CLASS)               
forrest@0
    35
 NPP1  = data_file_ob2->LAI      
forrest@0
    36
;************************************************
forrest@0
    37
; read in data: model       
forrest@0
    38
;************************************************
forrest@0
    39
 diri2  = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    40
;fili3  = "i01.03cn_1545-1569_ANN_climo.nc"
forrest@0
    41
 fili3  = "i01.04casa_1605-1629_ANN_climo.nc"
forrest@0
    42
 data_file_model = addfile(diri2+fili3,"r")
forrest@0
    43
      
forrest@0
    44
 NPP2  = data_file_model->TLAI      
forrest@0
    45
;************************************************
forrest@0
    46
; print min/max and unit
forrest@0
    47
;************************************************
forrest@0
    48
  pminmax(RAIN1,"RAIN1")
forrest@0
    49
  pminmax(NPP1,"NPP1")
forrest@0
    50
  pminmax(NPP2,"NPP2")
forrest@0
    51
forrest@0
    52
  RAIN1_1D = ndtooned(RAIN1)
forrest@0
    53
  NPP1_1D  = ndtooned(NPP1)
forrest@0
    54
  NPP2_1D  = ndtooned(NPP2)
forrest@0
    55
;
forrest@0
    56
; Calculate some "nice" bins for binning the data in equally spaced
forrest@0
    57
; ranges.
forrest@0
    58
;
forrest@0
    59
forrest@0
    60
; nbins       = nclass + 1         ; Number of bins to use.
forrest@0
    61
; nicevals    = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,False)
forrest@0
    62
; nvals       = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1)
forrest@0
    63
; range       = fspan(nicevals(0),nicevals(1),nvals)
forrest@0
    64
forrest@0
    65
  nclassn     = nclass + 1
forrest@0
    66
  range       = fspan(0,nclassn-1,nclassn)
forrest@0
    67
forrest@0
    68
; print (nicevals)
forrest@0
    69
; print (nvals)
forrest@0
    70
  print (range)
forrest@0
    71
; exit
forrest@0
    72
forrest@0
    73
;
forrest@0
    74
; Use this range information to grab all the values in a
forrest@0
    75
; particular range, and then take an average.
forrest@0
    76
;
forrest@0
    77
  nr      = dimsizes(range)
forrest@0
    78
  nx      = nr-1
forrest@0
    79
  xvalues     = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
    80
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
    81
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
    82
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
    83
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
    84
  yvalues      = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
    85
  mn_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
    86
  mx_yvalues   = new((/2,nx/),typeof(RAIN1_1D))
forrest@0
    87
forrest@0
    88
  do nd=0,1
forrest@0
    89
;
forrest@0
    90
; See if we are doing model or observational data.
forrest@0
    91
;
forrest@0
    92
    if(nd.eq.0) then
forrest@0
    93
      data     = RAIN1_1D
forrest@0
    94
      npp_data = NPP1_1D
forrest@0
    95
    else
forrest@0
    96
      data     = RAIN1_1D
forrest@0
    97
      npp_data = NPP2_1D
forrest@0
    98
    end if
forrest@0
    99
;
forrest@0
   100
; Loop through each range and check for values.
forrest@0
   101
;
forrest@0
   102
    do i=0,nr-2
forrest@0
   103
      if (i.ne.(nr-2)) then
forrest@0
   104
         print("")
forrest@0
   105
         print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
   106
        idx = ind((range(i).le.data).and.(data.lt.range(i+1)))
forrest@0
   107
      else
forrest@0
   108
         print("")
forrest@0
   109
         print("In range ["+range(i)+",)")
forrest@0
   110
        idx = ind(range(i).le.data)
forrest@0
   111
      end if
forrest@0
   112
;
forrest@0
   113
; Calculate average, and get min and max.
forrest@0
   114
;
forrest@0
   115
      if(.not.any(ismissing(idx))) then
forrest@0
   116
        yvalues(nd,i)    = avg(npp_data(idx))
forrest@0
   117
        mn_yvalues(nd,i) = min(npp_data(idx))
forrest@0
   118
        mx_yvalues(nd,i) = max(npp_data(idx))
forrest@0
   119
        count = dimsizes(idx)
forrest@0
   120
      else
forrest@0
   121
        count            = 0
forrest@0
   122
        yvalues(nd,i)    = yvalues@_FillValue
forrest@0
   123
        mn_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   124
        mx_yvalues(nd,i) = yvalues@_FillValue
forrest@0
   125
      end if
forrest@0
   126
;
forrest@0
   127
; Print out information.
forrest@0
   128
;
forrest@0
   129
       print(nd + ": " + count + " points, avg = " + yvalues(nd,i))
forrest@0
   130
       print("Min/Max:  " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i))
forrest@0
   131
forrest@0
   132
;
forrest@0
   133
; Clean up for next time in loop.
forrest@0
   134
;
forrest@0
   135
      delete(idx)
forrest@0
   136
    end do
forrest@0
   137
    delete(data)
forrest@0
   138
    delete(npp_data)
forrest@0
   139
  end do
forrest@0
   140
forrest@0
   141
;
forrest@0
   142
; Start the graphics.
forrest@0
   143
;
forrest@0
   144
forrest@0
   145
 u = yvalues(0,:)
forrest@0
   146
 v = yvalues(1,:)
forrest@0
   147
 print (u)
forrest@0
   148
 print (v)
forrest@0
   149
forrest@0
   150
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   151
 uu = u(good)
forrest@0
   152
 vv = v(good)
forrest@0
   153
 nz = dimsizes(uu)
forrest@0
   154
 print (nz)
forrest@0
   155
forrest@0
   156
 ccr = esccr(uu,vv,0)
forrest@0
   157
 print (ccr)
forrest@0
   158
forrest@0
   159
;new eq
forrest@0
   160
 bias = sum(abs(vv-uu)/(vv+uu))
forrest@0
   161
 M    = (1.- (bias/nz))*5.
forrest@0
   162
 print (bias)
forrest@0
   163
 print (M)
forrest@0
   164
forrest@0
   165
end
forrest@0
   166