Fit 2D time- and energy-resolved spectroscopy data
Project description
trspecfit — 2D Time- and Energy-resolved Spectroscopy Fitting
A Python library for fitting multi-component spectral models to time-resolved spectroscopy data.
trspecfit is a Python library to define and fit multi-component spectral models for 1D energy-resolved and 2D time-and-energy-resolved spectroscopy data. The package extends lmfit-based workflows to support component-based models, time-dynamics, convolution kernels and helpers for generating simulated data.
Key capabilities
- Define modular spectral components (Gaussian, Voigt/GLP/GLS, Doniach–Sunjic, backgrounds, convolution kernels).
- Build 1D (energy) and 2D (time × energy) spectra from components and attach time-dynamics to individual model parameters.
- Fit models with lmfit and wrappers for confidence intervals and optional MCMC sampling (lmfit.emcee).
- Simulate individual 1D/2D spectra to validate models, sets of spectra with noise to validate fits.
- Generate ML training data via parameter space exploration and model simulation with/out noise.
Repository layout
src/trspecfit/— library source code (core engine, functions, and utils)examples/— Jupyter notebooks and YAML model files that demonstrate usagetests/— pytest unit tests for core functionalitypyproject.toml— project metadata and dependency declaration
Installation
Install from GitHub
pip install git+https://github.com/InfinityMonkeyAtWork/time-resolved-spectroscopy-fit.git
Install for development
For local development, clone the repository and install in editable mode:
Windows PowerShell example:
python -m venv .venv
.\.venv\Scripts\Activate
pip install -U pip
pip install -e .
macOS / Linux example:
python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e .
Example Jupyter notebooks and YAML files
Open the notebooks in examples/ for runnable examples:
examples/simple_model/example.ipynb— basic usage example (NOT implemented)examples/dependent_parameters/example.ipynb— parameters of one peak depend on another peakexamples/subcycles/example.ipynb— multiple subcycles inside one pump-probe cycleexamples/simulator/example.ipynb— simulate (noisy) datasets based on your model inputexamples/simulator/ml_training_data_gen.ipynb— sample model parameter space and create (noisy) datasets
Fitting
Use trspecfit.fitlib.residual_fun together with fitlib.fit_wrapper to run
fits using lmfit. The wrapper supports sequential optimization, lmfit.conf_interval
and optional MCMC sampling with lmfit.emcee for robust uncertainty estimates.
Simulator
Generate synthetic data with realistic noise models. The simulator supports:
- 1D spectrum generation: Single energy-resolved spectra at specific time points
- 2D spectrum generation: Complete time- and energy-resolved datasets
- Multiple noise realizations: Generate N independent noisy datasets from the same model for statistical analysis
- Systematic parameter space exploration: Generate ML training datasets by sweeping model parameters through user-defined ranges or distributions
The simulator supports two detector types:
- Analog detectors (CCD, photodiode, lock-in): Continuous signals with Gaussian or Poisson noise
- Photon counting (APD, PMT, event mode): Discrete photon events with shot noise
See examples/simulator/ for complete examples (basic usage: example.ipynb, ML data generation: ml_training_data_gen.ipynb).
Testing
Run the unit tests with pytest (from the project root):
pip install pytest
pytest -q
Plotting with PlotConfig
Use PlotConfig to manage plot settings consistently across your project.
Basic Usage
from trspecfit import PlotConfig
from trspecfit.utils import plot as uplt
# Create config with custom settings
config = PlotConfig(x_label='Energy (eV)', x_dir='rev', dpi_plot=150)
uplt.plot_1D(data, x, config=config)
Using Project Settings
Load settings from your project.yaml file:
from trspecfit import Project, PlotConfig
project = Project(path='my_project', config_file='project.yaml')
config = PlotConfig.from_project(project)
# All plots use project settings
uplt.plot_1D(data, x, config=config)
uplt.plot_2D(data, x, y, config=config)
Quick Overrides
Override specific settings without creating a new config:
config = PlotConfig.from_project(project)
uplt.plot_1D(data, x, config=config, x_dir='rev', colors=['red', 'blue'])
Multiple Configurations
Create different configs for different purposes:
default_config = PlotConfig.from_project(project)
pub_config = PlotConfig.from_project(project, dpi_save=600, dpi_plot=150)
talk_config = PlotConfig.from_project(project, ticksize=14)
Copyright Notice
time-resolved spectroscopy fit (trspecfit) Copyright (c) 2025, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
If you have questions about your rights to use or distribute this software, please contact Berkeley Lab's Intellectual Property Office at IPO@lbl.gov.
NOTICE. This Software was developed under funding from the U.S. Department of Energy and the U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform publicly and display publicly, and to permit others to do so.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trspecfit-0.3.7.tar.gz.
File metadata
- Download URL: trspecfit-0.3.7.tar.gz
- Upload date:
- Size: 1.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f25ec72728fc55db6cf1e2990f1e41e8930259dc4f015e33c57325a25555ff4a
|
|
| MD5 |
daf2f5d3c2311ba77e73671eba21dae6
|
|
| BLAKE2b-256 |
d3ebd94fcb460b7aaf0fa96fcde25063b25e8e0f4a7a763b44147619725a9c8e
|
File details
Details for the file trspecfit-0.3.7-py3-none-any.whl.
File metadata
- Download URL: trspecfit-0.3.7-py3-none-any.whl
- Upload date:
- Size: 102.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ead612b312e98116c3eab4c25731b4e177cfc10455433edff10c6b48b10837f
|
|
| MD5 |
11799b26d0663a8f21186fcee315614a
|
|
| BLAKE2b-256 |
92c0fc6cee1f3e86a1b910e1efa66621cf92cf9468163cb976fd21f4c1aaaf8e
|