pybaselines


Namepybaselines JSON
Version 1.2.1 PyPI version JSON
download
home_pageNone
SummaryA library of algorithms for the baseline correction of experimental data.
upload_time2025-08-10 20:39:58
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords background baseline baseline correction baseline subtraction chemistry materials characterization materials science raman spectroscopy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===========
pybaselines
===========

.. image:: https://github.com/derb12/pybaselines/raw/main/docs/images/logo.png
    :alt: Logo
    :align: center

.. image:: https://img.shields.io/pypi/v/pybaselines.svg
    :target: https://pypi.python.org/pypi/pybaselines
    :alt: Current Pypi Version

.. image:: https://img.shields.io/conda/vn/conda-forge/pybaselines.svg
    :target: https://anaconda.org/conda-forge/pybaselines
    :alt: Current conda Version

.. image:: https://github.com/derb12/pybaselines/actions/workflows/python-test.yml/badge.svg
    :target: https://github.com/derb12/pybaselines/actions
    :alt: GitHub Actions test status

.. image:: https://readthedocs.org/projects/pybaselines/badge/?version=latest
    :target: https://pybaselines.readthedocs.io
    :alt: Documentation Status

.. image:: https://img.shields.io/pypi/pyversions/pybaselines.svg
    :target: https://pypi.python.org/pypi/pybaselines
    :alt: Supported Python versions

.. image:: https://zenodo.org/badge/350510397.svg
    :target: https://zenodo.org/badge/latestdoi/350510397
    :alt: Zenodo DOI

pybaselines is a library of algorithms for the baseline correction of experimental data.

* For Python 3.9 or later
* Open Source: BSD 3-Clause License
* Source Code: https://github.com/derb12/pybaselines
* Documentation: https://pybaselines.readthedocs.io.


.. contents:: **Contents**
    :depth: 1


Introduction
------------

pybaselines is a Python library that provides many different algorithms for
performing baseline correction on data from experimental techniques such as
Raman, FTIR, NMR, XRD, XRF, PIXE, MALDI-TOF, LIBS, 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 50+ baseline correction algorithms. These include popular algorithms,
such as AsLS, airPLS, ModPoly, and SNIP, as well as many lesser known algorithms. Most
algorithms are adapted directly from literature, although there are a few that are unique
to pybaselines, such as penalized spline versions of Whittaker-smoothing-based algorithms.
The full list of implemented algorithms can be found in the
`documentation <https://pybaselines.readthedocs.io/en/latest/api/Baseline.html>`_.


Installation
------------

Stable Release
~~~~~~~~~~~~~~

pybaselines can be installed from `pypi <https://pypi.org/project/pybaselines>`_
using `pip <https://pip.pypa.io>`_, by running the following command in the terminal:

.. code-block:: console

    pip install pybaselines

pybaselines can alternatively be installed from the
`conda-forge <https://anaconda.org/conda-forge/pybaselines>`_ channel using conda by running:

.. code-block:: console

    conda install -c conda-forge pybaselines


Development Version
~~~~~~~~~~~~~~~~~~~

The sources for pybaselines can be downloaded from the `GitHub repo`_.
To install the current version of pybaselines from GitHub, run:

.. code-block:: console

    pip install git+https://github.com/derb12/pybaselines.git


.. _GitHub repo: https://github.com/derb12/pybaselines


Dependencies
~~~~~~~~~~~~

pybaselines requires `Python <https://python.org>`_ version 3.9 or later
and the following libraries:

* `NumPy <https://numpy.org>`_
* `SciPy <https://scipy.org>`_


All of the required libraries should be automatically installed when
installing pybaselines using any of the installation methods above.

The `optional dependencies <https://pybaselines.readthedocs.io/en/latest/installation.html#optional-dependencies>`_
for pybaselines are listed in the documentation . To also install the optional
dependencies when installing pybaselines with pip, run:

.. code-block:: console

    pip install pybaselines[full]

If installing with conda, the optional dependencies have to be specified manually.

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. The main interface for all baseline correction
algorithms in pybaselines is through the ``Baseline`` object for one dimensional
data and ``Baseline2D`` for two dimensional data.

For more details on each baseline algorithm, refer to the `algorithms section`_ of
pybaselines's documentation. For examples of their usage, refer to the `examples section`_.

