Whittaker Smoother

This module houses the Whittaker smoothing algorithm wrappers.

The wrappers below call the Rust written library that runs the Whittaker smoother. There are multithreaded functions denoted by the prefix “multiple”. More will be added here in future, but for now this is sufficient for most EO applications.

EOkit.smoothers.whittaker.multiple_whittakers(y_inputs, weights_inputs, lambda_, d, n_threads=-1)

Run many Whittaker smoothers on 1D data in a multithreaded manner.

This runs an identical algorithm to the single_whittaker function. However, this functions takes a list of y inputs and corresponding list of weights. Rust is then used to multithread each Whittaker as a task leading to faster computations for pixel-based problems!

I have used a list here as apposed to a 2-D array so that arrays of different lengths can be supplied.

Parameters:
  • y_inputs (list of ndarrays of type float, size (N)) – A list of numpy arrays containing the values to be smoothed.

  • weights_inputs (list of ndarrays of type float, size (N)) – A list of numpy arrays containing the weights for the values to be smoothed. 0. ignores a given point (for interpolation) whereas 1. takes the point into full consideration.

  • lambda (float) – Smoothing coefficient. Larger = smoother.

  • d (float) – Order of smoothing. 1. for linear.

  • n_threads (int, optional) – Amount of worker threads spawned to complete the task. The default is -1 which uses all logical processor cores. To tone this down, use something between 1 and the number of processor cores you have. Setting this value to a number larger than the amount of logical cores you have will most likely degreade performance.

Returns:

A list of numpy arrays containing the smoothed data at y_inputs.

Return type:

list of ndarrays of type float, size (N)

EOkit.smoothers.whittaker.single_whittaker(x_input, y_input, weights_input, lambda_, d)

Run a single Whittaker smoother on 1D data.

The Whittaker smoother is based on penalized least squares. The main paper is behind a pay-wall, though the supporting information is available and contains extra details about the implementation of this algorithm [1].

The single function is able to take variably spaced data (through x_input).

Parameters:
  • x_input (ndarray of type float, size (N)) –

  • y_input (ndarray of type float, size (N)) – The inputs that are to be smoothed.

  • weights_input (ndarray of type float, size (N)) – The weight that should be given to each input, where 0. ignores a given point (useful for interpolation) and 1. applies the full weight.

  • lambda (float) – Smoothing coefficient. Larger = smoother.

  • d (float) – Order of the smoothing/interpolation. 1 = linear and so on.

Returns:

Smoothed data at y inputs.

Return type:

ndarray of type float, size (N)

Examples

Below is a simple example of how to use the Whittaker smoother.

>>> data_len = 1000
>>> vci = (np.sin(np.arange(0, data_len, 1., dtype=float))
>>>           + np.random.standard_normal(data_len) * 2))
>>> weights = np.full(vci.size, 1.0, dtype=np.float64)
>>> rust_smoothed_data = whittaker.single_whittaker(np.arange(0, data_len, 1., dtype=float), vci, weights, 5, 3)

References