A library of baseline correction algorithms to help estimate the baselines of experimental data
Project description
pybaselines is a library of baseline correction algorithms to help estimate the baselines of experimental data.
For Python 3.6+
Open Source: BSD 3-Clause License
Source Code: https://github.com/derb12/pybaselines
Documentation: https://pybaselines.readthedocs.io.
Introduction
pybaselines provides many different baseline correction algorithms for fitting baselines to data from experimental techniques such as Raman, FTIR, NMR, XRD, PIXE, etc. The aim of the project is to provide a semi-unified API to allow quickly testing and comparing multiple baseline correction algorithms to find the best one for a set of data.
pybaselines has 40+ baseline correction algorithms. The algorithms are grouped accordingly (note: when a method is labelled as ‘improved’, that is the method’s name, not editorialization):
Polynomial methods (pybaselines.polynomial)
poly (Regular Polynomial)
modpoly (Modified Polynomial)
imodpoly (Improved Modified Polynomial)
penalized_poly (Penalized Polynomial)
loess (Locally Estimated Scatterplot Smoothing)
quant_reg (Quantile Regression)
goldindec (Goldindec Method)
Whittaker-smoothing-based methods (pybaselines.whittaker)
asls (Asymmetric Least Squares)
iasls (Improved Asymmetric Least Squares)
airpls (Adaptive Iteratively Reweighted Penalized Least Squares)
arpls (Asymmetrically Reweighted Penalized Least Squares)
drpls (Doubly Reweighted Penalized Least Squares)
iarpls (Improved Asymmetrically Reweighted Penalized Least Squares)
aspls (Adaptive Smoothness Penalized Least Squares)
psalsa (Peaked Signal’s Asymmetric Least Squares Algorithm)
derpsalsa (Derivative Peak-Screening Asymmetric Least Squares Algorithm)
Morphological methods (pybaselines.morphological)
mpls (Morphological Penalized Least Squares)
mor (Morphological)
imor (Improved Morphological)
mormol (Morphological and Mollified Baseline)
amormol (Averaging Morphological and Mollified Baseline)
rolling_ball (Rolling Ball Baseline)
mwmv (Moving Window Minimum Value)
tophat (Top-hat Transformation)
mpspline (Morphology-Based Penalized Spline)
Smoothing-based methods (pybaselines.smooth)
noise_median (Noise Median method)
snip (Statistics-sensitive Non-linear Iterative Peak-clipping)
swima (Small-Window Moving Average)
Spline methods (pybaselines.spline)
mixture_model (Mixture Model)
irsqr (Iterative Reweighted Spline Quantile Regression)
corner_cutting (Corner-Cutting Method)
Baseline/Peak Classification methods (pybaselines.classification)
dietrich (Dietrich’s Classification Method)
golotvin (Golotvin’s Classification Method)
std_distribution (Standard Deviation Distribution)
fastchrom (FastChrom’s Baseline Method)
Optimizers (pybaselines.optimizers)
collab_pls (Collaborative Penalized Least Squares)
optimize_extended_range
adaptive_minmax (Adaptive MinMax)
Miscellaneous methods (pybaselines.misc)
interp_pts (Interpolation between points)
beads (Baseline Estimation And Denoising with Sparsity)
Installation
Stable Release
pybaselines is easily installed from pypi using pip, by running the following command in the terminal:
pip install pybaselines
To also install the optional dependencies when installing pybaselines, run:
pip install pybaselines[full]
Development Version
The sources for pybaselines can be downloaded from the Github repo.
The public repository can be cloned using:
git clone https://github.com/derb12/pybaselines.git
Once the repository is downloaded, it can be installed with:
cd pybaselines
pip install .
Dependencies
pybaselines requires Python version 3.6 or later and the following libraries:
All of the required libraries should be automatically installed when installing pybaselines using either of the two installation methods above.
The optional dependencies for pybaselines are listed in the documentation.
Quick Start
To use the various functions in pybaselines, simply input the measured data and any required parameters. All baseline correction functions in pybaselines will output two items: a numpy array of the calculated baseline and a dictionary of potentially useful parameters.
For more details on each baseline algorithm, refer to the algorithms section of pybaselines’s documentation.
A simple example is shown below.
import matplotlib.pyplot as plt
import numpy as np
import pybaselines
from pybaselines import utils
x = np.linspace(1, 1000, 1000)
# a measured signal containing several Gaussian peaks
signal = (
utils.gaussian(x, 4, 120, 5)
+ utils.gaussian(x, 5, 220, 12)
+ utils.gaussian(x, 5, 350, 10)
+ utils.gaussian(x, 7, 400, 8)
+ utils.gaussian(x, 4, 550, 6)
+ utils.gaussian(x, 5, 680, 14)
+ utils.gaussian(x, 4, 750, 12)
+ utils.gaussian(x, 5, 880, 8)
)
# exponentially decaying baseline
true_baseline = 2 + 10 * np.exp(-x / 400)
np.random.seed(1) # set random seed
noise = np.random.normal(0, 0.2, x.size)
y = signal + true_baseline + noise
bkg_1 = pybaselines.polynomial.modpoly(y, x, poly_order=3)[0]
bkg_2 = pybaselines.whittaker.asls(y, lam=1e7, p=0.02)[0]
bkg_3 = pybaselines.morphological.mor(y, half_window=30)[0]
try:
bkg_4 = pybaselines.smooth.snip(
y, max_half_window=40, decreasing=True, smooth_half_window=3
)[0]
except AttributeError:
# pybaselines.window was renamed to pybaselines.smooth in version 0.6
bkg_4 = pybaselines.window.snip(
y, max_half_window=40, decreasing=True, smooth_half_window=3
)[0]
plt.plot(x, y, label='raw data', lw=1.5)
plt.plot(x, true_baseline, lw=3, label='true baseline')
plt.plot(x, bkg_1, '--', label='modpoly')
plt.plot(x, bkg_2, '--', label='asls')
plt.plot(x, bkg_3, '--', label='mor')
plt.plot(x, bkg_4, '--', label='snip')
plt.legend()
plt.show()
The above code will produce the image shown below.
Contributing
Contributions are welcomed and greatly appreciated. For information on submitting bug reports, pull requests, or general feedback, please refer to the contributing guide.
Changelog
Refer to the changelog for information on pybaselines’s changes.
License
pybaselines is open source and freely available under the BSD 3-clause license. For more information, refer to the license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pybaselines-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3be47e856f601bd1f39aa8fcf549a4d93bb90ce97f8bacc61da7aed89d7c4ebf |
|
MD5 | 28dd1d484f44b226065858229e3fe982 |
|
BLAKE2b-256 | 7c8bf1e91ffb8a39b917eb23473f2a0b9b74fe5f677d13f2524957d43881410e |