{"id":17797103,"url":"https://github.com/anselmoo/spectrafit","last_synced_at":"2025-11-25T20:07:18.930Z","repository":{"id":37868191,"uuid":"387851926","full_name":"Anselmoo/spectrafit","owner":"Anselmoo","description":"📊📈🔬 SpectraFit is a command-line and Jupyter-notebook tool for quick data-fitting based on the regular expression of distribution functions.","archived":false,"fork":false,"pushed_at":"2025-03-31T11:05:29.000Z","size":567239,"stargazers_count":26,"open_issues_count":8,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-01T22:41:35.258Z","etag":null,"topics":["console-application","curve-fitting","data-analysis","data-analysis-python","data-science","data-visualization","fitting","juypter-notebook","python","science","science-research","scientific-plotting","spectral-analysis","spectroscopy"],"latest_commit_sha":null,"homepage":"https://anselmoo.github.io/spectrafit/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Anselmoo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-20T16:29:27.000Z","updated_at":"2025-03-30T00:08:38.000Z","dependencies_parsed_at":"2023-10-16T22:43:01.027Z","dependency_job_id":"441f9046-e998-4a5a-8a81-43c8236b9fdb","html_url":"https://github.com/Anselmoo/spectrafit","commit_stats":{"total_commits":1482,"total_committers":11,"mean_commits":"134.72727272727272","dds":"0.48043184885290147","last_synced_commit":"132ba95864b3a5657066114dc11988cf442ff3fb"},"previous_names":[],"tags_count":118,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anselmoo%2Fspectrafit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anselmoo%2Fspectrafit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anselmoo%2Fspectrafit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anselmoo%2Fspectrafit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Anselmoo","download_url":"https://codeload.github.com/Anselmoo/spectrafit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018060,"owners_count":21034048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["console-application","curve-fitting","data-analysis","data-analysis-python","data-science","data-visualization","fitting","juypter-notebook","python","science","science-research","scientific-plotting","spectral-analysis","spectroscopy"],"created_at":"2024-10-27T11:50:56.467Z","updated_at":"2025-11-25T20:07:18.898Z","avatar_url":"https://github.com/Anselmoo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI - Python Package](https://github.com/Anselmoo/spectrafit/actions/workflows/python-ci.yml/badge.svg?branch=main)](https://github.com/Anselmoo/spectrafit/actions/workflows/python-ci.yml)\n[![codecov](https://codecov.io/gh/Anselmoo/spectrafit/branch/main/graph/badge.svg?token=pNIMKwWsO2)](https://codecov.io/gh/Anselmoo/spectrafit)\n[![PyPI](https://img.shields.io/pypi/v/spectrafit?logo=PyPi\u0026logoColor=yellow)](https://pypi.org/project/spectrafit/)\n[![Conda](https://img.shields.io/conda/v/conda-forge/spectrafit?label=Anaconda.org\u0026logo=anaconda)](https://github.com/conda-forge/spectrafit-feedstock)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/spectrafit?color=gree\u0026logo=Python\u0026logoColor=yellow)](https://pypi.org/project/spectrafit/)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Anselmoo/spectrafit/main.svg)](https://results.pre-commit.ci/latest/github/Anselmoo/spectrafit/main)\n[![doi](https://img.shields.io/badge/10.1021/acsomega.3c09262-blue?logo=DOI\u0026logoColor=white)](https://pubs.acs.org/doi/full/10.1021/acsomega.3c09262)\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/Anselmoo/spectrafit/blob/c5f7ee05e5610fb8ef4e237a88f62977b6f832e5/docs/images/spectrafit_synopsis.png?raw=true\"\u003e\n\u003c/p\u003e\n\n# SpectraFit\n\n---\n\n\u003e Data Analysis Tool for All Kinds of Spectra\n\n`SpectraFit` is a Python tool for quick data fitting based on the regular\nexpression of distribution and linear functions via the command line (CMD) or\n[Jupyter Notebook](https://jupyter.org) It is designed to be easy to use and\nsupports all common ASCII data formats. SpectraFit runs on **Linux**,\n**Windows**, and **MacOS**.\n\n## Scope\n\n- Fitting of 2D data, also with multiple columns as _global fitting_\n- Using established and advanced solver methods\n- Extensibility of the fitting function\n- Guarantee traceability of the fitting results\n- Saving all results in a _SQL-like-format_ (`CSV`) for publications\n- Saving all results in a _NoSQL-like-format_ (`JSON`) for project management\n- Having an API interface for Graph-databases\n\n`SpectraFit` is a tool designed for researchers and scientists who require\nimmediate data fitting to a model. It proves to be especially beneficial for\nindividuals working with vast datasets or who need to conduct numerous fits\nwithin a limited time frame. `SpectraFit's` adaptability to various platforms\nand data formats makes it a versatile tool that caters to a broad spectrum of\nscientific applications.\n\n## Installation\n\nvia pip:\n\n```bash\npip install spectrafit\n\n# with support for Jupyter Notebook\n\npip install spectrafit[jupyter]\n\n# with support for the dashboard in the Jupyter Notebook\n\npip install spectrafit[jupyter-dash]\n\n# with support to visualize pkl-files as graph\n\npip install spectrafit[graph]\n\n# with all upcomming features\n\npip install spectrafit[all]\n\n# Upgrade\n\npip install spectrafit --upgrade\n```\n\nvia conda, see also\n[conda-forge](https://github.com/conda-forge/spectrafit-feedstock):\n\n```bash\nconda install -c conda-forge spectrafit\n\n# with support for Jupyter Notebook\n\nconda install -c conda-forge spectrafit-jupyter\n\n# with all upcomming features\n\nconda install -c conda-forge spectrafit-all\n```\n\n## Usage\n\n`SpectraFit` needs as command line tool only two things:\n\n1. The reference data, which should be fitted.\n2. The input file, which contains the initial model.\n\nAs model files [json](https://en.wikipedia.org/wiki/JSON),\n[toml](https://en.wikipedia.org/wiki/TOML), and\n[yaml](https://en.wikipedia.org/wiki/YAML) are supported. By making use of the\npython `**kwargs` feature, the input file can call most of the following\nfunctions of [LMFIT](https://lmfit.github.io/lmfit-py/index.html). LMFIT is the\nworkhorse for the fit optimization, which is macro wrapper based on:\n\n1. [NumPy](https://www.numpy.org/)\n2. [SciPy](https://www.scipy.org/)\n3. [uncertainties](https://pythonhosted.org/uncertainties/)\n\nIn case of `SpectraFit`, we have further extend the package by:\n\n1. [Pandas](https://pandas.pydata.org/)\n2. [statsmodels](https://www.statsmodels.org/stable/index.html)\n3. [numdifftools](https://github.com/pbrod/numdifftools)\n4. [Matplotlib](https://matplotlib.org/) in combination with\n   [Seaborn](https://seaborn.pydata.org/)\n\n```bash\nspectrafit data_file.txt -i input_file.json\n```\n\n```bash\nusage: spectrafit [-h] [-o OUTFILE] [-i INPUT] [-ov] [-e0 ENERGY_START]\n                  [-e1 ENERGY_STOP] [-s SMOOTH] [-sh SHIFT] [-c COLUMN COLUMN]\n                  [-sep {       ,,,;,:,|, ,s+}] [-dec {.,,}] [-hd HEADER]\n                  [-g {0,1,2}] [-auto] [-np] [-v] [-vb {0,1,2}]\n                  infile\n\nFast Fitting Program for ascii txt files.\n\npositional arguments:\n  infile                Filename of the spectra data\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -o OUTFILE, --outfile OUTFILE\n                        Filename for the export, default to set to\n                        'spectrafit_results'.\n  -i INPUT, --input INPUT\n                        Filename for the input parameter, default to set to\n                        'fitting_input.toml'.Supported fileformats are:\n                        '*.json', '*.yml', '*.yaml', and '*.toml'\n  -ov, --oversampling   Oversampling the spectra by using factor of 5;\n                        default to False.\n  -e0 ENERGY_START, --energy_start ENERGY_START\n                        Starting energy in eV; default to start of energy.\n  -e1 ENERGY_STOP, --energy_stop ENERGY_STOP\n                        Ending energy in eV; default to end of energy.\n  -s SMOOTH, --smooth SMOOTH\n                        Number of smooth points for lmfit; default to 0.\n  -sh SHIFT, --shift SHIFT\n                        Constant applied energy shift; default to 0.0.\n  -c COLUMN COLUMN, --column COLUMN COLUMN\n                        Selected columns for the energy- and intensity-values;\n                        default to '0' for energy (x-axis) and '1' for intensity\n                        (y-axis). In case of working with header, the column\n                        should be set to the column names as 'str'; default\n                        to 0 and 1.\n  -sep { ,,,;,:,|, ,s+}, --separator { ,,,;,:,|, ,s+}\n                        Redefine the type of separator; default to ' '.\n  -dec {.,,}, --decimal {.,,}\n                        Type of decimal separator; default to '.'.\n  -hd HEADER, --header HEADER\n                        Selected the header for the dataframe; default to None.\n  -cm COMMENT, --comment COMMENT\n                        Lines with comment characters like '#' should not be\n                        parsed; default to None.\n  -g {0,1,2}, --global_ {0,1,2}\n                        Perform a global fit over the complete dataframe. The\n                        options are '0' for classic fit (default). The\n                        option '1' for global fitting with auto-definition\n                        of the peaks depending on the column size and '2'\n                        for self-defined global fitting routines.\n  -auto, --autopeak     Auto detection of peaks in the spectra based on `SciPy`.\n                        The position, height, and width are used as estimation\n                        for the `Gaussian` models.The default option is 'False'\n                        for  manual peak definition.\n  -np, --noplot         No plotting the spectra and the fit of `SpectraFit`.\n  -v, --version         Display the current version of `SpectraFit`.\n  -vb {0,1,2}, --verbose {0,1,2}\n                        Display the initial configuration parameters and fit\n                        results, as a table '1', as a dictionary '2', or not in\n                        the terminal '0'. The default option is set to 1 for\n                        table `printout`.\n```\n\n### Jupyter Notebook\n\nOpen the `Jupyter Notebook` and run the following code:\n\n```bash\nspectrafit-jupyter\n```\n\nor via Docker Image for `\u003ccpu\u003e` with `amd64` and `arm64`:\n\n```bash\ndocker pull ghcr.io/anselmoo/spectrafit-\u003ccpu\u003e:latest\ndocker run -it -p 8888:8888 spectrafit-\u003ccpu\u003e:latest\n```\n\nor just:\n\n```bash\ndocker run -p 8888:8888 ghcr.io/anselmoo/spectrafit-\u003ccpu\u003e:latest\n```\n\nNext define your initial model and the reference data:\n\n```python\nfrom spectrafit.plugins.notebook import SpectraFitNotebook\nimport pandas as pd\n\ndf = pd.read_csv(\n    \"https://raw.githubusercontent.com/Anselmoo/spectrafit/main/Examples/data.csv\"\n)\n\ninitial_model = [\n    {\n        \"pseudovoigt\": {\n            \"amplitude\": {\"max\": 2, \"min\": 0, \"vary\": True, \"value\": 1},\n            \"center\": {\"max\": 2, \"min\": -2, \"vary\": True, \"value\": 0},\n            \"fwhmg\": {\"max\": 0.4, \"min\": 0.1, \"vary\": True, \"value\": 0.21},\n            \"fwhml\": {\"max\": 0.4, \"min\": 0.1, \"vary\": True, \"value\": 0.21},\n        }\n    },\n    {\n        \"pseudovoigt\": {\n            \"amplitude\": {\"max\": 2, \"min\": 0, \"vary\": True, \"value\": 1},\n            \"center\": {\"max\": 2, \"min\": -2, \"vary\": True, \"value\": 1},\n            \"fwhmg\": {\"max\": 0.4, \"min\": 0.1, \"vary\": True, \"value\": 0.21},\n            \"fwhml\": {\"max\": 0.4, \"min\": 0.1, \"vary\": True, \"value\": 0.21},\n        }\n    },\n    {\n        \"pseudovoigt\": {\n            \"amplitude\": {\"max\": 2, \"min\": 0, \"vary\": True, \"value\": 1},\n            \"center\": {\"max\": 2, \"min\": -2, \"vary\": True, \"value\": 1},\n            \"fwhmg\": {\"max\": 0.4, \"min\": 0.1, \"vary\": True, \"value\": 0.21},\n            \"fwhml\": {\"max\": 0.4, \"min\": 0.1, \"vary\": True, \"value\": 0.21},\n        }\n    },\n]\nspf = SpectraFitNotebook(df=df, x_column=\"Energy\", y_column=\"Noisy\")\nspf.solver_model(initial_model)\n```\n\nWhich results in the following output:\n\n![img_jupyter](https://github.com/Anselmoo/spectrafit/blob/8962a277b0c3d2aa05970617f0ac323a07de2fec/docs/images/jupyter_plot.png?raw=true)\n\n## Documentation\n\nPlease see the [extended documentation](https://anselmoo.github.io/spectrafit/)\nfor the full usage of `SpectraFit`.\n\nThe documentation is generated by\n\u003ca href=\"https://squidfunk.github.io/mkdocs-material/\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Material_for_MkDocs-526CFE?style=for-the-badge\u0026logo=MaterialForMkDocs\u0026logoColor=white\" alt=\"Built with Material for MkDocs\" style=\"vertical-align: middle; height: 20px;\"\u003e\n\u003c/a\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanselmoo%2Fspectrafit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanselmoo%2Fspectrafit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanselmoo%2Fspectrafit/lists"}