sda.signal.smooth#

Created on Wed May 3 09:24:38 2017.

@author: p38

Summary#

Useful 1d smoothing functions Basic 2d smoothing functions Baseline smoothing functions


Classes#

WhittakerSmoother

Whittaker Smoother.

Functions#

smooth(x[, window_len, window])

Smooth the data using a window with requested size.

smooth_matrix(x, window_len[, window, axis])

smooth2d(x[, kernel_dim, kernel])

Smooth the data using a kernel with requested size.

als_baseline(intensities[, asymmetry_param, ...])

Compute the asymmetric least squares baseline.

Module Contents#

sda.signal.smooth.smooth(x, window_len=11, window='hanning')#

Smooth the data using a window with requested size.

This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.

Parameters:
  • x (array_like) – The input signal.

  • window_len (int) – The dimension of the smoothing window; should be an odd integer.

  • window (str) – The type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’. Flat window will produce a moving average smoothing.

Returns:

The smoothed signal.

Return type:

array_like

Examples

>>> t = linspace(-5, 5, 1000)
>>> x = sin(t) + randn(len(t)) * 0.1
>>> y = smooth(x, 11, "hanning")

See also

np.hanning, np.hamming, np.bartlett, np.blackman, np.convolve, scipy.signal.lfilter

TODO

the window parameter could be the window itself if an array instead of a string

sda.signal.smooth.smooth_matrix(x, window_len, window='hanning', axis=0)#
sda.signal.smooth.smooth2d(x, kernel_dim=(11, 11), kernel='flat')#

Smooth the data using a kernel with requested size.

This method is based on the convolution of a scaled kernel with the signal. This method is based on the convolve2d method of scipy.signal.

The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal. (‘symm’ option convolve2d)

Parameters:
  • x (array_like) – The input signal.

  • kernel_dim (tuple of int) – The dimension of the smoothing kernel; should be a tuple of odd integers.

  • kernel (str or array_like) – The type of kernel, can be the ‘flat’ option or a specific kernel with 2d array shape.

Returns:

the smoothed signal

Return type:

array_like

sda.signal.smooth.als_baseline(intensities, asymmetry_param=0.05, smoothness_param=1000000.0, max_iters=10, conv_thresh=1e-05, verbose=False)#

Compute the asymmetric least squares baseline.

Parameters:
  • intensities (array_like) – vector to smooth

  • asymmetry_param (float) – value will shift the baseline fit below or above your average line. To cancel gaussian noise, you would want the value to be 0.5. To remove a positive peak would want it to be close to 0. To remove a negative peaks (from a transmittance signal for instance) you would want it to be close to 1. Default 0.05

  • smoothness_param (float) – Relative importance of smoothness of the predicted response: the higher, the smoother the baseline. Suggested range: 1e2 to 1e8. Default 1e6

  • max_iters (int) – number of iterations

  • conv_thresh (float) – convergence

  • verbose (boolean)

Examples

from sda.signal.smooth import als_baseline
I = als_baseline(I, smoothness_param=1e5, aymmetry_param=0.1)

References

Notes

Implementation:

class sda.signal.smooth.WhittakerSmoother(signal, smoothness_param, deriv_order=1)#

Bases: object

Whittaker Smoother.

References

See also

als_baseline()

y#
upper_bands#
smooth(w)#