.. _algorithms section: https://pybaselines.readthedocs.io/en/latest/algorithms/index.html

.. _examples section: https://pybaselines.readthedocs.io/en/latest/examples/index.html

A simple example is shown below.

.. code-block:: python

    import matplotlib.pyplot as plt
    import numpy as np
    from pybaselines import Baseline, 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)
    noise = np.random.default_rng(1).normal(0, 0.2, x.size)

    y = signal + true_baseline + noise

    baseline_fitter = Baseline(x_data=x)

    bkg_1, params_1 = baseline_fitter.modpoly(y, poly_order=3)
    bkg_2, params_2 = baseline_fitter.asls(y, lam=1e7, p=0.02)
    bkg_3, params_3 = baseline_fitter.mor(y, half_window=30)
    bkg_4, params_4 = baseline_fitter.snip(
        y, max_half_window=40, decreasing=True, smooth_half_window=3
    )

    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.

.. image:: https://github.com/derb12/pybaselines/raw/main/docs/images/quickstart.jpg
   :align: center
   :alt: various baselines


Contributing
------------

Contributions are welcomed and greatly appreciated. For information on
submitting bug reports, pull requests, or general feedback, please refer
to the `contributing guide`_.

.. _contributing guide: https://github.com/derb12/pybaselines/tree/main/docs/contributing.rst


Changelog
---------

Refer to the changelog_ for information on pybaselines's changes.

.. _changelog: https://github.com/derb12/pybaselines/tree/main/CHANGELOG.rst


License
-------

pybaselines is open source and freely available under the BSD-3-Clause license.
For more information, refer to the license_.

.. _license: https://github.com/derb12/pybaselines/tree/main/LICENSE.txt


Citing
------

If you use pybaselines for published research, please consider citing
by following the `guidelines in the documentation
<https://pybaselines.readthedocs.io/en/latest/citing.html>`_.


Author
------

