co2/15.metric.ncl
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/co2/15.metric.ncl	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,191 @@
     1.4 +; ***********************************************
     1.5 +; xy_4.ncl
     1.6 +; ***********************************************
     1.7 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
     1.8 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
     1.9 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    1.10 +;************************************************
    1.11 +begin
    1.12 +;************************************************
    1.13 +; read in data: observed
    1.14 +;************************************************
    1.15 + diri  = "/fis/cgd/cseg/people/jeff/clamp_data/co2/"
    1.16 + fili  = "co2_globalView_98.nc"
    1.17 + g     = addfile (diri+fili,"r")
    1.18 + val   = g->CO2_SEAS  
    1.19 + lon   = g->LON 
    1.20 + lat   = g->LAT
    1.21 + sta   = chartostring(g->STATION) 
    1.22 + delete (g)
    1.23 + 
    1.24 +;print (sta(0))
    1.25 +
    1.26 + ncase = dimsizes(lat)
    1.27 +;print (ncase)
    1.28 +
    1.29 +;**************************************************************
    1.30 +; get only the lowest level at each station 
    1.31 +;**************************************************************
    1.32 + lat_tmp = lat
    1.33 + lat_tmp@_FillValue = 1.e+36
    1.34 + 
    1.35 + do n = 0,ncase-1
    1.36 +    if (.not. ismissing(lat_tmp(n))) then 
    1.37 +       indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
    1.38 +       if (dimsizes(indexes) .gt. 1) then
    1.39 +          lat_tmp(indexes(1:)) = lat_tmp@_FillValue
    1.40 +       end if
    1.41 +       delete (indexes)
    1.42 +    end if
    1.43 + end do
    1.44 +
    1.45 + indexes = ind(.not. ismissing(lat_tmp))
    1.46 +;print (dimsizes(indexes))
    1.47 +;print (indexes)
    1.48 + 
    1.49 + lat_ob = lat(indexes)
    1.50 + lon_ob = lon(indexes)
    1.51 + val_ob = val(indexes,:)
    1.52 +;printVarSummary (val_ob)
    1.53 +;print (lat_ob +"/"+lon_ob)
    1.54 +
    1.55 +;************************************************
    1.56 +; read in model data
    1.57 +;************************************************
    1.58 +  diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
    1.59 +; fili2 = "b30.061m_401_425_MONS_climo.nc"
    1.60 +  fili2 = "b30.061n_1995-2004_MONS_climo.nc"
    1.61 +
    1.62 +  g     = addfile(diri2+fili2,"r")
    1.63 +  x     = g->CO2
    1.64 +  xi    = g->lon
    1.65 +  yi    = g->lat
    1.66 +  xdim  = dimsizes(x)
    1.67 +  nlev  = xdim(1)
    1.68 +  y     = x(:,0,:,:)
    1.69 +; printVarSummary (y)
    1.70 +  
    1.71 +; get the co2 at the lowest level
    1.72 +  y     = x(:,nlev-1,:,:)
    1.73 +
    1.74 +; change to unit of observed (u mol/mol)
    1.75 +; Model_units [=] kgCO2 / kgDryAir
    1.76 +; 28.966 = molecular weight of dry air
    1.77 +; 44.       = molecular weight of CO2
    1.78 +; u mol = 1e-6 mol
    1.79 +
    1.80 +  factor = (28.966/44.) * 1e6
    1.81 +  y      = y * factor
    1.82 +
    1.83 +  y@_FillValue = 1.e36
    1.84 +  y@units      = "u mol/mol"
    1.85 +; y = where(y0 .lt. 287.,y@_FillValue,y)
    1.86 +; printVarSummary (y)
    1.87 +; print (min(y)+"/"+max(y))
    1.88 +
    1.89 +; interpolate into observed station
    1.90 +; note: model is 0-360E, 90S-90N
    1.91 +
    1.92 +; to be able to handle observation at (-89.98,-24.80)
    1.93 +  print (yi(0))
    1.94 +  yi(0) = -90.
    1.95 +
    1.96 +  i = ind(lon_ob .lt. 0.)
    1.97 +  lon_ob(i) = lon_ob(i) + 360.  
    1.98 +
    1.99 +  yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0)
   1.100 +
   1.101 +  val_model = yo(pts|:,time|:)
   1.102 +; printVarSummary (val_model)
   1.103 +; print (min(val_model)+"/"+max(val_model))
   1.104 +
   1.105 +; remove annual mean
   1.106 +  val_model = val_model - conform(val_model,dim_avg(val_model),0)
   1.107 +; print (min(val_model)+"/"+max(val_model))
   1.108 +
   1.109 +  nzone = 4
   1.110 +  do z = 0,nzone-1
   1.111 +
   1.112 +  if (z .eq. 0) then 
   1.113 +;    maximum score for the zone, 60N-90N 
   1.114 +     score_max = 5.0
   1.115 +;    index of stations in this zone
   1.116 +     ind_z = ind(lat_ob .ge. 60.)
   1.117 +;    print (ind_z)
   1.118 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.119 +;    print (val_ob(ind_z,:))
   1.120 +;    print (val_model(ind_z,:))
   1.121 +  end if
   1.122 +
   1.123 +  if (z .eq. 1) then 
   1.124 +;    maximum score for the zone, 30N-60N 
   1.125 +     score_max = 5.0
   1.126 +;    index of stations in this zone
   1.127 +     ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
   1.128 +;    print (ind_z)
   1.129 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.130 +;    print (val_ob(ind_z,:))
   1.131 +;    print (val_model(ind_z,:))
   1.132 +  end if
   1.133 +
   1.134 +  if (z .eq. 2) then 
   1.135 +;    maximum score for the zone, EQ-30N 
   1.136 +     score_max = 5.0
   1.137 +;    index of stations in this zone
   1.138 +     ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
   1.139 +;    print (ind_z)
   1.140 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.141 +;    print (val_ob(ind_z,:))
   1.142 +;    print (val_model(ind_z,:))
   1.143 +  end if
   1.144 +
   1.145 +  if (z .eq. 3) then 
   1.146 +;    maximum score for the zone, 90S-EQ 
   1.147 +     score_max = 5.0
   1.148 +;    index of stations in this zone
   1.149 +     ind_z = ind(lat_ob .lt. 0. )
   1.150 +;    print (ind_z)
   1.151 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.152 +;    print (val_ob(ind_z,:))
   1.153 +;    print (val_model(ind_z,:))
   1.154 +  end if
   1.155 +
   1.156 + npts = dimsizes(ind_z)
   1.157 + print (npts)
   1.158 +
   1.159 + amp_ob        = new((/npts/),float)
   1.160 + amp_model     = new((/npts/),float)
   1.161 +
   1.162 + amp_ratio_sta = new((/npts/),float)
   1.163 + ccr_sta       = new((/npts/),float)
   1.164 + M_sta         = new((/npts/),float)
   1.165 + score_sta     = new((/npts/),float)
   1.166 +
   1.167 + do n=0,npts-1
   1.168 +    amp_ob(n)    = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) 
   1.169 +    amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:))
   1.170 +
   1.171 +    amp_ratio_sta(n) = amp_model(n)/amp_ob(n)
   1.172 +    ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0)
   1.173 +    M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.)
   1.174 +    score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max
   1.175 +
   1.176 +    print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n))  
   1.177 + end do
   1.178 +
   1.179 + amp_ratio_zone = avg(amp_ratio_sta)
   1.180 + ccr_zone       = avg(ccr_sta)
   1.181 + M_zone   = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) 
   1.182 + score_zone   = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max
   1.183 +
   1.184 + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone)  
   1.185 +
   1.186 + delete (ind_z)
   1.187 + delete (amp_model)
   1.188 + delete (amp_ob)
   1.189 + delete (amp_ratio_sta)
   1.190 + delete (ccr_sta)
   1.191 + delete (M_sta)
   1.192 + delete (score_sta)
   1.193 + end do
   1.194 +end