plot_trsp_sigma.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate time-series of volume trasnport by sigma0 class
  5. #
  6. # L. Brodeau, 2013
  7. #
  8. import sys
  9. import numpy as nmp
  10. from netCDF4 import Dataset
  11. import barakuda_tool as bt
  12. import barakuda_plot as bp
  13. import barakuda_physics as bphy
  14. venv_needed = {'ORCA','EXP','DIAG_D','DENSITY_SECTION_FILE'}
  15. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  16. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  17. rsigdense0 = bphy.rsigma_dense
  18. cfig_type = 'png'
  19. path_fig = vdic['DIAG_D']+'/'
  20. cf_dens_sect = vdic['DENSITY_SECTION_FILE']
  21. print ' Using cf_dens_sect = '+cf_dens_sect
  22. list_sections = bt.get_sections_from_file(cf_dens_sect)
  23. print 'List of sections to treat: ', list_sections
  24. nbsec = len(list_sections)
  25. cf_in = vdic['DIAG_D']+'/transport_by_sigma_class.nc' ; bt.chck4f(cf_in)
  26. id_in = Dataset(cf_in)
  27. vtime = id_in.variables['time'][:]
  28. (nby, nbm, nbr, ittic) = bt.test_nb_years(vtime, 'trsp_sigma')
  29. vsigma = id_in.variables['sigma_bins'][:] ; nbin = len(vsigma)
  30. print ' => '+str(nbin)+' sigma-density bins and '+str(nbr)+' time records...'
  31. # Reconstructing bounds of bins:
  32. vsigma_bounds = nmp.zeros(nbin+1)
  33. dsigma = vsigma[1]-vsigma[0]
  34. vsigma_bounds[:nbin] = vsigma[:] - 0.5*dsigma
  35. vsigma_bounds[nbin] = vsigma[nbin-1] + 0.5*dsigma
  36. # Loop along sections:
  37. ######################
  38. jsec = 0
  39. for csec in list_sections:
  40. Xst = nmp.flipud(nmp.rot90(id_in.variables['sigtrsp_'+csec][:,:]))
  41. print ' Shape of "sigtrsp_'+csec+'" => ', nmp.shape(Xst)
  42. # Annual array: lolo
  43. if nbm >= 12:
  44. # the file contains monthly data (nbm=-1 otherwize)
  45. vtime_ann, Xst_ann = bt.monthly_2_annual(vtime, Xst)
  46. else:
  47. vtime_ann = vtime
  48. Xst_ann = Xst
  49. # FIGURE 1
  50. ###########
  51. rmax = nmp.amax(nmp.abs(Xst_ann)) ; rmin = -rmax
  52. rmin, rmax, dc = bp.__suitable_axis_dx__(rmin, rmax, nb_val=25, lsym0=True)
  53. i_cbssmp=2
  54. if dc in [0.5,1.,2.,5.]: i_cbssmp=1
  55. bp.plot("trsp_sig_class")(vtime_ann, vsigma_bounds, Xst_ann, rmin, rmax, dc,
  56. lkcont=False, cpal='ncview_jaisnb', dt=ittic,
  57. cfignm='transport_sigma_class_'+csec+'_'+CONFEXP,
  58. cfig_type='png', ctitle=r'Transport by $\sigma_0$ class, '+csec+', '+CONFEXP,
  59. vcont_spec1 = [], i_cb_subsamp=i_cbssmp)
  60. # Volume transport for density > rsigma_dense
  61. # ====================================
  62. if jsec == 0:
  63. v278 = nmp.zeros(nby*nbsec) ; v278.shape = [ nbsec, nby ]
  64. j278 = 0 ; nsig = len(vsigma)
  65. while vsigma[j278] < rsigdense0: j278 = j278 + 1
  66. for jt in range(nby): v278[jsec,jt] = nmp.sum(Xst_ann[j278:,jt])
  67. jsec = jsec + 1
  68. # Closing netcdf file:
  69. id_in.close()
  70. bp.plot("1d_multi")(vtime_ann, v278, list_sections, cfignm='tr_sigma_gt278_'+CONFEXP,
  71. dt=ittic, cyunit='Sv',
  72. ctitle=r'Transport of volume for $\sigma_0$ > '+str(rsigdense0)+', '+CONFEXP,
  73. ymin=0., ymax=0., loc_legend='out')
  74. print '\n trsp_sigma.py => done!\n\n'