Skip to main content

Fitspy: a generic tool to fit spectra in python

Project description

PyPI Github Doc DOI status

Fitspy is a generic tool dedicated to fit spectra in python with GUIs that aims to be as simple and intuitive to use as possible.

Illustration of the PySide GUI (left) and Tkinter GUI (right).

Processed spectra may be independent of each other or may result from 2D-maps acquisitions.


Example of fitspy 2D-map frame interacting with the main GUI.

Demo

The predefined peak models considered in Fitspy are Gaussian, Lorentzian, Asymetric Gaussian, Asymetric Lorentzian and Pseudovoigt.

A Constant, Linear, Parabolic, Exponential or Power Law background model can also be added in the fitting.

In both cases, user-defined models can be added, for instance in XRD or XRF, to fit peaks resulting from bichromatic sources, as explained here

Fitspy main features:

  • Fitspy uses the lmfit library to fit the spectra
  • The fit processing can be multi-threaded
  • Bounds and constraints can be set on each peaks models parameter
  • From an automatic noise level estimation, according to the local noise, peak models can be automatically deactivated
  • Fitspy also includes automatic outlier detection to be excluded during the fitting process

All actions allowed with the GUI can be executed in script mode (see examples here). These actions (like baseline and peaks definition, parameters constraints, ...) can be saved in a Fitspy model and replayed as-is or applied to other new spectra datasets.

Installation

From PyPI (recommended)

pip install fitspy

From GitHub (latest version)

pip install git+https://github.com/CEA-MetroCarac/fitspy

(See the documentation for more details)

Tests and examples execution

pip install pytest
git clone https://github.com/CEA-MetroCarac/fitspy.git
cd fitspy
pytest
python examples/ex_gui_auto_decomposition.py
python examples/ex_.......

(See the documentation for more details)

Quick start

Since its 2025.1 version, Fitspy can be launched using two interfaces: either the one corresponding to the original GUI built with Tkinter, or a more recent and advanced one, using PySide. As of 2025, both GUIs offer nearly identical features, but future efforts regarding fixes and updates will primarily focus on the PySide GUI.

PySide GUI:

Launch the application:

fitspy

From the right to the left, select the files to work with (considering the drag and drop capabilities). Then, use the Model panel to set the model parameters to be used during the fitting process. Peaks and an optional baseline associated with the model can be defined interactively by clicking on the desired position in the figure after activating Peak points (or Baseline points resp.) from the Click Mode radiobuttons located under the figure. Once the model build, The Fit can be launched. The corresponding model can be saved (in the Model panel) to be reload later (from the bottom-central panel) as-it with the same spectra (if the pathnames are still available) or just as a model for other spectra to be processed.

Tkinter GUI:

Launch the application:

fitspy-tk

From the top to the bottom of the right panel:

  • Select file(s)
  • (Optional) Define the X-range
  • Define the baseline to subtract (left or right click on the figure to add or delete (resp.) a baseline point)
  • (Optional) Normalize the spectrum/spectra
  • Click on the Fitting panel to activate it
  • Select Peak model and add peaks (left or right click on the figure to add or delete (resp.) a peak)
  • (Optional) Add a background (BKG model) to be fitted
  • (Optional) Use Parameters to set bounds and constraints
  • Fit the selected spectrum/spectra
  • (Optional) Save the parameters in .csv format
  • (Optional) Save the Model in a .json file (to be replayed later)

(See the documentation for more details)

Acknowledgements

This work, carried out on the CEA - Platform for Nanocharacterisation (PFNC), was supported by the “Recherche Technologique de Base” program of the French National Research Agency (ANR).

Warm thanks to the JOSS reviewers (@maurov and @FCMeng) and editor (@phibeck) for their contributions to enhancing Fitspy.

Citations

In case you use the results of this code in an article, please cite:

  • Quéméré P., (2024). Fitspy: A python package for spectral decomposition. Journal of Open Source Software. doi: 10.21105/joss.05868

  • Newville M., (2014). LMFIT: Non-Linear Least-Square Minimization and Curve-Fitting for Python. Zenodo. doi: 10.5281/zenodo.11813.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fitspy-2025.4.tar.gz (18.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fitspy-2025.4-py3-none-any.whl (420.6 kB view details)

Uploaded Python 3

File details

Details for the file fitspy-2025.4.tar.gz.

File metadata

  • Download URL: fitspy-2025.4.tar.gz
  • Upload date:
  • Size: 18.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fitspy-2025.4.tar.gz
Algorithm Hash digest
SHA256 7e5f7df2d28dfb7b31c95587e2d4aebf83176254c23f596f4b47828a1e9b73b2
MD5 d2dee91d2e13169ca1c5b4af84c82610
BLAKE2b-256 9b85cea6e7afc956b0e99febd725ccac66ad629fa35f233992b719618e8f954f

See more details on using hashes here.

File details

Details for the file fitspy-2025.4-py3-none-any.whl.

File metadata

  • Download URL: fitspy-2025.4-py3-none-any.whl
  • Upload date:
  • Size: 420.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fitspy-2025.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f796f56c126229e941cf1d2a1bb57d7645d92267e31fac4a7c96f0e926153d3d
MD5 b338c29b06bbb7d450961f3eec8f0211
BLAKE2b-256 96ffafb14a0a7df2950024dea7ded99ac08bcfb9009289365cf6f780a3e15669

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page