pybaselines.Baseline.modpoly

Baseline.modpoly(data, poly_order=2, tol=0.001, max_iter=250, weights=None, use_original=False, mask_initial_peaks=False, return_coef=False)[source]

The modified polynomial (ModPoly) baseline algorithm.

Parameters:
dataarray_like, shape (N,)

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

x_dataarray_like, shape (N,), optional

The x-values of the measured data. Default is None, which will create an array from -1 to 1 with N points.

poly_orderint, optional

The polynomial order for fitting the baseline. Default is 2.

tolfloat, optional

The exit criteria. Default is 1e-3.

max_iterint, optional

The maximum number of iterations. Default is 250.

weightsarray_like, shape (N,), optional

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

use_originalbool, optional

If False (default), will compare the baseline of each iteration with the y-values of that iteration [1] when choosing minimum values. If True, will compare the baseline with the original y-values given by data [2].

mask_initial_peaksbool, optional

If True, will mask any data where the initial baseline fit + the standard deviation of the residual is less than measured data [3]. Default is False.

return_coefbool, optional

If True, will convert the polynomial coefficients for the fit baseline to a form that fits the input x_data and return them in the params dictionary. Default is False, since the conversion takes time.

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.

  • '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.

  • 'coef': numpy.ndarray, shape (poly_order + 1,)

    Only if return_coef is True. The array of polynomial parameters for the baseline, in increasing order. Can be used to create a polynomial using numpy.polynomial.polynomial.Polynomial.

Notes

Algorithm originally developed in [2] and then slightly modified in [1].

References

[1] (1,2)

Gan, F., et al. Baseline correction by improved iterative polynomial fitting with automatic threshold. Chemometrics and Intelligent Laboratory Systems, 2006, 82, 59-65.

[2] (1,2)

Lieber, C., et al. Automated method for subtraction of fluorescence from biological raman spectra. Applied Spectroscopy, 2003, 57(11), 1363-1367.

[3]

Zhao, J., et al. Automated Autofluorescence Background Subtraction Algorithm for Biomedical Raman Spectroscopy, Applied Spectroscopy, 2007, 61(11), 1225-1232.