Metadata-Version: 2.1
Name: fitspy
Version: 2024.5
Summary: Fitspy: a generic tool to fit spectra in python
Author-email: Patrick Quéméré <patrick.quemere@cea.fr>
License: GPL v3
Project-URL: Homepage, https://github.dev/CEA-MetroCarac/fitspy
Project-URL: Documentation, https://cea-metrocarac.github.io/fitspy/doc/index.html
Keywords: Fitspy,fit,spectra,spectrum,map,1D,2D,decomposition,Gaussian,Lorentzian,Pseudovoigt,GUI
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Environment :: Console
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: matplotlib
Requires-Dist: scipy
Requires-Dist: lmfit
Requires-Dist: parse
Requires-Dist: dill
Requires-Dist: rosettasciio
Requires-Dist: pywin32 ; platform_system == "Windows"

[![PyPI](https://badge.fury.io/py/fitspy.svg)](https://pypi.org/project/fitspy/)
[![Github](https://img.shields.io/badge/GitHub-GPL--3.0-informational)](https://github.com/CEA-MetroCarac/fitspy)
[![Doc](https://img.shields.io/badge/%F0%9F%95%AE-docs-green.svg)](https://cea-metrocarac.github.io/fitspy/doc/index.html)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10812333.svg)](https://doi.org/10.5281/zenodo.10812333)
[![status](https://joss.theoj.org/papers/971a02868d903c0b7c0cbc3d1cd3d139/status.svg)](https://joss.theoj.org/papers/971a02868d903c0b7c0cbc3d1cd3d139)


<p align="center" width="100%">
    <img align="center" width=250 src=https://cea-metrocarac.github.io/fitspy/logo.png>
</p>


**Fitspy** is a generic tool dedicated to **fit sp**ectra in **py**thon with a GUI that aims to be as simple and intuitive to use as possible.

<p align="center" width="100%">
    <img align="center" width="75%" src=https://cea-metrocarac.github.io/fitspy/fitspy.png>
</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`.

A `constant`, `linear`, `parabolic` or `exponential` 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](https://github.com/lmfit/lmfit-py) 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](https://github.com/CEA-MetroCarac/fitspy/tree/main/examples)).
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

```
pip install fitspy
```

*(See the [documentation](https://cea-metrocarac.github.io/fitspy/doc/user_guide/intro.html#install-and-launching) 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](https://cea-metrocarac.github.io/fitspy/doc/user_guide/intro.html#install-and-launching) for more details)*

## Quick start

Launch the application:

```
fitspy
```

Then, 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](https://cea-metrocarac.github.io/fitspy/doc/user_guide/workflow.html) 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](https://joss.theoj.org/) reviewers ([@maurov](https://github.com/maurov) and [@FCMeng](https://github.com/FCMeng)) and editor ([@phibeck](https://github.com/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](https://doi.org/10.21105/joss.05868)

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