plot_enso.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. # L. Brodeau, April 2011
  3. import sys
  4. from string import replace
  5. import os
  6. import numpy as nmp
  7. from netCDF4 import Dataset
  8. import barakuda_tool as bt
  9. import barakuda_plot as bp
  10. import barakuda_stat as bs
  11. fig_form = os.getenv('FIG_FORM')
  12. if fig_form is None: fig_form = 'png'
  13. if len(sys.argv) != 3:
  14. print 'Usage: '+sys.argv[0]+' <monthly_SST_time_series.nc> <name_sst>'
  15. sys.exit(0)
  16. cf_in = sys.argv[1]
  17. cv_in = sys.argv[2]
  18. bt.chck4f(cf_in)
  19. cname = replace(os.path.basename(cf_in), '.nc', '')
  20. id_in = Dataset(cf_in)
  21. vt = id_in.variables['time'][:]
  22. vsst = id_in.variables[cv_in][:]
  23. id_in.close()
  24. Nt = len(vsst)
  25. vtmp = nmp.zeros(Nt)
  26. vtime = nmp.zeros(Nt-5)
  27. xplot = nmp.zeros((Nt-5,4)) ; # Nt-5 because 5-month-running mean
  28. vtime[:] = vt[2:-3]
  29. vtmp = bs.running_mean_5(vsst) ; # 5-month running mean
  30. xplot[:,0] = vsst[2:-3]
  31. xplot[:,1] = vtmp[2:-3]
  32. (za,zb) = bs.least_sqr_line(vtime[:], xplot[:,1]) ; # Least-square linear trend
  33. xplot[:,2] = za*vtime[:] + zb
  34. xplot[:,3] = xplot[:,1] - xplot[:,2] ; # anomaly for 5-month running mean
  35. ittic = bt.iaxe_tick(Nt/12)
  36. bp.plot("oscillation_index")( vtime, xplot[:,3], ymax=2.1, dy=0.5, yplusminus=0.4, dt=ittic,
  37. cfignm=cname, cfig_type=fig_form,
  38. cyunit=r'SST anomaly ($^{\circ}$C)',
  39. ctitle='ENSO (over Nino box 3.4)' )