sda.signal.smooth ================= .. py:module:: sda.signal.smooth .. autoapi-nested-parse:: Created on Wed May 3 09:24:38 2017. @author: p38 Summary ------- Useful 1d smoothing functions Basic 2d smoothing functions Baseline smoothing functions ---------- Classes ------- .. autoapisummary:: sda.signal.smooth.WhittakerSmoother Functions --------- .. autoapisummary:: sda.signal.smooth.smooth sda.signal.smooth.smooth_matrix sda.signal.smooth.smooth2d sda.signal.smooth.als_baseline Module Contents --------------- .. py:function:: 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. :param x: The input signal. :type x: :py:class:`array_like` :param window_len: The dimension of the smoothing window; should be an odd integer. :type window_len: :py:class:`int` :param window: The type of window from 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'. Flat window will produce a moving average smoothing. :type window: :py:class:`str` :returns: The smoothed signal. :rtype: :py:class:`array_like` .. rubric:: Examples >>> t = linspace(-5, 5, 1000) >>> x = sin(t) + randn(len(t)) * 0.1 >>> y = smooth(x, 11, "hanning") .. minigallery:: sda.signal.smooth.smooth .. seealso:: :py:obj:`np.hanning`, :py:obj:`np.hamming`, :py:obj:`np.bartlett`, :py:obj:`np.blackman`, :py:obj:`np.convolve`, :py:obj:`scipy.signal.lfilter` :py:obj:`TODO` the window parameter could be the window itself if an array instead of a string .. py:function:: smooth_matrix(x, window_len, window='hanning', axis=0) .. py:function:: 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) :param x: The input signal. :type x: :py:class:`array_like` :param kernel_dim: The dimension of the smoothing kernel; should be a tuple of odd integers. :type kernel_dim: :py:class:`tuple` of :py:class:`int` :param kernel: The type of kernel, can be the 'flat' option or a specific kernel with 2d array shape. :type kernel: :py:class:`str` or :py:class:`array_like` :returns: the smoothed signal :rtype: :py:class:`array_like` .. py:function:: 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. :param intensities: vector to smooth :type intensities: :py:class:`array_like` :param asymmetry_param: 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`` :type asymmetry_param: :py:class:`float` :param smoothness_param: Relative importance of smoothness of the predicted response: the higher, the smoother the baseline. Suggested range: ``1e2`` to ``1e8``. Default ``1e6`` :type smoothness_param: :py:class:`float` :param max_iters: number of iterations :type max_iters: :py:class:`int` :param conv_thresh: convergence :type conv_thresh: :py:class:`float` :param verbose: :type verbose: :py:class:`boolean` .. rubric:: Examples :: from sda.signal.smooth import als_baseline I = als_baseline(I, smoothness_param=1e5, aymmetry_param=0.1) .. rubric:: References * https://zanran_storage.s3.amazonaws.com/www.science.uva.nl/ContentPages/443199618.pdf * http://www.science.uva.nl/~hboelens/publications/draftpub/Eilers_2005.pdf .. rubric:: Notes Implementation: - uses :func:`~sda.signal.smooth.WhittakerSmoother` internally - kudos to https://gist.github.com/perimosocordiae .. seealso:: :func:`~sda.signal.smooth.WhittakerSmoother` .. py:class:: WhittakerSmoother(signal, smoothness_param, deriv_order=1) Bases: :py:obj:`object` Whittaker Smoother. .. rubric:: References - kudos to https://gist.github.com/perimosocordiae .. seealso:: :func:`~sda.signal.smooth.als_baseline` .. py:attribute:: y .. py:attribute:: upper_bands .. py:method:: smooth(w)