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

Baseline

Baseline correction is a preprocessing technique in spectroscopy that corrects for baseline shifts and variations in signal intensity by subtracting a baseline from a spectrum. The following algorithms are available:

Non-negative

Non-negative baseline correction is a preprocessing technique in spectroscopy that corrects for baseline by removing negative values from a spectrum. Negative values are either replaced by 0, or set to their absolute value.

Arguments:

Argument Description Type Default
mode 'zero', negative values are replaced by 0. 'abs', negative values are set to their absolute value. str 'zero'

Usage example:

from chemotools.baseline import NonNegative

nnz = NonNegative(mode='zero')
nna = NonNegative(mode='abs')
spectra_nnz = nnz.fit_transform(spectra_baseline)
spectra_nna = nna.fit_transform(spectra_baseline)

Plotting example:

Subtract reference spectrum

Subtract reference spectrum is a preprocessing technique in spectroscopy that subtracts a reference spectrum from a target spectrum. The reference spectrum must be a single spectrum. The target spectrum can be a single spectrum or a list of spectra.

Arguments:

Argument Description Type Default
reference The reference spectrum. numpyp.ndarray None

The following arguments can be set:

  • reference: np.array The reference spectrum. Default: None. When it is set to None, the algorithm will not subtract the reference spectrum.

Usage example:

from chemotools.baseline import SubtractReference

sr = SubtractReference(reference=reference_spectrum)
spectra_sr = sr.fit_transform(spectra)

Plotting example:

Constant baseline correction

Constant baseline correction is a preprocessing technique in spectroscopy that corrects for baseline by subtracting a constant value from a spectrum. The constant value is the mean of a region in the spectrum. This processing step is specially useful in UV-Vis spectroscopy, where there can be a large region in the spectra without any absorption.

Arguments:

Argument Description Type Default
start The start index of the region to use for calculating the mean. If no wavenumbers are provided, it will take the index of the spectrum. If wavenumbers are provided it will take the index corresponding to the wavenumber int 0
end The end index of the region to use for calculating the mean. If no wavenumbers are provided, it will take the index of the spectrum. If wavenumbers are provided it will take the index corresponding to the wavenumber int 1
wavenumbers The wavenumbers of the spectrum. numpy.ndarray None

The wavenumbers vector must be sorted in ascending order.

Usage example:

Case 1: No wavenumbers provided

from chemotools.baseline import ConstantBaselineCorrection

cbc = ConstantBaselineCorrection(start=0, end=30)
spectra_baseline = cbc.fit_transform(spectra)

Case 2: Wavenumbers provided

from chemotools.baseline import ConstantBaselineCorrection

cbc = ConstantBaselineCorrection(start=950, end=975, wavenumbers=wn)
spectra_baseline = cbc.fit_transform(spectra)

Plotting example:

Linear baseline correction

Linear baseline correction is a preprocessing technique in spectroscopy that corrects for baseline shifts and variations in signal intensity by subtracting a linear baseline from a spectrum. The current implementation subtracts a linear baseline between the first and last point of the spectrum.

Usage examples:

from chemotools.baseline import LinearCorrection

lc = LinearCorrection()
spectra_baseline = lc.fit_transform(spectra)

Plotting example:

Polynomial baseline correction

Polynomial baseline correction is a preprocessing technique in spectroscopy that approximates a baseline by fitting a polynomial to selected points of the spectrum. The selected points often correspond to minima in the spectra, and are selected by their index (not by the wavenumber). If no points are selected, the algorithm will select all the points in the spectrum to fit a polynomial of a given order. This case is often called detrending in other spectral processing software.

Arguments:

Argument Description Type Default
order The order of the polynomial to fit. int 1
indices The indices of the points to use for fitting the polynomial. list None

Usage examples:

from chemotools.baseline import PolynomialCorrection

pc = PolynomialCorrection(order=2, indices=[0, 75, 150, 200, 337])
spectra_baseline = pc.fit_transform(spectra)

Plotting example:

Cubic spline baseline correction

Cubic spline baseline correction is a preprocessing technique in spectroscopy that approximates a baseline by fitting a cubic spline to selected points of the spectrum. Similar to the PolynomialCorrection, the selected points often correspond to minima in the spectra, and are selected by their index (not by the wavenumber). If no points are selected, the algorithm will select the first and last point of the spectrum.

Arguments:

Argument Description Type Default
indices The indices of the points to use for fitting the polynomial. list None

Usage examples:

from chemotools.baseline import CubicSplineCorrection

cspl = CubicSplineCorrection(indices=[0, 75, 150, 200, 337])
spectra_baseline = cspl.fit_transform(spectra)

Plotting example:

Adaptive iteratively reweighed penalized least squares baseline correction (AirPLS)

It is an automated baseline correction algorithm that uses a penalized least squares approach to fit a baseline to a spectrum. The original algorithm is based on the paper by Zhang et al.. The current implementation is based on the Python implementation by zmzhang.

Arguments:

Argument Description Type Default
lam The smoothing factor. float 1e2
polynomial_order The order of the polynomial used to fit the samples. int 1
nr_iterations The number of iterations before exiting the algorithm. int 15

Usage examples:

from chemotools.baseline import AirPls

airpls = AirPls()
spectra_baseline = airpls.fit_transform(spectra)

Plotting example:

Asymmetrically reweighed penalized least squares baseline correction (ArPLS)

This is an automated baseline correction algorithm that uses a penalized least squares approach to fit a baseline to a spectrum. The original algorithm is based on the paper by Sung-June et al

Arguments:

Argument Description Type Default
lam The smoothing factor. float 1e2
ratio The convergence criteria for the algorithm to exit. float 0.001
nr_iterations The number of iterations before exiting the algorithm. int 100

Usage examples:

from chemotools.baseline import ArPls

arpls = ArPls()
spectra_baseline = arpls.fit_transform(spectra)

Plotting example: