pybaselines.Baseline.rubberband

Baseline.rubberband(data, segments=1, lam=None, diff_order=2, weights=None, smooth_half_window=None, pad_kwargs=None, **kwargs)[source]

Identifies baseline points by fitting a convex hull to the bottom of the data.

Parameters:
dataarray_like, shape (N,)

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

segmentsint or sequence[int, ...], optional

Used to fit multiple convex hulls to the data to negate the effects of concave data. If the input is an integer, it sets the number of equally sized segments the data will be split into. If the input is a sequence, each integer in the sequence will be the index that splits two segments, which allows constructing unequally sized segments. Default is 1, which fits a single convex hull to the data.

lamfloat or None, optional

The smoothing parameter for interpolating the baseline points using Whittaker smoothing. Set to 0 or None to use linear interpolation instead. Default is None, which does not smooth.

diff_orderint, optional

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

weightsarray_like, shape (N,), optional

The weighting array, used to override the function's baseline identification to designate peak points. Only elements with 0 or False values will have an effect; all non-zero values are considered potential baseline points. If None (default), then will be an array with size equal to N and all values set to 1.

smooth_half_windowint or None, optional

The half window to use for smoothing the input data with a moving average before calculating the convex hull, which gives much better results for noisy data. Set to None (default) or 0 to not smooth the data.

pad_kwargsdict, optional

A dictionary of keyword arguments to pass to pad_edges() for padding the edges of the data to prevent edge effects from smoothing. 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 pad_kwargs.

Returns:
baselinenumpy.ndarray, shape (N,)

The calculated baseline.

dict

A dictionary with the following items:

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

    The boolean array designating baseline points as True and peak points as False.

Raises:
ValueError

Raised if the number of segments is less than 1 or too large to allow interpolation.