Warning

You are reading the documentation related to the development version. Go here if you are looking for the documentation of the stable release.

spectrochempy.BaselineCorrection

class BaselineCorrection(log_level='WARNING', warm_start=False, *, asymmetry=0.05, include_limits=True, lamb=100000.0, lls=False, max_iter=50, model='polynomial', multivariate=False, n_components=5, order=1, ranges, snip_width=0, tol=0.001)[source]

Attributes Summary

X

Return the X input dataset (eventually modified by the model).

asymmetry

The asymmetry parameter for the AsLS method.

baseline

Computed baseline.

breakpoints

Breakpoints to define piecewise segments of the data, specified as a vector containing coordinate values or indices indicating the location of the breakpoints.

config

traitlets.config.Config object.

corrected

Dataset with baseline removed.

include_limits

Whether to automatically include the features limits to the specified ranges.

lamb

The smoothness parameter for the AsLS method.

lls

If True, the baseline is determined on data transformed using the log-log-square transform.

log

Return log output.

max_iter

Maximum number of AsLS iteration.

model

The model used to determine the baseline.

multivariate

For 2D datasets, if True or if multivariate='svd' or 'nmf' , a multivariate method is used to fit a baseline on the principal components determined using a SVD decomposition if multivariate='svd'or True, or a NMF factorization if multivariate='nmf',followed by an inverse-transform to retrieve the baseline corrected dataset.

n_components

Number of components to use for the multivariate method (n_observations >= n_components).

name

Object name

order

Polynom order to use for polynomial/pchip interpolation or detrend.

ranges

A sequence of features values or feature's regions which are assumed to belong to the baseline.

snip_width

The width of the window used to determine the baseline using the SNIP algorithm.

tol

The tolerance parameter for the AsLS method.

used_ranges

The actual ranges used during fitting

Methods Summary

fit(X)

Fit a baseline model on a X dataset.

parameters([replace, removed, default])

Alias for params method.

params([default])

Current or default configuration values.

plot(**kwargs)

Plot the original, baseline and corrected dataset.

reset()

Reset configuration parameters to their default values

to_dict()

Return config value in a dict form.

transform()

Return a dataset with baseline removed.

Attributes Documentation

X

Return the X input dataset (eventually modified by the model).

asymmetry

The asymmetry parameter for the AsLS method. It is typically between 0.001 and 0.1. 0.001 gives almost the same fit as the unconstrained least squares

baseline

Computed baseline.

breakpoints

Breakpoints to define piecewise segments of the data, specified as a vector containing coordinate values or indices indicating the location of the breakpoints. Breakpoints are useful when you want to compute separate baseline/trends for different segments of the data.

config

traitlets.config.Config object.

corrected

Dataset with baseline removed.

include_limits

Whether to automatically include the features limits to the specified ranges.

lamb

The smoothness parameter for the AsLS method. Larger values make the baseline stiffer. Values should be in the range (0, 1e9).

lls

If True, the baseline is determined on data transformed using the log-log-square transform. This compress the dynamic range of signal and thus emphasize smaller features. This parameter is always True for the ‘snip’ model.

log

Return log output.

max_iter

Maximum number of AsLS iteration.

model

The model used to determine the baseline.

  • ‘polynomial’: the baseline correction is determined by a nth-degree polynomial fitted on the data belonging to the selected ranges. The order parameter to determine the degree of the polynomial.

  • ‘detrend’: removes a constant, linear or polynomial trend to the data. The order of the trend is determined by the order parameter.

  • ‘asls’: the baseline is determined by an asymmetric least square algorithm.

  • ‘snip’: the baseline is determined by a simple non-iterative peak detection algorithm.

  • ‘rubberband’: the baseline is determined by a rubberband algorithm.

multivariate

For 2D datasets, if True or if multivariate=’svd’ or ‘nmf’ , a multivariate method is used to fit a baseline on the principal components determined using a SVD decomposition if multivariate='svd'or True, or a NMF factorization if multivariate='nmf',followed by an inverse-transform to retrieve the baseline corrected dataset. If False , a sequential method is used which consists in fitting a baseline on each row (observations) of the dataset.

n_components

Number of components to use for the multivariate method (n_observations >= n_components).

name

Object name

order

Polynom order to use for polynomial/pchip interpolation or detrend.

  • If an integer is provided, it is the order of the polynom to fit, i.e. 1 for linear,

  • If a string if provided among ‘constant’, ‘linear’, ‘quadratic’ and ‘cubic’, it is equivalent to order O (constant) to 3 (cubic).

  • If a string equal to pchip is provided, the polynomial interpolation is replaced by a piecewise cubic hermite interpolation (see scipy.interpolate.PchipInterpolator

ranges

A sequence of features values or feature’s regions which are assumed to belong to the baseline. Feature ranges are defined as a list of 2 numerical values (start, end). Single values are internally converted to a pair (start=value, end=start). The limits of the spectra are automatically added during the fit process unless the remove_limit parameter is True

snip_width

The width of the window used to determine the baseline using the SNIP algorithm.

tol

The tolerance parameter for the AsLS method. Smaller values make the fitting better but potentially increases the number of iterations and the running time. Values should be in the range (0, 1).

used_ranges

The actual ranges used during fitting

Eventually the features limits are included and the list returned is trimmed, cleaned and ordered.

Methods Documentation

fit(X)[source]

Fit a baseline model on a X dataset.

Parameters

X (NDDataset or array-like of shape (n_observations, n_features)) – Training data.

Returns

self – The fitted instance itself.

parameters(replace="params", removed="0.7.1") def parameters(self, default=False)[source]

Alias for params method.

params(default=False)[source]

Current or default configuration values.

Parameters

default (bool, optional, default: False) – If default is True, the default parameters are returned, else the current values.

Returns

dict – Current or default configuration values.

plot(**kwargs)[source]

Plot the original, baseline and corrected dataset.

Parameters

**kwargs (keyword parameters, optional) – See Other Parameters.

Returns

Axes – Matplotlib subplot axe.

Other Parameters
  • colors (tuple or ndarray of 3 colors, optional) – Colors for original , baseline and corrected data. in the case of 2D, The default colormap is used for the original data. By default, the three colors are NBlue , NGreen and NRed (which are colorblind friendly).

  • offset (float, optional, default: None) – Specify the separation (in percent) between the original and corrected data.

  • nb_traces (int or 'all', optional) – Number of lines to display. Default is 'all'.

  • **others (Other keywords parameters) – Parameters passed to the internal plot method of the datasets.

reset()[source]

Reset configuration parameters to their default values

to_dict()[source]

Return config value in a dict form.

Returns

dict – A regular dictionary.

transform()[source]

Return a dataset with baseline removed.

Examples using spectrochempy.BaselineCorrection