pybaselines.Baseline.snip
- Baseline.snip(data, max_half_window=None, decreasing=False, smooth_half_window=None, filter_order=2, pad_kwargs=None, **kwargs)[source]
Statistics-sensitive Non-linear Iterative Peak-clipping (SNIP).
- Parameters:
- dataarray_like, shape (N,)
The y-values of the measured data, with N data points.
- max_half_window
intor sequence(int,int), optional The maximum number of iterations. Should be set such that max_half_window is approxiamtely
(w-1)/2, wherewis the index-based width of a feature or peak. max_half_window can also be a sequence of two integers for asymmetric peaks, with the first item corresponding to the max_half_window of the peak's left edge, and the second item for the peak's right edge [3]. Default is None, which will use the output fromoptimize_window(), which is an okay starting value.- decreasingbool, optional
If False (default), will iterate through window sizes from 1 to max_half_window. If True, will reverse the order and iterate from max_half_window to 1, which gives a smoother baseline according to [3] and [4].
- smooth_half_window
int, optional The half window to use for smoothing the data. If smooth_half_window is greater than 0, will perform a moving average smooth on the data for each window, which gives better results for noisy data [3]. Default is None, which will not perform any smoothing.
- filter_order{2, 4, 6, 8}, optional
If the measured data has a more complicated baseline consisting of other elements such as Compton edges, then a higher filter_order should be selected [3]. Default is 2, which works well for approximating a linear baseline.
- pad_kwargs
dict, 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:
- baseline
numpy.ndarray, shape (N,) The calculated baseline.
dictAn empty dictionary, just to match the output of all other algorithms.
- baseline
- Raises:
ValueErrorRaised if filter_order is not 2, 4, 6, or 8.
- Warns:
UserWarningRaised if max_half_window is greater than (len(data) - 1) // 2.
Notes
Algorithm initially developed by [1], and this specific version of the algorithm is adapted from [2], [3], and [4].
If data covers several orders of magnitude, better results can be obtained by first transforming the data using log-log-square transform before using SNIP [2]:
transformed_data = np.log(np.log(np.sqrt(data + 1) + 1) + 1)
and then baseline can then be reverted back to the original scale using inverse:
baseline = -1 + (np.exp(np.exp(snip(transformed_data)) - 1) - 1)**2
References
[1]Ryan, C.G., et al. SNIP, A Statistics-Sensitive Background Treatment For The Quantitative Analysis Of Pixe Spectra In Geoscience Applications. Nuclear Instruments and Methods in Physics Research B, 1988, 934, 396-402.
[2] (1,2)Morháč, M., et al. Background elimination methods for multidimensional coincidence γ-ray spectra. Nuclear Instruments and Methods in Physics Research A, 1997, 401, 113-132.