sfluxes.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate zonal (and maybe one day global) plots related to
  5. # air-sea fluxes
  6. # Use climatology fields built with 'build_clim.sh'
  7. #
  8. # L. Brodeau, 2017
  9. import sys
  10. from os import path
  11. import numpy as nmp
  12. from netCDF4 import Dataset
  13. import barakuda_tool as bt
  14. import barakuda_plot as bp
  15. venv_needed = {'ORCA','EXP','DIAG_D','MM_FILE','FIG_FORM','FILE_FLX_SUFFIX',
  16. 'NN_QNET','NN_QSOL','NM_QSOL_OBS','F_QSOL_OBS_12','NN_QSOL_OBS'}
  17. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  18. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  19. cd_clim = vdic['DIAG_D']+'/clim'
  20. path_fig='./'
  21. fig_type=vdic['FIG_FORM']
  22. narg = len(sys.argv)
  23. if narg < 3: print 'Usage: '+sys.argv[0]+' <year1> <year2>'; sys.exit(0)
  24. cy1 = sys.argv[1] ; cy2=sys.argv[2]; jy1=int(cy1); jy2=int(cy2)
  25. jy1_clim = jy1 ; jy2_clim = jy2
  26. print ' => mean on the clim : ', jy1_clim, jy2_clim, '\n'
  27. ctag = CONFEXP+'_'+cy1+'-'+cy2
  28. ct_nemo = vdic['FILE_FLX_SUFFIX'] ; # (SBC or grid_T, ect.)
  29. # Getting coordinates and mask:
  30. bt.chck4f(vdic['MM_FILE'])
  31. id_mm = Dataset(vdic['MM_FILE'])
  32. xlon = id_mm.variables['glamt'][0,:,:]
  33. xlat = id_mm.variables['gphit'][0,:,:]
  34. Xmask = id_mm.variables['tmask'][0,0,:,:]
  35. id_mm.close()
  36. # Getting NEMO mean monthly climatology surface flux:
  37. cextra_qsol = ''
  38. cv_qsol = vdic['NN_QSOL']
  39. if cv_qsol != 'X':
  40. cf_nemo_qsol = cd_clim+'/mclim_'+ctag+'_'+ct_nemo+'.nc4'
  41. else:
  42. print '\n *** WARNING: sfluxes.py : if no "NN_QSOL" ! No sfluxes.py! Aborting !!!\n'
  43. sys.exit(0)
  44. bt.chck4f(cf_nemo_qsol)
  45. id_nemo = Dataset(cf_nemo_qsol)
  46. Xqsol_nemo = id_nemo.variables[cv_qsol][:,:,:]
  47. id_nemo.close()
  48. [ Nt, nj, ni ] = Xqsol_nemo.shape ; print ' Shape of QSOL :', Nt, nj, ni, '\n'
  49. if not Nt in [1,12]:
  50. print '\n *** ERROR: sfluxes.py => only accepting monthly or annual climatologies (NEMO)!', Nt
  51. sys.exit(0)
  52. if ( nj, ni ) != nmp.shape(Xmask):
  53. print '\n *** ERROR: sfluxes.py => mask and field disagree in shape!'; sys.exit(0)
  54. # Getting OBS.:
  55. cf_obs_qsol = vdic['F_QSOL_OBS_12'] ; cv_obs_qsol = vdic['NN_QSOL_OBS']
  56. bt.chck4f(cf_obs_qsol)
  57. id_obs = Dataset(cf_obs_qsol)
  58. Xqsol_obs = id_obs.variables[cv_obs_qsol][:,:,:]
  59. vlat_obs = id_obs.variables['lat'][:]
  60. id_obs.close()
  61. [ Nto, njo, nio ] = Xqsol_obs.shape ; print ' Shape of observation QSOL :', Nto, njo, nio, '\n'
  62. if not Nto == Nt:
  63. print '\n *** ERROR: sfluxes.py => Obs. and NEMO clim should have same number of time records!', Nto, Nt
  64. sys.exit(0)
  65. # Zonal stuffs....
  66. vz_obs = nmp.zeros((Nt,njo)) ; # a zonal profile...
  67. vz_obs[:,:] = bt.mk_zonal(Xqsol_obs, r_mask_from_val=-9999.)
  68. # Creating 1D long. and lat. for NEMO
  69. vlon = nmp.zeros(ni) ; vlon[:] = xlon[nj/8,:]
  70. ji_lat0 = nmp.argmax(xlat[nj-1,:])
  71. vlat = nmp.zeros(nj) ; vlat[:] = xlat[:,ji_lat0]
  72. vz_nemo = nmp.zeros((Nt,nj)) ; # a zonal profile...
  73. vz_nemo[:,:] = bt.mk_zonal(Xqsol_nemo, XMSK=Xmask)
  74. ctt = 'Zonnaly-averaged annual Net Solar heat flux, '+CONFEXP+' ('+cy1+'-'+cy2+') vs OBS.'
  75. bp.plot("zonal")(vlat, nmp.mean(vz_nemo,axis=0), VY1=vlat_obs, VZ1=nmp.mean(vz_obs,axis=0),
  76. cfignm=path_fig+'zonal_Qsol_vs_obs_annual_'+CONFEXP, zmin=50., zmax=250., dz=10.,
  77. xmin=-70., xmax=65., dx=10., czunit=r'$(W/m^2)$', cfig_type=fig_type,
  78. ctitle=ctt, lab='NEMO ('+cv_qsol+')', lab1=vdic['NM_QSOL_OBS'], loc_legend='center')
  79. if Nt == 12:
  80. ctt = 'Zonnaly-averaged JFM Net Solar heat flux, '+CONFEXP+' ('+cy1+'-'+cy2+') vs OBS.'
  81. bp.plot("zonal")(vlat, nmp.mean(vz_nemo[:3,:],axis=0), VY1=vlat_obs, VZ1=nmp.mean(vz_obs[:3,:],axis=0),
  82. cfignm=path_fig+'zonal_Qsol_vs_obs_JFM_'+CONFEXP, zmin=0., zmax=260., dz=20.,
  83. xmin=-70., xmax=65., dx=10., czunit=r'$(W/m^2)$', cfig_type=fig_type,
  84. ctitle=ctt, lab='NEMO ('+cv_qsol+')', lab1=vdic['NM_QSOL_OBS'], loc_legend='center')
  85. ctt = 'Zonnaly-averaged JAS Net Solar heat flux, '+CONFEXP+' ('+cy1+'-'+cy2+') vs OBS.'
  86. bp.plot("zonal")(vlat, nmp.mean(vz_nemo[6:9,:],axis=0), VY1=vlat_obs, VZ1=nmp.mean(vz_obs[6:9,:],axis=0),
  87. cfignm=path_fig+'zonal_Qsol_vs_obs_JAS_'+CONFEXP, zmin=0., zmax=260., dz=20.,
  88. xmin=-70., xmax=65., dx=10., czunit=r'$(W/m^2)$', cfig_type=fig_type,
  89. ctitle=ctt, lab='NEMO ('+cv_qsol+')', lab1=vdic['NM_QSOL_OBS'], loc_legend='center')