mld.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate 2D plots and maps of the Mixed layer depth
  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. import barakuda_physics as bphys
  13. venv_needed = {'ORCA','EXP','DIAG_D','COMP2D','MM_FILE','NN_MLD','NN_S_OBS','NN_T_OBS','F_T_OBS_3D_12','F_S_OBS_3D_12'}
  14. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  15. corca = vdic['ORCA']
  16. EXP = vdic['EXP']
  17. CONFEXP = corca+'-'+EXP
  18. ldebug = False
  19. zmax_mld_atl = 1600. ; dz_mld = 100.
  20. l_obs_mld = False
  21. if (not vdic['F_T_OBS_3D_12'] == None) and (not vdic['F_T_OBS_3D_12'] == None):
  22. l_obs_mld = True ; print 'Since obs Temp and Sali here will compute observed MLD!'
  23. path_fig='./'
  24. fig_type='png'
  25. narg = len(sys.argv)
  26. if narg < 3: print 'Usage: '+sys.argv[0]+' <year1> <year2>'; sys.exit(0)
  27. cy1 = sys.argv[1] ; cy2=sys.argv[2]; jy1=int(cy1); jy2=int(cy2)
  28. jy1_clim = jy1 ; jy2_clim = jy2
  29. print ' => mean on the clim : ', jy1_clim, jy2_clim, '\n'
  30. # Getting coordinates:
  31. bt.chck4f(vdic['MM_FILE'])
  32. id_mm = Dataset(vdic['MM_FILE'])
  33. xlon = id_mm.variables['glamt'][0,:,:] ; xlat = id_mm.variables['gphit'][0,:,:]
  34. Xmask = id_mm.variables['tmask'][0,:,:,:]
  35. vlev = id_mm.variables['gdept_1d'][0,:]
  36. id_mm.close()
  37. nk = len(vlev)
  38. # Getting NEMO mean monthly climatology of MLD coverage:
  39. cf_nemo_mnmc = vdic['DIAG_D']+'/clim/mclim_'+CONFEXP+'_'+cy1+'-'+cy2+'_grid_T.nc4'
  40. bt.chck4f(cf_nemo_mnmc)
  41. id_nemo = Dataset(cf_nemo_mnmc)
  42. mldr10 = id_nemo.variables[vdic['NN_MLD']][:,:,:]
  43. id_nemo.close()
  44. [ nt, nj, ni ] = mldr10.shape ; print ' Shape of MLD :', nt, nj, ni, '\n'
  45. if l_obs_mld:
  46. # Getting 3D+T 12-month climatology of T and S
  47. # --------------------------------------------
  48. # Temperature
  49. bt.chck4f(vdic['F_T_OBS_3D_12']) ; id_clim = Dataset(vdic['F_T_OBS_3D_12'])
  50. Tclim = id_clim.variables[vdic['NN_T_OBS']][:,:,:,:]; print '(has ',Tclim.shape[0],' time snapshots)\n'
  51. id_clim.close()
  52. # Salinity
  53. bt.chck4f(vdic['F_S_OBS_3D_12']) ; id_clim = Dataset(vdic['F_S_OBS_3D_12'])
  54. Sclim = id_clim.variables[vdic['NN_S_OBS']][:,:,:,:]; print '(has ',Sclim.shape[0],' time snapshots)\n'
  55. id_clim.close()
  56. [ nmn , nk0, nj0 , ni0 ] = Tclim.shape
  57. if nj != nj0 or ni != ni0 or nk != nk0:
  58. print 'ERROR: 3D clim and NEMO file do no agree in shape!'
  59. print ' clim => '+str(ni0)+', '+str(nj0)+', '+str(nk0)+' ('+vdic['F_T_OBS_3D_12']+')'
  60. print ' NEMO => '+str(ni)+', '+str(nj)+', '+str(nk)
  61. sys.exit(0)
  62. #############
  63. # M A R C H #
  64. #############
  65. imnth = 2 ; # march
  66. # Computing sigma0 3D field:
  67. Sigma0 = bphys.sigma0(Tclim[imnth,:,:,:], Sclim[imnth,:,:,:])*Xmask[:,:,:]
  68. if ldebug: Sigma0_nemo = bphys.sigma0(Tnemo[imnth:,:,:], Snemo[imnth,:,:,:])*Xmask[:,:,:]
  69. Xmld_obs = nmp.zeros((nj,ni))
  70. mmask = nmp.zeros((nj,ni))
  71. mmask[:,:] = 1.
  72. for jk in range(nk-1):
  73. zz = vlev[jk]
  74. Sigma0[jk,:,:] = Sigma0[jk,:,:]*mmask[:,:]
  75. Sigma0[jk+1,:,:] = Sigma0[jk+1,:,:]*mmask[:,:]
  76. ijloc = nmp.where( Sigma0[jk+1,:,:] - 0.01 > Sigma0[jk,:,:] )
  77. mmask[ijloc] = 0. ; # these points won't be checked again only first occurence of the criterion matters!
  78. if ldebug:
  79. # Testing my MLD method built of T and S from NEMO (to check the obs. MLD I build the same way...)
  80. Xmld_obs[:,:] = 0.
  81. mmask[:,:] = 1.
  82. for jk in range(nk-1):
  83. zz = vlev[jk]
  84. Sigma0_nemo[jk,:,:] = Sigma0_nemo[jk,:,:]*mmask[:,:]
  85. Sigma0_nemo[jk+1,:,:] = Sigma0_nemo[jk+1,:,:]*mmask[:,:]
  86. ijloc = nmp.where( Sigma0_nemo[jk+1,:,:] - 0.01 > Sigma0_nemo[jk,:,:] )
  87. Xmld_obs[ijloc] = zz
  88. mmask[ijloc] = 0. ; # these points won't be checked again only first occurence of the criterion matters!
  89. bp.plot("nproj")('nseas', 100., zmax_mld_atl, dz_mld, xlon, xlat, Xmld_obs[:,:],
  90. cfignm=path_fig+'mld_NEMO_001_NSeas_march_'+CONFEXP+'_vs_'+vdic['COMP2D'],
  91. cpal='ncview_nrl', cbunit='m',
  92. ctitle='MLD NEMO, March, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  93. lkcont=True, cfig_type=fig_type, lforce_lim=True)
  94. # FIGURES MARCH #
  95. #################
  96. # the Jean-Marc Molines method:
  97. ji_lat0 = nmp.argmax(xlat[nj-1,:])
  98. bp.plot("nproj")('nseas', 100., zmax_mld_atl, dz_mld, xlon, xlat, mldr10[imnth,:,:],
  99. cfignm=path_fig+'mld_NSeas_march_'+CONFEXP, cpal='ncview_nrl', cbunit='(m)',
  100. ctitle='MLD, March, '+EXP+' ('+cy1+'-'+cy2+')',
  101. lkcont=True, cfig_type=fig_type,
  102. lforce_lim=True)
  103. bp.plot("nproj")('spstere', 50., 200., 10., xlon, xlat, mldr10[imnth,:,:],
  104. cfignm=path_fig+'mld_ACC_march_'+CONFEXP, cpal='ncview_nrl', cbunit='(m)',
  105. ctitle='MLD, March, '+EXP+' ('+cy1+'-'+cy2+')',
  106. lkcont=True, cfig_type=fig_type,
  107. lforce_lim=True)
  108. bp.plot("2d")(xlon[nj/3,:], xlat[:,ji_lat0], mldr10[imnth,:,:], Xmask[0,:,:], 0., 600., 20.,
  109. corca=corca, lkcont=True, cpal='ncview_nrl',
  110. cfignm=path_fig+'mld_Global_march_'+CONFEXP, cbunit='(m)',
  111. ctitle='MLD, March, '+CONFEXP+' ('+cy1+'-'+cy2+')', lforce_lim=True, i_cb_subsamp=2,
  112. cfig_type=fig_type, lat_min=-80., lat_max=75., lpix=False)
  113. if l_obs_mld:
  114. bp.plot("nproj")('nseas', 100., zmax_mld_atl, dz_mld, xlon, xlat, Xmld_obs[:,:],
  115. cfignm=path_fig+'mld_obs_001_NSeas_march_'+CONFEXP, cpal='ncview_nrl', cbunit='(m)',
  116. ctitle='MLD, March (Levitus 1980-1999)',
  117. lkcont=True, cfig_type=fig_type, lforce_lim=True)
  118. bp.plot("2d")(xlon[nj/3,:], xlat[:,ji_lat0], Xmld_obs[:,:], Xmask[0,:,:], 0., 600., 20.,
  119. corca=corca, lkcont=True, cpal='ncview_nrl',
  120. cfignm=path_fig+'mld_obs_001_Global_march_'+CONFEXP, cbunit='(m)',
  121. ctitle='MLD, March (Levitus 1980-1999)', lforce_lim=True, i_cb_subsamp=2,
  122. cfig_type=fig_type, lat_min=-80., lat_max=75., lpix=False)
  123. #####################
  124. # S E P T E M B E R #
  125. #####################
  126. imnth = 8 ; # september
  127. if l_obs_mld:
  128. # Computing sigma0 3D field:
  129. Sigma0 = bphys.sigma0(Tclim[imnth,:,:,:], Sclim[imnth,:,:,:])*Xmask[:,:,:]
  130. mmask[:,:] = 1.
  131. for jk in range(nk-1):
  132. zz = vlev[jk]
  133. Sigma0[jk,:,:] = Sigma0[jk,:,:]*mmask[:,:]
  134. Sigma0[jk+1,:,:] = Sigma0[jk+1,:,:]*mmask[:,:]
  135. ijloc = nmp.where( Sigma0[jk+1,:,:] - 0.01 > Sigma0[jk,:,:] )
  136. #lolo:Xmld_obs[ijloc] = zz ;# Problem lolo!!!
  137. mmask[ijloc] = 0. ; # these points won't be checked again only first occurence of the criterion matters!
  138. # Figures september:
  139. bp.plot("nproj")('spstere', 100., 2000., dz_mld, xlon, xlat, mldr10[imnth,:,:],
  140. cfignm=path_fig+'mld_ACC_september_'+CONFEXP, cpal='ncview_nrl', cbunit='(m)',
  141. ctitle='MLD, September, '+EXP+' ('+cy1+'-'+cy2+')',
  142. lkcont=True, cfig_type=fig_type,
  143. lforce_lim=True)
  144. bp.plot("2d")(xlon[nj/3,:], xlat[:,ji_lat0], mldr10[imnth,:,:], Xmask[0,:,:], 0., 600., 20.,
  145. corca=corca, lkcont=True, cpal='ncview_nrl',
  146. cfignm=path_fig+'mld_Global_september_'+CONFEXP, cbunit='(m)',
  147. ctitle='MLD, September, '+CONFEXP+' ('+cy1+'-'+cy2+')', lforce_lim=True, i_cb_subsamp=2,
  148. cfig_type=fig_type, lat_min=-80., lat_max=75., lpix=False)
  149. if l_obs_mld:
  150. bp.plot("2d")(xlon[nj/3,:], xlat[:,ji_lat0], Xmld_obs[:,:], Xmask[0,:,:], 0., 600., 20.,
  151. corca=corca, lkcont=True, cpal='ncview_nrl',
  152. cfignm=path_fig+'mld_obs_001_Global_september_'+CONFEXP, cbunit='(m)',
  153. ctitle='MLD, March (Levitus 1980-1999)', lforce_lim=True, i_cb_subsamp=2,
  154. cfig_type=fig_type, lat_min=-80., lat_max=75., lpix=False)
  155. print '\n Bye!'