plot_hovm_merid_trsp.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env python
  2. #
  3. # L. Brodeau, July 2011
  4. #
  5. import sys
  6. import os
  7. import numpy as nmp
  8. from netCDF4 import Dataset
  9. import barakuda_orca as bo
  10. import barakuda_plot as bp
  11. import barakuda_tool as bt
  12. dy = 10. ; # latitude increment in figure...
  13. venv_needed = {'ORCA','EXP','DIAG_D','BM_FILE'}
  14. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  15. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  16. path_fig=vdic['DIAG_D']+'/'
  17. fig_type='png'
  18. cf_in = vdic['DIAG_D']+'/merid_transport_T_S_'+CONFEXP+'.nc'
  19. if not os.path.exists(cf_in):
  20. print ' ERROR: plot_hovm_merid_trsp.py => old ascii file system not supported anymore!'
  21. print ' => need file '+cf_in+' !!!' ; sys.exit(0)
  22. #list_basin_names, list_basin_lgnms = bo.get_basin_info(vdic['BM_FILE'])
  23. # As in cdfmhst.F90:
  24. list_basin_names = [ 'GLO','atl','pac','ind' ]
  25. list_basin_lgnms = [ 'Global Ocean','Atlantic Ocean','Pacific Ocean','Indian Ocean' ]
  26. nbasins = len(list_basin_names)
  27. id_in = Dataset(cf_in)
  28. vyear = id_in.variables['time'][:] ; Nby = len(vyear) ; ittic = bt.iaxe_tick(Nby)
  29. vyear = vyear - 0.5
  30. vlat = id_in.variables['lat'][:] ; Nlat = len(vlat)
  31. for joce in range(nbasins):
  32. cbas = list_basin_names[joce] ; # name as in cf_in ...
  33. cbasin = list_basin_lgnms[joce] ; # long name of basin
  34. if joce == 0:
  35. Xheat = nmp.zeros(nbasins*Nby*Nlat) ; Xheat.shape = [ nbasins, Nby, Nlat ]
  36. Xsalt = nmp.zeros(nbasins*Nby*Nlat) ; Xsalt.shape = [ nbasins, Nby, Nlat ]
  37. rmiss_val = id_in.variables['zomht_'+cbas].getncattr('_FillValue')
  38. Xheat[joce,:,:] = id_in.variables['zomht_'+cbas][:,:]
  39. Xsalt[joce,:,:] = id_in.variables['zomst_'+cbas][:,:]
  40. print ' *** zomht_'+cbas+' and zomst_'+cbas+' sucessfully read into '+cf_in
  41. id_in.close()
  42. print ''
  43. mask = nmp.zeros((Nby, Nlat)) + 1.
  44. for joce in range(nbasins):
  45. if joce == 0:
  46. vyear = nmp.trunc(vyear) + 0.5 ; # in case 1990 and not 1990.5 !!!
  47. yr1=float(int(min(vyear)))
  48. yr2=float(int(max(vyear)))
  49. cbas = list_basin_names[joce] ; # name as in cf_in ...
  50. cbasin = list_basin_lgnms[joce] ; # long name of basin
  51. #mask[:,:] = 0
  52. #Lfinite = nmp.isfinite(Xheat[joce,:,:]) ; idx_good = nmp.where(Lfinite)
  53. #mask[idx_good] = 1
  54. # time record to consider to chose a min and a max for colorbar:
  55. jt_ini = 5
  56. if Nby <= 10: jt_ini = 1
  57. if Nby == 1: jt_ini = 0
  58. # Finding the first and last j that make sense (not NaN)
  59. js = -1 ; lfound=False
  60. while not lfound:
  61. js = js + 1
  62. #if not nmp.isnan(Xheat[joce,1,js]): lfound=True
  63. if Xheat[joce,1,js] != rmiss_val: lfound=True
  64. je = Nlat ; lfound=False
  65. while not lfound:
  66. je = je - 1
  67. #if not nmp.isnan(Xheat[joce,1,je]): lfound=True
  68. if Xheat[joce,1,je] != rmiss_val: lfound=True
  69. dyh=dy/2
  70. ymin = (int(vlat[js]/dyh)-1)*dyh
  71. ymax = (int(vlat[je]/dyh)+1)*dyh
  72. # min and max for field:
  73. [ rmin, rmax, rdf ] = bt.get_min_max_df(Xheat[joce,jt_ini:,js+1:je-1],40)
  74. bp.plot("hovmoeller")(vyear[:], vlat[:], nmp.flipud(nmp.rot90(Xheat[joce,:,:])), mask,
  75. rmin, rmax, rdf, c_y_is='latitude',
  76. cpal='RdBu_r', tmin=yr1, tmax=yr2+1., dt=ittic, lkcont=True,
  77. ymin = ymin, ymax = ymax, dy=dy,
  78. cfignm=path_fig+'MHT_'+CONFEXP+'_'+cbas, cbunit='PW', ctunit='',
  79. cyunit=r'Latitude ($^{\circ}$N)',
  80. ctitle=CONFEXP+': Northward advective meridional heat transport, '+cbasin,
  81. cfig_type=fig_type, i_cb_subsamp=2, l_y_increase=True)
  82. # Salt transport
  83. [ rmin, rmax, rdf ] = bt.get_min_max_df(Xsalt[joce,jt_ini:,js+1:je-1],40)
  84. bp.plot("hovmoeller")(vyear[:], vlat[:], nmp.flipud(nmp.rot90(Xsalt[joce,:,:])), mask,
  85. rmin, rmax, rdf, c_y_is='latitude',
  86. cpal='PiYG_r', tmin=yr1, tmax=yr2+1., dt=ittic, lkcont=True,
  87. ymin = ymin, ymax = ymax, dy=dy,
  88. cfignm=path_fig+'MST_'+CONFEXP+'_'+cbas, cbunit=r'10$^3$ tons/s', ctunit='',
  89. cyunit=r'Latitude ($^{\circ}$N)',
  90. ctitle=CONFEXP+': Northward advective meridional salt transport, '+cbasin,
  91. cfig_type=fig_type, i_cb_subsamp=2, l_y_increase=True)