co2/19.metric_plot.ncl
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/co2/19.metric_plot.ncl	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,268 @@
     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 +load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
    1.11 +;************************************************
    1.12 +begin
    1.13 +;************************************************
    1.14 +; read in data: observed
    1.15 +;************************************************
    1.16 + diri  = "/fis/cgd/cseg/people/jeff/clamp_data/co2/"
    1.17 + fili  = "co2_globalView_98.nc"
    1.18 + g     = addfile (diri+fili,"r")
    1.19 + val   = g->CO2_SEAS  
    1.20 + lon   = g->LON 
    1.21 + lat   = g->LAT
    1.22 + sta   = chartostring(g->STATION) 
    1.23 + delete (g)
    1.24 + 
    1.25 +;print (sta(0))
    1.26 +
    1.27 + ncase = dimsizes(lat)
    1.28 +;print (ncase)
    1.29 +
    1.30 +;**************************************************************
    1.31 +; get only the lowest level at each station 
    1.32 +;**************************************************************
    1.33 + lat_tmp = lat
    1.34 + lat_tmp@_FillValue = 1.e+36
    1.35 + 
    1.36 + do n = 0,ncase-1
    1.37 +    if (.not. ismissing(lat_tmp(n))) then 
    1.38 +       indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
    1.39 +       if (dimsizes(indexes) .gt. 1) then
    1.40 +          lat_tmp(indexes(1:)) = lat_tmp@_FillValue
    1.41 +       end if
    1.42 +       delete (indexes)
    1.43 +    end if
    1.44 + end do
    1.45 +
    1.46 + indexes = ind(.not. ismissing(lat_tmp))
    1.47 +;print (dimsizes(indexes))
    1.48 +;print (indexes)
    1.49 + 
    1.50 + lat_ob = lat(indexes)
    1.51 + lon_ob = lon(indexes)
    1.52 + val_ob = val(indexes,:)
    1.53 +;printVarSummary (val_ob)
    1.54 +;print (lat_ob +"/"+lon_ob)
    1.55 +
    1.56 +;************************************************
    1.57 +; read in model data
    1.58 +;************************************************
    1.59 +  diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
    1.60 +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc"
    1.61 +  fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc"
    1.62 +
    1.63 +  g     = addfile(diri2+fili2,"r")
    1.64 +  x     = g->CO2
    1.65 +  xi    = g->lon
    1.66 +  yi    = g->lat
    1.67 +  xdim  = dimsizes(x)
    1.68 +  nlev  = xdim(1)
    1.69 +  y     = x(:,0,:,:)
    1.70 +; printVarSummary (y)
    1.71 +  
    1.72 +; get the co2 at the lowest level
    1.73 +  y     = x(:,nlev-1,:,:)
    1.74 +
    1.75 +; change to unit of observed (u mol/mol)
    1.76 +; Model_units [=] kgCO2 / kgDryAir
    1.77 +; 28.966 = molecular weight of dry air
    1.78 +; 44.       = molecular weight of CO2
    1.79 +; u mol = 1e-6 mol
    1.80 +
    1.81 +  factor = (28.966/44.) * 1e6
    1.82 +  y      = y * factor
    1.83 +
    1.84 +  y@_FillValue = 1.e36
    1.85 +  y@units      = "u mol/mol"
    1.86 +; y = where(y0 .lt. 287.,y@_FillValue,y)
    1.87 +; printVarSummary (y)
    1.88 +; print (min(y)+"/"+max(y))
    1.89 +
    1.90 +; interpolate into observed station
    1.91 +; note: model is 0-360E, 90S-90N
    1.92 +
    1.93 +; to be able to handle observation at (-89.98,-24.80)
    1.94 +  print (yi(0))
    1.95 +  yi(0) = -90.
    1.96 +
    1.97 +  i = ind(lon_ob .lt. 0.)
    1.98 +  lon_ob(i) = lon_ob(i) + 360.  
    1.99 +
   1.100 +  yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0)
   1.101 +
   1.102 +  val_model = yo(pts|:,time|:)
   1.103 +; printVarSummary (val_model)
   1.104 +; print (min(val_model)+"/"+max(val_model))
   1.105 +
   1.106 +; remove annual mean
   1.107 +  val_model = val_model - conform(val_model,dim_avg(val_model),0)
   1.108 +; print (min(val_model)+"/"+max(val_model))
   1.109 +
   1.110 +  nzone = 4
   1.111 +
   1.112 +; column
   1.113 +  case_zone = (/"Stations","Amplitude Ratio", \
   1.114 +                "Correlation Coef","M score","Combined Score"/)
   1.115 +  nCase_zone = dimsizes(case_zone ) 
   1.116 +
   1.117 +; row
   1.118 +  var_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/)  
   1.119 +  nVar_zone = dimsizes(var_zone)                  
   1.120 +
   1.121 +; arrays to be passed to diagram. 
   1.122 +  case_value_zone = new ((/nCase_zone, nVar_zone/),float )  
   1.123 +
   1.124 +  do z = 0,nzone-1
   1.125 +
   1.126 +  if (z .eq. 0) then 
   1.127 +;    maximum score for the zone, 60N-90N
   1.128 +     zone = "60N-90N" 
   1.129 +     score_max = 5.0
   1.130 +;    index of stations in this zone
   1.131 +     ind_z = ind(lat_ob .ge. 60.)
   1.132 +;    print (ind_z)
   1.133 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.134 +;    print (val_ob(ind_z,:))
   1.135 +;    print (val_model(ind_z,:))
   1.136 +  end if
   1.137 +
   1.138 +  if (z .eq. 1) then 
   1.139 +;    maximum score for the zone, 30N-60N
   1.140 +     zone = "30N-60N" 
   1.141 +     score_max = 5.0
   1.142 +;    index of stations in this zone
   1.143 +     ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
   1.144 +;    print (ind_z)
   1.145 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.146 +;    print (val_ob(ind_z,:))
   1.147 +;    print (val_model(ind_z,:))
   1.148 +  end if
   1.149 +
   1.150 +  if (z .eq. 2) then 
   1.151 +;    maximum score for the zone, EQ-30N 
   1.152 +     zone = "EQ-30N"
   1.153 +     score_max = 5.0
   1.154 +;    index of stations in this zone
   1.155 +     ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
   1.156 +;    print (ind_z)
   1.157 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.158 +;    print (val_ob(ind_z,:))
   1.159 +;    print (val_model(ind_z,:))
   1.160 +  end if
   1.161 +
   1.162 +  if (z .eq. 3) then 
   1.163 +;    maximum score for the zone, 90S-EQ
   1.164 +     zone = "90S-EQ" 
   1.165 +     score_max = 5.0
   1.166 +;    index of stations in this zone
   1.167 +     ind_z = ind(lat_ob .lt. 0. )
   1.168 +;    print (ind_z)
   1.169 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.170 +;    print (val_ob(ind_z,:))
   1.171 +;    print (val_model(ind_z,:))
   1.172 +  end if
   1.173 +
   1.174 + npts = dimsizes(ind_z)
   1.175 + print (npts)
   1.176 +
   1.177 + amp_ob        = new((/npts/),float)
   1.178 + amp_model     = new((/npts/),float)
   1.179 +
   1.180 + amp_ratio_sta = new((/npts/),float)
   1.181 + ccr_sta       = new((/npts/),float)
   1.182 + M_sta         = new((/npts/),float)
   1.183 + score_sta     = new((/npts/),float)
   1.184 +
   1.185 + do n=0,npts-1
   1.186 +    amp_ob(n)    = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) 
   1.187 +    amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:))
   1.188 +
   1.189 +    amp_ratio_sta(n) = amp_model(n)/amp_ob(n)
   1.190 +    ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0)
   1.191 +    M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.)
   1.192 +    score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max
   1.193 +
   1.194 +    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.195 + end do
   1.196 +
   1.197 + amp_ratio_zone = avg(amp_ratio_sta)
   1.198 + ccr_zone       = avg(ccr_sta)
   1.199 + M_zone   = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) 
   1.200 + score_zone   = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max
   1.201 +
   1.202 + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone)
   1.203 +
   1.204 +  case_value_zone(0,z) = npts
   1.205 +  case_value_zone(1,z) = (/amp_ratio_zone/)
   1.206 +  case_value_zone(2,z) = (/ccr_zone/)
   1.207 +  case_value_zone(3,z) = (/M_zone/)
   1.208 +  case_value_zone(4,z) = (/score_zone/)  
   1.209 +;**************************************************
   1.210 +; plot station table
   1.211 +;**************************************************
   1.212 +; column for station table
   1.213 +  case_sta   = (/"Latitude","Longitude","Amplitude Ratio", \
   1.214 +                 "Correlation Coef","M score","Combined Score"/) 
   1.215 +  nCase_sta  = dimsizes(case_sta )                 
   1.216 +
   1.217 +; row for station table
   1.218 +  var_sta  = sta(ind_z) 
   1.219 +  nVar_sta = dimsizes(var_sta)                 
   1.220 +
   1.221 +; arrays to be passed to diagram. 
   1.222 +  case_value_sta = new ((/nCase_sta, nVar_sta/),float )  
   1.223 +
   1.224 +  case_value_sta(0,:) = (/lat(ind_z)/)
   1.225 +  case_value_sta(1,:) = (/lon(ind_z)/)
   1.226 +  case_value_sta(2,:) = (/amp_ratio_sta/)
   1.227 +  case_value_sta(3,:) = (/ccr_sta/)
   1.228 +  case_value_sta(4,:) = (/M_sta/)
   1.229 +  case_value_sta(5,:) = (/score_sta/)
   1.230 + 
   1.231 +;**************************************************
   1.232 +; plot station table
   1.233 +;**************************************************
   1.234 +  tt_opt        = True
   1.235 +  tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps"
   1.236 +                        ; "png", "gif" [if you have ImageMajik 'convert']
   1.237 +
   1.238 +  tt_opt@tableTitle = "Zone "+ zone
   1.239 +  plot_name         = "table_sta." + zone
   1.240 +
   1.241 +  metrics_table(plot_name, var_sta, case_sta , case_value_sta, tt_opt)
   1.242 +
   1.243 + delete (ind_z)
   1.244 + delete (amp_model)
   1.245 + delete (amp_ob)
   1.246 + delete (amp_ratio_sta)
   1.247 + delete (ccr_sta)
   1.248 + delete (M_sta)
   1.249 + delete (score_sta)
   1.250 + delete (var_sta)
   1.251 + delete (case_value_sta)
   1.252 + end do
   1.253 +;**************************************************
   1.254 +; plot zone table
   1.255 +;**************************************************
   1.256 +  case_value_zone(0,4) = case_value_zone(0,0)+case_value_zone(0,1)+case_value_zone(0,2)+case_value_zone(0,3) 
   1.257 +  case_value_zone(1,4) = 0.
   1.258 +  case_value_zone(2,4) = 0.
   1.259 +  case_value_zone(3,4) = 0.
   1.260 +  case_value_zone(4,4) = case_value_zone(4,0)+case_value_zone(4,1)+case_value_zone(4,2)+case_value_zone(4,3) 
   1.261 +  
   1.262 +  tt_opt        = True
   1.263 +  tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps"
   1.264 +                        ; "png", "gif" [if you have ImageMajik 'convert']
   1.265 +
   1.266 +  tt_opt@tableTitle = "Zone"
   1.267 +  plot_name         = "table_zone" 
   1.268 +
   1.269 +  metrics_table(plot_name, var_zone, case_zone , case_value_zone, tt_opt)
   1.270 +
   1.271 +end