esmtools.spatial.find_indices

esmtools.spatial.find_indices(xgrid, ygrid, xpoint, ypoint)[source]

Returns the i, j index for a latitude/longitude point on a grid.

Note

Longitude and latitude points (xpoint/ypoint) should be in the same range as the grid itself (e.g., if the longitude grid is 0-360, should be 200 instead of -160).

Parameters:
  • xgrid (array_like) – Longitude meshgrid (shape M, N)
  • ygrid (array_like) – Latitude meshgrid (shape M, N)
  • xpoint (int or double) – Longitude of point searching for on grid.
  • ypoint (int or double) – Latitude of point searching for on grid.
Returns:

Keys for the inputted grid that lead to the lat/lon point the user is seeking.

Return type:

i, j (int)

Examples

>>> import esmtools as et
>>> import numpy as np
>>> x = np.linspace(0, 360, 37)
>>> y = np.linspace(-90, 90, 19)
>>> xx, yy = np.meshgrid(x, y)
>>> xp = 20
>>> yp = -20
>>> i, j = et.spatial.find_indices(xx, yy, xp, yp)
>>> print(xx[i, j])
20.0
>>> print(yy[i, j])
-20.0