verde.inside

Contents

verde.inside#

verde.inside(coordinates, region)[source]#

Determine which points fall inside a given region.

Points at the boundary are counted as being outsize.

Parameters:
  • coordinates (tuple of arrays) – Arrays with the coordinates of each data point. Should be in the following order: (easting, northing, vertical, …). Only easting and northing will be used, all subsequent coordinates will be ignored.

  • region (list = [W, E, S, N]) – The boundaries of a given region in Cartesian or geographic coordinates.

Returns:

are_inside (array of booleans) – An array of booleans with the same shape as the input coordinate arrays. Will be True if the respective coordinates fall inside the area, False otherwise.

Examples

>>> import numpy as np
>>> east = np.array([1, 2, 3, 4, 5, 6])
>>> north = np.array([10, 11, 12, 13, 14, 15])
>>> region = [2.5, 5.5, 12, 15]
>>> print(inside((east, north), region))
[False False  True  True  True False]
>>> # This also works for 2D-arrays
>>> east = np.array([[1, 1, 1],
...                  [2, 2, 2],
...                  [3, 3, 3]])
>>> north = np.array([[5, 7, 9],
...                   [5, 7, 9],
...                   [5, 7, 9]])
>>> region = [0.5, 2.5, 6, 9]
>>> print(inside((east, north), region))
[[False  True  True]
 [False  True  True]
 [False False False]]

Geographic coordinates are also supported using verde.longitude_continuity:

>>> from verde import longitude_continuity
>>> east, north = grid_coordinates([0, 350, -20, 20], spacing=10)
>>> region = [-10, 10, -10, 10]
>>> are_inside = inside(*longitude_continuity([east, north], region))
>>> print(east[are_inside])
[  0.  10. 350.   0.  10. 350.   0.  10. 350.]
>>> print(north[are_inside])
[-10. -10. -10.   0.   0.   0.  10.  10.  10.]