# trspecfit examples

**trspecfit** fits multi-component spectral models to 1D energy-resolved and
2D time- and energy-resolved spectroscopy data: modular lineshapes, time
dynamics, convolution kernels, parameter profiles, and lmfit-based fitting
with confidence intervals and MCMC.

The pages here are the package's example notebooks, executed end to end, so
you can read the plots, fit reports and tables without installing anything.
They were run with trspecfit {{ trspecfit_version }} (git ref
{{ trspecfit_ref }}) on {{ build_date }}. Every page has a download button
for the executed notebook.

To run them yourself:

```bash
python -m pip install "trspecfit[lab]"
```

[Source on GitHub](https://github.com/InfinityMonkeyAtWork/time-resolved-spectroscopy-fit)
· [Documentation](https://time-resolved-spectroscopy-fit.readthedocs.io/)
· [PyPI](https://pypi.org/project/trspecfit/)

Pick the notebook that matches what you are trying to do; each one is
self-contained. The fitting workflows are numbered in blocks: 0x single-file
fitting skills, 1x post-fit work, 2x multi-file workflows.

% The example tables, the data generator list and the sidebar entries follow
% here at build time, generated by scripts/build_site.py from the examples
% tree (see its docstring for the layout it expects).

## Fitting workflows

| Notebook | What you learn |
|---|---|
| [01 basic fitting](examples/fitting_workflows/01_basic_fitting/example.ipynb) | Load data, define a model, fit baseline + 2D, visualize results. |
| [02 dependent parameters](examples/fitting_workflows/02_dependent_parameters/example.ipynb) | Link parameters with expressions and physical constraints. |
| [03 multi cycle dynamics](examples/fitting_workflows/03_multi_cycle_dynamics/example.ipynb) | Multi-cycle dynamics with subcycles and frequency. |
| [04 parameter profiles](examples/fitting_workflows/04_parameter_profiles/example.ipynb) | Depth-dependent parameters via profile functions (with optional time-dependence). |
| [10 model comparison](examples/fitting_workflows/10_model_comparison/example.ipynb) | Compare two models on the same file (baseline / SbS / 2D). |
| [11 save load export](examples/fitting_workflows/11_save_load_export/example.ipynb) | `FitResults` HDF5 round-trip, CSV/PNG export, "ship just the winners". |
| [12 uncertainty mcmc](examples/fitting_workflows/12_uncertainty_mcmc/example.ipynb) | Declare the noise model, then three tiers of parameter uncertainty — `stderr`, profiled CIs, and MCMC — checked against truth and the Cramér-Rao bound. |
| [13 missing noise model](examples/fitting_workflows/13_missing_noise_model/example.ipynb) | What the `unknown` default does to `stderr`, profiled CIs and MCMC on the same data as 12, and the Gaussian fallback. |
| [20 multi file independent fit](examples/fitting_workflows/20_multi_file_independent_fit/example.ipynb) | Multi-file workspace, per-file independent fits (bridge to shared-parameter fitting). |
| [21 multi file shared fit](examples/fitting_workflows/21_multi_file_shared_fit/example.ipynb) | Multi-file workspace, shared-parameter fits across files. |

## Synthetic data

| Notebook | What you learn |
|---|---|
| [01 simulator](examples/synthetic_data/01_simulator/example.ipynb) | Generate synthetic noisy data from a known ground truth. |
| [02 ml training data](examples/synthetic_data/02_ml_training_data/example.ipynb) | Sweep parameter space for ML training datasets. |

## Data generators

Some examples ship synthetic data made by a notebook in their `data/` directory from truth model files, which those pages show. The build re-runs the generators and checks that the regenerated data matches what the examples were fitted to.

- [01 basic fitting](examples/fitting_workflows/01_basic_fitting/data/generate_data.ipynb)
- [03 multi cycle dynamics](examples/fitting_workflows/03_multi_cycle_dynamics/data/generate_data.ipynb)
- [04 parameter profiles](examples/fitting_workflows/04_parameter_profiles/data/generate_data.ipynb)
- [21 multi file shared fit](examples/fitting_workflows/21_multi_file_shared_fit/data/generate_data.ipynb)

```{toctree}
:hidden:
:caption: Fitting workflows

01 basic fitting <examples/fitting_workflows/01_basic_fitting/example>
02 dependent parameters <examples/fitting_workflows/02_dependent_parameters/example>
03 multi cycle dynamics <examples/fitting_workflows/03_multi_cycle_dynamics/example>
04 parameter profiles <examples/fitting_workflows/04_parameter_profiles/example>
10 model comparison <examples/fitting_workflows/10_model_comparison/example>
11 save load export <examples/fitting_workflows/11_save_load_export/example>
12 uncertainty mcmc <examples/fitting_workflows/12_uncertainty_mcmc/example>
13 missing noise model <examples/fitting_workflows/13_missing_noise_model/example>
20 multi file independent fit <examples/fitting_workflows/20_multi_file_independent_fit/example>
21 multi file shared fit <examples/fitting_workflows/21_multi_file_shared_fit/example>
```

```{toctree}
:hidden:
:caption: Synthetic data

01 simulator <examples/synthetic_data/01_simulator/example>
02 ml training data <examples/synthetic_data/02_ml_training_data/example>
```

```{toctree}
:hidden:
:caption: Data generators

01 basic fitting <examples/fitting_workflows/01_basic_fitting/data/generate_data>
03 multi cycle dynamics <examples/fitting_workflows/03_multi_cycle_dynamics/data/generate_data>
04 parameter profiles <examples/fitting_workflows/04_parameter_profiles/data/generate_data>
21 multi file shared fit <examples/fitting_workflows/21_multi_file_shared_fit/data/generate_data>
```
