pybaselines.Baseline.mpls

Baseline.mpls(data, half_window=None, lam=1000000.0, p=0.0, diff_order=2, tol=None, max_iter=None, weights=None, window_kwargs=None, **kwargs)[source]

The Morphological penalized least squares (MPLS) baseline algorithm.

Parameters:
dataarray_like, shape (N,)

The y-values of the measured data, with N data points.

half_windowint, optional

The half-window used for the morphology functions. If a value is input, then that value will be used. Default is None, which will optimize the half-window size using optimize_window() and window_kwargs.

lamfloat, optional

The smoothing parameter. Larger values will create smoother baselines. Default is 1e6.

pfloat, optional

The penalizing weighting factor. Must be between 0 and 1. Anchor points identified by the procedure in [1] are given a weight of 1 - p, and all other points have a weight of p. Default is 0.0.

diff_orderint, optional

The order of the differential matrix. Must be greater than 0. Default is 2 (second order differential matrix). Typical values are 2 or 1.

tolfloat, optional, deprecated

Deprecated since version 1.2.0: tol is deprecated since it was not used within mpls and will be removed in pybaselines version 1.4.0.

max_iterint, optional, deprecated

Deprecated since version 1.2.0: max_iter is deprecated since it was not used within mpls and will be removed in pybaselines version 1.4.0.

weightsarray_like, shape (N,), optional

The weighting array. If None (default), then the weights will be calculated following the procedure in [1].

window_kwargsdict, optional

A dictionary of keyword arguments to pass to optimize_window() for estimating the half window if half_window is None. Default is None.

**kwargs

Deprecated since version 1.2.0: Passing additional keyword arguments is deprecated and will be removed in version 1.4.0. Pass keyword arguments using window_kwargs.

Returns:
baselinenumpy.ndarray, shape (N,)

The calculated baseline.

paramsdict

A dictionary with the following items:

  • 'weights': numpy.ndarray, shape (N,)

    The weight array used for fitting the data.

  • 'half_window': int

    The half window used for the morphological calculations.

Raises:
ValueError

Raised if p is not between 0 and 1.

References

[1] (1,2)

Li, Zhong, et al. Morphological weighted penalized least squares for background correction. Analyst, 2013, 138, 4483-4492.