co2/14.metric.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
; xy_4.ncl
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
begin
forrest@0
     9
;************************************************
forrest@0
    10
; read in data: observed
forrest@0
    11
;************************************************
forrest@0
    12
 diri  = "/fis/cgd/cseg/people/jeff/clamp_data/co2/"
forrest@0
    13
 fili  = "co2_globalView_98.nc"
forrest@0
    14
 g     = addfile (diri+fili,"r")
forrest@0
    15
 val   = g->CO2_SEAS  
forrest@0
    16
 lon   = g->LON 
forrest@0
    17
 lat   = g->LAT
forrest@0
    18
 sta   = chartostring(g->STATION) 
forrest@0
    19
 delete (g)
forrest@0
    20
 
forrest@0
    21
;print (sta(0))
forrest@0
    22
forrest@0
    23
 ncase = dimsizes(lat)
forrest@0
    24
;print (ncase)
forrest@0
    25
forrest@0
    26
;**************************************************************
forrest@0
    27
; get only the lowest level at each station 
forrest@0
    28
;**************************************************************
forrest@0
    29
 lat_tmp = lat
forrest@0
    30
 lat_tmp@_FillValue = 1.e+36
forrest@0
    31
 
forrest@0
    32
 do n = 0,ncase-1
forrest@0
    33
    if (.not. ismissing(lat_tmp(n))) then 
forrest@0
    34
       indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
forrest@0
    35
       if (dimsizes(indexes) .gt. 1) then
forrest@0
    36
          lat_tmp(indexes(1:)) = lat_tmp@_FillValue
forrest@0
    37
       end if
forrest@0
    38
       delete (indexes)
forrest@0
    39
    end if
forrest@0
    40
 end do
forrest@0
    41
forrest@0
    42
 indexes = ind(.not. ismissing(lat_tmp))
forrest@0
    43
;print (dimsizes(indexes))
forrest@0
    44
;print (indexes)
forrest@0
    45
 
forrest@0
    46
 lat_ob = lat(indexes)
forrest@0
    47
 lon_ob = lon(indexes)
forrest@0
    48
 val_ob = val(indexes,:)
forrest@0
    49
;printVarSummary (val_ob)
forrest@0
    50
;print (lat_ob +"/"+lon_ob)
forrest@0
    51
forrest@0
    52
;************************************************
forrest@0
    53
; read in model data
forrest@0
    54
;************************************************
forrest@0
    55
  diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    56
  fili2 = "b30.061m_401_425_MONS_climo.nc"
forrest@0
    57
forrest@0
    58
  g     = addfile(diri2+fili2,"r")
forrest@0
    59
  x     = g->CO2
forrest@0
    60
  xi    = g->lon
forrest@0
    61
  yi    = g->lat
forrest@0
    62
  xdim  = dimsizes(x)
forrest@0
    63
  nlev  = xdim(1)
forrest@0
    64
  y     = x(:,0,:,:)
forrest@0
    65
; printVarSummary (y)
forrest@0
    66
  
forrest@0
    67
; get the co2 at the lowest level
forrest@0
    68
  y     = x(:,nlev-1,:,:)
forrest@0
    69
forrest@0
    70
; change to unit of observed (u mol/mol)
forrest@0
    71
; Model_units [=] kgCO2 / kgDryAir
forrest@0
    72
; 28.966 = molecular weight of dry air
forrest@0
    73
; 44.       = molecular weight of CO2
forrest@0
    74
; u mol = 1e-6 mol
forrest@0
    75
forrest@0
    76
  factor = (28.966/44.) * 1e6
forrest@0
    77
  y      = y * factor
forrest@0
    78
forrest@0
    79
  y@_FillValue = 1.e36
forrest@0
    80
  y@units      = "u mol/mol"
forrest@0
    81
; y = where(y0 .lt. 287.,y@_FillValue,y)
forrest@0
    82
; printVarSummary (y)
forrest@0
    83
; print (min(y)+"/"+max(y))
forrest@0
    84
forrest@0
    85
; interpolate into observed station
forrest@0
    86
; note: model is 0-360E, 90S-90N
forrest@0
    87
forrest@0
    88
  i = ind(lon_ob .lt. 0.)
forrest@0
    89
  lon_ob(i) = lon_ob(i) + 360.  
forrest@0
    90
forrest@0
    91
  yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0)
forrest@0
    92
forrest@0
    93
  val_model = val_ob
forrest@0
    94
  val_model = yo(pts|:,time|:)
forrest@0
    95
; printVarSummary (val_model)
forrest@0
    96
; print (min(val_model)+"/"+max(val_model))
forrest@0
    97
forrest@0
    98
