co2/24.lines.ncl
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/co2/24.lines.ncl	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,319 @@
     1.4 +; ***********************************************
     1.5 +; add another model to plot
     1.6 +; add panel plot to 22.lines.ncl
     1.7 +; add zone plot to 21.lines.ncl
     1.8 +; ***********************************************
     1.9 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    1.10 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
    1.11 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    1.12 +;************************************************
    1.13 +begin
    1.14 +;************************************************
    1.15 +; read in data: observed
    1.16 +;************************************************
    1.17 + diri  = "/fis/cgd/cseg/people/jeff/clamp_data/co2/"
    1.18 + fili  = "co2_globalView_98.nc"
    1.19 + g     = addfile (diri+fili,"r")
    1.20 + val   = g->CO2_SEAS  
    1.21 + lon   = g->LON 
    1.22 + lat   = g->LAT
    1.23 + sta   = chartostring(g->STATION) 
    1.24 + delete (g)
    1.25 + 
    1.26 +;print (sta(0))
    1.27 +
    1.28 + ncase = dimsizes(lat)
    1.29 +;print (ncase)
    1.30 +
    1.31 +;**************************************************************
    1.32 +; get only the lowest level at each station 
    1.33 +;**************************************************************
    1.34 + lat_tmp = lat
    1.35 + lat_tmp@_FillValue = 1.e+36
    1.36 + 
    1.37 + do n = 0,ncase-1
    1.38 +    if (.not. ismissing(lat_tmp(n))) then 
    1.39 +       indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
    1.40 +       if (dimsizes(indexes) .gt. 1) then
    1.41 +          lat_tmp(indexes(1:)) = lat_tmp@_FillValue
    1.42 +       end if
    1.43 +       delete (indexes)
    1.44 +    end if
    1.45 + end do
    1.46 +
    1.47 + indexes = ind(.not. ismissing(lat_tmp))
    1.48 +;print (dimsizes(indexes))
    1.49 +;print (indexes)
    1.50 + 
    1.51 + lat_ob = lat(indexes)
    1.52 + lon_ob = lon(indexes)
    1.53 + val_ob = val(indexes,:)
    1.54 +;printVarSummary (val_ob)
    1.55 +;print (lat_ob +"/"+lon_ob)
    1.56 +
    1.57 +;************************************************
    1.58 +; read in model data
    1.59 +;************************************************
    1.60 +  diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
    1.61 +  fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc"
    1.62 +  fili3 = "b30.061m_401_425_MONS_climo_atm.nc"
    1.63 +;--------------------------------------------
    1.64 +  g    = addfile(diri2+fili2,"r")
    1.65 +  x1   = g->CO2
    1.66 +  xi   = g->lon
    1.67 +  yi   = g->lat
    1.68 +  delete (g)
    1.69 +
    1.70 +  xdim  = dimsizes(x1)
    1.71 +  nlev  = xdim(1)
    1.72 +  y1     = x1(:,0,:,:)
    1.73 +; printVarSummary (y1)
    1.74 +  
    1.75 +; get the co2 at the lowest level
    1.76 +  y1     = x1(:,nlev-1,:,:)
    1.77 +  delete (x1)
    1.78 +;---------------------------------------------
    1.79 +  g     = addfile(diri2+fili3,"r")
    1.80 +  x2    = g->CO2
    1.81 +  delete (g)
    1.82 +  y2     = x2(:,0,:,:)
    1.83 +  y2     = x2(:,nlev-1,:,:)
    1.84 +  delete (x2)
    1.85 +;---------------------------------------------
    1.86 +; change to unit of observed (u mol/mol)
    1.87 +; Model_units [=] kgCO2 / kgDryAir
    1.88 +; 28.966 = molecular weight of dry air
    1.89 +; 44.       = molecular weight of CO2
    1.90 +; u mol = 1e-6 mol
    1.91 +
    1.92 +  factor = (28.966/44.) * 1e6
    1.93 +;---------------------------------------------
    1.94 +  y1 = y1 * factor
    1.95 +  y1@_FillValue = 1.e36
    1.96 +  y1@units      = "u mol/mol"
    1.97 +; y1 = where(y0 .lt. 287.,1y@_FillValue,y1)
    1.98 +; printVarSummary (y1)
    1.99 +; print (min(y1)+"/"+max(y1))
   1.100 +;---------------------------------------------
   1.101 +  y2 = y2 * factor
   1.102 +  y2@_FillValue = 1.e36
   1.103 +  y2@units      = "u mol/mol"
   1.104 +;---------------------------------------------
   1.105 +; interpolate into observed station
   1.106 +; note: model is 0-360E,   90S-90N
   1.107 +;       ob    is -180-180, 90S-90N
   1.108 +
   1.109 +; to be able to handle observation at (-89.98,-24.80)
   1.110 +  print (yi(0))
   1.111 +  yi(0) = -90.
   1.112 +
   1.113 +  i = ind(lon_ob .lt. 0.)
   1.114 +  lon_ob(i) = lon_ob(i) + 360.  
   1.115 +;----------------------------------------------------------------
   1.116 +  yo = linint2_points_Wrap(xi,yi,y1,True,lon_ob,lat_ob,0)
   1.117 +
   1.118 +  val_model1 = yo(pts|:,time|:)
   1.119 +  val_model1_0 = val_model1
   1.120 +; printVarSummary (val_model1)
   1.121 +; print (min(val_model1)+"/"+max(val_model1))
   1.122 +
   1.123 +; remove annual mean
   1.124 +  val_model1 = val_model1 - conform(val_model1,dim_avg(val_model1),0)
   1.125 +; print (min(val_model1)+"/"+max(val_model1))
   1.126 +  delete (yo)
   1.127 +;-----------------------------------------------------------------
   1.128 +  yo = linint2_points_Wrap(xi,yi,y2,True,lon_ob,lat_ob,0)
   1.129 +
   1.130 +  val_model2 = yo(pts|:,time|:)
   1.131 +  val_model2_0 = val_model2
   1.132 +; printVarSummary (val_model2)
   1.133 +; print (min(val_model2)+"/"+max(val_model2))
   1.134 +
   1.135 +; remove annual mean
   1.136 +  val_model2 = val_model2 - conform(val_model2,dim_avg(val_model2),0)
   1.137 +; print (min(val_model2)+"/"+max(val_model2))
   1.138 +  delete (yo)
   1.139 +;-----------------------------------------------------------------
   1.140 +; for x-axis in xyplot
   1.141 +  mon = ispan(1,12,1)
   1.142 +  mon@long_name = "month"
   1.143 +;-----------------------------------------------------------------
   1.144 +  plot_type = "ps"
   1.145 +  plot_type_new = "png"
   1.146 +
   1.147 +  res                   = True                      ; plot mods desired
   1.148 +  res@xyLineThicknesses = (/2.0,2.0,2.0/)           ; make 2nd lines thicker
   1.149 +  res@xyLineColors      = (/"red","blue","black"/)  ; change line color
   1.150 +;------------------------------------------------------------------
   1.151 +; Add a boxed legend using the more simple method
   1.152 +
   1.153 +  res@pmLegendDisplayMode    = "Always"
   1.154 +; res@pmLegendWidthF         = 0.1
   1.155 +  res@pmLegendWidthF         = 0.08
   1.156 +  res@pmLegendHeightF        = 0.06
   1.157 +; res@pmLegendOrthogonalPosF = -1.17
   1.158 +; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
   1.159 +  res@pmLegendOrthogonalPosF = -0.30  ;(downward)
   1.160 +
   1.161 +; res@pmLegendParallelPosF   =  0.18
   1.162 +  res@pmLegendParallelPosF   =  0.23  ;(rightward)
   1.163 +
   1.164 +; res@lgPerimOn             = False
   1.165 +  res@lgLabelFontHeightF     = 0.015
   1.166 +  res@xyExplicitLegendLabels = (/"b30.061n","b30.061m","observed"/)
   1.167 +;-------------------------------------------------------------------
   1.168 +
   1.169 +  nzone = 4
   1.170 +  do z = 0,nzone-1
   1.171 +
   1.172 +  if (z .eq. 0) then 
   1.173 +;    maximum score for the zone, 60N-90N 
   1.174 +     score_max = 5.0
   1.175 +     zone = "60N-90N"
   1.176 +;    index of stations in this zone
   1.177 +     ind_z = ind(lat_ob .ge. 60.)
   1.178 +;    print (ind_z)
   1.179 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.180 +;    print (val_ob(ind_z,:))
   1.181 +;    print (val_model(ind_z,:))
   1.182 +  end if
   1.183 +
   1.184 +  if (z .eq. 1) then 
   1.185 +;    maximum score for the zone, 30N-60N 
   1.186 +     score_max = 5.0
   1.187 +     zone = "30N-60N"
   1.188 +;    index of stations in this zone
   1.189 +     ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
   1.190 +;    print (ind_z)
   1.191 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.192 +;    print (val_ob(ind_z,:))
   1.193 +;    print (val_model(ind_z,:))
   1.194 +  end if
   1.195 +
   1.196 +  if (z .eq. 2) then 
   1.197 +;    maximum score for the zone, EQ-30N 
   1.198 +     score_max = 5.0
   1.199 +     zone = "EQ-30N"
   1.200 +;    index of stations in this zone
   1.201 +     ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
   1.202 +;    print (ind_z)
   1.203 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.204 +;    print (val_ob(ind_z,:))
   1.205 +;    print (val_model(ind_z,:))
   1.206 +  end if
   1.207 +
   1.208 +  if (z .eq. 3) then 
   1.209 +;    maximum score for the zone, 90S-EQ 
   1.210 +     score_max = 5.0
   1.211 +     zone = "90S-EQ"     
   1.212 +;    index of stations in this zone
   1.213 +     ind_z = ind(lat_ob .lt. 0. )
   1.214 +;    print (ind_z)
   1.215 +;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
   1.216 +;    print (val_ob(ind_z,:))
   1.217 +;    print (val_model(ind_z,:))
   1.218 +  end if
   1.219 +
   1.220 +  npts = dimsizes(ind_z)
   1.221 +  print (npts)
   1.222 +
   1.223 +  npts_str = ""
   1.224 +  npts_str = npts
   1.225 +; print (npts_str)
   1.226 +
   1.227 +  plot_data   = new((/3,12,npts/),float)
   1.228 +  plot_data_0 = new((/2,12,npts/),float)
   1.229 +
   1.230 +  plot_data!0 = "case"
   1.231 +  plot_data!1 = "month"
   1.232 +  plot_data!2 = "pts"
   1.233 +  plot_data@long_name   = "CO2 Seasonal"
   1.234 +
   1.235 +  plot_data_0!0 = "month"
   1.236 +  plot_data_0!1 = "pts"
   1.237 +  plot_data_0@long_name = "CO2"
   1.238 +
   1.239 +  do n=0,npts-1
   1.240 +
   1.241 +    plot_data(0,:,n) = (/val_model1(ind_z(n),:)/)
   1.242 +    plot_data(1,:,n) = (/val_model2(ind_z(n),:)/)
   1.243 +    plot_data(2,:,n) = (/val_ob(ind_z(n),:)/)
   1.244 +
   1.245 +    plot_data_0(0,:,n) = (/val_model1_0(ind_z(n),:)/)
   1.246 +    plot_data_0(1,:,n) = (/val_model2_0(ind_z(n),:)/)
   1.247 +
   1.248 +;*****************************************************
   1.249 +; create plot with 3 lines for each observed station
   1.250 +;*****************************************************   
   1.251 +    plot_name = sta(ind_z(n))    
   1.252 +    title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")"
   1.253 +;   print (title)
   1.254 +;   print (plot_name)
   1.255 +
   1.256 +    wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
   1.257 +;---------------------------------------------------------------------------
   1.258 +;   for panel plot
   1.259 +   
   1.260 +    plot=new(2,graphic)                        ; create graphic array
   1.261 +    res@gsnFrame     = False                   ; Do not draw plot 
   1.262 +    res@gsnDraw      = False                   ; Do not advance frame
   1.263 +
   1.264 +    pres                            = True     ; panel plot mods desired
   1.265 +    pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
   1.266 +                                               ; indiv. plots in panel
   1.267 +    pres@gsnMaximize                = True     ; fill the page
   1.268 +;---------------------------------------------------------------------------
   1.269 +    res@tiMainString = title                           ; add title
   1.270 +
   1.271 +    plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res)   ; create plot 1
   1.272 +
   1.273 +;   plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,:,n),res) ; create plot 2
   1.274 +    plot(1)=gsn_csm_xy(wks,mon,plot_data_0(0,:,n),res) ; create plot 2
   1.275 +
   1.276 +    gsn_panel(wks,plot,(/2,1/),pres)                 ; create panel plot
   1.277 +
   1.278 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
   1.279 +    system("rm "+plot_name+"."+plot_type)
   1.280 +    clear (wks)
   1.281 + end do
   1.282 +;*****************************************************************************    
   1.283 +; plot zone average
   1.284 +;*****************************************************************************  
   1.285 +    plot_name = "All_"+npts_str
   1.286 +    title = plot_name + " in "+ zone
   1.287 +;   print (title)
   1.288 +;   print (plot_name)
   1.289 +
   1.290 +    wks = gsn_open_wks (plot_type,plot_name)        ; open workstation
   1.291 +;---------------------------------------------------------------------------
   1.292 +;   for panel plot
   1.293 +   
   1.294 +    plot=new(2,graphic)                        ; create graphic array
   1.295 +    res@gsnFrame     = False                   ; Do not draw plot 
   1.296 +    res@gsnDraw      = False                   ; Do not advance frame
   1.297 +
   1.298 +    pres                            = True     ; panel plot mods desired
   1.299 +    pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
   1.300 +                                               ; indiv. plots in panel
   1.301 +    pres@gsnMaximize                = True     ; fill the page
   1.302 +;---------------------------------------------------------------------------
   1.303 +    res@tiMainString = title                                     ; add title
   1.304 +
   1.305 +    plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res)   ; create plot 1
   1.306 +    
   1.307 +;   plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2
   1.308 +
   1.309 +    xx = dim_avg_Wrap(plot_data_0)
   1.310 +    plot(1) = gsn_csm_xy (wks,mon,xx(0,:),res) ; create plot 2
   1.311 +
   1.312 +    gsn_panel(wks,plot,(/2,1/),pres)                 ; create panel plot
   1.313 +
   1.314 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
   1.315 +    system("rm "+plot_name+"."+plot_type)
   1.316 +
   1.317 +    clear (wks)
   1.318 +    delete (ind_z)
   1.319 +    delete (plot_data)
   1.320 +    delete (plot_data_0)    
   1.321 + end do
   1.322 +end