co2/22.lines.ncl
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/co2/22.lines.ncl	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,247 @@
     1.4 +; ***********************************************
     1.5 +; add zone plot to 21.lines.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 +
    1.61 +  g     = addfile(diri2+fili2,"r")
    1.62 +  x     = g->CO2
    1.63 +  xi    = g->lon
    1.64 +  yi    = g->lat
    1.65 +  xdim  = dimsizes(x)
    1.66 +  nlev  = xdim(1)
    1.67 +  y     = x(:,0,:,:)
    1.68 +; printVarSummary (y)
    1.69 +  
    1.70 +; get the co2 at the lowest level
    1.71 +  y     = x(:,nlev-1,:,:)
    1.72 +
    1.73 +; change to unit of observed (u mol/mol)
    1.74 +; Model_units [=] kgCO2 / kgDryAir
    1.75 +; 28.966 = molecular weight of dry air
    1.76 +; 44.       = molecular weight of CO2
    1.77 +; u mol = 1e-6 mol
    1.78 +
    1.79 +  factor = (28.966/44.) * 1e6
    1.80 +  y      = y * factor
    1.81 +
    1.82 +  y@_FillValue = 1.e36
    1.83 +  y@units      = "u mol/mol"
    1.84 +; y = where(y0 .lt. 287.,y@_FillValue,y)
    1.85 +; printVarSummary (y)
    1.86 +; print (min(y)+"/"+max(y))
    1.87 +
    1.88 +; interpolate into observed station
    1.89 +; note: model is 0-360E, 90S-90N
    1.90 +
    1.91 +; to be able to handle observation at (-89.98,-24.80)
    1.92 +  print (yi(0))
    1.93 +  yi(0) = -90.
    1.94 +
    1.95 +  i = ind(lon_ob .lt. 0.)
    1.96 +  lon_ob(i) = lon_ob(i) + 360.  
    1.97 +
    1.98 +  yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0)
    1.99 +
   1.100 +  val_model = yo(pts|:,time|:)
   1.101 +; printVarSummary (val_model)
   1.102 +; print (min(val_model)+"/"+max(val_model))
   1.103 +
   1.104 +; remove annual mean
   1.105 +  val_model = val_model - conform(val_model,dim_avg(val_model),0)
   1.106 +; print (min(val_model)+"/"+max(val_model))
   1.107 +
   1.108 +  plot_sta      = new((/2,12/),float)
   1.109 +  plot_sta@long_name = "Seasonal CO2"
   1.110 +
   1.111 +  mon = ispan(1,12,1)
   1.112 +  mon@long_name = "month"
   1.113 +
   1.114 +  plot_type = "ps"
   1.115 +  plot_type_new = "png"
   1.116 +
   1.117 +  res                   = True                      ; plot mods desired
   1.118 +  res@xyLineThicknesses = (/1.0,2.0/)               ; make 2nd lines thicker
   1.119 +  res@xyLineColors      = (/"blue","red"/)          ; change line color
   1.120 +
   1.121 +;------------------------------------------------------------------
   1.122 +; Add a boxed legend using the more simple method, which won't have
   1.123 +; vertical lines going through the markers.
   1.124 +
   1.125 +  res@pmLegendDisplayMode    = "Always"
   1.126 +; res@pmLegendWidthF         = 0.1
   1.127 +  res@pmLegendWidthF         = 0.08
   1.128 +  res@pmLegendHeightF        = 0.05
   1.129 +; res@pmLegendOrthogonalPosF = -1.17
   1.130 +; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
   1.131 +  res@pmLegendOrthogonalPosF = -0.30  ;(downward)
   1.132 +
   1.133 +; res@pmLegendParallelPosF   =  0.18
   1.134 +  res@pmLegendParallelPosF   =  0.23  ;(rightward)
   1.135 +
   1.136 +; res@lgPerimOn             = False
   1.137 +  res@lgLabelFontHeightF     = 0.015
   1.138 +  res@xyExplicitLegendLabels = (/"observed","model_b30.061m"/)
   1.139 +;-------------------------------------------------------------------
   1.140 +
   1.141 +  nzone = 4
   1.142 +  do z = 0,nzone-1
   1.143 +
   1.144 +  if (z .eq. 0) then 
   1.145 +;    maximum score for the zone, 60N-90N 
   1.146 +     score_max = 5.0
   1.147 +     zone = "60N-90N"
   1.148 +;    index of stations in this zone
   1.149 +     ind_z = ind(lat_ob .ge. 60.)
   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 +  if (z .eq. 1) then 
   1.157 +;    maximum score for the zone, 30N-60N 
   1.158 +     score_max = 5.0
   1.159 +     zone = "30N-60N"
   1.160 +;    index of stations in this zone
   1.161 +     ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
   1.162 +;    print (ind_z)
   1.163 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.164 +;    print (val_ob(ind_z,:))
   1.165 +;    print (val_model(ind_z,:))
   1.166 +  end if
   1.167 +
   1.168 +  if (z .eq. 2) then 
   1.169 +;    maximum score for the zone, EQ-30N 
   1.170 +     score_max = 5.0
   1.171 +     zone = "EQ-30N"
   1.172 +;    index of stations in this zone
   1.173 +     ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
   1.174 +;    print (ind_z)
   1.175 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.176 +;    print (val_ob(ind_z,:))
   1.177 +;    print (val_model(ind_z,:))
   1.178 +  end if
   1.179 +
   1.180 +  if (z .eq. 3) then 
   1.181 +;    maximum score for the zone, 90S-EQ 
   1.182 +     score_max = 5.0
   1.183 +     zone = "90S-EQ"     
   1.184 +;    index of stations in this zone
   1.185 +     ind_z = ind(lat_ob .lt. 0. )
   1.186 +;    print (ind_z)
   1.187 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.188 +;    print (val_ob(ind_z,:))
   1.189 +;    print (val_model(ind_z,:))
   1.190 +  end if
   1.191 +
   1.192 + npts = dimsizes(ind_z)
   1.193 + print (npts)
   1.194 +
   1.195 + npts_str = ""
   1.196 + npts_str = npts
   1.197 +;print (npts_str)
   1.198 +
   1.199 + plot_zon      = new((/2,12,npts/),float)
   1.200 +
   1.201 + do n=0,npts-1
   1.202 +    plot_zon(0,:,n) = (/val_ob(ind_z(n),:)/)
   1.203 +    plot_zon(1,:,n) = (/val_model(ind_z(n),:)/)
   1.204 +
   1.205 +;   plot_sta(0,:) = (/val_ob(ind_z(n),:)/)
   1.206 +;   plot_sta(1,:) = (/val_model(ind_z(n),:)/)
   1.207 +    
   1.208 +;   title = sta(ind_z(n))+"("+lat(ind_z(n))+","+lon(ind_z(n))+")"
   1.209 +;   plot_name = sta(ind_z(n))
   1.210 +    
   1.211 +;   print (title)
   1.212 +;   print (plot_name)
   1.213 +
   1.214 +;   wks = gsn_open_wks (plot_type,plot_name)          ; open workstation
   1.215 +;   res@tiMainString      = title                     ; add title
   1.216 + 
   1.217 +;   plot  = gsn_csm_xy (wks,mon,plot_sta,res)         ; create plot
   1.218 +;   frame(wks)
   1.219 +
   1.220 +;   system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
   1.221 +;   system("rm "+plot_name+"."+plot_type)
   1.222 +;   system("rm "+plot_name+"-1."+plot_type_new)
   1.223 +;   system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
   1.224 +;   clear (wks)
   1.225 + end do
   1.226 +    
   1.227 +    plot_sta = dim_avg(plot_zon)
   1.228 +  
   1.229 +    plot_name = "All_"+npts_str
   1.230 +    title = plot_name + " in "+ zone
   1.231 +
   1.232 +    print (title)
   1.233 +    print (plot_name)
   1.234 +
   1.235 +    wks = gsn_open_wks (plot_type,plot_name)          ; open workstation
   1.236 +    res@tiMainString      = title                     ; add title
   1.237 + 
   1.238 +    plot  = gsn_csm_xy (wks,mon,plot_sta,res)         ; create plot
   1.239 +    frame(wks)
   1.240 +
   1.241 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
   1.242 +    system("rm "+plot_name+"."+plot_type)
   1.243 +    system("rm "+plot_name+"-1."+plot_type_new)
   1.244 +    system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new)
   1.245 +    clear (wks)
   1.246 +    delete (ind_z)
   1.247 +    delete (plot_zon)
   1.248 +
   1.249 + end do
   1.250 +end