test_loc_ij.py 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. import string
  8. import os
  9. from netCDF4 import Dataset
  10. import barakuda_orca as bo
  11. narg = len(sys.argv)
  12. if narg != 4:
  13. print 'Usage: '+sys.argv[0]+' <mesh_mask> <lon> <lat>'; sys.exit(0)
  14. cf_mm = sys.argv[1]
  15. clon = sys.argv[2] ; rlon = float(clon)
  16. clat = sys.argv[3] ; rlat = float(clat)
  17. print rlon, rlat
  18. # Opening mesh_mask:
  19. f_mm = Dataset(cf_mm)
  20. nav_lon = f_mm.variables['nav_lon'][:,:]
  21. nav_lat = f_mm.variables['nav_lat'][:,:]
  22. #mask = f_mm.variables['tmask'][0,0,:,:]
  23. f_mm.close()
  24. (nj,ni) = nmp.shape(nav_lon)
  25. (ji, jj) = bo.ij_from_xy(rlon, rlat, nav_lon, nav_lat)
  26. print '\nSolution:'
  27. print ' ORCA => ji, jj =', ji,jj
  28. rlon = nav_lon[jj,ji]
  29. if rlon > 180. : rlon = rlon - 360.
  30. rlat = nav_lat[jj,ji]
  31. print ' ORCA => lon, lat =', rlon, rlat, '\n'