erlab.analysis.mask¶
Functions related to masking.
Polygon masking is adapted from the CGAL library. More information on point-in-polygon strategies can be found in Ref. [5].
Modules¶
Point-in-polygon algorithm. |
Functions
|
Return a mask for given points. |
|
Return map masked with a hexagonal BZ. |
|
|
|
Create a mask based on a polygon defined by its vertices. |
|
Compute a mask indicating whether points are inside or outside a polygon. |
- erlab.analysis.mask.hex_bz_mask_points(x, y, a=3.54, rotate=0, offset=(0.0, 0.0), reciprocal=False, invert=False)[source]¶
Return a mask for given points.
- erlab.analysis.mask.mask_with_hex_bz(kxymap, a=3.54, rotate=0.0, invert=False)[source]¶
Return map masked with a hexagonal BZ.
- erlab.analysis.mask.polygon_mask(vertices, x, y, invert=False)[source]¶
Create a mask based on a polygon defined by its vertices.
- Parameters:
vertices (ndarray[Any, dtype[float64]]) – The vertices of the polygon. The shape should be (N, 2), where N is the number of vertices.
x (ndarray[Any, dtype[float64]]) – The x-coordinates of the grid points.
y (ndarray[Any, dtype[float64]]) – The y-coordinates of the grid points.
invert (bool) – If
True
, invert the mask (i.e., setTrue
where the polygon is outside andFalse
where it is inside). Default isFalse
.
- Returns:
mask – The mask array with shape
(len(x), len(y))
. The mask containsTrue
where the polygon is inside andFalse
where it is outside (or vice versa ifinvert
isTrue
).- Return type:
ndarray
Note
This function uses the
erlab.analysis.mask.polygon.bounded_side_bool
to determine whether a point is inside or outside the polygon.Example
>>> vertices = np.array([[0.2, 0.2], [0.2, 0.8], [0.8, 0.8], [0.8, 0.2]]) >>> x = np.linspace(0, 1, 5) >>> y = np.linspace(0, 1, 5) >>> polygon_mask(vertices, x, y) array([[False, False, False, False, False], [False, True, True, True, False], [False, True, True, True, False], [False, True, True, True, False], [False, False, False, False, False]])
- erlab.analysis.mask.polygon_mask_points(vertices, x, y, invert=False)[source]¶
Compute a mask indicating whether points are inside or outside a polygon.
- Parameters:
vertices (ndarray[Any, dtype[float64]]) – The vertices of the polygon. The shape should be (N, 2), where N is the number of vertices.
x (ndarray[Any, dtype[float64]]) – The x-coordinates of the points.
y (ndarray[Any, dtype[float64]]) – The y-coordinates of the points.
invert (bool) – If
True
, invert the mask (i.e., setTrue
where the polygon is outside andFalse
where it is inside). Default isFalse
.
- Returns:
mask – A boolean array of shape
(len(x),)
indicating whether each point is inside or outside the polygon.- Return type:
ndarray
- Raises:
ValueError – If the lengths of x and y are not equal.
Notes
This function uses the
erlab.analysis.mask.polygon.bounded_side_bool
to determine whether a point is inside or outside the polygon.