Skip to content

Masks Module

sensingpy.masks provides boolean mask functions for filtering array values by comparison and range operations.


is_valid

is_valid

is_valid(array: ndarray) -> np.ndarray

Returns a mask of valid values in the array, excluding NaNs.

Source code in sensingpy/masks.py
4
5
6
def is_valid(array: np.ndarray) -> np.ndarray:
    """Returns a mask of valid values in the array, excluding NaNs."""
    return ~np.isnan(array)

is_lt

is_lt

is_lt(array: ndarray, value: float) -> np.ndarray

Returns a mask of values in the array that are less than the given value.

Source code in sensingpy/masks.py
def is_lt(array: np.ndarray, value: float) -> np.ndarray:
    """Returns a mask of values in the array that are less than the given value."""
    return array < value

is_eq

is_eq

is_eq(array: ndarray, value: float) -> np.ndarray

Returns a mask of values in the array that are equal to the given value.

Source code in sensingpy/masks.py
def is_eq(array: np.ndarray, value: float) -> np.ndarray:
    """Returns a mask of values in the array that are equal to the given value."""
    return array == value

is_gt

is_gt

is_gt(array: ndarray, value: float) -> np.ndarray

Returns a mask of values in the array that are greater than the given value.

Source code in sensingpy/masks.py
def is_gt(array: np.ndarray, value: float) -> np.ndarray:
    """Returns a mask of values in the array that are greater than the given value."""
    return array > value

is_lte

is_lte

is_lte(array: ndarray, value: float) -> np.ndarray

Returns a mask of values in the array that are less than or equal to the given value.

Source code in sensingpy/masks.py
def is_lte(array: np.ndarray, value: float) -> np.ndarray:
    """Returns a mask of values in the array that are less than or equal to the given value."""
    return is_lt(array, value) | is_eq(array, value)

is_gte

is_gte

is_gte(array: ndarray, value: float) -> np.ndarray

Returns a mask of values in the array that are greater than or equal to the given value.

Source code in sensingpy/masks.py
def is_gte(array: np.ndarray, value: float) -> np.ndarray:
    """Returns a mask of values in the array that are greater than or equal to the given value."""
    return is_gt(array, value) | is_eq(array, value)

is_in_range

is_in_range

is_in_range(array: ndarray, vmin: float, vmax: float) -> np.ndarray

"Returns a mask of values in the array that are within the given range [vmin, vmax].

Source code in sensingpy/masks.py
def is_in_range(array: np.ndarray, vmin: float, vmax: float) -> np.ndarray:
    """ "Returns a mask of values in the array that are within the given range [vmin, vmax]."""
    return is_gte(array, vmin) & is_lte(array, vmax)