smart_median_2d

sofia_redux.scan.utilities.numba_functions.smart_median_2d(values, weights=None, max_dependence=0.0)[source]

Returns the weighted median of values in two dimensions.

For a 2-dimensional array of shape (m, n), the median calculation is performed over the 2nd dimension such that the resulting output arrays are of shape (m,).

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 of values (m, n).

weightsnumpy.ndarray (float)

An array of weights (m, n).

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 and weights evaluated over the 2nd dimension (n). The returned arrays will be of shape (m,).