orca_mesh_mask_to_bitmap.py 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # L. Brodeau, 2017]
  5. import sys
  6. import numpy as nmp
  7. from PIL import Image
  8. import string
  9. import os
  10. from netCDF4 import Dataset
  11. narg = len(sys.argv)
  12. if narg != 2:
  13. print 'Usage: '+sys.argv[0]+' <mesh_mask>'; sys.exit(0)
  14. cf_mm = sys.argv[1]
  15. cf_bmp = string.replace(os.path.basename(cf_mm), '.nc', '_orig.bmp')
  16. cf_bmp = string.replace(os.path.basename(cf_bmp), '_orig.bmp4', '_orig.bmp')
  17. # Opening mesh_mask:
  18. f_mm = Dataset(cf_mm)
  19. mask = f_mm.variables['tmask'][0,0,:,:]
  20. f_mm.close()
  21. (nj, ni) = nmp.shape(mask)
  22. print ' nj, ni =>', nj, ni
  23. #imask= nmp.zeros((nj, ni), dtype=nmp.int8)
  24. #imask[:,:] = mask[:,:]
  25. #del mask
  26. imask = (255*mask).astype(nmp.uint8)
  27. # Then save it:
  28. result = Image.fromarray(nmp.flipud(imask))
  29. result.save(cf_bmp)
  30. print ' *** Image '+cf_bmp+' saved!\n'