pybaselines.Baseline.adaptive_minmax

Baseline.adaptive_minmax(data, poly_order=None, method='modpoly', weights=None, constrained_fraction=0.01, constrained_weight=100000.0, estimation_poly_order=2, method_kwargs=None)[source]

Fits polynomials of different orders and uses the maximum values as the baseline.

Each polynomial order fit is done both unconstrained and constrained at the endpoints.

Parameters:
dataarray_like, shape (N,)

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

poly_orderint or sequence(int, int) or None, optional

The two polynomial orders to use for fitting. If a single integer is given, then will use the input value and one plus the input value. Default is None, which will do a preliminary fit using a polynomial of order estimation_poly_order and then select the appropriate polynomial orders according to [1].

method{'modpoly', 'imodpoly'}, optional

The method to use for fitting each polynomial. Default is 'modpoly'.

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.

constrained_fractionfloat or sequence(float, float), optional

The fraction of points at the left and right edges to use for the constrained fit. Default is 0.01. If constrained_fraction is a sequence, the first item is the fraction for the left edge and the second is the fraction for the right edge.

constrained_weightfloat or sequence(float, float), optional

The weighting to give to the endpoints. Higher values ensure that the end points are fit, but can cause large fluctuations in the other sections of the polynomial. Default is 1e5. If constrained_weight is a sequence, the first item is the weight for the left edge and the second is the weight for the right edge.

estimation_poly_orderint, optional

The polynomial order used for estimating the baseline-to-signal ratio to select the appropriate polynomial orders if poly_order is None. Default is 2.

method_kwargsdict, optional

Additional keyword arguments to pass to modpoly() or imodpoly(). These include tol, max_iter, use_original, mask_initial_peaks, and num_std.

Returns:
numpy.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.

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

    The weight array used for the endpoint-constrained fits.

  • 'poly_order': numpy.ndarray, shape (2,)

    An array of the two polynomial orders used for the fitting.

  • 'method_params': dict[str, list]

    A dictionary containing the output parameters for each individual fit. Keys will depend on the selected method and will have a list of values, with each item corresponding to a fit.

References

[1]

Cao, A., et al. A robust method for automated background subtraction of tissue fluorescence. Journal of Raman Spectroscopy, 2007, 38, 1199-1205.