Metadata-Version: 2.5
Name: diamond-NAgg-map
Version: 0.9.0
Summary: A Script for processing FTIR MAPS of diamond plates and calculating nitrogen aggregation state
Author-email: WHTowbin <24940778+whtowbin@users.noreply.github.com>
License-File: LICENSE
Requires-Python: >=3.13
Requires-Dist: ftir-omnic-map-reader>=1.0.0
Requires-Dist: imageio>=2.37.0
Requires-Dist: matplotlib>=3.10.3
Requires-Dist: numpy>=2.2.6
Requires-Dist: pandas>=2.2.3
Requires-Dist: pybaselines>=1.2.0
Requires-Dist: scipy>=1.15.3
Requires-Dist: seaborn>=0.13.2
Requires-Dist: xarray>=2025.4.0
Provides-Extra: dev
Requires-Dist: ipykernel>=6.29.5; extra == 'dev'
Description-Content-Type: text/markdown

# Diamond NAgg Map

Calculates nitrogen concentration and aggregation state across FTIR maps of diamond plates. Each spectrum in the map gets a baseline correction, a thickness normalization and a least-squares fit to reference spectra, and the results are saved as maps.

## How it works

1. Reads a Thermo Fisher Nicolet OMNIC `.map` file with [FTIR_OMNIC_MAP_Reader](https://github.com/whtowbin/FTIR_OMNIC_MAP_Reader) into an xarray dataset.
2. Removes the baseline of each spectrum with asymmetric least squares (pybaselines).
3. Normalizes each spectrum for thickness by comparing it with a type IIa reference spectrum over 1800-2313 and 2390-2670 cm<sup>-1</sup>.
4. Fits the nitrogen region (up to 1400 cm<sup>-1</sup>) with a bounded least-squares combination of the C, A, X, B and D center reference spectra plus a constant and a linear term. The reference spectra come from the QUIDDIT program.
5. Converts the A and B fits to ppm (factors 16.5 and 79.4) and calculates total nitrogen and %B for every point.
6. Saves maps of A ppm, B ppm, %B, total N, C and D as PNG and TIFF, plus example plots of the baseline, type IIa and nitrogen fits on a grid of points across the map.

## Install and run

Requires Python 3.13 or later.

```bash
uv tool install diamond-nagg-map
diamond-nagg-map path/to/sample.map --output Results
```

`pip install diamond-nagg-map` also works. Versions before 0.9.0 have a broken `diamond-nagg-map` command. To install the latest code from GitHub instead, use `uv tool install git+https://github.com/whtowbin/Diamond_NAgg_Map`.

Options:

- `--output`: folder for the maps and plots (default `Results`).
- `--lam`, `--p`: baseline parameters passed to `pybaselines.whittaker.asls` (defaults 2e7 and 1e-6).
- `--n_examples`: grid of points to plot example fits for, either `N` for an N x N grid or `NX NY` (default 5). Each point produces three plots.

From Python:

```python
from diamond_nagg_map.DiamondNAggMap import process_map

process_map("sample.map", "Results", baseline_lam=1e7, baseline_p=1e-5, n_examples=(3, 3))
```

## Limitations

- Reads only OMNIC `.map` files from Nicolet FTIR microscopes.
- Fits type IaA/B diamonds. Type Ib support is not finished.
- Single-spectrum processing lives in [diamond-ftir-package](https://github.com/whtowbin/diamond-ftir-package).

## License

MIT. See [LICENSE](LICENSE).