* Donald Erb <donnie.erb@gmail.com>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pybaselines",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "background, baseline, baseline correction, baseline subtraction, chemistry, materials characterization, materials science, raman, spectroscopy",
    "author": null,
    "author_email": "Donald Erb <donnie.erb@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/7b/45/60ed7d059023b45eb45a4279356379d13ef883b7efd1c48242e0c1a30d3a/pybaselines-1.2.1.tar.gz",
    "platform": null,
    "description": "===========\npybaselines\n===========\n\n.. image:: https://github.com/derb12/pybaselines/raw/main/docs/images/logo.png\n    :alt: Logo\n    :align: center\n\n.. image:: https://img.shields.io/pypi/v/pybaselines.svg\n    :target: https://pypi.python.org/pypi/pybaselines\n    :alt: Current Pypi Version\n\n.. image:: https://img.shields.io/conda/vn/conda-forge/pybaselines.svg\n    :target: https://anaconda.org/conda-forge/pybaselines\n    :alt: Current conda Version\n\n.. image:: https://github.com/derb12/pybaselines/actions/workflows/python-test.yml/badge.svg\n    :target: https://github.com/derb12/pybaselines/actions\n    :alt: GitHub Actions test status\n\n.. image:: https://readthedocs.org/projects/pybaselines/badge/?version=latest\n    :target: https://pybaselines.readthedocs.io\n    :alt: Documentation Status\n\n.. image:: https://img.shields.io/pypi/pyversions/pybaselines.svg\n    :target: https://pypi.python.org/pypi/pybaselines\n    :alt: Supported Python versions\n\n.. image:: https://zenodo.org/badge/350510397.svg\n    :target: https://zenodo.org/badge/latestdoi/350510397\n    :alt: Zenodo DOI\n\npybaselines is a library of algorithms for the baseline correction of experimental data.\n\n* For Python 3.9 or later\n* Open Source: BSD 3-Clause License\n* Source Code: https://github.com/derb12/pybaselines\n* Documentation: https://pybaselines.readthedocs.io.\n\n\n.. contents:: **Contents**\n    :depth: 1\n\n\nIntroduction\n------------\n\npybaselines is a Python library that provides many different algorithms for\nperforming baseline correction on data from experimental techniques such as\nRaman, FTIR, NMR, XRD, XRF, PIXE, MALDI-TOF, LIBS, etc. The aim of the project is\nto provide a semi-unified API to allow quickly testing and comparing multiple baseline\ncorrection algorithms to find the best one for a set of data.\n\npybaselines has 50+ baseline correction algorithms. These include popular algorithms,\nsuch as AsLS, airPLS, ModPoly, and SNIP, as well as many lesser known algorithms. Most\nalgorithms are adapted directly from literature, although there are a few that are unique\nto pybaselines, such as penalized spline versions of Whittaker-smoothing-based algorithms.\nThe full list of implemented algorithms can be found in the\n`documentation <https://pybaselines.readthedocs.io/en/latest/api/Baseline.html>`_.\n\n\nInstallation\n------------\n\nStable Release\n~~~~~~~~~~~~~~\n\npybaselines can be installed from `pypi <https://pypi.org/project/pybaselines>`_\nusing `pip <https://pip.pypa.io>`_, by running the following command in the terminal:\n\n.. code-block:: console\n\n    pip install pybaselines\n\npybaselines can alternatively be installed from the\n`conda-forge <https://anaconda.org/conda-forge/pybaselines>`_ channel using conda by running:\n\n.. code-block:: console\n\n    conda install -c conda-forge pybaselines\n\n\nDevelopment Version\n~~~~~~~~~~~~~~~~~~~\n\nThe sources for pybaselines can be downloaded from the `GitHub repo`_.\nTo install the current version of pybaselines from GitHub, run:\n\n.. code-block:: console\n\n    pip install git+https://github.com/derb12/pybaselines.git\n\n\n.. _GitHub repo: https://github.com/derb12/pybaselines\n\n\nDependencies\n~~~~~~~~~~~~\n\npybaselines requires `Python <https://python.org>`_ version 3.9 or later\nand the following libraries:\n\n* `NumPy <https://numpy.org>`_\n* `SciPy <https://scipy.org>`_\n\n\nAll of the required libraries should be automatically installed when\ninstalling pybaselines using any of the installation methods above.\n\nThe `optional dependencies <https://pybaselines.readthedocs.io/en/latest/installation.html#optional-dependencies>`_\nfor pybaselines are listed in the documentation . To also install the optional\ndependencies when installing pybaselines with pip, run:\n\n.. code-block:: console\n\n    pip install pybaselines[full]\n\nIf installing with conda, the optional dependencies have to be specified manually.\n\nQuick Start\n-----------\n\nTo use the various functions in pybaselines, simply input the measured\ndata and any required parameters. All baseline correction functions in pybaselines\nwill output two items: a numpy array of the calculated baseline and a\ndictionary of potentially useful parameters. The main interface for all baseline correction\nalgorithms in pybaselines is through the ``Baseline`` object for one dimensional\ndata and ``Baseline2D`` for two dimensional data.\n\nFor more details on each baseline algorithm, refer to the `algorithms section`_ of\npybaselines's documentation. For examples of their usage, refer to the `examples section`_.\n\n.. _algorithms section: https://pybaselines.readthedocs.io/en/latest/algorithms/index.html\n\n.. _examples section: https://pybaselines.readthedocs.io/en/latest/examples/index.html\n\nA simple example is shown below.\n\n.. code-block:: python\n\n    import matplotlib.pyplot as plt\n    import numpy as np\n    from pybaselines import Baseline, utils\n\n    x = np.linspace(1, 1000, 1000)\n    # a measured signal containing several Gaussian peaks\n    signal = (\n        utils.gaussian(x, 4, 120, 5)\n        + utils.gaussian(x, 5, 220, 12)\n        + utils.gaussian(x, 5, 350, 10)\n        + utils.gaussian(x, 7, 400, 8)\n        + utils.gaussian(x, 4, 550, 6)\n        + utils.gaussian(x, 5, 680, 14)\n        + utils.gaussian(x, 4, 750, 12)\n        + utils.gaussian(x, 5, 880, 8)\n    )\n    # exponentially decaying baseline\n    true_baseline = 2 + 10 * np.exp(-x / 400)\n    noise = np.random.default_rng(1).normal(0, 0.2, x.size)\n\n    y = signal + true_baseline + noise\n\n    baseline_fitter = Baseline(x_data=x)\n\n    bkg_1, params_1 = baseline_fitter.modpoly(y, poly_order=3)\n    bkg_2, params_2 = baseline_fitter.asls(y, lam=1e7, p=0.02)\n    bkg_3, params_3 = baseline_fitter.mor(y, half_window=30)\n    bkg_4, params_4 = baseline_fitter.snip(\n        y, max_half_window=40, decreasing=True, smooth_half_window=3\n    )\n\n    plt.plot(x, y, label='raw data', lw=1.5)\n    plt.plot(x, true_baseline, lw=3, label='true baseline')\n    plt.plot(x, bkg_1, '--', label='modpoly')\n    plt.plot(x, bkg_2, '--', label='asls')\n    plt.plot(x, bkg_3, '--', label='mor')\n    plt.plot(x, bkg_4, '--', label='snip')\n\n    plt.legend()\n    plt.show()\n\n\nThe above code will produce the image shown below.\n\n.. image:: https://github.com/derb12/pybaselines/raw/main/docs/images/quickstart.jpg\n   :align: center\n   :alt: various baselines\n\n\nContributing\n------------\n\nContributions are welcomed and greatly appreciated. For information on\nsubmitting bug reports, pull requests, or general feedback, please refer\nto the `contributing guide`_.\n\n.. _contributing guide: https://github.com/derb12/pybaselines/tree/main/docs/contributing.rst\n\n\nChangelog\n---------\n\nRefer to the changelog_ for information on pybaselines's changes.\n\n.. _changelog: https://github.com/derb12/pybaselines/tree/main/CHANGELOG.rst\n\n\nLicense\n-------\n\npybaselines is open source and freely available under the BSD-3-Clause license.\nFor more information, refer to the license_.\n\n.. _license: https://github.com/derb12/pybaselines/tree/main/LICENSE.txt\n\n\nCiting\n------\n\nIf you use pybaselines for published research, please consider citing\nby following the `guidelines in the documentation\n<https://pybaselines.readthedocs.io/en/latest/citing.html>`_.\n\n\nAuthor\n------\n\n* Donald Erb <donnie.erb@gmail.com>\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A library of algorithms for the baseline correction of experimental data.",
    "version": "1.2.1",
    "project_urls": {
        "Documentation": "https://pybaselines.readthedocs.io",
        "Homepage": "https://github.com/derb12/pybaselines"
    },
    "split_keywords": [
        "background",
        " baseline",
        " baseline correction",
        " baseline subtraction",
        " chemistry",
        " materials characterization",
        " materials science",
        " raman",
        " spectroscopy"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3d66f044d53935b142d47ce2a65b8c4f51fdb5ca85ee1035fb2b7857971b122e",
                "md5": "62dd77704aa135bc4e7cb9b35edd8171",
                "sha256": "d8f224a0b5ac4cdcef861bc60533131c37255b4d1193f18a410bc37fe5217c73"
            },
            "downloads": -1,
            "filename": "pybaselines-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "62dd77704aa135bc4e7cb9b35edd8171",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 211891,
            "upload_time": "2025-08-10T20:39:56",
            "upload_time_iso_8601": "2025-08-10T20:39:56.813520Z",
            "url": "https://files.pythonhosted.org/packages/3d/66/f044d53935b142d47ce2a65b8c4f51fdb5ca85ee1035fb2b7857971b122e/pybaselines-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7b4560ed7d059023b45eb45a4279356379d13ef883b7efd1c48242e0c1a30d3a",
                "md5": "306495903c616462eccf1d66f27b4b28",
                "sha256": "5cae63e00cc9f469e446d05e64c731b87a54dbfd9b70ef049e46cf80fc91ad1a"
            },
            "downloads": -1,
            "filename": "pybaselines-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "306495903c616462eccf1d66f27b4b28",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 340155,
            "upload_time": "2025-08-10T20:39:58",
            "upload_time_iso_8601": "2025-08-10T20:39:58.277803Z",
            "url": "https://files.pythonhosted.org/packages/7b/45/60ed7d059023b45eb45a4279356379d13ef883b7efd1c48242e0c1a30d3a/pybaselines-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-10 20:39:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "derb12",
    "github_project": "pybaselines",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pybaselines"
}
        
Elapsed time: 0.80921s