smart_median¶
- sofia_redux.scan.utilities.numba_functions.smart_median(values, weights=None, axis=None, max_dependence=1.0)[source]¶
Returns the weighted median of values in K-dimensions.
The weighted median is defined as the value at which the cumulative weight of the sorted values is equal to half of the weight sum. If this occurs at a midpoint between two values, the weighted mean of the two neighboring values is returned. NaN values and weights are not included in any computation.
This is a numba compiled function.
- Parameters:
- valuesnumpy.ndarray (float)
An array values of shape (shape)
- weightsnumpy.ndarray (float)
An array of weights of shape (shape)
- axisint, optional
The axis over which to perform the median calculation. The default of
None
applies the median calculation over all values.- max_dependencefloat
A value between 0 and 1. If the maximum weight value is greater than max_dependence * sum(weights) the median calculation is aborted, and the weighted mean is calculated instead.
- Returns:
- median, weightnumpy.ndarray (float), numpy.ndarray (float)
The median value(s) and weight(s).