Fitspy
Generic tool dedicated to fit spectra in python
Install / Use
/learn @CEA-MetroCarac/FitspyREADME
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.
<p align="center" width="100%"> <img align="center" width="45%" src="https://cea-metrocarac.github.io/fitspy/_static/pyside/fitspy.png"> <img align="center" width="45%" src="https://cea-metrocarac.github.io/fitspy/_static/tkinter/fitspy.png"> </p> <p align="center"> <em>Illustration of the PySide GUI (left) and Tkinter GUI (right).</em> </p>Processed spectra may be independent of each other or may result from 2D-maps acquisitions.
<p align="center" width="100%"> <img align="center" width="30%" src=https://cea-metrocarac.github.io/fitspy/2d-map.png> <br> <em>Example of fitspy 2D-map frame interacting with the main GUI.</em> </p>
The predefined peak models considered in Fitspy are Gaussian, Lorentzian, Asymetric Gaussian, Asymetric Lorentzian and Pseudovoigt. Some Bichromatic models related to bichromatic sources are also available as explained here
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.
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)
Upgrade
In the case of 'just' a Fitspy upgrade:
pip uninstall fitspy
pip install fistspy # considering here the install from Pypi
For a full upgrade (Fitspy and its dependencies):
pip install fitspy --upgrade # considering here the install from Pypi
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.
<u>PySide GUI</u>:
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.
<u>Tkinter GUI</u>:
Launch the application:
fitspy-tk
From the top to the bottom of the right panel:
Selectfile(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
Fittingpanel to activate it - Select
Peak modeland 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
Fitthe 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)
Reset GUI settings
For PySide GUI, settings are stored using QSettings (in registry on Windows, .ini files on Linux and MacOS). Fitspy provides a command line tool to list or reset these settings.
List current settings
python -m fitspy reset-settings --list
Reset settings to default values
python -m fitspy reset-settings
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.
Related Skills
claude-opus-4-5-migration
110.6kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
351.2kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
TrendRadar
51.1k⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。
mcp-for-beginners
15.8kThis open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
