pybaselines.Baseline2D.pspline_psalsa

Baseline2D.pspline_psalsa(data, lam=1000.0, p=0.5, k=None, num_knots=25, spline_degree=3, diff_order=2, max_iter=50, tol=0.001, weights=None)[source]

A penalized spline version of the psalsa algorithm.

Parameters:
dataarray_like, shape (M, N)

The y-values of the measured data. Must not contain missing data (NaN) or Inf.

lamfloat or sequence[float, float], optional

The smoothing parameter for the rows and columns, respectively. If a single value is given, both will use the same value. Larger values will create smoother baselines. Default is 1e3.

pfloat, optional

The penalizing weighting factor. Must be between 0 and 1. Values greater than the baseline will be given p weight, and values less than the baseline will be given 1 - p weight. Default is 0.5.

kfloat, optional

A factor that controls the exponential decay of the weights for baseline values greater than the data. Should be approximately the height at which a value could be considered a peak. Default is None, which sets k to one-tenth of the standard deviation of the input data. A large k value will produce similar results to asls().

num_knotsint or sequence[int, int], optional

The number of knots for the splines along the rows and columns, respectively. If a single value is given, both will use the same value. Default is 25.

spline_degreeint or sequence[int, int], optional

The degree of the splines along the rows and columns, respectively. If a single value is given, both will use the same value. Default is 3, which is a cubic spline.

diff_orderint or sequence[int, int], optional

The order of the differential matrix for the rows and columns, respectively. If a single value is given, both will use the same value. Must be greater than 0. Default is 2 (second order differential matrix). Typical values are 1 or 2.

max_iterint, optional

The max number of fit iterations. Default is 50.

tolfloat, optional

The exit criteria. Default is 1e-3.

weightsarray_like, shape (M, N), optional

The weighting array. If None (default), then the initial weights will be an array with size equal to N and all values set to 1.

Returns:
baselinenumpy.ndarray, shape (M, N)

The calculated baseline.

paramsdict

A dictionary with the following items:

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

    The weight array used for fitting the data.

  • 'tol_history': numpy.ndarray

    An array containing the calculated tolerance values for each iteration. The length of the array is the number of iterations completed. If the last value in the array is greater than the input tol value, then the function did not converge.

Raises:
ValueError

Raised if p is not between 0 and 1. Also raised if k is not greater than 0.

References

Oller-Moreno, S., et al. Adaptive Asymmetric Least Squares baseline estimation for analytical instruments. 2014 IEEE 11th International Multi-Conference on Systems, Signals, and Devices, 2014, 1-5.

Eilers, P., et al. Splines, knots, and penalties. Wiley Interdisciplinary Reviews: Computational Statistics, 2010, 2(6), 637-653.