robust_mask

sofia_redux.toolkit.stats.stats.robust_mask(data, threshold, mask=None, axis=None, mask_data=False, cval=nan)[source]

Computes a mask derived from data Median Absolute Deviation (MAD).

Calculates a robust mask based on the input data and optional input mask. If \(threshold > 0\), the dataset is searched for outliers. Outliers are identified for point \(i\) if

\[\frac{|y_i - median[y]|}{MAD} > threshold\]

where \(MAD\) is the Median Absolute Deviation defined as

\[MAD = 1.482 * median[|y_i - median[y]|]\]
Parameters:
dataarray_like of float

The data on which to derive a robust mask.

thresholdfloat

Threshold as described above.

maskarray_like of bool, optional

If supplied, must be the same shape as data. Any masked (False) data values will not be included in the \(MAD\) calculation. Additionally, masked elements will also be masked (False) in the output mask.

axisint, optional

Axis over which to calculate the \(MAD\). The default (None) derives the \(MAD\) from the entire set of data.

mask_databool, optional

If True, return a copy of data with masked values replaced by cval in addition to the output mask. The default is False. Note that the output type will

cvalint or float, optional

if mask_data is set to True, masked values will be replaced by cval. The default is numpy.nan.

Returns:
numpy.ndarray of bool, [numpy.ndarray of numpy.float64]

The output mask where False indicates a masked value, while True indicates that associated data deviation is below the threshold limit. If mask_data was True, also returns a copy of data with masked values replaced by cval.