smart_median_1d

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

Returns the weighted median of values in one dimension.

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 (size,).

weightsnumpy.ndarray (float), optional

An array of weights (size,).

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, weightfloat, float

The median value and weight.