runoffs.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env python
  2. # L. Brodeau, 2016
  3. import sys
  4. import numpy as nmp
  5. from netCDF4 import Dataset
  6. import barakuda_tool as bt
  7. import barakuda_plot as bp
  8. ldebug = False
  9. rmult = 1.E3
  10. zmax_rnf_atl = 0.1 ; dz_rnf = 0.005
  11. venv_needed = {'ORCA','EXP','DIAG_D','NN_RNF','MM_FILE'}
  12. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  13. #if 'ORCA2' in vdic['ORCA']:
  14. # ji_lat0 = 132
  15. #elif 'ORCA1' in vdic['ORCA']:
  16. # #ji_lat0 = 265
  17. # ji_lat0 = 100
  18. #else:
  19. # print 'FIX ME!!! '+sys.argv[0]+' => dont know ji_lat0 for conf '+vdic['ORCA']+' !!!'; sys.exit(0)
  20. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  21. path_fig='./'
  22. fig_type='png'
  23. narg = len(sys.argv)
  24. if narg < 3:
  25. print 'Usage: '+sys.argv[0]+' <year1> <year2>'; sys.exit(0)
  26. cy1 = sys.argv[1] ; cy2=sys.argv[2]; jy1=int(cy1); jy2=int(cy2)
  27. jy1_clim = jy1 ; jy2_clim = jy2
  28. print ' => mean on the clim : ', jy1_clim, jy2_clim, '\n'
  29. # Getting coordinates:
  30. bt.chck4f(vdic['MM_FILE'])
  31. id_mm = Dataset(vdic['MM_FILE'])
  32. xlon = id_mm.variables['glamt'][0,:,:] ; xlat = id_mm.variables['gphit'][0,:,:]
  33. Xmask = id_mm.variables['tmask'][0,:,:,:]
  34. vlev = id_mm.variables['gdept_1d'][0,:]
  35. id_mm.close()
  36. nk = len(vlev)
  37. # Getting NEMO mean monthly climatology of RNF coverage:
  38. cf_nemo_mnmc = vdic['DIAG_D']+'/clim/mclim_'+CONFEXP+'_'+cy1+'-'+cy2+'_SBC.nc4'
  39. bt.chck4f(cf_nemo_mnmc)
  40. id_nemo = Dataset(cf_nemo_mnmc)
  41. rnf = rmult*id_nemo.variables[vdic['NN_RNF']][:,:,:]
  42. id_nemo.close()
  43. [ nt, nj, ni ] = rnf.shape ; print ' Shape of Runoffs :', nt, nj, ni, '\n'
  44. rnf_plot = nmp.zeros(nj*ni) ; rnf_plot.shape = [ nj , ni ]
  45. rnf_plot[:,:] = nmp.mean(rnf[:,:,:],axis=0)
  46. #rnf_plot[:,:] = nmp.log(rnf_plot[:,:]+1.0)
  47. # With lat-lon axis:
  48. #bp.plot_2d(xlon[0,:], xlat[:,ji_lat0], rnf_plot[:,:], Xmask[0,:,:], 0., zmax_rnf_atl, dz_rnf,
  49. # corca=vdic['ORCA'], lkcont=False, cpal='sst',
  50. # cfignm=path_fig+'runoffs_mean_'+CONFEXP, cbunit=r'10$^{-3}$mm/day',
  51. # ctitle='Mean Runoffs, '+CONFEXP+' ('+cy1+'-'+cy2+')', lforce_lim=True, i_cb_subsamp=2,
  52. # cfig_type=fig_type, lat_min=-79., lat_max=85., lpix=True)
  53. # Without:
  54. bp.plot("2d")([0], [0], rnf_plot[:,:], Xmask[0,:,:], 0., zmax_rnf_atl, dz_rnf,
  55. corca=vdic['ORCA'], lkcont=False, cpal='sst',
  56. cfignm=path_fig+'runoffs_mean_'+CONFEXP, cbunit=r'10$^{-3}$mm/day',
  57. ctitle='Mean Runoffs, '+CONFEXP+' ('+cy1+'-'+cy2+')', lforce_lim=True, i_cb_subsamp=2,
  58. cfig_type=fig_type, lpix=True)
  59. print '\n Bye!'