; remove annual mean
forrest@0
    99
  val_model = val_model - conform(val_model,dim_avg(val_model),0)
forrest@0
   100
; print (min(val_model)+"/"+max(val_model))
forrest@0
   101
forrest@0
   102
  nzone = 4
forrest@0
   103
  do z = 0,nzone-1
forrest@0
   104
forrest@0
   105
  if (z .eq. 0) then 
forrest@0
   106
;    maximum score for the zone, 60N-90N 
forrest@0
   107
     score_max = 5.0
forrest@0
   108
;    index of stations in this zone
forrest@0
   109
     ind_z = ind(lat_ob .ge. 60.)
forrest@0
   110
;    print (ind_z)
forrest@0
   111
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   112
;    print (val_ob(ind_z,:))
forrest@0
   113
;    print (val_model(ind_z,:))
forrest@0
   114
  end if
forrest@0
   115
forrest@0
   116
  if (z .eq. 1) then 
forrest@0
   117
;    maximum score for the zone, 30N-60N 
forrest@0
   118
     score_max = 5.0
forrest@0
   119
;    index of stations in this zone
forrest@0
   120
     ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
forrest@0
   121
;    print (ind_z)
forrest@0
   122
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   123
;    print (val_ob(ind_z,:))
forrest@0
   124
;    print (val_model(ind_z,:))
forrest@0
   125
  end if
forrest@0
   126
forrest@0
   127
  if (z .eq. 2) then 
forrest@0
   128
;    maximum score for the zone, EQ-30N 
forrest@0
   129
     score_max = 5.0
forrest@0
   130
;    index of stations in this zone
forrest@0
   131
     ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
forrest@0
   132
;    print (ind_z)
forrest@0
   133
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   134
;    print (val_ob(ind_z,:))
forrest@0
   135
;    print (val_model(ind_z,:))
forrest@0
   136
  end if
forrest@0
   137
forrest@0
   138
  if (z .eq. 3) then 
forrest@0
   139
;    maximum score for the zone, 90S-EQ 
forrest@0
   140
     score_max = 5.0
forrest@0
   141
;    index of stations in this zone
forrest@0
   142
     ind_z = ind(lat_ob .lt. 0. )
forrest@0
   143
;    print (ind_z)
forrest@0
   144
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   145
;    print (val_ob(ind_z,:))
forrest@0
   146
;    print (val_model(ind_z,:))
forrest@0
   147
  end if
forrest@0
   148
forrest@0
   149
 u = ndtooned(val_ob(ind_z,:))
forrest@0
   150
 v = ndtooned(val_model(ind_z,:))
forrest@0
   151
forrest@0
   152
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   153
forrest@0
   154
 uu = u(good)
forrest@0
   155
 vv = v(good)
forrest@0
   156
 st = sta(ind_z)
forrest@0
   157
forrest@0
   158
 npts = dimsizes(st)
forrest@0
   159
 print (npts)
forrest@0
   160
forrest@0
   161
 ccr = esccr(uu,vv,0)
forrest@0
   162
;print (ccr)
forrest@0
   163
forrest@0
   164
 un =  onedtond(uu,(/npts,12/))
forrest@0
   165
 vn =  onedtond(vv,(/npts,12/))
forrest@0
   166
;print (un)
forrest@0
   167
;print (vn)
forrest@0
   168
forrest@0
   169
 score = new((/npts/),float)
forrest@0
   170
forrest@0
   171
 do n=0,npts-1
forrest@0
   172
    amp_ob    = max(un(n,:)) - min(un(n,:)) 
forrest@0
   173
    amp_model = max(vn(n,:)) - min(vn(n,:))
forrest@0
   174
    score(n) = 1.-abs((amp_model/amp_ob)-1.)
forrest@0
   175
;   print (amp_ob)
forrest@0
   176
;   print (amp_model)  
forrest@0
   177
 end do
forrest@0
   178
;print (score)
forrest@0
   179
forrest@0
   180
 M = avg(score)
forrest@0
   181
 print (M)
forrest@0
   182
forrest@0
   183
 M_total = (ccr*ccr + M)*0.5 * score_max
forrest@0
   184
 print (M_total)
forrest@0
   185
forrest@0
   186
 delete (ind_z)
forrest@0
   187
 delete (good)
forrest@0
   188
 delete (u)
forrest@0
   189
 delete (v)
forrest@0
   190
 delete (uu)
forrest@0
   191
 delete (vv)
forrest@0
   192
 delete (un)
forrest@0
   193
 delete (vn)
forrest@0
   194
 delete (st) 
forrest@0
   195
 delete (score)
forrest@0
   196
 end do
forrest@0
   197
end