astroimtools.utils.mask_databounds(data, mask=None, lower_bound=None, upper_bound=None, value=None, mask_invalid=True)[source]

Create or update a mask by masking data values that are below a lower bound, above an upper bound, equal to particular value, or are invalid (e.g. np.nan or np.inf).


The data array.

maskbool ndarray, optional

A boolean mask array with the same shape as data.

lower_boundfloat, optional

The value of the lower bound. Data values lower than lower_bound will be masked.

upper_boundfloat, optional

The value of the upper bound. Data values greater than upper_bound will be masked.

valuefloat, optional

A data value (e.g., 0.0) to mask.

mask_invalidbool, optional

If True (the default), then any unmasked invalid values (e.g. NaN, inf) will be masked.

maskbool ndarray

The resulting boolean mask array with the same shape as data.


>>> from astroimtools import mask_databounds
>>> data = np.arange(7)
>>> print(data)
[0 1 2 3 4 5 6]
>>> mask_databounds(data, lower_bound=2, upper_bound=5, value=3)
array([ True,  True, False,  True, False, False,  True]...)