1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/co2/13.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_222.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 + delete (g)
1.22 +
1.23 + ncase = dimsizes(lat)
1.24 +;print (ncase)
1.25 +
1.26 +;**************************************************************
1.27 +; get only the lowest level at each station
1.28 +;**************************************************************
1.29 + lat_tmp = lat
1.30 + lat_tmp@_FillValue = 1.e+36
1.31 +
1.32 + do n = 0,ncase-1
1.33 + if (.not. ismissing(lat_tmp(n))) then
1.34 + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
1.35 + if (dimsizes(indexes) .gt. 1) then
1.36 + lat_tmp(indexes(1:)) = lat_tmp@_FillValue
1.37 + end if
1.38 + delete (indexes)
1.39 + end if
1.40 + end do
1.41 +
1.42 + indexes = ind(.not. ismissing(lat_tmp))
1.43 +;print (indexes)
1.44 +
1.45 + lat_ob = lat(indexes)
1.46 + lon_ob = lon(indexes)
1.47 + val_ob = val(indexes,:)
1.48 +;printVarSummary (val_ob)
1.49 +;print (lat_ob +"/"+lon_ob)
1.50 +
1.51 +;************************************************
1.52 +; read in model data
1.53 +;************************************************
1.54 + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
1.55 + fili2 = "b30.061m_401_425_MONS_climo.nc"
1.56 +
1.57 + g = addfile(diri2+fili2,"r")
1.58 + x = g->CO2
1.59 + xi = g->lon
1.60 + yi = g->lat
1.61 + xdim = dimsizes(x)
1.62 + nlev = xdim(1)
1.63 + y = x(:,0,:,:)
1.64 +; printVarSummary (y)
1.65 +
1.66 +; get the co2 at the lowest level
1.67 + y = x(:,nlev-1,:,:)
1.68 +
1.69 +; change to unit of observed (u mol/mol)
1.70 +; Model_units [=] kgCO2 / kgDryAir
1.71 +; 28.966 = molecular weight of dry air
1.72 +; 44. = molecular weight of CO2
1.73 +; u mol = 1e-6 mol
1.74 +
1.75 + factor = (28.966/44.) * 1e6
1.76 + y = y * factor
1.77 +
1.78 + y@_FillValue = 1.e36
1.79 + y@units = "u mol/mol"
1.80 +; y = where(y0 .lt. 287.,y@_FillValue,y)
1.81 +; printVarSummary (y)
1.82 +; print (min(y)+"/"+max(y))
1.83 +
1.84 +; interpolate into observed station
1.85 +; note: model is 0-360E, 90S-90N
1.86 +
1.87 + i = ind(lon_ob .lt. 0.)
1.88 + lon_ob(i) = lon_ob(i) + 360.
1.89 +
1.90 + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0)
1.91 +
1.92 + val_model = val_ob
1.93 + val_model = yo(pts|:,time|:)
1.94 +; printVarSummary (val_model)
1.95 +; print (min(val_model)+"/"+max(val_model))
1.96 +
1.97 +; remove annual mean
1.98 + val_model = val_model - conform(val_model,dim_avg(val_model),0)
1.99 +; print (min(val_model)+"/"+max(val_model))
1.100 +
1.101 + nzone = 4
1.102 + do z = 0,nzone-1
1.103 +
1.104 + if (z .eq. 0) then
1.105 +; maximum score for the zone, 60N-90N
1.106 + score_max = 5.0
1.107 +; index of stations in this zone
1.108 + ind_z = ind(lat_ob .ge. 60.)
1.109 +; print (ind_z)
1.110 +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
1.111 +; print (val_ob(ind_z,:))
1.112 +; print (val_model(ind_z,:))
1.113 + end if
1.114 +
1.115 + if (z .eq. 1) then
1.116 +; maximum score for the zone, 30N-60N
1.117 + score_max = 5.0
1.118 +; index of stations in this zone
1.119 + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
1.120 +; print (ind_z)
1.121 +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
1.122 +; print (val_ob(ind_z,:))
1.123 +; print (val_model(ind_z,:))
1.124 + end if
1.125 +
1.126 + if (z .eq. 2) then
1.127 +; maximum score for the zone, EQ-30N
1.128 + score_max = 5.0
1.129 +; index of stations in this zone
1.130 + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
1.131 +; print (ind_z)
1.132 +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
1.133 +; print (val_ob(ind_z,:))
1.134 +; print (val_model(ind_z,:))
1.135 + end if
1.136 +
1.137 + if (z .eq. 3) then
1.138 +; maximum score for the zone, 90S-EQ
1.139 + score_max = 5.0
1.140 +; index of stations in this zone
1.141 + ind_z = ind(lat_ob .lt. 0. )
1.142 +; print (ind_z)
1.143 +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
1.144 +; print (val_ob(ind_z,:))
1.145 +; print (val_model(ind_z,:))
1.146 + end if
1.147 +
1.148 + u = ndtooned(val_ob(ind_z,:))
1.149 + v = ndtooned(val_model(ind_z,:))
1.150 +
1.151 + good = ind(.not.ismissing(u) .and. .not.ismissing(v))
1.152 +
1.153 + uu = u(good)
1.154 + vv = v(good)
1.155 +
1.156 + npts = dimsizes(uu)/12
1.157 + print (npts)
1.158 +
1.159 + ccr = esccr(uu,vv,0)
1.160 + print (ccr)
1.161 +
1.162 + un = onedtond(uu,(/npts,12/))
1.163 + vn = onedtond(vv,(/npts,12/))
1.164 +;print (un)
1.165 +;print (vn)
1.166 +
1.167 + score = new((/npts/),float)
1.168 +
1.169 + do n=0,npts-1
1.170 + amp_ob = max(un(n,:)) - min(un(n,:))
1.171 + amp_model = max(vn(n,:)) - min(vn(n,:))
1.172 + score(n) = 1.-abs((amp_model/amp_ob)-1.)
1.173 +; print (amp_ob)
1.174 +; print (amp_model)
1.175 + end do
1.176 +;print (score)
1.177 +
1.178 + M = avg(score)
1.179 + print (M)
1.180 +
1.181 + M_total = (ccr*ccr + M)*0.5 * score_max
1.182 + print (M_total)
1.183 +
1.184 + delete (ind_z)
1.185 + delete (good)
1.186 + delete (u)
1.187 + delete (v)
1.188 + delete (uu)
1.189 + delete (vv)
1.190 + delete (un)
1.191 + delete (vn)
1.192 + delete (score)
1.193 + end do
1.194 +end