Metadata-Version: 2.4
Name: tldecpy
Version: 1.0.1
Summary: TLDecPy core library for thermoluminescence glow-curve deconvolution.
Project-URL: Homepage, https://github.com/HideOnParadise/TLDecPy
Project-URL: Documentation, https://hideonparadise.github.io/TLDecPy/
Project-URL: Bug Tracker, https://github.com/HideOnParadise/TLDecPy/issues
Project-URL: Source, https://github.com/HideOnParadise/TLDecPy
Project-URL: Changelog, https://github.com/HideOnParadise/TLDecPy/blob/main/CHANGELOG.md
Project-URL: Citation, https://github.com/HideOnParadise/TLDecPy#citation
Author-email: Cesar Romero <csronun@gmail.com>
License: BSD 3-Clause License
        
        Copyright (c) 2026, Cesar Romero
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Keywords: deconvolution,dosimetry,fitting,physics,radiation,science,thermoluminescence
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.20
Requires-Dist: pandas>=1.3
Requires-Dist: pydantic>=2.0.0
Requires-Dist: scipy>=1.7
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: matplotlib; extra == 'dev'
Requires-Dist: mike; extra == 'dev'
Requires-Dist: mkdocs-material<10.0,>=9.5; extra == 'dev'
Requires-Dist: mkdocs<2.0,>=1.5; extra == 'dev'
Requires-Dist: mkdocstrings[python]; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: numpydoc; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mike; extra == 'docs'
Requires-Dist: mkdocs-material<10.0,>=9.5; extra == 'docs'
Requires-Dist: mkdocs<2.0,>=1.5; extra == 'docs'
Requires-Dist: mkdocstrings[python]; extra == 'docs'
Requires-Dist: numpydoc; extra == 'docs'
Provides-Extra: perf
Requires-Dist: numba; extra == 'perf'
Provides-Extra: test
Requires-Dist: pytest>=8.0; extra == 'test'
Description-Content-Type: text/markdown

[<img align="left" height="110" width="110" src="https://raw.githubusercontent.com/HideOnParadise/TLDecPy/main/assets/icon.png" style="max-width: 100%; height: auto; max-height: 110px;">](https://hideonparadise.github.io/TLDecPy/)

# TLDecPy: Thermoluminescence Glow-Curve Deconvolution in Python

[![License: BSD-3-Clause](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Python](https://img.shields.io/badge/Python-3.10%20%7C%203.11%20%7C%203.12-3776AB?logo=python&logoColor=white)](https://www.python.org/)
[![CI](https://github.com/HideOnParadise/TLDecPy/actions/workflows/ci.yml/badge.svg)](https://github.com/HideOnParadise/TLDecPy/actions/workflows/ci.yml)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.18779807.svg)](https://doi.org/10.5281/zenodo.18779807)
[![Docs](https://img.shields.io/badge/docs-online-blue)](https://hideonparadise.github.io/TLDecPy/)
[![Web App](https://img.shields.io/badge/web%20app-tldec.tech-green)](https://tldec.tech)

`tldecpy` is an open-source Python library for thermoluminescence (TL) glow-curve deconvolution and kinetic-model benchmarking.

**[Documentation](https://hideonparadise.github.io/TLDecPy/)** · **[Web interface](https://tldec.tech)** (TLDec Web — powered by tldecpy)

## Supported Kinetic Models

- First-order (FO): `fo_rq`, `fo_ka`, `fo_wp`, `fo_rb`
- Second-order (SO): `so_ks`, `so_la`
- General-order (GO): `go_kg`, `go_rq`, `go_ge`
- One-Trap One-Recombination center (OTOR): `otor_lw` (Lambert W), `otor_wo` (Wright Omega)
- Mixed-order: `mo_kitis`, `mo_quad`, `mo_vej`
- Continuous trap-distribution models (Gaussian and Exponential forms)

## Highlights

- Full manual control over peak number, model selection, initial parameters, and bounds
- Multi-component deconvolution with robust loss functions and optional Poisson weighting
- Uncertainty propagation and fit quality metrics (FOM, R², AIC, BIC) in all fit outputs
- Synthetic curve generation for method validation
- Bundled Refglow benchmark datasets (`x001`–`x010`)
- Typed API with Pydantic v2 schemas (`py.typed`)

## Installation

```bash
pip install tldecpy
```

Or from source:

```bash
git clone https://github.com/HideOnParadise/TLDecPy.git
cd TLDecPy
pip install -e ".[dev]"
```

## Quickstart

The recommended workflow is to define peaks explicitly, with physically motivated initial values and bounds for each component:

```python
import tldecpy as tl

T, I = tl.load_refglow("x002")

peaks = [
    tl.PeakSpec(
        name="P1", model="fo_rq",
        init={"Tm": 417.0, "Im": 12000.0, "E": 1.35},
        bounds={"Tm": (390.0, 435.0), "Im": (0.0, 40000.0), "E": (0.8, 2.2)},
    ),
    tl.PeakSpec(
        name="P2", model="fo_rq",
        init={"Tm": 456.0, "Im": 18000.0, "E": 1.48},
        bounds={"Tm": (435.0, 472.0), "Im": (0.0, 50000.0), "E": (0.8, 2.4)},
    ),
    tl.PeakSpec(
        name="P3", model="fo_rq",
        init={"Tm": 484.0, "Im": 28000.0, "E": 1.60},
        bounds={"Tm": (468.0, 500.0), "Im": (0.0, 70000.0), "E": (0.9, 2.6)},
    ),
]

result = tl.fit_multi(
    T, I,
    peaks=peaks,
    bg=None,
    beta=8.4,
    options=tl.FitOptions(local_optimizer="trf"),
)

print(f"Converged: {result.converged}")
print(f"R2: {result.metrics.R2:.4f}   FOM: {result.metrics.FOM:.3f}%")
for p in result.peaks:
    print(p.name, p.model, p.params)
```

For more examples, including OTOR fits and robust loss functions, see the [`examples/`](examples/) directory and the [documentation](https://hideonparadise.github.io/TLDecPy/).

## Reproducibility Scripts

All scripts used to generate paper figures and validation results are in `scripts/`:

- Refglow benchmarks: `phase4_refglow_benchmark.py`, `phase5_refglow_x009_otor_lw.py`
- Continuous-distribution validation: `phase6_gdalo_continuous_validation.py`
- Uncertainty validation: `phase7_uncertainty_validation.py`
- Figure generation: `make_paper_figures.py`

See `scripts/README.md` for details.

## Development

```bash
make lint
make typecheck
make test
make qa
```

## Citation

If TLDecPy contributes to your research, please cite:

- DOI: [10.5281/zenodo.18779807](https://doi.org/10.5281/zenodo.18779807)

```bibtex
@software{romero2026tldecpy,
  title   = {TLDecPy},
  author  = {Romero, Cesar},
  version = {1.0.0},
  year    = {2026},
  doi     = {10.5281/zenodo.18779807},
  url     = {https://doi.org/10.5281/zenodo.18779807}
}
```

## License

BSD 3-Clause License. See [LICENSE](LICENSE).
