Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Smooth

Smooth is a preprocessing technique in spectroscopy that smooths the spectra. The following algorithms are available:

Savitzky-Golay filter

Savitzky-Golay filter is a preprocessing technique in spectroscopy that smooths the spectra by fitting a polynomial to the data. The current implementation is based on the scipy.signal.savgol_filter function.

Arguments:

Argument Description Type Default
window_size The length of the window. Must be an odd integer number. int 3
polynomial_order The order of the polynomial used to fit the samples. Must be less than window_size. int 1
derivative_order The order of the derivative to compute. int 1
mode The mode of the boundary. Options are 'nearest', 'constant', 'reflect', 'wrap', 'mirror', 'interp'. See the scipy.savgol_filter for more information. str 'nearest'

Usage examples:

from chemotools.smooth import SavitzkyGolayFilter

sgf = SavitzkyGolayFilter(window_size=15, polynomial_order=2)
spectra_norm = sgf.fit_transform(spectra)

Plotting example:

Whittaker smoother

It is an automated smoothing algorithm that uses a penalized least squares approach to iteratively apply a smoothing operation to the data by minimizing a penalty function that balances the degree of smoothness and the fidelity to the original data.

Arguments:

Argument Description Type Default
lam smoothing factor. float 1e2
differences The number of differences to use. int 1

Usage examples:

from chemotools.smooth import WhittakerSmooth

wtk = WhittakerSmooth(lam=10)
spectra_norm = wtk.fit_transform(spectra)

Plotting example:

Mean filter

Mean filter is a preprocessing technique in spectroscopy that smooths the spectra by applying a mean filter. The current implementation is based on the scipy.ndimage.uniform_filter function.

Arguments:

Argument Description Type Default
window_size The length of the window. Must be an odd integer number. int 3
mode The mode parameter determines how the array borders are handled, where 'constant', 'reflect', 'wrap', 'mirror', 'interp'. See the official documentation for more information. str 'nearest'

Usage examples:

from chemotools.smooth import MeanFilter

mean_filter = MeanFilter()
spectra_norm = mean_filter.fit_transform(spectra)

Plotting example:

Median filter

Median filter is a preprocessing technique in spectroscopy that smooths the spectra by applying a median filter. The current implementation is based on the scipy.ndimage.median_filter function.

Arguments:

Argument Description Type Default
window_size The length of the window. Must be an odd integer number. int 3
mode The mode parameter determines how the array borders are handled, where 'constant', 'reflect', 'wrap', 'mirror', 'interp'. See the official documentation for more information. str 'nearest'

Usage examples:

from chemotools.smooth import MedianFilter

median_filter = MedianFilter()
spectra_norm = median_filter.fit_transform(spectra)

Plotting example: