psi.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate global plot of the barotropic stream function
  5. #
  6. # L. Brodeau, 2017
  7. import sys
  8. import numpy as nmp
  9. from netCDF4 import Dataset
  10. import barakuda_tool as bt
  11. import barakuda_plot as bp
  12. cv_psi = 'sobarstf'
  13. venv_needed = {'ORCA','EXP','DIAG_D','MM_FILE'}
  14. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  15. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  16. path_fig='./'
  17. fig_type='png'
  18. narg = len(sys.argv)
  19. if narg < 3: print 'Usage: '+sys.argv[0]+' <year1> <year2>'; sys.exit(0)
  20. cy1 = sys.argv[1] ; cy2=sys.argv[2]; jy1=int(cy1); jy2=int(cy2)
  21. jy1_clim = jy1 ; jy2_clim = jy2
  22. print ' => mean on the clim : ', jy1_clim, jy2_clim, '\n'
  23. # Getting coordinates:
  24. bt.chck4f(vdic['MM_FILE'])
  25. id_mm = Dataset(vdic['MM_FILE'])
  26. xlon = id_mm.variables['glamt'][0,:,:] ; xlat = id_mm.variables['gphit'][0,:,:]
  27. Xmask = id_mm.variables['tmask'][0,0,:,:]
  28. #Xe1t = id_mm.variables['e1t'][0,:,:]
  29. #Xe2t = id_mm.variables['e2t'][0,:,:]
  30. id_mm.close()
  31. # Getting NEMO mean monthly climatology of PSI:
  32. cf_nemo_mnmc = vdic['DIAG_D']+'/clim/mclim_'+CONFEXP+'_'+cy1+'-'+cy2+'_PSI.nc4'
  33. bt.chck4f(cf_nemo_mnmc)
  34. id_nemo = Dataset(cf_nemo_mnmc)
  35. psi = 1.E-6 * id_nemo.variables[cv_psi][:,:,:]
  36. id_nemo.close()
  37. [ nt, nj, ni ] = psi.shape ; print ' Shape of Psi :', nt, nj, ni, '\n'
  38. psi_plot = nmp.zeros((nj,ni))
  39. if nt == 1:
  40. psi_plot[:,:] = psi[0,:,:]
  41. elif nt > 1:
  42. psi_plot[:,:] = nmp.mean(psi[:,:,:],axis=0)
  43. else:
  44. print ' psi.py : Problem!!!'
  45. print psi_plot[61,:]
  46. #ztot = nmp.sum(psi_plot*Xmask*Xe1t*Xe2t)/nmp.sum(Xmask*Xe1t*Xe2t)
  47. #print 'ztot =', ztot
  48. #
  49. #psi_plot = psi_plot - ztot
  50. #cztot = str(round(ztot,2))
  51. # the Jean-Marc Molines method:
  52. ji_lat0 = nmp.argmax(xlat[nj-1,:])
  53. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], psi_plot[:,:], Xmask, -100., 100., 5.,
  54. corca=vdic['ORCA'], lkcont=True, cpal='BrBG_r',
  55. cfignm=path_fig+'psi_mean_'+CONFEXP, cbunit=r'$(10^{6} m^3/s)$',
  56. ctitle='Mean barotropic stream function , '+CONFEXP+' ('+cy1+'-'+cy2+')',
  57. lforce_lim=True, i_cb_subsamp=2,
  58. cfig_type=fig_type, lat_min=-70., lat_max=68., lpix=False, vcont_spec = [ 0. ])