ice.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate stereographic plot of sea-ice extent at both poles
  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','COMP2D','NM_IC_OBS','F_ICE_OBS_12','NN_ICEF_OBS',
  13. 'NN_ICEF','NN_ICET','FILE_ICE_SUFFIX'}
  14. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  15. cexp = vdic['EXP']
  16. CONFEXP = vdic['ORCA']+'-'+cexp
  17. path_fig='./'
  18. fig_type='png'
  19. cn_obs = vdic['NM_IC_OBS']
  20. narg = len(sys.argv)
  21. if narg < 3: print 'Usage: '+sys.argv[0]+' <year1> <year2>'; sys.exit(0)
  22. cy1 = sys.argv[1] ; cy2=sys.argv[2]; jy1=int(cy1); jy2=int(cy2)
  23. jy1_clim = jy1 ; jy2_clim = jy2
  24. print ' => mean on the clim : ', jy1_clim, jy2_clim, '\n'
  25. # Getting coordinates and mask :
  26. bt.chck4f(vdic['MM_FILE'])
  27. id_mm = Dataset(vdic['MM_FILE'])
  28. xlon = id_mm.variables['nav_lon'][:,:]
  29. xlat = id_mm.variables['nav_lat'][:,:]
  30. xmask = id_mm.variables['tmask'][0,0,:,:]
  31. id_mm.close()
  32. # Getting obs:
  33. bt.chck4f(vdic['F_ICE_OBS_12'])
  34. id_clim = Dataset(vdic['F_ICE_OBS_12'])
  35. xclim03 = id_clim.variables[vdic['NN_ICEF_OBS']][2,:,:]
  36. xclim09 = id_clim.variables[vdic['NN_ICEF_OBS']][8,:,:]
  37. id_clim.close()
  38. # Getting NEMO mean monthly climatology of sea-ice coverage:
  39. cf_nemo_mnmc = vdic['DIAG_D']+'/clim/mclim_'+CONFEXP+'_'+cy1+'-'+cy2+'_'+vdic['FILE_ICE_SUFFIX']+'.nc4'
  40. bt.chck4f(cf_nemo_mnmc)
  41. id_ice = Dataset(cf_nemo_mnmc)
  42. xnemo_frac_03 = id_ice.variables[vdic['NN_ICEF']][2,:,:]
  43. xnemo_frac_09 = id_ice.variables[vdic['NN_ICEF']][8,:,:]
  44. xnemo_thic_03 = id_ice.variables[vdic['NN_ICET']][2,:,:]
  45. xnemo_thic_09 = id_ice.variables[vdic['NN_ICET']][8,:,:]
  46. id_ice.close()
  47. [ nj, ni ] = xnemo_frac_03.shape ; print ' Shape of sea-ice :', nj, ni, '\n'
  48. # Extraoplating sea values on continents:
  49. bt.drown(xnemo_frac_03, xmask, k_ew=2, nb_max_inc=10, nb_smooth=10)
  50. bt.drown(xnemo_frac_09, xmask, k_ew=2, nb_max_inc=10, nb_smooth=10)
  51. bt.drown(xnemo_thic_03, xmask, k_ew=2, nb_max_inc=10, nb_smooth=10)
  52. bt.drown(xnemo_thic_09, xmask, k_ew=2, nb_max_inc=10, nb_smooth=10)
  53. bt.drown(xclim03, xmask, k_ew=2, nb_max_inc=10, nb_smooth=10)
  54. bt.drown(xclim09, xmask, k_ew=2, nb_max_inc=10, nb_smooth=10)
  55. # Time for figures:
  56. # -----------------
  57. #
  58. # Extending to 90S: (from 78 to 90):
  59. #
  60. js_ext = 12; nje = nj + js_ext
  61. xlat0 = nmp.zeros((nje,ni))
  62. xlon0 = nmp.zeros((nje,ni))
  63. xnemo_frac_030 = nmp.zeros((nje,ni))
  64. xnemo_frac_090 = nmp.zeros((nje,ni))
  65. xnemo_thic_030 = nmp.zeros((nje,ni))
  66. xnemo_thic_090 = nmp.zeros((nje,ni))
  67. xclim030 = nmp.zeros((nje,ni))
  68. xclim090 = nmp.zeros((nje,ni))
  69. #
  70. for jj in range(js_ext):
  71. xlat0[jj,:] = -90. + float(jj)
  72. xlon0[jj,:] = xlon[0,:]
  73. xnemo_frac_030[jj,:] = xnemo_frac_03[1,:] #persistence
  74. xnemo_frac_090[jj,:] = xnemo_frac_09[1,:] #persistence
  75. xnemo_thic_030[jj,:] = xnemo_thic_03[1,:] #persistence
  76. xnemo_thic_090[jj,:] = xnemo_thic_09[1,:] #persistence
  77. xclim030[jj,:] = xclim03[1,:] #persistence
  78. xclim090[jj,:] = xclim09[1,:] #persistence
  79. xlat0[js_ext:nje,:] = xlat[:,:]
  80. xlon0[js_ext:nje,:] = xlon[:,:]
  81. xnemo_frac_030[js_ext:nje,:] = xnemo_frac_03[:,:]
  82. xnemo_frac_090[js_ext:nje,:] = xnemo_frac_09[:,:]
  83. xnemo_thic_030[js_ext:nje,:] = xnemo_thic_03[:,:]
  84. xnemo_thic_090[js_ext:nje,:] = xnemo_thic_09[:,:]
  85. xclim030[js_ext:nje,:] = xclim03[:,:]
  86. xclim090[js_ext:nje,:] = xclim09[:,:]
  87. ratio = 1.
  88. #if vdic['COMP2D'] == 'OBS': ratio = 100.
  89. if xclim03.max()>90.:
  90. ratio = 100.
  91. #DEBUG:
  92. if False:
  93. bp.plot("nproj")('spstere', 0., 1., 0.1, xlon0, xlat0, xclim090[:,:]/ratio,
  94. cfignm=path_fig+'sea-ice_SP_sept_obs', cpal='ice', cbunit='(frac.)',
  95. ctitle='Ice fraction, Sept., "'+cn_obs+'"',
  96. lkcont=True, cfig_type=fig_type,
  97. lforce_lim=True)
  98. bp.plot("nproj")('npol2', 0., 1., 0.1, xlon, xlat, xclim03[:,:]/ratio,
  99. cfignm=path_fig+'sea-ice_NP_march_obs', cpal='ice', cbunit='(frac.)',
  100. ctitle='Ice fraction, March, "'+cn_obs+'"',
  101. lkcont=True, cfig_type=fig_type,
  102. lforce_lim=True)
  103. sys.exit(0)
  104. #DEBUG.
  105. # September
  106. # ~~~~~~~~~
  107. if vdic['COMP2D'] == 'OBS':
  108. ctit_clim = 'Ice fraction, Sept., "'+cn_obs+'"'
  109. else:
  110. ctit_clim = 'Ice fraction, Sept., '+vdic['COMP2D']
  111. # Nordic Seas:
  112. bp.plot("nproj")('npol2', 0., 1., 0.1, xlon, xlat, xnemo_frac_09[:,:],
  113. cfignm=path_fig+'sea-ice_NP_sept_'+CONFEXP, cpal='ice', cbunit='(frac.)',
  114. ctitle='Ice fraction, Sept., '+cexp+' ('+cy1+'-'+cy2+')',
  115. lkcont=True, cfig_type=fig_type,
  116. lforce_lim=True)
  117. bp.plot("nproj")('npol2', 0., 1., 0.1, xlon, xlat, xclim09[:,:]/ratio,
  118. cfignm=path_fig+'sea-ice_NP_sept_'+vdic['COMP2D'], cpal='ice', cbunit='(frac.)',
  119. ctitle=ctit_clim,
  120. lkcont=True, cfig_type=fig_type,
  121. lforce_lim=True)
  122. bp.plot("nproj")('npol2', 0., 10., 0.25, xlon, xlat, xnemo_thic_09[:,:],
  123. cfignm=path_fig+'sea-ice_thickness_NP_sept_'+CONFEXP, cpal='cubehelix_r', cbunit='(m)',
  124. ctitle='Ice thickness, Sept., '+cexp+' ('+cy1+'-'+cy2+')',
  125. lkcont=True, cfig_type=fig_type, i_cb_subsamp=2,
  126. lforce_lim=True)
  127. # September, big South:
  128. bp.plot("nproj")('spstere', 0., 1., 0.1, xlon0, xlat0, xnemo_frac_090[:,:],
  129. cfignm=path_fig+'sea-ice_SP_sept_'+CONFEXP, cpal='ice', cbunit='(frac.)',
  130. ctitle='Ice fraction, Sept., '+cexp+' ('+cy1+'-'+cy2+')',
  131. lkcont=True, cfig_type=fig_type,
  132. lforce_lim=True)
  133. bp.plot("nproj")('spstere', 0., 1., 0.1, xlon0, xlat0, xclim090[:,:]/ratio,
  134. cfignm=path_fig+'sea-ice_SP_sept_'+vdic['COMP2D'], cpal='ice', cbunit='(frac.)',
  135. ctitle=ctit_clim,
  136. lkcont=True, cfig_type=fig_type,
  137. lforce_lim=True)
  138. bp.plot("nproj")('spstere', 0., 5., 0.1, xlon0, xlat0, xnemo_thic_090[:,:],
  139. cfignm=path_fig+'sea-ice_thickness_SP_sept_'+CONFEXP, cpal='cubehelix_r', cbunit='(m)',
  140. ctitle='Ice thickness, Sept., '+cexp+' ('+cy1+'-'+cy2+')',
  141. lkcont=True, cfig_type=fig_type, i_cb_subsamp=2,
  142. lforce_lim=True)
  143. # March:
  144. # ~~~~~~
  145. if vdic['COMP2D'] == 'OBS':
  146. ctit_clim = 'Ice fraction, March, "'+cn_obs+'"'
  147. else:
  148. ctit_clim = 'Ice fraction, March, '+vdic['COMP2D']
  149. # Nordic Seas:
  150. #print " -- doing stereographic projection of sea-ice fraction / March / N.E."
  151. bp.plot("nproj")('npol2', 0., 1., 0.1, xlon, xlat, xnemo_frac_03[:,:],
  152. cfignm=path_fig+'sea-ice_NP_march_'+CONFEXP, cpal='ice', cbunit='(frac.)',
  153. ctitle='Ice fraction, March, '+cexp+' ('+cy1+'-'+cy2+')',
  154. lkcont=True, cfig_type=fig_type,
  155. lforce_lim=True)
  156. bp.plot("nproj")('npol2', 0., 1., 0.1, xlon, xlat, xclim03[:,:]/ratio,
  157. cfignm=path_fig+'sea-ice_NP_march_'+vdic['COMP2D'], cpal='ice', cbunit='(frac.)',
  158. ctitle=ctit_clim,
  159. lkcont=True, cfig_type=fig_type,
  160. lforce_lim=True)
  161. #print " -- doing stereographic projection of sea-ice thickness / March / N.E."
  162. bp.plot("nproj")('npol2', 0., 10., 0.25, xlon, xlat, xnemo_thic_03[:,:],
  163. cfignm=path_fig+'sea-ice_thickness_NP_march_'+CONFEXP, cpal='cubehelix_r', cbunit='(m)',
  164. ctitle='Ice thickness, March, '+cexp+' ('+cy1+'-'+cy2+')',
  165. lkcont=True, cfig_type=fig_type, i_cb_subsamp=2,
  166. lforce_lim=True)
  167. # Big south:
  168. bp.plot("nproj")('spstere', 0., 1., 0.1, xlon0, xlat0, xnemo_frac_030[:,:],
  169. cfignm=path_fig+'sea-ice_SP_march_'+CONFEXP, cpal='ice', cbunit='(frac.)',
  170. ctitle='Ice fraction, March, '+cexp+' ('+cy1+'-'+cy2+')',
  171. lkcont=True, cfig_type=fig_type,
  172. lforce_lim=True)
  173. bp.plot("nproj")('spstere', 0., 1., 0.1, xlon0, xlat0, xclim030[:,:]/ratio,
  174. cfignm=path_fig+'sea-ice_SP_march_'+vdic['COMP2D'], cpal='ice', cbunit='(frac.)',
  175. ctitle=ctit_clim,
  176. lkcont=True, cfig_type=fig_type,
  177. lforce_lim=True)
  178. bp.plot("nproj")('spstere', 0., 5., 0.1, xlon0, xlat0, xnemo_thic_030[:,:],
  179. cfignm=path_fig+'sea-ice_thickness_SP_march_'+CONFEXP, cpal='cubehelix_r', cbunit='(m)',
  180. ctitle='Ice thickness, March, '+cexp+' ('+cy1+'-'+cy2+')',
  181. lkcont=True, cfig_type=fig_type, i_cb_subsamp=2,
  182. lforce_lim=True)
  183. print '\n Bye!'