wind.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate global plots related to wind
  5. # wind stress, its curl, wind speed, etc
  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. cv_curl = 'socurl' ; # as generated by CDFTOOLS...
  16. #CPAL_CURL='BrBG_r'
  17. CPAL_CURL='ncview_jaisnb'
  18. #CPAL_TAUM='ncview_nrl'
  19. CPAL_TAUM='cubehelix_r'
  20. CPAL_WNDM='CMRmap_r'
  21. # Max values and increment for figures:
  22. Rmax = 0.3 ; dR = 0.05 ; # Wind stress curl (10^-6 s)
  23. Tmax = 0.3 ; dT = 0.025 ; # Wind stress module (N/m^2)
  24. Wmax = 15. ; Wmin = 2. ; dW = 1. ; # Surface wind speed module (m/s)
  25. venv_needed = {'ORCA','EXP','DIAG_D','MM_FILE','FIG_FORM','FILE_FLX_SUFFIX','NN_TAUM','NN_WNDM'}
  26. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  27. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  28. cd_clim = vdic['DIAG_D']+'/clim'
  29. path_fig='./'
  30. fig_type=vdic['FIG_FORM']
  31. narg = len(sys.argv)
  32. if narg < 3: print 'Usage: '+sys.argv[0]+' <year1> <year2>'; sys.exit(0)
  33. cy1 = sys.argv[1] ; cy2=sys.argv[2]; jy1=int(cy1); jy2=int(cy2)
  34. jy1_clim = jy1 ; jy2_clim = jy2
  35. print ' => mean on the clim : ', jy1_clim, jy2_clim, '\n'
  36. ctag = CONFEXP+'_'+cy1+'-'+cy2
  37. # Getting coordinates:
  38. bt.chck4f(vdic['MM_FILE'])
  39. id_mm = Dataset(vdic['MM_FILE'])
  40. xlon = id_mm.variables['glamt'][0,:,:] ; xlat = id_mm.variables['gphit'][0,:,:]
  41. Xmask = id_mm.variables['tmask'][0,0,:,:]
  42. id_mm.close()
  43. l_tau_is_annual = False
  44. cf_nemo_curl = cd_clim+'/mclim_'+ctag+'_TCURL.nc4'
  45. if not path.exists(cf_nemo_curl):
  46. cf_nemo_curl = cd_clim+'/aclim_'+ctag+'_TCURL.nc4'
  47. if path.exists(cf_nemo_curl):
  48. l_tau_is_annual = True
  49. print '\n *** wind.py : wind stress is annual...'
  50. else:
  51. print '\n *** WARNING: wind.py : giving up neither annual nor monthly curl clim found!'
  52. sys.exit(0)
  53. # Getting NEMO mean monthly climatology of wind stress module:
  54. cextra_tau = ''
  55. cv_taum = vdic['NN_TAUM']
  56. if cv_taum != 'X':
  57. cf_nemo_taum = cd_clim+'/mclim_'+ctag+'_'+vdic['FILE_FLX_SUFFIX']+'.nc4'
  58. if l_tau_is_annual: cf_nemo_taum = cd_clim+'/aclim_'+ctag+'_'+vdic['FILE_FLX_SUFFIX']+'.nc4'
  59. else:
  60. #Falling back on what cdfcurl.x has computed from monthly averaged Taux and Tauy:
  61. cf_nemo_taum = cf_nemo_curl
  62. cv_taum = 'sotaum'
  63. cextra_tau = ' (from monthly-averaged Tau_x & Tau_y !)'
  64. if l_tau_is_annual: cextra_tau = ' (from annually-averaged Tau_x & Tau_y !)'
  65. bt.chck4f(cf_nemo_taum)
  66. id_nemo = Dataset(cf_nemo_taum)
  67. Xtaum = id_nemo.variables[cv_taum][:,:,:]
  68. id_nemo.close()
  69. [ Nt, nj, ni ] = Xtaum.shape ; print ' Shape of TAUM :', Nt, nj, ni, '\n'
  70. if not Nt in [1,12]:
  71. print '\n *** ERROR: wind.py : only accepting monthly or annual climatologies!', Nt
  72. sys.exit(0)
  73. # Getting NEMO mean monthly climatology of CURL:
  74. bt.chck4f(cf_nemo_curl)
  75. id_nemo = Dataset(cf_nemo_curl)
  76. Xcurl = id_nemo.variables[cv_curl][:,:,:]
  77. id_nemo.close()
  78. cextra_crl = ' (from monthly-averaged Tau_x & Tau_y !)'
  79. if l_tau_is_annual: cextra_crl = ' (from annually-averaged Tau_x & Tau_y !)'
  80. # Getting surface wind speed as seen in NEMO if we find it!!!
  81. l_do_wndm = False
  82. cv_wndm = vdic['NN_WNDM']
  83. if cv_wndm != 'X':
  84. cf_nemo_wndm = cd_clim+'/mclim_'+ctag+'_'+vdic['FILE_FLX_SUFFIX']+'.nc4'
  85. if path.exists(cf_nemo_wndm):
  86. id_nemo = Dataset(cf_nemo_wndm)
  87. list_var = id_nemo.variables.keys()
  88. if cv_wndm in list_var:
  89. Xwndm = id_nemo.variables[cv_wndm][:,:,:]
  90. l_do_wndm = True
  91. print '\n *** wind.py : we found wind speed in '+cf_nemo_wndm ; #lolo
  92. id_nemo.close()
  93. nper = 3
  94. if l_tau_is_annual: nper = 1
  95. Xtaum_plot = nmp.zeros((nper,nj,ni))
  96. Xcurl_plot = nmp.zeros((3,nj,ni))
  97. Xtaum_plot[0,:,:] = nmp.mean(Xtaum[:,:,:] ,axis=0) ; # Annual
  98. Xcurl_plot[0,:,:] = nmp.mean(Xcurl[:,:,:] ,axis=0) ; # Annual
  99. if not l_tau_is_annual:
  100. Xtaum_plot[1,:,:] = nmp.mean(Xtaum[:3,:,:] ,axis=0) ; # Winter
  101. Xtaum_plot[2,:,:] = nmp.mean(Xtaum[6:9,:,:],axis=0) ; # Summer
  102. Xcurl_plot[1,:,:] = nmp.mean(Xcurl[:3,:,:] ,axis=0) ; # Winter
  103. Xcurl_plot[2,:,:] = nmp.mean(Xcurl[6:9,:,:],axis=0) ; # Summer
  104. if l_do_wndm:
  105. Xwndm_plot = nmp.zeros((nper,nj,ni))
  106. Xwndm_plot[0,:,:] = nmp.mean(Xwndm[:,:,:] ,axis=0) ; # Annual
  107. Xwndm_plot[1,:,:] = nmp.mean(Xwndm[:3,:,:] ,axis=0) ; # Winter
  108. Xwndm_plot[2,:,:] = nmp.mean(Xwndm[6:9,:,:],axis=0) ; # Summer
  109. # the Jean-Marc Molines method:
  110. ji_lat0 = nmp.argmax(xlat[nj-1,:])
  111. # Annual Curl:
  112. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xcurl_plot[0,:,:], Xmask, -Rmax, Rmax, dR,
  113. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_CURL,
  114. cfignm=path_fig+'tau_curl_annual_'+CONFEXP, cbunit=r'$(10^{-6}s^{-1})$',
  115. ctitle='Wind stress curl, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_crl,
  116. lforce_lim=False, i_cb_subsamp=1,
  117. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)
  118. if not l_tau_is_annual:
  119. # JFM Curl:
  120. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xcurl_plot[1,:,:], Xmask, -Rmax, Rmax, dR,
  121. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_CURL,
  122. cfignm=path_fig+'tau_curl_JFM_'+CONFEXP, cbunit=r'$(10^{-6}s^{-1})$',
  123. ctitle='Wind stress curl, JFM, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_crl,
  124. lforce_lim=False, i_cb_subsamp=1,
  125. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)
  126. # JAS Curl:
  127. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xcurl_plot[2,:,:], Xmask, -Rmax, Rmax, dR,
  128. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_CURL,
  129. cfignm=path_fig+'tau_curl_JAS_'+CONFEXP, cbunit=r'$(10^{-6}s^{-1})$',
  130. ctitle='Wind stress curl, JAS, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_crl,
  131. lforce_lim=False, i_cb_subsamp=1,
  132. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)
  133. # Annual Taum:
  134. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xtaum_plot[0,:,:], Xmask, 0., Tmax, dT,
  135. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_TAUM,
  136. cfignm=path_fig+'taum_annual_'+CONFEXP, cbunit=r'$(N/m^2)$',
  137. ctitle='Wind stress module, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_tau,
  138. lforce_lim=False, i_cb_subsamp=1,
  139. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)
  140. if not l_tau_is_annual:
  141. # JFM Taum:
  142. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xtaum_plot[1,:,:], Xmask, 0., Tmax, dT,
  143. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_TAUM,
  144. cfignm=path_fig+'taum_JFM_'+CONFEXP, cbunit=r'$(N/m^2)$',
  145. ctitle='Wind stress module, JFM, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_tau,
  146. lforce_lim=False, i_cb_subsamp=1,
  147. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)
  148. # JAS Taum:
  149. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xtaum_plot[2,:,:], Xmask, 0., Tmax, dT,
  150. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_TAUM,
  151. cfignm=path_fig+'taum_JAS_'+CONFEXP, cbunit=r'$(N/m^2)$',
  152. ctitle='Wind stress module, JAS, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_tau,
  153. lforce_lim=False, i_cb_subsamp=1,
  154. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)
  155. if l_do_wndm:
  156. # Annual Wndm:
  157. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xwndm_plot[0,:,:], Xmask, Wmin, Wmax, dW,
  158. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_WNDM,
  159. cfignm=path_fig+'wndm_annual_'+CONFEXP, cbunit=r'$(m/s)$',
  160. ctitle='Surface wind speed module, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_tau,
  161. lforce_lim=False, i_cb_subsamp=1,
  162. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)
  163. # JFM Wndm:
  164. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xwndm_plot[1,:,:], Xmask, Wmin, Wmax, dW,
  165. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_WNDM,
  166. cfignm=path_fig+'wndm_JFM_'+CONFEXP, cbunit=r'$(m/s)$',
  167. ctitle='Surface wind speed module, JFM, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_tau,
  168. lforce_lim=False, i_cb_subsamp=1,
  169. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)
  170. # JAS Wndm:
  171. bp.plot("2d")(xlon[0,:], xlat[:,ji_lat0], Xwndm_plot[2,:,:], Xmask, Wmin, Wmax, dW,
  172. corca=vdic['ORCA'], lkcont=False, cpal=CPAL_WNDM,
  173. cfignm=path_fig+'wndm_JAS_'+CONFEXP, cbunit=r'$(m/s)$',
  174. ctitle='Surface wind speed module, JAS, '+CONFEXP+' ('+cy1+'-'+cy2+')'+cextra_tau,
  175. lforce_lim=False, i_cb_subsamp=1,
  176. cfig_type=fig_type, lat_min=-77., lat_max=75., lpix=True)