Registry / data / pybaselines

pybaselines

JSON →
library1.2.1pypypi✓ verified 87d ago

pybaselines is a Python library providing a comprehensive collection of algorithms for baseline correction of experimental data, particularly useful in fields like spectroscopy and chromatography. It is currently at version 1.2.1 and maintains an active release cadence with minor versions and patches released every few months, and major versions less frequently.

pip install pybaselines
INSTALL
IMPORT
SIG · PYBASELINES
P
pybaselines
datapythonv1.2.1
Install
9.1s avg
Import
2970ms
Disk
415MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
2/4 runs
✓ 8.78s
py 3.11
2/4 runs
✓ 8.65s
py 3.12
2/4 runs
✓ 9.08s
py 3.13
2/4 runs
✓ 9.08s
py 3.9
2/4 runs
✓ 9.78s
415MB installed
● package 415MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Baseline
from pybaselines.api import Baseline
from pybaselines import Baseline
The class-based API 'Baseline' was introduced in v1.0.0 and resides in the `pybaselines.api` submodule.
Baseline2D
from pybaselines.api import Baseline2D
For 2D data processing, introduced in v1.1.0.
asls
from pybaselines.whittaker import asls
Example of importing a specific functional algorithm. Most algorithms are in submodules like `whittaker`, `polynomial`, `morphological`, `smooth`.
window
import pybaselines.smooth as smooth_algos
import pybaselines.window as window_algos
The `pybaselines.window` module was deprecated in v0.7.0 and removed in v0.8.0. Its functionality was moved to `pybaselines.smooth`.

This quickstart demonstrates how to use the recommended class-based API (available since v1.0.0) to perform baseline correction using the Asymmetric Least Squares (ASLS) algorithm. It generates synthetic data with a peak and a sloping baseline, then applies the correction to estimate and remove the baseline.

import numpy as np from pybaselines.api import Baseline # 1. Generate some example data x = np.linspace(0, 100, 500) y_peak = 10 * np.exp(-((x - 50)**2) / 20) # A simple peak y_baseline = 0.1 * x + 5 # A sloping baseline y_data = y_peak + y_baseline + np.random.normal(0, 0.5, x.shape) # 2. Initialize the Baseline object (using the class-based API, recommended for v1.0.0+) baseline_fitter = Baseline() # 3. Apply a baseline correction algorithm, e.g., Asymmetric Least Squares (ASLS) # The first return value is the estimated baseline, the second is a dictionary of parameters estimated_baseline, params = baseline_fitter.asls(y_data, lam=1e6, p=0.01) # 4. The corrected signal is the original data minus the estimated baseline corrected_signal = y_data - estimated_baseline print("Baseline estimation complete.") print(f"First 5 original data values: {y_data[:5].round(2)}") print(f"First 5 estimated baseline values: {estimated_baseline[:5].round(2)}") print(f"First 5 corrected signal values: {corrected_signal[:5].round(2)}")
Debug
Known issues
deprecatedThe `pybaselines.window` module was deprecated in version 0.7.0 and completely removed in version 0.8.0. Attempting to import or use functions from this module will result in an `AttributeError` or `ImportError`.
fix
Migrate any code using `pybaselines.window` functions to their equivalent implementations within the `pybaselines.smooth` module.
affects: >=0.8.0
gotchaA new class-based API, `pybaselines.api.Baseline`, was introduced in v1.0.0. While the functional API (e.g., `pybaselines.whittaker.asls`) is maintained for backward compatibility, the class-based approach is now the recommended pattern for new development and offers better organization and potential future features.
fix
For new projects or refactoring, consider using `from pybaselines.api import Baseline` and accessing algorithms as methods (e.g., `baseliner.asls(...)`).
affects: >=1.0.0
gotchaThe `tol` and `eps` parameters for `pybaselines.polynomial.quant_reg` had their default values and internal usage changed in version 0.5.1. Specifically, `tol` default changed to 1e-6 and `eps` is now used directly rather than its square. This could subtly alter results if not adjusted.
fix
If using `quant_reg`, review your existing code's `tol` and `eps` values and compare results with the updated behavior. Explicitly set these parameters if specific values are required for compatibility with older results.
affects: >=0.5.1
gotchaFor optimal performance, especially with Whittaker-smoothing-based algorithms, the optional dependencies `numba` and `pentapy` are highly recommended. Without them, calculations might be significantly slower.
fix
Install pybaselines with full dependencies using `pip install pybaselines[full]` or `pip install numba pentapy` separately, if performance is a concern.
affects: all
Errors
Common errors & fixes
AttributeError: module 'pybaselines' has no attribute 'window'
Attempting to import or access the `window` module, which was deprecated in v0.7.0 and removed in v0.8.0.
fix
Replace any usage of `pybaselines.window` with `pybaselines.smooth`. For example, change `from pybaselines.window import imodpoly` to `from pybaselines.smooth import imodpoly`.
TypeError: 'Baseline' object is not callable
Attempting to call the `Baseline` class instance directly like a function, instead of calling one of its method algorithms.
fix
Ensure you are calling a specific algorithm method on the `Baseline` instance. For example, `baseliner = Baseline(); baseline, params = baseliner.asls(data)` instead of `baseline, params = baseliner(data)`.
ImportError: cannot import name 'Baseline' from 'pybaselines' (.../site-packages/pybaselines/__init__.py)
Attempting to import the `Baseline` class directly from the top-level `pybaselines` package, or using a version prior to 1.0.0 where the class-based API did not exist.
fix
Correct the import statement to `from pybaselines.api import Baseline`. If you are using an older version, either upgrade to v1.0.0+ or use the functional API (e.g., `from pybaselines.whittaker import asls`).
Upgrade
Version history
1.2.1latest on PyPI · released Aug 10, 2025
Audit
Dependencies
pythonrequiredRequired Python version
numpyrequiredFundamental for numerical operations and array handling.
scipyrequiredUsed for scientific computing, including sparse matrices and optimization.
numbaoptionalOptional dependency for significant performance improvements in some algorithms.
pentapyoptionalOptional dependency for faster banded matrix solvers in Whittaker-smoothing algorithms.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
pybaselines — pip install pybaselines · libregistry