pybaselines.smooth.peak_filling
- pybaselines.smooth.peak_filling(data, x_data=None, half_window=None, sections=None, max_iter=5, lam_smooth=None)[source]
The 4S (Smooth, Subsample, Suppress, Stretch) Peak Filling algorithm.
Smooths and truncates the input. Each value is then replaced in-place by the minimum of the value or the average of the moving window, with the half-window size decreasing exponentially from the input half_window to 1. The result is then interpolated back into the original data size.
- 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. Not used within this function.
- half_window
int, optional The index-based size to use for the moving average window. The total window size will range from [-half_window, ..., half_window] with size
2 * half_window + 1. Default is None, which will use two or three times the output from func:.optimize_window, which is an okay starting value.- sections
int, optional The number of sections to divide the input data into for subsampling. The minimum of each section will be used to represent the input data for determining the baseline. Higher sections values are needed for baselines with higher curvature. Default is None, which will use
N // 10.- max_iter
int, optional The number of iterations to perform smoothing. Each iteration, the size of the window used for the moving average will shrink logarithmically, starting at
2 * half_window + 1and ending at 3. Default is 5.- lam_smooth
floatorNone, optional The parameter for smoothing the input using Whittaker smoothing. Set to 0 or None (default) to skip smoothing.
- Returns:
- baseline
numpy.ndarray, shape (N,) The calculated baseline.
- params
dict A dictionary with the following items:
- 'x_fit': numpy.ndarray, shape (P,)
The truncated x-values used for fitting the baseline.
- 'baseline_fit': numpy.ndarray, shape (P,)
The truncated y-values used for fitting the baseline.
- baseline
- Raises:
TypeErrorRaised if sections is not an integer.
Notes
The input parameter sections will determine the necessary half_window and max_iter values required to correctly fit the baseline. Likewise, max_iter is highly correlated with half_window.
References
Liland, K. 4S Peak Filling - baseline estimation by iterative mean suppression. MethodsX. 2015, 2, 135-140.