ssh.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate global plot of sea surface height
  5. #
  6. # L. Brodeau, 2009
  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. venv_needed = {'ORCA','EXP','DIAG_D','MM_FILE','NN_SSH'}
  13. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  14. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  15. path_fig='./'
  16. fig_type='png'
  17. narg = len(sys.argv)
  18. if narg < 3: print 'Usage: '+sys.argv[0]+' <year1> <year2>'; sys.exit(0)
  19. cy1 = sys.argv[1] ; cy2=sys.argv[2]; jy1=int(cy1); jy2=int(cy2)
  20. jy1_clim = jy1 ; jy2_clim = jy2
  21. print ' => mean on the clim : ', jy1_clim, jy2_clim, '\n'
  22. # Getting coordinates:
  23. bt.chck4f(vdic['MM_FILE'])
  24. id_mm = Dataset(vdic['MM_FILE'])
  25. xlon = id_mm.variables['glamt'][0,:,:] ; xlat = id_mm.variables['gphit'][0,:,:]
  26. Xmask = id_mm.variables['tmask'][0,0,:,:]
  27. Xe1t = id_mm.variables['e1t'][0,:,:]
  28. Xe2t = id_mm.variables['e2t'][0,:,:]
  29. id_mm.close()
  30. # Getting NEMO mean monthly climatology of SSH coverage:
  31. cf_nemo_mnmc = vdic['DIAG_D']+'/clim/mclim_'+CONFEXP+'_'+cy1+'-'+cy2+'_grid_T.nc4'
  32. bt.chck4f(cf_nemo_mnmc)
  33. id_nemo = Dataset(cf_nemo_mnmc)
  34. ssh = id_nemo.variables[vdic['NN_SSH']][:,:,:]
  35. id_nemo.close()
  36. [ nt, nj, ni ] = ssh.shape ; print ' Shape of SSH :', nt, nj, ni, '\n'
  37. ssh_plot = nmp.zeros((nj,ni))
  38. ssh_plot[:,:] = nmp.mean(ssh[:,:,:],axis=0)
  39. ztot = nmp.sum(ssh_plot*Xmask*Xe1t*Xe2t)/nmp.sum(Xmask*Xe1t*Xe2t)
  40. print 'ztot =', ztot
  41. ssh_plot = ssh_plot - ztot
  42. cztot = str(round(ztot,2))
  43. # the Jean-Marc Molines method:
  44. ji_lat0 = nmp.argmax(xlat[nj-1,:])
  45. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], ssh_plot[:,:], Xmask, -2., 2., 0.1,
  46. corca=vdic['ORCA'], lkcont=True, cpal='BrBG_r',
  47. cfignm=path_fig+'ssh_mean_'+CONFEXP, cbunit=r'$(m)$',
  48. ctitle='Mean SSH (corrected about z=0, removed '+cztot+'m), '+CONFEXP+' ('+cy1+'-'+cy2+')',
  49. lforce_lim=True, i_cb_subsamp=2,
  50. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=False, vcont_spec = [ 0. ])