plot_hovm_tz.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate time-depth Hovmoeller diagrams of 3D fields out of NEMO output files...
  5. #
  6. # L. Brodeau, 2011
  7. #
  8. import sys
  9. import os
  10. import numpy as nmp
  11. from netCDF4 import Dataset
  12. import barakuda_tool as bt
  13. import barakuda_orca as bo
  14. import barakuda_plot as bp
  15. venv_needed = {'ORCA','EXP','DIAG_D','NN_T','NN_S','BM_FILE'}
  16. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  17. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  18. cname_temp = vdic['NN_T']
  19. cname_sali = vdic['NN_S']
  20. #if len(sys.argv) != 4 and len(sys.argv) != 6 :
  21. # print 'Usage: '+sys.argv[0]+' <YYYY1> <YYYY2> <Nb. Levels> (<name temp.> <name salin.>)'
  22. # sys.exit(0)
  23. #cy1 = sys.argv[1] ; cy2 = sys.argv[2] ; jy1=int(cy1); jy2=int(cy2)
  24. path_fig=vdic['DIAG_D']+'/'
  25. fig_type='png'
  26. list_basin_names, list_basin_lgnms = bo.get_basin_info(vdic['BM_FILE'])
  27. #list_basin_names_U = [cc.upper() for cc in list_basin_names] ; # same list but in uppercase
  28. jo = 0
  29. for coce in list_basin_names:
  30. cf_temp = cname_temp+'_mean_Vprofile_'+CONFEXP+'_'+coce+'.nc' ; bt.chck4f(cf_temp)
  31. cf_sali = cname_sali+'_mean_Vprofile_'+CONFEXP+'_'+coce+'.nc' ; bt.chck4f(cf_sali)
  32. id_temp = Dataset(cf_temp)
  33. if jo == 0:
  34. vyears = id_temp.variables['time'][:]
  35. vdepth = id_temp.variables['deptht'][:]
  36. XT = id_temp.variables[cname_temp][:,:]
  37. id_temp.close()
  38. id_sali = Dataset(cf_sali)
  39. XS = id_sali.variables[cname_sali][:,:]
  40. id_sali.close()
  41. if jo == 0:
  42. vyears = nmp.trunc(vyears) + 0.5 ; # in case 1990 and not 1990.5 !!!
  43. yr1=float(int(min(vyears)))
  44. yr2=float(int(max(vyears)))
  45. [nby, nz] = XT.shape
  46. ixtics = bt.iaxe_tick(nby)
  47. # Number of NaN vertical points:
  48. visnan = nmp.isnan(XT[0,:])
  49. nz_nan = nmp.sum(visnan)
  50. nz = nz - nz_nan
  51. XTe = nmp.zeros((nz,nby))
  52. XTe[:,:] = nmp.flipud(nmp.rot90(XT[:,:nz]))
  53. XSe = nmp.zeros((nz,nby))
  54. XSe[:,:] = nmp.flipud(nmp.rot90(XS[:,:nz]))
  55. # Removing value for first year to all years:
  56. vy1 = nmp.zeros(nz) ; vy1[:] = XTe[:,0]
  57. for jy in range(nby): XTe[:,jy] = XTe[:,jy] - vy1[:]
  58. vy1 = nmp.zeros(nz) ; vy1[:] = XSe[:,0]
  59. for jy in range(nby): XSe[:,jy] = XSe[:,jy] - vy1[:]
  60. z0 = vdepth[0]
  61. zK = max(vdepth)
  62. [ rmin, rmax, rdf ] = bt.get_min_max_df(XTe,40)
  63. bp.plot("hovmoeller")(vyears[:], vdepth[:nz], XTe[:,:], XTe[:,:]*0.+1., rmin, rmax, rdf, c_y_is='depth', #
  64. cpal='RdBu_r', tmin=yr1, tmax=yr2+1., dt=ixtics, lkcont=True,
  65. ymin = z0, ymax = zK, l_ylog=True,
  66. cfignm=path_fig+'hov_temperature_'+CONFEXP+'_'+coce, cbunit=r'$^{\circ}$C', ctunit='',
  67. cyunit='Depth (m)',
  68. ctitle=CONFEXP+': Temperature evolution, '+list_basin_lgnms[jo]+', ('+str(int(yr1))+'-'+str(int(yr2))+')',
  69. cfig_type=fig_type, i_cb_subsamp=2)
  70. XSe = 1000.*XSe
  71. [ rmin, rmax, rdf ] = bt.get_min_max_df(XSe,40)
  72. bp.plot("hovmoeller")(vyears[:], vdepth[:nz], XSe[:,:], XSe[:,:]*0.+1., rmin, rmax, rdf, c_y_is='depth',
  73. cpal='PiYG_r', tmin=yr1, tmax=yr2+1., dt=ixtics, lkcont=True,
  74. ymin = z0, ymax = zK, l_ylog=True,
  75. cfignm=path_fig+'hov_salinity_'+CONFEXP+'_'+coce, cbunit=r'10$^{-3}$PSU', ctunit='',
  76. cyunit='Depth (m)',
  77. ctitle=CONFEXP+': Salinity evolution, '+list_basin_lgnms[jo]+', ('+str(int(yr1))+'-'+str(int(yr2))+')',
  78. cfig_type=fig_type, i_cb_subsamp=2)
  79. jo = jo +1