movie_ice_nemo.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python
  2. # Misc :
  3. import os
  4. import sys
  5. from netCDF4 import Dataset
  6. import numpy as nmp
  7. from string import replace
  8. # Mine:
  9. import barakuda_tool as bt
  10. import barakuda_plot as bp
  11. #FIF='eps'
  12. #FIF='svg'
  13. FIF='png'
  14. na = len(sys.argv)
  15. if len(sys.argv) < 3:
  16. print 'Usage : '+sys.argv[0]+' <NEMO_FILE.nc4> <2D_variable_name>'
  17. sys.exit(0)
  18. cf_in = sys.argv[1]
  19. cv_in = sys.argv[2]
  20. if cv_in == 'siconc' or 'ileadfra':
  21. rmax = 1. ; rmin = 0. ; dr = 0.1
  22. colmap = 'ice' ; cunit = 'frac.'
  23. elif cv_in == 'sithic' or 'iicethic':
  24. rmax = 6. ; rmin = 0. ; dr = 0.25
  25. colmap = 'jet' ; cunit = 'm'
  26. else:
  27. print 'ERROR!!! variable '+cv_in+' is unknown!!!' ; sys.exit(0)
  28. cfig_suff = replace(os.path.basename(cf_in), '.nc4', '')
  29. bt.chck4f(cf_in)
  30. id_in = Dataset(cf_in)
  31. xlon = id_in.variables['nav_lon'][:,:]
  32. xlat = id_in.variables['nav_lat'][:,:]
  33. XF2D = id_in.variables[cv_in][:,:,:]
  34. id_in.close()
  35. [Nt, nj, ni] = nmp.shape(XF2D)
  36. print 'Shape of Ice =', [Nt, nj, ni]
  37. #Nt = 24
  38. jm = 0
  39. for jt in range(Nt):
  40. jy = jt/12 + 1
  41. if jt % 12 == 0: jm = 0
  42. jm = jm + 1
  43. #print 'jt, jm, jy =', jt, jm, jy
  44. ct = str(jt).zfill(4)
  45. cm = str(jm).zfill(2)
  46. cy = str(jy).zfill(4)
  47. cfig = cv_in+'_'+cfig_suff+'_'+ct
  48. print ' *** will create fig '+cfig+' (year = '+cy+', month = '+cm+')'
  49. bp.plot("nproj")('spstere', rmin, rmax, dr, xlon, xlat, XF2D[jt,:,:],
  50. cfignm=cfig, cpal=colmap, cbunit=cunit,
  51. ctitle='Sea-Ice, year = '+cy+', month = '+cm,
  52. lkcont=True, cfig_type=FIF,
  53. lforce_lim=True)
  54. cfig_out = cv_in+'_'+cfig_suff+'.gif'
  55. os.system("convert -delay 100 -loop 0 "+cv_in+"*.png "+cfig_out+" > out_conv.out")