moving_weighted_median#

caput.algorithms.median.moving_weighted_median(data: numpy.typing.ArrayLike[numpy.float64], weights: numpy.typing.ArrayLike[numpy.float64], size: int | tuple[int, int], method: Literal['lower', 'higher', 'split'] = 'split') numpy.ndarray[numpy.float64][source]#

Compute moving weighted median for 1 and 2 dimensional arrays.

Parameters:
dataarray_like

The data to move the window over. Can have 1 or 2 dimensions. The data type should be float64 or something that can be converted to float64.

weightsarray_like

The weights for the data. Can have 1 or 2 dimensions. The data type should be float64 or something that can be converted to float64.

sizeint | tuple[int, int]

Size of the window. All values must be uneven.

method{“lower”, “higher”, “split”}

Either ‘split’, ‘lower’ or ‘higher’. If multiple values sastisfy the conditions to be the weighted median of a window, this decides what is returned:

  • split: The average of all candidate values is returned.

  • lower: The lowest of all candidate values is returned.

  • higher: The highest of all candidate values is returned.

Default is “split”.

Returns:
medianarray_like

An array containing the weighted median values. The size is the same as the given data and weights.

Raises:
ValueError

If the value of the window size was not odd.

RuntimeError

If there was an internal error in the C++ implementation.

NotImplementedError

If the data has more than two dimensions.