orcaX_edit_bathy.py 740 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python
  2. import sys
  3. import numpy as nmp
  4. from os import system
  5. from netCDF4 import Dataset
  6. from string import replace
  7. if len(sys.argv) != 2:
  8. print 'Usage: '+sys.argv[0]+' <nemo_bathy.nc>'
  9. sys.exit(0)
  10. cf_old = sys.argv[1]
  11. cf_new = replace(cf_old, '.nc', '_new.nc')
  12. cv_bathy = 'Bathymetry'
  13. # First, creating a copy:
  14. system('rm -f '+cf_new)
  15. system('cp '+cf_old+' '+cf_new)
  16. print '\n'
  17. # Opening the Netcdf file:
  18. f_new = Dataset(cf_new, 'r+')
  19. print 'File ', cf_new, 'is open...\n'
  20. Xbathy = f_new.variables[cv_bathy][:,:]
  21. # Edit zone:
  22. # Removing caspian sea in ORCA1:
  23. Xbathy[200:238,332:346] = 0.
  24. f_new.variables[cv_bathy][:,:] = Xbathy[:,:]
  25. f_new.close()
  26. print cf_new+' sucessfully created!'