{"id":9206,"library":"pybaselines","title":"pybaselines","description":"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.","status":"active","version":"1.2.1","language":"en","source_language":"en","source_url":"https://github.com/derb12/pybaselines","tags":["signal processing","baseline correction","spectroscopy","chromatography","data analysis","whittaker smoothing"],"install":[{"cmd":"pip install pybaselines","lang":"bash","label":"Basic Installation"},{"cmd":"pip install pybaselines[full]","lang":"bash","label":"Installation with optional dependencies (for performance)"}],"dependencies":[{"reason":"Required Python version","package":"python","optional":false},{"reason":"Fundamental for numerical operations and array handling.","package":"numpy","optional":false},{"reason":"Used for scientific computing, including sparse matrices and optimization.","package":"scipy","optional":false},{"reason":"Optional dependency for significant performance improvements in some algorithms.","package":"numba","optional":true},{"reason":"Optional dependency for faster banded matrix solvers in Whittaker-smoothing algorithms.","package":"pentapy","optional":true}],"imports":[{"note":"The class-based API 'Baseline' was introduced in v1.0.0 and resides in the `pybaselines.api` submodule.","wrong":"from pybaselines import Baseline","symbol":"Baseline","correct":"from pybaselines.api import Baseline"},{"note":"For 2D data processing, introduced in v1.1.0.","symbol":"Baseline2D","correct":"from pybaselines.api import Baseline2D"},{"note":"Example of importing a specific functional algorithm. Most algorithms are in submodules like `whittaker`, `polynomial`, `morphological`, `smooth`.","symbol":"asls","correct":"from pybaselines.whittaker import asls"},{"note":"The `pybaselines.window` module was deprecated in v0.7.0 and removed in v0.8.0. Its functionality was moved to `pybaselines.smooth`.","wrong":"import pybaselines.window as window_algos","symbol":"window","correct":"import pybaselines.smooth as smooth_algos"}],"quickstart":{"code":"import numpy as np\nfrom pybaselines.api import Baseline\n\n# 1. Generate some example data\nx = np.linspace(0, 100, 500)\ny_peak = 10 * np.exp(-((x - 50)**2) / 20) # A simple peak\ny_baseline = 0.1 * x + 5 # A sloping baseline\ny_data = y_peak + y_baseline + np.random.normal(0, 0.5, x.shape)\n\n# 2. Initialize the Baseline object (using the class-based API, recommended for v1.0.0+)\nbaseline_fitter = Baseline()\n\n# 3. Apply a baseline correction algorithm, e.g., Asymmetric Least Squares (ASLS)\n# The first return value is the estimated baseline, the second is a dictionary of parameters\nestimated_baseline, params = baseline_fitter.asls(y_data, lam=1e6, p=0.01)\n\n# 4. The corrected signal is the original data minus the estimated baseline\ncorrected_signal = y_data - estimated_baseline\n\nprint(\"Baseline estimation complete.\")\nprint(f\"First 5 original data values: {y_data[:5].round(2)}\")\nprint(f\"First 5 estimated baseline values: {estimated_baseline[:5].round(2)}\")\nprint(f\"First 5 corrected signal values: {corrected_signal[:5].round(2)}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Migrate any code using `pybaselines.window` functions to their equivalent implementations within the `pybaselines.smooth` module.","message":"The `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`.","severity":"deprecated","affected_versions":">=0.8.0"},{"fix":"For new projects or refactoring, consider using `from pybaselines.api import Baseline` and accessing algorithms as methods (e.g., `baseliner.asls(...)`).","message":"A 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=0.5.1"},{"fix":"Install pybaselines with full dependencies using `pip install pybaselines[full]` or `pip install numba pentapy` separately, if performance is a concern.","message":"For optimal performance, especially with Whittaker-smoothing-based algorithms, the optional dependencies `numba` and `pentapy` are highly recommended. Without them, calculations might be significantly slower.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Replace any usage of `pybaselines.window` with `pybaselines.smooth`. For example, change `from pybaselines.window import imodpoly` to `from pybaselines.smooth import imodpoly`.","cause":"Attempting to import or access the `window` module, which was deprecated in v0.7.0 and removed in v0.8.0.","error":"AttributeError: module 'pybaselines' has no attribute 'window'"},{"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)`.","cause":"Attempting to call the `Baseline` class instance directly like a function, instead of calling one of its method algorithms.","error":"TypeError: 'Baseline' object is not callable"},{"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`).","cause":"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.","error":"ImportError: cannot import name 'Baseline' from 'pybaselines' (.../site-packages/pybaselines/__init__.py)"}]}