temp_sal.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # Generate misc. spatial plots of potential temperature and salinity out of
  5. # NEMO output and climatology (from initial condition and surface restoring
  6. # NEMO files)
  7. #
  8. # L. Brodeau, november 2013
  9. import sys
  10. import os
  11. import numpy as nmp
  12. from netCDF4 import Dataset
  13. import barakuda_tool as bt
  14. import barakuda_orca as bo
  15. import barakuda_plot as bp
  16. lfig0 = True
  17. lfig1 = True
  18. lfig2 = True
  19. venv_needed = {'ORCA','EXP','DIAG_D','COMP2D','i_do_sect','MM_FILE','ANNUAL_3D',
  20. 'NN_SST','NN_T','NN_SSS','NN_S','F_T_OBS_3D_12','F_S_OBS_3D_12',
  21. 'F_SST_OBS_12','NN_SST_OBS','NN_T_OBS','NN_S_OBS','NM_TS_OBS'}
  22. vdic = bt.check_env_var(sys.argv[0], venv_needed)
  23. CONFEXP = vdic['ORCA']+'-'+vdic['EXP']
  24. CC = vdic['COMP2D']
  25. i_do_sect = int(vdic['i_do_sect'])
  26. l_3df_are_annual = False ; # we expect 3D fields (T & S) to be in monthly 'grid_T' mclim file
  27. if len(vdic['ANNUAL_3D']) != 0:
  28. l_3df_are_annual = True ; # 3D fields (T & S) are in annual 'grid_T' aclim file
  29. # Bounds and increment for comparison maps:
  30. if CC == 'OBS':
  31. cname_obs = vdic['NM_TS_OBS']
  32. tmin=-5. ; tmax=5. ; dtemp = 0.5
  33. smin=-2.5 ; smax=2.5 ; dsali = 0.25
  34. else:
  35. cname_obs = CC
  36. tmin=-1. ; tmax=1. ; dtemp = 0.05
  37. smin=-0.5 ; smax=.5 ; dsali = 0.025
  38. path_fig='./'
  39. fig_type='png'
  40. narg = len(sys.argv)
  41. if narg < 3: print 'Usage: '+sys.argv[0]+' <year1> <year2>'; sys.exit(0)
  42. cy1 = sys.argv[1] ; cy2=sys.argv[2]; jy1=int(cy1); jy2=int(cy2)
  43. #
  44. if not ( jy1 >= 1984 and jy2 <= 2006 ):
  45. jy1_clim = 1984 ; jy2_clim = 2006
  46. else:
  47. jy1_clim = jy1 ; jy2_clim = jy2
  48. print ' First and last year to treat:', jy1, jy2
  49. print ' => mean on the clim : ', jy1_clim, jy2_clim, '\n'
  50. # 3D climatology :
  51. # ------------
  52. # Temperature
  53. bt.chck4f(vdic['F_T_OBS_3D_12'])
  54. id_obs = Dataset(vdic['F_T_OBS_3D_12'])
  55. Tobs = id_obs.variables[vdic['NN_T_OBS']][:,:,:,:]; print '(has ',Tobs.shape[0],' time snapshots)\n'
  56. id_obs.close()
  57. [ nmn , nk0 , nj0 , ni0 ] = Tobs.shape
  58. # Salinity
  59. bt.chck4f(vdic['F_S_OBS_3D_12'])
  60. id_obs = Dataset(vdic['F_S_OBS_3D_12'])
  61. Sobs = id_obs.variables[vdic['NN_S_OBS']][:,:,:,:]; print '(has ',Sobs.shape[0],' time snapshots)\n'
  62. id_obs.close()
  63. # 2D SST obs :
  64. print 'We use the following SST climatology:'; print vdic['F_SST_OBS_12']
  65. cv_sst_obs = vdic['NN_SST_OBS']
  66. bt.chck4f(vdic['F_SST_OBS_12'])
  67. id_obs_sst = Dataset(vdic['F_SST_OBS_12'])
  68. nb_dim = len(id_obs_sst.variables[cv_sst_obs].dimensions)
  69. if nb_dim == 3:
  70. SSTobs = id_obs_sst.variables[cv_sst_obs][:,:,:]; print '(has ',SSTobs.shape[0],' time snapshots)\n'
  71. elif nb_dim == 4:
  72. # reading the first level
  73. SSTobs = id_obs_sst.variables[cv_sst_obs][:,0,:,:]; print '(has ',SSTobs.shape[0],' time snapshots)\n'
  74. else:
  75. print 'ERROR (prepare_movies.py): shape of '+cv_sst_obs+' in '+vdic['F_SST_OBS_12']+' is problematic!'
  76. sys.exit(0)
  77. id_obs_sst.close()
  78. # Table to host 1 zonal profile per EXP:
  79. vzc = nmp.zeros(nj0) ; # a zonal profile...
  80. # Getting land-sea mask and coordinates:
  81. bt.chck4f(vdic['MM_FILE'])
  82. id_mask = Dataset(vdic['MM_FILE'])
  83. xlon = id_mask.variables['nav_lon'][:,:]
  84. xlat = id_mask.variables['nav_lat'][:,:]
  85. imask = id_mask.variables['tmask'][0,:,:,:]
  86. id_mask.close()
  87. # Getting NEMO mean monthly climatology of temperature and salinity:
  88. # ------------------------------------------------------------------
  89. cvT3d = vdic['NN_T']
  90. cvS3d = vdic['NN_S']
  91. cf_nemo_mn = vdic['DIAG_D']+'/clim/mclim_'+CONFEXP+'_'+cy1+'-'+cy2+'_grid_T.nc4'
  92. cf_nemo_an = vdic['DIAG_D']+'/clim/aclim_'+CONFEXP+'_'+cy1+'-'+cy2+'_grid_T.nc4'
  93. bt.chck4f(cf_nemo_mn)
  94. id_nemo_mn = Dataset(cf_nemo_mn)
  95. list_var = id_nemo_mn.variables.keys()
  96. if vdic['NN_SST'] == cvT3d:
  97. SSTnemo = id_nemo_mn.variables[cvT3d][:,0,:,:]
  98. else:
  99. SSTnemo = id_nemo_mn.variables[vdic['NN_SST']][:,:,:]
  100. if vdic['NN_SSS'] == cvS3d:
  101. SSSnemo = id_nemo_mn.variables[cvS3d][:,0,:,:]
  102. else:
  103. SSSnemo = id_nemo_mn.variables[vdic['NN_SSS']][:,:,:]
  104. l_do_monthly_3d=True
  105. if 'deptht' in list_var:
  106. try:
  107. vdepth = id_nemo_mn.variables['deptht'][:]
  108. except KeyError as e:
  109. vdepth = id_nemo_mn.variables['olevel'][:]
  110. else:
  111. print 'WARNING: depth vector "deptht" not present in '+cf_nemo_mn+'!\n'
  112. l_do_monthly_3d=False
  113. if cvT3d in list_var:
  114. Tnemo = id_nemo_mn.variables[cvT3d][:,:,:,:]
  115. print '(has ',Tnemo.shape[0],' time snapshots)\n'
  116. else:
  117. print 'WARNING: 3D NEMO T '+cvT3d+' not present in '+cf_nemo_mn+'!\n'
  118. l_do_monthly_3d=False
  119. if cvS3d in list_var:
  120. Snemo = id_nemo_mn.variables[cvS3d][:,:,:,:]
  121. else:
  122. print 'WARNING: 3D NEMO S '+cvS3d+' not present in '+cf_nemo_mn+'!\n'
  123. l_do_monthly_3d=False
  124. id_nemo_mn.close()
  125. if (not l_3df_are_annual) and (not l_do_monthly_3d):
  126. print 'ERROR (temp_sal.py) (temp_sal.py): something is wrong, where are 3D fields!?'
  127. sys.exit(0)
  128. # Reading annual 3D fields if relevant:
  129. if l_3df_are_annual:
  130. bt.chck4f(cf_nemo_an)
  131. id_nemo_an = Dataset(cf_nemo_an)
  132. list_var = id_nemo_an.variables.keys()
  133. if 'deptht' in list_var:
  134. vdepth = id_nemo_an.variables['deptht'][:]
  135. else:
  136. print 'ERROR (temp_sal.py): depth vector "deptht" not present in '+cf_nemo_an+'!\n'; sys.exit(0)
  137. if cvT3d in list_var:
  138. Tnemo = id_nemo_an.variables[cvT3d][:,:,:,:]
  139. print '(has ',Tnemo.shape[0],' time snapshots)\n'
  140. else:
  141. print 'ERROR (temp_sal.py): 3D NEMO T '+cvT3d+' not present in '+cf_nemo_an+'!\n'; sys.exit(0)
  142. if cvS3d in list_var:
  143. Snemo = id_nemo_an.variables[cvS3d][:,:,:,:]
  144. else:
  145. print 'ERROR (temp_sal.py): 3D NEMO S '+cvS3d+' not present in '+cf_nemo_an+'!\n'; sys.exit(0)
  146. id_nemo_an.close()
  147. if l_do_monthly_3d or l_3df_are_annual:
  148. ( nt, nk, nj, ni ) = Tnemo.shape
  149. if (nk,nj,ni) != (nk0,nj0,ni0):
  150. print 'ERROR (temp_sal.py): 3D clim and NEMO file do no agree in shape!'
  151. print ' clim => '+str(ni0)+', '+str(nj0)+', '+str(nk0),' ('+vdic['F_T_OBS_3D_12']+')'
  152. print ' NEMO => '+str(ni)+', '+str(nj)+', '+str(nk)
  153. sys.exit(0)
  154. else:
  155. ( nt, nj, ni ) = SSTnemo.shape
  156. if (nj,ni) != (nj0,ni0):
  157. print 'ERROR (temp_sal.py): 3D clim and NEMO file do no agree in shape!'
  158. print ' clim => '+str(ni0)+', '+str(nj0),' ('+vdic['F_T_OBS_3D_12']+')'
  159. print ' NEMO => '+str(ni)+', '+str(nj)
  160. sys.exit(0)
  161. if nt not in [1,12]:
  162. print 'ERROR (temp_sal.py): 3D fields are either monthly or annual! nt =>', nt
  163. sys.exit(0)
  164. # Saving some array to avoid to call 'nmp.mean' all the time:
  165. #Annual (temperature):
  166. if l_do_monthly_3d or l_3df_are_annual:
  167. Tnemo_annual = nmp.zeros((nk,nj,ni))
  168. Tobs_annual = nmp.zeros((nk,nj,ni))
  169. Tobs_annual[:,:,:] = nmp.mean(Tobs[:,:,:,:], axis=0)
  170. if l_do_monthly_3d:
  171. Tnemo_annual[:,:,:] = nmp.mean(Tnemo[:,:,:,:], axis=0)
  172. if l_3df_are_annual:
  173. Tnemo_annual[:,:,:] = Tnemo[0,:,:,:]
  174. SSTnemo_annual = nmp.zeros((nj,ni))
  175. SSTnemo_annual[:,:] = nmp.mean(SSTnemo[:,:,:], axis=0)
  176. SSTobs_annual = nmp.zeros((nj,ni))
  177. SSTobs_annual[:,:] = nmp.mean(SSTobs[:,:,:], axis=0)
  178. #JFM (temperature):
  179. if l_do_monthly_3d:
  180. Tnemo_JFM = nmp.zeros((nk,nj,ni))
  181. Tnemo_JFM[:,:,:] = nmp.mean(Tnemo[:3,:,:,:], axis=0)
  182. Tobs_JFM = nmp.zeros((nk,nj,ni))
  183. Tobs_JFM[:,:,:] = nmp.mean(Tobs[:3,:,:,:], axis=0)
  184. SSTnemo_JFM = nmp.zeros((nj,ni))
  185. SSTnemo_JFM[:,:] = nmp.mean(SSTnemo[:3,:,:], axis=0)
  186. SSTobs_JFM = nmp.zeros((nj,ni))
  187. SSTobs_JFM[:,:] = nmp.mean(SSTobs[:3,:,:], axis=0)
  188. #JAS (temperature):
  189. if l_do_monthly_3d:
  190. Tnemo_JAS = nmp.zeros((nk,nj,ni))
  191. Tnemo_JAS[:,:,:] = nmp.mean(Tnemo[6:9,:,:,:], axis=0)
  192. Tobs_JAS = nmp.zeros((nk,nj,ni))
  193. Tobs_JAS[:,:,:] = nmp.mean(Tobs[6:9,:,:,:], axis=0)
  194. SSTnemo_JAS = nmp.zeros((nj,ni))
  195. SSTnemo_JAS[:,:] = nmp.mean(SSTnemo[6:9,:,:], axis=0)
  196. SSTobs_JAS = nmp.zeros((nj,ni))
  197. SSTobs_JAS[:,:] = nmp.mean(SSTobs[6:9,:,:], axis=0)
  198. # Can release some memory!
  199. del Tnemo, Tobs, SSTnemo, SSTobs
  200. #Annual (salinity):
  201. if l_do_monthly_3d or l_3df_are_annual:
  202. Snemo_annual = nmp.zeros((nk,nj,ni))
  203. if l_do_monthly_3d:
  204. Snemo_annual[:,:,:] = nmp.mean(Snemo[:,:,:,:], axis=0)
  205. if l_3df_are_annual:
  206. Snemo_annual[:,:,:] = Snemo[0,:,:,:]
  207. Sobs_annual = nmp.zeros((nk0,nj,ni))
  208. Sobs_annual[:,:,:] = nmp.mean(Sobs[:,:,:,:], axis=0)
  209. SSSnemo_annual = nmp.zeros((nj,ni))
  210. SSSnemo_annual[:,:] = nmp.mean(SSSnemo[:,:,:], axis=0)
  211. #JFM (salinity):
  212. if l_do_monthly_3d:
  213. Snemo_JFM = nmp.zeros((nk,nj,ni))
  214. Snemo_JFM[:,:,:] = nmp.mean(Snemo[:3,:,:,:], axis=0)
  215. Sobs_JFM = nmp.zeros((nk0,nj,ni))
  216. Sobs_JFM[:,:,:] = nmp.mean(Sobs[:3,:,:,:], axis=0)
  217. SSSnemo_JFM = nmp.zeros((nj,ni))
  218. SSSnemo_JFM[:,:] = nmp.mean(SSSnemo[:3,:,:], axis=0)
  219. #JAS (salinity):
  220. if l_do_monthly_3d:
  221. Snemo_JAS = nmp.zeros((nk,nj,ni))
  222. Snemo_JAS[:,:,:] = nmp.mean(Snemo[6:9,:,:,:], axis=0)
  223. Sobs_JAS = nmp.zeros((nk0,nj,ni))
  224. Sobs_JAS[:,:,:] = nmp.mean(Sobs[6:9,:,:,:], axis=0)
  225. SSSnemo_JAS = nmp.zeros((nj,ni))
  226. SSSnemo_JAS[:,:] = nmp.mean(SSSnemo[6:9,:,:], axis=0)
  227. # Can release some memory!
  228. del Snemo, Sobs, SSSnemo
  229. if l_do_monthly_3d or l_3df_are_annual:
  230. jk100 = bt.find_index_from_value(100. , vdepth) ; print 'jk100 = ', jk100, '=> ', vdepth[jk100]
  231. jk1000 = bt.find_index_from_value(1000. , vdepth) ; print 'jk1000 = ', jk1000, '=> ', vdepth[jk1000]
  232. jk3000 = bt.find_index_from_value(3000. , vdepth) ; print 'jk3000 = ', jk3000, '=> ', vdepth[jk3000]
  233. tdj = [ jk100, jk1000, jk3000 ]
  234. tdd_true = [ str(int(round(vdepth[jk100])))+'m' , str(int(round(vdepth[jk1000])))+'m' , str(int(round(vdepth[jk3000])))+'m' ]
  235. tdd = [ '100m', '1000m', '3000m' ]
  236. print '\n', tdd_true[:], '\n'
  237. # Creating 1D long. and lat.:
  238. vlon = nmp.zeros(ni) ; vlon[:] = xlon[0,:]
  239. ji_lat0 = nmp.argmax(xlat[nj-1,:])
  240. vlat = nmp.zeros(nj) ; vlat[:] = xlat[:,ji_lat0]
  241. # Time for figures:
  242. # -----------------
  243. if lfig0:
  244. ctt = CONFEXP+': Mean Annual Zonal Anomaly of SST / "'+cname_obs+'", ('+cy1+'-'+cy2+')'
  245. vzc[:] = bt.mk_zonal(SSTnemo_annual[:,:] - SSTobs_annual[:,:], XMSK=imask[0,:,:])
  246. # Only at the end of all the experiments we do 2d plotting:
  247. bp.plot("zonal")(vlat, vzc, cfignm=path_fig+'1d_zonal_temp_anom_vs_'+CC, zmin=-5., zmax=5., dz=1.,
  248. xmin=-75., xmax=65., czunit=r'$^{\circ}$C', cfig_type=fig_type,
  249. ctitle=ctt)
  250. ctt = CONFEXP+': Mean Annual Zonal Anomaly of SSS / "'+cname_obs+'", ('+cy1+'-'+cy2+')'
  251. vzc[:] = bt.mk_zonal(SSSnemo_annual[:,:] - Sobs_annual[0,:,:], XMSK=imask[0,:,:])
  252. # Only at the end of all the experiments we do 2d plotting:
  253. bp.plot("zonal")(vlat, vzc, cfignm=path_fig+'1d_zonal_sali_anom_vs_'+CC , zmin=-2.5, zmax=2.5, dz=0.5,
  254. xmin=-75., xmax=65., czunit='PSU', cfig_type=fig_type,
  255. ctitle=ctt)
  256. if lfig1:
  257. # SST / Reynolds
  258. # JFM
  259. bp.plot("2d")(vlon, vlat, SSTnemo_JFM[:,:] - SSTobs_JFM[:,:],
  260. imask[0,:,:], tmin, tmax, dtemp,
  261. corca=vdic['ORCA'], lkcont=False, cpal='RdBu_r', cfignm=path_fig+'dsst_JFM_'+CONFEXP+'_-_'+CC,
  262. cbunit='K', cfig_type=fig_type,
  263. ctitle='SST difference to "'+cname_obs+'", JFM, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  264. lforce_lim=True)
  265. # JAS
  266. bp.plot("2d")(vlon, vlat, SSTnemo_JAS[:,:] - SSTobs_JAS[:,:],
  267. imask[0,:,:], tmin, tmax, dtemp,
  268. corca=vdic['ORCA'], lkcont=False, cpal='RdBu_r', cfignm=path_fig+'dsst_JAS_'+CONFEXP+'_-_'+CC,
  269. cbunit='K', cfig_type=fig_type,
  270. ctitle='SST difference to "'+cname_obs+'", JAS, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  271. lforce_lim=True)
  272. # Annual
  273. bp.plot("2d")(vlon, vlat, SSTnemo_annual[:,:] - SSTobs_annual[:,:],
  274. imask[0,:,:], tmin, tmax, dtemp,
  275. corca=vdic['ORCA'], lkcont=False, cpal='RdBu_r', cfignm=path_fig+'dsst_annual_'+CONFEXP+'_-_'+CC,
  276. cbunit='K', cfig_type=fig_type,
  277. ctitle='SST difference to "'+cname_obs+'", '+CONFEXP+' ('+cy1+'-'+cy2+')',
  278. lforce_lim=True)
  279. # Temperature 100m, 1000m... / climatology
  280. if l_do_monthly_3d or l_3df_are_annual:
  281. for jd in range(nmp.size(tdj)):
  282. jdepth = tdj[jd] ; cdepth = tdd[jd] ; cdepth_true = tdd_true[jd]
  283. print '\n Treating depth '+str(vdepth[jdepth])+' !!!'
  284. if jd < 1 and (not l_3df_are_annual):
  285. # JFM
  286. bp.plot("2d")(vlon, vlat, Tnemo_JFM[jdepth,:,:] - Tobs_JFM[jdepth,:,:],
  287. imask[jdepth,:,:], tmin, tmax, dtemp,
  288. corca=vdic['ORCA'], lkcont=False, cpal='RdBu_r', cfignm=path_fig+'dT_JFM_'+cdepth+'_'+CONFEXP+'_-_'+CC,
  289. cbunit='K', cfig_type=fig_type,
  290. ctitle='Temperature diff. to "'+cname_obs+'" at '+cdepth_true+', JFM, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  291. lforce_lim=True)
  292. # JAS
  293. bp.plot("2d")(vlon, vlat, Tnemo_JAS[jdepth,:,:] - Tobs_JAS[jdepth,:,:],
  294. imask[jdepth,:,:], tmin, tmax, dtemp,
  295. corca=vdic['ORCA'], lkcont=False, cpal='RdBu_r', cfignm=path_fig+'dT_JAS_'+cdepth+'_'+CONFEXP+'_-_'+CC,
  296. cbunit='K', cfig_type=fig_type,
  297. ctitle='Temperature diff. to "'+cname_obs+'" at '+cdepth_true+', JAS, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  298. lforce_lim=True)
  299. # Annual
  300. bp.plot("2d")(vlon, vlat, Tnemo_annual[jdepth,:,:] - Tobs_annual[jdepth,:,:],
  301. imask[jdepth,:,:], tmin, tmax, dtemp,
  302. corca=vdic['ORCA'], lkcont=False, cpal='RdBu_r', cfignm=path_fig+'dT_annual_'+cdepth+'_'+CONFEXP+'_-_'+CC,
  303. cbunit='K', cfig_type=fig_type,
  304. ctitle='Temperature diff. to "'+cname_obs+'" at '+cdepth_true+', '+CONFEXP+' ('+cy1+'-'+cy2+')',
  305. lforce_lim=True)
  306. # S S S
  307. # JFM
  308. bp.plot("2d")(vlon, vlat, SSSnemo_JFM[:,:] - Sobs_JFM[0,:,:],
  309. imask[0,:,:], smin, smax, dsali, cpal='PiYG_r',
  310. corca=vdic['ORCA'], lkcont=False, cfignm=path_fig+'dsss_JFM_'+CONFEXP+'_-_'+CC,
  311. cbunit='PSU', cfig_type=fig_type,
  312. ctitle='SSS difference to "'+cname_obs+'", JFM, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  313. lforce_lim=True)
  314. # JAS
  315. bp.plot("2d")(vlon, vlat, SSSnemo_JAS[:,:] - Sobs_JAS[0,:,:],
  316. imask[0,:,:], smin, smax, dsali, cpal='PiYG_r',
  317. corca=vdic['ORCA'], lkcont=False, cfignm=path_fig+'dsss_JAS_'+CONFEXP+'_-_'+CC,
  318. cbunit='PSU', cfig_type=fig_type,
  319. ctitle='SSS difference to "'+cname_obs+'", JAS, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  320. lforce_lim=True)
  321. # Annual
  322. bp.plot("2d")(vlon, vlat, SSSnemo_annual[:,:] - Sobs_annual[0,:,:],
  323. imask[0,:,:], smin, smax, dsali, cpal='PiYG_r',
  324. corca=vdic['ORCA'], lkcont=False, cfignm=path_fig+'dsss_annual_'+CONFEXP+'_-_'+CC,
  325. cbunit='PSU', cfig_type=fig_type,
  326. ctitle='SSS difference to "'+cname_obs+'", '+CONFEXP+' ('+cy1+'-'+cy2+')',
  327. lforce_lim=True)
  328. # Salinity 100m, 1000m... / climatology
  329. if l_do_monthly_3d or l_3df_are_annual:
  330. for jd in range(nmp.size(tdj)):
  331. jdepth = tdj[jd] ; cdepth = tdd[jd] ; cdepth_true = tdd_true[jd]
  332. print '\n Treating depth '+str(vdepth[jdepth])+' !!!'
  333. if jd < 1 and (not l_3df_are_annual):
  334. # JFM
  335. bp.plot("2d")(vlon, vlat, Snemo_JFM[jdepth,:,:] - Sobs_JFM[jdepth,:,:],
  336. imask[jdepth,:,:], smin, smax, dsali, cpal='PiYG_r',
  337. corca=vdic['ORCA'], lkcont=False, cfignm=path_fig+'dS_JFM_'+cdepth+'_'+CONFEXP+'_-_'+CC,
  338. cbunit='PSU', cfig_type=fig_type,
  339. ctitle='Salinity diff. to "'+cname_obs+'" at '+cdepth_true+', JFM, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  340. lforce_lim=True)
  341. # JAS
  342. bp.plot("2d")(vlon, vlat, Snemo_JAS[jdepth,:,:] - Sobs_JAS[jdepth,:,:],
  343. imask[jdepth,:,:], smin, smax, dsali, cpal='PiYG_r',
  344. corca=vdic['ORCA'], lkcont=False, cfignm=path_fig+'dS_JAS_'+cdepth+'_'+CONFEXP+'_-_'+CC,
  345. cbunit='PSU', cfig_type=fig_type,
  346. ctitle='Salinity diff. to "'+cname_obs+'" at '+cdepth_true+', JAS, '+CONFEXP+' ('+cy1+'-'+cy2+')',
  347. lforce_lim=True)
  348. # Annual
  349. bp.plot("2d")(vlon, vlat, Snemo_annual[jdepth,:,:] - Sobs_annual[jdepth,:,:],
  350. imask[jdepth,:,:], smin, smax, dsali, cpal='PiYG_r',
  351. corca=vdic['ORCA'], lkcont=False, cfignm=path_fig+'dS_annual_'+cdepth+'_'+CONFEXP+'_-_'+CC,
  352. cbunit='PSU', cfig_type=fig_type,
  353. ctitle='Salinity diff. to "'+cname_obs+'" at '+cdepth_true+', '+CONFEXP+' ('+cy1+'-'+cy2+')',
  354. lforce_lim=True)
  355. del Sobs_JFM, Sobs_JAS
  356. if l_do_monthly_3d: del Tnemo_JFM, Tnemo_JAS, Snemo_JFM, Snemo_JAS, Tobs_JFM, Tobs_JAS
  357. # Temperature and salinity for vertical sections
  358. if lfig2 and i_do_sect==1 and (l_do_monthly_3d or l_3df_are_annual):
  359. vdico = bt.check_env_var(sys.argv[0], {'TS_SECTION_FILE'})
  360. vboxes, vlon1, vlat1, vlon2, vlat2, vTmin, vTmax, vSmin, vSmax = bt.read_coor(vdico['TS_SECTION_FILE'], ctype='float', lTS_bounds=True)
  361. js = 0
  362. for csname in vboxes:
  363. [ i1, i2, j1, j2 ] = bo.transect_zon_or_med(vlon1[js], vlon2[js], vlat1[js], vlat2[js], xlon, xlat)
  364. if i2>i1 and i2 < ni0-1: i2 = i2+1
  365. if j2>j1 and j2 < nj0-1: j2 = j2+1
  366. print '\n *** Section: '+csname+':'
  367. print ' lon1, lon2, lat1, lat2 =', vlon1[js], vlon2[js], vlat1[js], vlat2[js]
  368. print ' => i1, i2, j1, j2 =', i1, i2, j1, j2
  369. #print ' xlon[j1,i1], xlon[j1,i2] =', xlon[j1,i1]-360., xlon[j1,i2]
  370. print ''
  371. if i1 > i2: print 'ERROR (temp_sal.py) => i1 > i2 !'; sys.exit(0)
  372. if j1 > j2: print 'ERROR (temp_sal.py) => j1 > j2 !'; sys.exit(0)
  373. lzonal = False
  374. if i1 == i2:
  375. print ' ==> Meridional section!'
  376. vaxis = xlat[j1:j2+1,i1]
  377. ZT = Tnemo_annual[:,j1:j2+1,i1] ; ZS = Snemo_annual[:,j1:j2+1,i1]
  378. OT = Tobs_annual[:,j1:j2+1,i1] ; OS = Sobs_annual[:,j1:j2+1,i1]
  379. imsk = imask[:,j1:j2+1,i1]
  380. cinfo = ', lon='+str(vlon1[js])
  381. xmn=vlat1[js]; xmx=vlat2[js]
  382. if j1 == j2:
  383. print ' ==> Zonal section!'
  384. lzonal = True
  385. xmn=vlon1[js]; xmx=vlon2[js]
  386. vx = xlon[j1,i1:i2+1] ; vaxis = nmp.zeros(len(vx)) ; vaxis[:] = vx[:]
  387. if xmx<0. and xmn>0.:
  388. xmx = 360. + xmx
  389. else:
  390. ivf = nmp.where(vx>180.); vaxis[ivf] = vx[ivf] - 360.
  391. ZT = Tnemo_annual[:,j1,i1:i2+1] ; ZS = Snemo_annual[:,j1,i1:i2+1]
  392. OT = Tobs_annual[:,j1,i1:i2+1] ; OS = Sobs_annual[:,j1,i1:i2+1]
  393. imsk = imask[:,j1,i1:i2+1]
  394. cinfo = ', lat='+str(vlat1[js])
  395. Ta = vTmax[js] - vTmin[js]
  396. if Ta < 1. : print 'ERROR (temp_sal.py) => Problem with your min and max for T for section "'+csname+'" !'; sys.exit(0)
  397. if Ta >= 25.: dT = 1.
  398. if Ta >= 10. and Ta < 25.: dT = 0.5
  399. if Ta >= 5. and Ta < 10.: dT = 0.25
  400. if Ta > 0. and Ta < 5.: dT = 0.1
  401. Sa = vSmax[js] - vSmin[js]
  402. if Sa < 0.001 : print 'ERROR (temp_sal.py) => Problem with your min and max for S for section "'+csname+'" !'; sys.exit(0)
  403. if Sa >= 3. : dS = 0.1
  404. if Sa >= 1.5 and Sa < 3. : dS = 0.05
  405. if Sa >= 0.5 and Sa < 1.5: dS = 0.025
  406. if Sa >= 0. and Sa < 0.5: dS = 0.01
  407. bp.plot("vert_section")(vaxis, vdepth, ZT, imsk, vTmin[js], vTmax[js], dT,
  408. cpal='ncview_nrl', lzonal=lzonal, xmin=xmn, xmax=xmx, dx=5.,
  409. cfignm=path_fig+'section_T_'+csname+'_'+CONFEXP, cbunit=r'$^{\circ}$C', cxunit=r'Latitude ($^{\circ}$N)',
  410. czunit='Depth (m)', ctitle='Temperature, ('+cy1+'-'+cy2+'), '+csname+', '+CONFEXP+cinfo,
  411. cfig_type=fig_type, lforce_lim=False, i_cb_subsamp=2)
  412. bp.plot("vert_section")(vaxis, vdepth, ZS, imsk, vSmin[js], vSmax[js], dS,
  413. cpal='ncview_jaisnb', lzonal=lzonal, xmin=xmn, xmax=xmx, dx=5.,
  414. cfignm=path_fig+'section_S_'+csname+'_'+CONFEXP, cbunit='PSU', cxunit=r'Latitude ($^{\circ}$N)',
  415. czunit='Depth (m)', ctitle='Salinity, ('+cy1+'-'+cy2+'), '+csname+', '+CONFEXP+cinfo,
  416. cfig_type=fig_type, lforce_lim=False, i_cb_subsamp=2)
  417. # OBS:
  418. bp.plot("vert_section")(vaxis, vdepth, OT, imsk, vTmin[js], vTmax[js], dT,
  419. cpal='ncview_nrl', lzonal=lzonal, xmin=xmn, xmax=xmx, dx=5.,
  420. cfignm=path_fig+'section_T_'+csname+'_'+CC, cbunit=r'$^{\circ}$C',
  421. cxunit=r'Latitude ($^{\circ}$N)',
  422. czunit='Depth (m)', ctitle='Temperature, '+csname+', "'+cname_obs+'"'+cinfo,
  423. cfig_type=fig_type, lforce_lim=False, i_cb_subsamp=2)
  424. #
  425. bp.plot("vert_section")(vaxis, vdepth, OS, imsk, vSmin[js], vSmax[js], dS,
  426. cpal='ncview_jaisnb', lzonal=lzonal, xmin=xmn, xmax=xmx, dx=5.,
  427. cfignm=path_fig+'section_S_'+csname+'_'+CC, cbunit='PSU',
  428. cxunit=r'Latitude ($^{\circ}$N)',
  429. czunit='Depth (m)', ctitle='Salinity, '+csname+', "'+cname_obs+'"'+cinfo,
  430. cfig_type=fig_type, lforce_lim=False, i_cb_subsamp=2)
  431. js=js+1
  432. print '\n Bye!'