pybaselines.Baseline.custom_bc
- Baseline.custom_bc(data, method='asls', regions=((None, None),), sampling=1, lam=None, diff_order=2, method_kwargs=None)[source]
Customized baseline correction for fine tuned stiffness of the baseline at specific regions.
Divides the data into regions with variable number of data points and then uses other baseline algorithms to fit the truncated data. Regions with less points effectively makes the fit baseline more stiff in those regions.
- Parameters:
- dataarray_like, shape (N,)
The y-values of the measured data, with N data points.
- method
str
, optional A string indicating the algorithm to use for fitting the baseline; can be any non-optimizer algorithm in pybaselines. Default is 'asls'.
- regionsarray_like, shape (M, 2), optional
The two dimensional array containing the start and stop indices for each region of interest. Each region is defined as
data[start:stop]
. Default is ((None, None),), which will use all points.- sampling
int
or array_like, optional The sampling step size for each region defined in regions. If sampling is an integer, then all regions will use the same index step size; if sampling is an array-like, its length must be equal to M, the first dimension in regions. Default is 1, which will use all points.
- lam
float
orNone
, optional The value for smoothing the calculated interpolated baseline using Whittaker smoothing, in order to reduce the kinks between regions. Default is None, which will not smooth the baseline; a value of 0 will also not perform smoothing.
- diff_order
int
, optional The difference order used for Whittaker smoothing of the calculated baseline. Default is 2.
- method_kwargs
dict
, optional A dictionary of keyword arguments to pass to the selected method function. Default is None, which will use an empty dictionary.
- Returns:
- baseline
numpy.ndarray
, shape (N,) The baseline calculated with the optimum parameter.
- params
dict
A dictionary with the following items:
- 'x_fit': numpy.ndarray, shape (P,)
The truncated x-values used for fitting the baseline.
- 'y_fit': numpy.ndarray, shape (P,)
The truncated y-values used for fitting the baseline.
- 'baseline_fit': numpy.ndarray, shape (P,)
The truncated baseline before interpolating from P points to N points.
- 'method_params': dict
A dictionary containing the output parameters for the fit using the selected method.
- baseline
- Raises:
ValueError
Raised if regions is not two dimensional, if sampling is not the same length as rois.shape[0], if any values in sampling or regions is less than 1, if segments in regions overlap, or if any value in regions is greater than the length of the input data.
Notes
Uses Whittaker smoothing to smooth the transitions between regions rather than LOESS as used in [1].
Uses binning rather than direct truncation of the regions in order to get better results for noisy data.
References
[1]Liland, K., et al. Customized baseline correction. Chemometrics and Intelligent Laboratory Systems, 2011, 109(1), 51-56.