eemkit 0.2.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {eemkit-0.2.0 → eemkit-0.4.0}/CHANGELOG.md +47 -1
- {eemkit-0.2.0 → eemkit-0.4.0}/CITATION.cff +5 -2
- {eemkit-0.2.0 → eemkit-0.4.0}/PKG-INFO +6 -2
- {eemkit-0.2.0 → eemkit-0.4.0}/README.md +5 -1
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/app-guide.md +11 -1
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/index.md +2 -1
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/indices.md +8 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/parafac.md +40 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/plotting.md +1 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/__init__.py +1 -1
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/parafac_tab.py +166 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/state.py +11 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/indices.py +41 -9
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/parafac/__init__.py +2 -0
- eemkit-0.4.0/src/eemkit/parafac/channels.py +164 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/pipeline.py +64 -1
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/plot.py +79 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/report.py +37 -1
- eemkit-0.4.0/tests/test_channels.py +280 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_gui.py +18 -1
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_indices.py +43 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_outliers_report.py +11 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/.gitignore +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/LICENSE +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/absorbance.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/api.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/campaigns.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/cli.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/corrections.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/data_model.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/gui.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/1_project.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/2_corrections.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/3_indices.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/4a_parafac_ranks.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/4b_parafac_outliers.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/4c_parafac_final.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/4d_parafac_by_model.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/5a_rivers_time.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/5b_rivers_composition.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/5c_rivers_tests.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/img/app/6_export.png +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/instruments.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/docs/quickstart.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/pyproject.toml +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/__main__.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/absorbance.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/campaigns.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/cli.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/core/__init__.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/core/dataset.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/core/grid.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/core/history.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/__init__.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/_common.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/blank.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/crop.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/dilution.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/inner_filter.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/instrument.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/raman.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/scatter.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/spectral.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/corrections/zap.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/errors.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/__init__.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/__main__.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/campaigns_tab.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/common.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/corrections_tab.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/export_tab.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/indices_tab.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/main_window.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/project_tab.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/gui/theme.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/io/__init__.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/io/_cary_csv.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/io/cary60.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/io/cary_eclipse.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/io/discover.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/io/instruments.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/io/loader.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/io/pairing.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/parafac/_cp.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/parafac/compare.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/parafac/diagnostics.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/parafac/export.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/parafac/model.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/parafac/outliers.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/src/eemkit/parafac/validation.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/conftest.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/README.md +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/aqualog/sample4.dat +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/eemR_DESCRIPTION.txt +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/fluoromax4/f1.dat +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/fluoromax4/f2.dat +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/fluoromax4/f3.dat +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/hitachi-f7000-fl/hitachi1.TXT +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/hitachi-f7000-fl/hitachi2.TXT +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/data/eemR/shimadzu/shimadzu.TXT +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_absorbance.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_campaigns.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_cary60.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_cary_eclipse.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_cli.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_corrections.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_dataset.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_dilution_zap.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_grid.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_instruments.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_pairing.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_parafac.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_parafac_compare.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_pipeline.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_plot.py +0 -0
- {eemkit-0.2.0 → eemkit-0.4.0}/tests/test_real_data.py +0 -0
|
@@ -3,6 +3,53 @@
|
|
|
3
3
|
All notable changes are listed here. Versions follow
|
|
4
4
|
[semantic versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## 0.4.0 (2026-11-23)
|
|
7
|
+
|
|
8
|
+
Sensor channels (LED and filter) in the application, the figures and the
|
|
9
|
+
report. Nothing that existed before changes.
|
|
10
|
+
|
|
11
|
+
* **Sensor channels in the application, the figures and the report.** The
|
|
12
|
+
PARAFAC page has a new view, `Sensor channels`: type the LED wavelength and
|
|
13
|
+
the filter band of each channel and see, for the final or any exploratory
|
|
14
|
+
model, which components it follows (the channels on the mean modelled EEM,
|
|
15
|
+
the share of each component per channel with its range between samples).
|
|
16
|
+
The channels are saved in the project (`[channels.NAME]`), and with them
|
|
17
|
+
the export writes `parafac_*comp_channels.csv`,
|
|
18
|
+
`parafac_*comp_channel_sensitivity.csv` and `figures/channel_signals`; the
|
|
19
|
+
HTML report gets a `Sensor channels` section. New figure
|
|
20
|
+
`plot.channel_signals`; `pipeline.channel_signals`, `channel_specs` and
|
|
21
|
+
`channel_tables` do the same from scripts and the command line
|
|
22
|
+
(`eemkit run`). `component_signals` now also returns where each channel
|
|
23
|
+
sits (`ex_min`, `ex_max`, `em_min`, `em_max`).
|
|
24
|
+
|
|
25
|
+
## 0.3.0 (2026-11-23)
|
|
26
|
+
|
|
27
|
+
A new function to check what a filter-based optical channel sees, and a fix
|
|
28
|
+
to the indices table. The values of everything that could be computed in 0.2.0
|
|
29
|
+
are unchanged.
|
|
30
|
+
|
|
31
|
+
* New: `parafac.component_signals(model, channels)`: the signal each PARAFAC
|
|
32
|
+
component gives in an LED and filter channel, for every sample (score x
|
|
33
|
+
excitation loading weighted by the LED x emission loading integrated over the
|
|
34
|
+
filter), with the share of each component and the channel's sensitivity.
|
|
35
|
+
Meant to check whether a channel (e.g. a tryptophan-like one) follows the
|
|
36
|
+
component it is meant to follow.
|
|
37
|
+
* **Fixed: one index that cannot be computed no longer stops the whole
|
|
38
|
+
index table.** In 0.2.0, `compute_indices` (and so the application, the
|
|
39
|
+
command line and `pipeline.compute_indices`) raised as soon as one index or
|
|
40
|
+
peak needed a wavelength outside the measured range: for example, on data
|
|
41
|
+
whose emission starts at 300.3 nm (the drEEM tutorial data), HIX needs
|
|
42
|
+
300 nm and no index at all was returned. Now that index is left empty
|
|
43
|
+
(NaN) with an `EEMKitWarning` giving the reason, every other index and peak
|
|
44
|
+
is computed, and the reasons are kept in
|
|
45
|
+
`df.attrs["settings"]["not_computed"]` (also in the JSON file of
|
|
46
|
+
`export_indices`). Each peak is computed on its own, so one peak outside
|
|
47
|
+
the data does not empty the others. `on_error="raise"` keeps the old,
|
|
48
|
+
strict behaviour. Values of the indices that can be computed do not
|
|
49
|
+
change.
|
|
50
|
+
* HTML report: index columns that are empty for every sample are listed with
|
|
51
|
+
their reason, instead of being left out of the summary without a word.
|
|
52
|
+
|
|
6
53
|
## 0.2.0 (2026-11-06)
|
|
7
54
|
|
|
8
55
|
Other fluorometers, diluted samples, zap, PARAFAC model comparison and
|
|
@@ -25,7 +72,6 @@ consistency is now computed as in drEEM (first item).
|
|
|
25
72
|
wide laptop screen.
|
|
26
73
|
* Benchmark of the PARAFAC fit against drEEM 2.26.03 (N-way and parafac3w
|
|
27
74
|
engines) on the Ombrone data: same model, Tucker congruence ≥ 0.9999.
|
|
28
|
-
|
|
29
75
|
* Command line: `eemkit check project.toml` reports missing files and
|
|
30
76
|
settings; `eemkit run project.toml` runs the whole chain and exports the
|
|
31
77
|
results, as the application does (also `python -m eemkit`).
|
|
@@ -6,13 +6,16 @@ authors:
|
|
|
6
6
|
- family-names: Cirrone
|
|
7
7
|
given-names: Riccardo Gaetano
|
|
8
8
|
affiliation: University of Siena
|
|
9
|
-
version: 0.
|
|
10
|
-
date-released: "2026-11-
|
|
9
|
+
version: 0.4.0
|
|
10
|
+
date-released: "2026-11-23"
|
|
11
11
|
doi: 10.5281/zenodo.23982732
|
|
12
12
|
identifiers:
|
|
13
13
|
- type: doi
|
|
14
14
|
value: 10.5281/zenodo.23982732
|
|
15
15
|
description: "All versions (concept DOI); resolves to the latest release"
|
|
16
|
+
- type: doi
|
|
17
|
+
value: 10.5281/zenodo.24015024
|
|
18
|
+
description: "Version 0.2.0"
|
|
16
19
|
- type: doi
|
|
17
20
|
value: 10.5281/zenodo.23982733
|
|
18
21
|
description: "Version 0.1.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: eemkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Excitation-emission matrix (EEM) processing and PARAFAC modelling of dissolved organic matter fluorescence
|
|
5
5
|
Project-URL: Homepage, https://github.com/LowCostSensor/eemkit
|
|
6
6
|
Project-URL: Documentation, https://lowcostsensor.github.io/eemkit/
|
|
@@ -86,6 +86,9 @@ step recorded so that an analysis can be repeated exactly.
|
|
|
86
86
|
& Vidal 2011); models and ranks can be compared component by component.
|
|
87
87
|
* **Outliers**: leverage, residuals by sample and by wavelength, and residual
|
|
88
88
|
EEMs of the worst-fitted samples.
|
|
89
|
+
* **Sensor channels**: which components an LED and filter channel follows
|
|
90
|
+
(signal and share of each component per sample), in the application, the
|
|
91
|
+
figures, the report and from Python (`parafac.component_signals`).
|
|
89
92
|
* **New samples** can be scored on a fitted model with its spectra fixed;
|
|
90
93
|
samples the model describes worse than any of its own are flagged.
|
|
91
94
|
* **Rivers, sites and dates**: any index, CDOM metric or PARAFAC component
|
|
@@ -211,7 +214,8 @@ If you use eemkit, please cite it, together with the methods it implements
|
|
|
211
214
|
> [doi:10.5281/zenodo.23982732](https://doi.org/10.5281/zenodo.23982732)
|
|
212
215
|
|
|
213
216
|
This DOI always points to the latest version; each release also has its own
|
|
214
|
-
DOI, listed on the Zenodo page (0.
|
|
217
|
+
DOI, listed on the Zenodo page (0.2.0:
|
|
218
|
+
[10.5281/zenodo.24015024](https://doi.org/10.5281/zenodo.24015024); 0.1.0:
|
|
215
219
|
[10.5281/zenodo.23982733](https://doi.org/10.5281/zenodo.23982733)). The
|
|
216
220
|
details are in
|
|
217
221
|
[CITATION.cff](https://github.com/LowCostSensor/eemkit/blob/main/CITATION.cff).
|
|
@@ -42,6 +42,9 @@ step recorded so that an analysis can be repeated exactly.
|
|
|
42
42
|
& Vidal 2011); models and ranks can be compared component by component.
|
|
43
43
|
* **Outliers**: leverage, residuals by sample and by wavelength, and residual
|
|
44
44
|
EEMs of the worst-fitted samples.
|
|
45
|
+
* **Sensor channels**: which components an LED and filter channel follows
|
|
46
|
+
(signal and share of each component per sample), in the application, the
|
|
47
|
+
figures, the report and from Python (`parafac.component_signals`).
|
|
45
48
|
* **New samples** can be scored on a fitted model with its spectra fixed;
|
|
46
49
|
samples the model describes worse than any of its own are flagged.
|
|
47
50
|
* **Rivers, sites and dates**: any index, CDOM metric or PARAFAC component
|
|
@@ -167,7 +170,8 @@ If you use eemkit, please cite it, together with the methods it implements
|
|
|
167
170
|
> [doi:10.5281/zenodo.23982732](https://doi.org/10.5281/zenodo.23982732)
|
|
168
171
|
|
|
169
172
|
This DOI always points to the latest version; each release also has its own
|
|
170
|
-
DOI, listed on the Zenodo page (0.
|
|
173
|
+
DOI, listed on the Zenodo page (0.2.0:
|
|
174
|
+
[10.5281/zenodo.24015024](https://doi.org/10.5281/zenodo.24015024); 0.1.0:
|
|
171
175
|
[10.5281/zenodo.23982733](https://doi.org/10.5281/zenodo.23982733)). The
|
|
172
176
|
details are in
|
|
173
177
|
[CITATION.cff](https://github.com/LowCostSensor/eemkit/blob/main/CITATION.cff).
|
|
@@ -259,6 +259,15 @@ In the `Final model` box set the number of components, initialisations (20), tol
|
|
|
259
259
|
|
|
260
260
|
*The final Ombrone model (20 initialisations, all at the same minimum). The line at the top gives explained variance, core consistency, initialisations at the minimum and the split-half verdict.*
|
|
261
261
|
|
|
262
|
+
### “Sensor channels” view
|
|
263
|
+
|
|
264
|
+
For a sensor with an LED and an emission filter: which components does each channel follow? One row per channel in the table: its name, the **LED wavelength** and the **filter band** (from, to), all in nm. `Add channel` inserts a row with starting values to edit (LED 280 nm, filter 330–370 nm); `Remove selected` deletes the selected rows. The `Model` menu chooses the final model or any exploratory model, so channels can be tried before the final fit.
|
|
265
|
+
|
|
266
|
+
* **Left figure:** the mean modelled EEM with each channel drawn on it: the LED excitation is the height of the bar, the filter band its length. A channel on the edge of a humic peak instead of the protein peak is visible at once.
|
|
267
|
+
* **Right figure and table:** the share of each component in the signal of each channel, mean over samples; the table also gives the range between samples (min–max). A channel meant to follow the protein-like component should have most of its signal there in every sample.
|
|
268
|
+
* The signal of a component in a channel is its score × its excitation loading at the LED wavelength × its emission loading integrated over the filter band. The numbers describe the model, not the sensor: lamp output, detector response and filter blocking outside the band are not included.
|
|
269
|
+
* A channel outside the wavelength range of the model is refused with a message. The channels are saved in the project (`[channels.NAME]`, with `ex` and `em = [from, to]`) and written on export. LED spectra and filter transmission curves (not just a line and a flat band) are available from Python: see [PARAFAC](parafac.md).
|
|
270
|
+
|
|
262
271
|
## 5 · Rivers and dates
|
|
263
272
|
|
|
264
273
|
Compares campaigns, sites and rivers for any variable of the indices table or of the final model: indices, CDOM metrics, the Fmax of each component and its share of the total (`C1_pct`, …). The methods are described in [Rivers, sites and dates](campaigns.md).
|
|
@@ -312,9 +321,10 @@ Compares campaigns, sites and rivers for any variable of the indices table or of
|
|
|
312
321
|
| `parafac_exploration.csv` | The “Number of components” table. |
|
|
313
322
|
| `parafac_3comp_fmax.csv` | Fmax of every component per sample, in Raman units. |
|
|
314
323
|
| `parafac_3comp_ex_loadings.csv` `parafac_3comp_em_loadings.csv` | Excitation and emission loadings. |
|
|
324
|
+
| `parafac_3comp_channels.csv` `parafac_3comp_channel_sensitivity.csv` | With sensor channels defined: signal and share of each component in each channel per sample, and the signal per unit score of each channel (see “Sensor channels”). |
|
|
315
325
|
| `parafac_3comp_openfluor.txt` | File for OpenFluor. Check it against the current upload template before submitting it. |
|
|
316
326
|
| `parafac_3comp_model.nc` | The complete model. |
|
|
317
|
-
| `figures/` | Number-of-components diagnostics, components and leverage, as PDF and PNG, in the colours chosen in `View` → `EEM colours`. |
|
|
327
|
+
| `figures/` | Number-of-components diagnostics, components and leverage (and the sensor channels, when defined), as PDF and PNG, in the colours chosen in `View` → `EEM colours`. |
|
|
318
328
|
| `report.html` | One page with the whole analysis: samples, every processing step, indices, the exploratory models, the final model with its validation, outlier diagnostics (residual EEMs of the worst-fitted samples, residuals by wavelength) and the settings. The figures are inside the page, so it can be e-mailed or archived as it is. |
|
|
319
329
|
|
|
320
330
|
The `3` in the names is the number of components of the final model.
|
|
@@ -88,7 +88,8 @@ Cite eemkit as *Cirrone, R. G. eemkit: EEM processing and PARAFAC modelling
|
|
|
88
88
|
of dissolved organic matter fluorescence. Zenodo.
|
|
89
89
|
[doi:10.5281/zenodo.23982732](https://doi.org/10.5281/zenodo.23982732)*,
|
|
90
90
|
together with the methods you used. This DOI always points to the latest
|
|
91
|
-
version; each release has its own DOI on the Zenodo page (0.
|
|
91
|
+
version; each release has its own DOI on the Zenodo page (0.2.0:
|
|
92
|
+
[10.5281/zenodo.24015024](https://doi.org/10.5281/zenodo.24015024); 0.1.0:
|
|
92
93
|
[10.5281/zenodo.23982733](https://doi.org/10.5281/zenodo.23982733)). Full
|
|
93
94
|
metadata:
|
|
94
95
|
[CITATION.cff](https://github.com/LowCostSensor/eemkit/blob/main/CITATION.cff). eemkit is free software under the GNU General Public License v3.0 or
|
|
@@ -24,6 +24,14 @@ emission pair used by eemR, or `peak_definitions=` for other peaks.
|
|
|
24
24
|
* A value that would need a missing point (removed scatter) is NaN and raises
|
|
25
25
|
a warning, so compute indices **before** scatter removal: peak B at ex 275 /
|
|
26
26
|
em 310 lies inside the first-order Raman band.
|
|
27
|
+
* An index or peak the data cannot give at all (a wavelength outside the
|
|
28
|
+
measured range, e.g. HIX needs emission from 300 nm and the data start at
|
|
29
|
+
300.3 nm; or an excitation that was not measured with `ex_method="exact"`)
|
|
30
|
+
is left **empty** with a warning that gives the reason; the other indices
|
|
31
|
+
are still computed. The reasons are stored in
|
|
32
|
+
`df.attrs["settings"]["not_computed"]`, written to the JSON file of
|
|
33
|
+
`export_indices`, and listed in the HTML report. Pass `on_error="raise"` to
|
|
34
|
+
stop at the first index that cannot be computed instead.
|
|
27
35
|
* Ratios depend on the instrument's spectral response (Cory et al. 2010).
|
|
28
36
|
Without [spectral correction](corrections.md#spectral-correction), compare
|
|
29
37
|
them only with values from the same instrument.
|
|
@@ -149,6 +149,46 @@ the same way; a warning says when their processing history differs.
|
|
|
149
149
|
sample used to build the model: the model does not describe them well, and
|
|
150
150
|
they may contain a component the model does not have.
|
|
151
151
|
|
|
152
|
+
## Signal of each component in an LED and filter channel
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
ch = {"T": {"ex": 280.0, "em": (330.0, 370.0)}, # LED line, flat filter band (nm)
|
|
156
|
+
"H": {"ex": 330.0, "em": ([420, 440, 480], [0.0, 0.8, 0.0])}} # filter table
|
|
157
|
+
sig = eemkit.parafac.component_signals(model, ch)
|
|
158
|
+
sig["signal"] # sample x channel x component
|
|
159
|
+
sig["share"] # each component's share of the channel signal
|
|
160
|
+
sig["sensitivity"] # channel x component: signal per unit score
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
A sensor with an LED and an emission filter records one number per sample.
|
|
164
|
+
The fitted model says how much of it each component accounts for: the
|
|
165
|
+
component's score times its excitation loading at the LED wavelength times its
|
|
166
|
+
emission loading integrated over the filter. With `ex` a single wavelength the
|
|
167
|
+
LED is a line; a band `(low, high)` or a table `(wavelengths, weights)` is
|
|
168
|
+
averaged with its weights, so a wide LED is not counted as a single line.
|
|
169
|
+
The filter is a band `(low, high)` with flat transmission or a table
|
|
170
|
+
`(wavelengths, transmission)`; band edges need not fall on the model's grid
|
|
171
|
+
(the loadings are interpolated linearly). Loadings have unit norm and the
|
|
172
|
+
scores carry the scale, so the signal is in the units of the data times nm
|
|
173
|
+
(`reduce="integral"`, the default) or in data units (`reduce="mean"`, the
|
|
174
|
+
integral divided by the filter's area). Wavelengths outside the model's range
|
|
175
|
+
raise an error. `sensitivity` does not depend on the samples: it shows which
|
|
176
|
+
components a channel can see at all, e.g. whether a tryptophan-like channel
|
|
177
|
+
sits on the protein component or on a humic tail.
|
|
178
|
+
|
|
179
|
+
The numbers describe the model, not the sensor: lamp output, detector
|
|
180
|
+
response and filter blocking beyond the table are not included.
|
|
181
|
+
|
|
182
|
+
`eemkit.plot.channel_signals(sig, model)` draws the channels on the mean
|
|
183
|
+
modelled EEM next to the share of each component in each channel. In the
|
|
184
|
+
application, the `Sensor channels` view of the PARAFAC page does the same for
|
|
185
|
+
the final or an exploratory model, with channels typed as a table (LED
|
|
186
|
+
wavelength, filter from and to); they are saved in the project as
|
|
187
|
+
`[channels.NAME]` with `ex = 280.0` and `em = [330.0, 370.0]`, and written on
|
|
188
|
+
export (`parafac_*comp_channels.csv`, `figures/channel_signals`) and in the
|
|
189
|
+
HTML report. LED spectra and filter transmission tables are available from
|
|
190
|
+
Python only.
|
|
191
|
+
|
|
152
192
|
## References
|
|
153
193
|
|
|
154
194
|
Andersson, C.A., Bro, R. (2000) *Chemometrics and Intelligent Laboratory Systems* 52, 1–4 ·
|
|
@@ -12,6 +12,7 @@ Each function returns a matplotlib figure; `plot.save(fig, "fig1")` writes
|
|
|
12
12
|
| `spectral_factors(ds)` | the excitation and emission correction factors applied |
|
|
13
13
|
| `rank_diagnostics(table, chosen=3)` | explained variance, core consistency and split-half congruence vs rank, one panel each |
|
|
14
14
|
| `leverage(model, by="river")` | leverage vs residuals, the most extreme samples labelled |
|
|
15
|
+
| `channel_signals(sig, model)` | LED and filter channels on the mean modelled EEM, and the share of each component in each channel |
|
|
15
16
|
| `scores_over(df, cols, x="campaign", by="river")` | mean ± SD per group over time, samples as faint points |
|
|
16
17
|
|
|
17
18
|
Widths default to two journal columns (180 mm); `plot.SINGLE_COLUMN` is 85 mm.
|
|
@@ -9,6 +9,7 @@ from PySide6.QtWidgets import (
|
|
|
9
9
|
QComboBox,
|
|
10
10
|
QFormLayout,
|
|
11
11
|
QGroupBox,
|
|
12
|
+
QHeaderView,
|
|
12
13
|
QLabel,
|
|
13
14
|
QLineEdit,
|
|
14
15
|
QListWidget,
|
|
@@ -18,12 +19,15 @@ from PySide6.QtWidgets import (
|
|
|
18
19
|
QSpinBox,
|
|
19
20
|
QSplitter,
|
|
20
21
|
QTableView,
|
|
22
|
+
QTableWidget,
|
|
23
|
+
QTableWidgetItem,
|
|
21
24
|
QTabWidget,
|
|
22
25
|
QVBoxLayout,
|
|
23
26
|
QWidget,
|
|
24
27
|
)
|
|
25
28
|
|
|
26
29
|
from eemkit import pipeline, plot
|
|
30
|
+
from eemkit.errors import SettingsError
|
|
27
31
|
from eemkit.gui.common import DataFrameModel, PlotPanel, TaskBar, note, pair, primary, spin
|
|
28
32
|
from eemkit.gui.state import Project
|
|
29
33
|
|
|
@@ -172,11 +176,50 @@ class ParafacTab(QWidget):
|
|
|
172
176
|
v.addWidget(self.final_text)
|
|
173
177
|
v.addWidget(self.final_plot, 1)
|
|
174
178
|
|
|
179
|
+
# sensor channels: which components an LED and filter channel follows
|
|
180
|
+
self._editing_channels = False
|
|
181
|
+
self.ch_table = QTableWidget(0, 4)
|
|
182
|
+
self.ch_table.setHorizontalHeaderLabels(
|
|
183
|
+
["Channel", "LED (nm)", "Filter from (nm)", "Filter to (nm)"])
|
|
184
|
+
self.ch_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|
185
|
+
self.ch_table.setMaximumHeight(150)
|
|
186
|
+
self.ch_table.itemChanged.connect(self._channels_edited)
|
|
187
|
+
b_add = QPushButton("Add channel")
|
|
188
|
+
b_add.clicked.connect(self.add_channel)
|
|
189
|
+
b_remove = QPushButton("Remove selected")
|
|
190
|
+
b_remove.clicked.connect(self.remove_channels)
|
|
191
|
+
self.ch_model = QComboBox()
|
|
192
|
+
self.ch_model.currentIndexChanged.connect(self.draw_channels)
|
|
193
|
+
self.ch_status = QLabel("")
|
|
194
|
+
self.ch_status.setWordWrap(True)
|
|
195
|
+
self.ch_plot = PlotPanel()
|
|
196
|
+
self.ch_shares_model = DataFrameModel()
|
|
197
|
+
ch_shares = QTableView()
|
|
198
|
+
ch_shares.setModel(self.ch_shares_model)
|
|
199
|
+
ch_shares.setMaximumHeight(130)
|
|
200
|
+
page_ch = QWidget()
|
|
201
|
+
v = QVBoxLayout(page_ch)
|
|
202
|
+
v.addWidget(note(
|
|
203
|
+
"A sensor with an LED and an emission filter records one number per sample. The "
|
|
204
|
+
"signal of a component in a channel is its score × its excitation loading at the "
|
|
205
|
+
"LED wavelength × its emission loading integrated over the filter band. These "
|
|
206
|
+
"numbers describe the model, not the sensor: lamp output, detector response and "
|
|
207
|
+
"filter blocking outside the band are not included."))
|
|
208
|
+
v.addWidget(pair(QLabel("Model"), self.ch_model))
|
|
209
|
+
v.addWidget(self.ch_table)
|
|
210
|
+
v.addWidget(pair(b_add, b_remove))
|
|
211
|
+
v.addWidget(self.ch_status)
|
|
212
|
+
v.addWidget(self.ch_plot, 1)
|
|
213
|
+
v.addWidget(QLabel("Share of each component in the channel signal, % (mean over "
|
|
214
|
+
"samples, with the range between samples)"))
|
|
215
|
+
v.addWidget(ch_shares)
|
|
216
|
+
|
|
175
217
|
self.results = QTabWidget()
|
|
176
218
|
self.results.addTab(page_summary, "Number of components")
|
|
177
219
|
self.results.addTab(page_load, "Components by model")
|
|
178
220
|
self.results.addTab(page_out, "Outliers")
|
|
179
221
|
self.results.addTab(page_final, "Final model")
|
|
222
|
+
self.results.addTab(page_ch, "Sensor channels")
|
|
180
223
|
|
|
181
224
|
split = QSplitter()
|
|
182
225
|
split.addWidget(scroll)
|
|
@@ -216,6 +259,126 @@ class ParafacTab(QWidget):
|
|
|
216
259
|
self.f_init.setValue(int(fin["n_init"]))
|
|
217
260
|
self.f_tol.setText(f"{float(fin['tol']):g}")
|
|
218
261
|
self.f_iter.setValue(int(fin["max_iter"]))
|
|
262
|
+
if not self._editing_channels:
|
|
263
|
+
self._fill_channels(self.project.settings.get("channels") or {})
|
|
264
|
+
|
|
265
|
+
# sensor channels ---------------------------------------------------- #
|
|
266
|
+
|
|
267
|
+
def _fill_channels(self, channels: dict) -> None:
|
|
268
|
+
self.ch_table.blockSignals(True)
|
|
269
|
+
self.ch_table.setRowCount(0)
|
|
270
|
+
for name, c in channels.items():
|
|
271
|
+
self._append_row([str(name), f"{float(c['ex']):g}", f"{float(c['em'][0]):g}",
|
|
272
|
+
f"{float(c['em'][1]):g}"])
|
|
273
|
+
self.ch_table.blockSignals(False)
|
|
274
|
+
|
|
275
|
+
def _append_row(self, cells: list[str]) -> None:
|
|
276
|
+
r = self.ch_table.rowCount()
|
|
277
|
+
self.ch_table.insertRow(r)
|
|
278
|
+
for c, text in enumerate(cells):
|
|
279
|
+
self.ch_table.setItem(r, c, QTableWidgetItem(text))
|
|
280
|
+
|
|
281
|
+
def add_channel(self) -> None:
|
|
282
|
+
"""A new row with starting values to edit (a protein-like LED and filter)."""
|
|
283
|
+
taken = {self.ch_table.item(r, 0).text() for r in range(self.ch_table.rowCount())
|
|
284
|
+
if self.ch_table.item(r, 0)}
|
|
285
|
+
k = 1
|
|
286
|
+
while f"Ch{k}" in taken:
|
|
287
|
+
k += 1
|
|
288
|
+
self.ch_table.blockSignals(True)
|
|
289
|
+
self._append_row([f"Ch{k}", "280", "330", "370"])
|
|
290
|
+
self.ch_table.blockSignals(False)
|
|
291
|
+
self._channels_edited()
|
|
292
|
+
|
|
293
|
+
def remove_channels(self) -> None:
|
|
294
|
+
rows = sorted({i.row() for i in self.ch_table.selectedIndexes()}, reverse=True)
|
|
295
|
+
self.ch_table.blockSignals(True)
|
|
296
|
+
for r in rows:
|
|
297
|
+
self.ch_table.removeRow(r)
|
|
298
|
+
self.ch_table.blockSignals(False)
|
|
299
|
+
self._channels_edited()
|
|
300
|
+
|
|
301
|
+
def _read_channels(self) -> dict:
|
|
302
|
+
"""The table as the ``channels`` settings; raises ValueError for a bad row."""
|
|
303
|
+
out: dict = {}
|
|
304
|
+
for r in range(self.ch_table.rowCount()):
|
|
305
|
+
cells = [(self.ch_table.item(r, c).text() if self.ch_table.item(r, c) else "").strip()
|
|
306
|
+
for c in range(4)]
|
|
307
|
+
if not any(cells):
|
|
308
|
+
continue
|
|
309
|
+
try:
|
|
310
|
+
ex, lo, hi = (float(x.replace(",", ".")) for x in cells[1:])
|
|
311
|
+
except ValueError:
|
|
312
|
+
raise ValueError(f"Row {r + 1}: the LED and the filter limits must be numbers "
|
|
313
|
+
"(nm).") from None
|
|
314
|
+
if cells[0] in out:
|
|
315
|
+
raise ValueError(f"The channel name {cells[0]!r} is used twice.")
|
|
316
|
+
out[cells[0]] = {"ex": ex, "em": [lo, hi]}
|
|
317
|
+
return out
|
|
318
|
+
|
|
319
|
+
def _channels_edited(self, *_args) -> None:
|
|
320
|
+
try:
|
|
321
|
+
channels = self._read_channels()
|
|
322
|
+
pipeline.channel_specs({"channels": channels})
|
|
323
|
+
except (ValueError, SettingsError) as exc:
|
|
324
|
+
self.ch_status.setText(str(exc))
|
|
325
|
+
return
|
|
326
|
+
self.ch_status.setText("")
|
|
327
|
+
self._editing_channels = True
|
|
328
|
+
try:
|
|
329
|
+
self.project.set_channels(channels)
|
|
330
|
+
finally:
|
|
331
|
+
self._editing_channels = False
|
|
332
|
+
self.draw_channels()
|
|
333
|
+
|
|
334
|
+
def _refresh_channel_models(self) -> None:
|
|
335
|
+
"""The models channels can be computed on: the final one and the exploratory ones."""
|
|
336
|
+
keep = self.ch_model.currentData()
|
|
337
|
+
items: list[tuple[str, object]] = []
|
|
338
|
+
if self.project.model is not None:
|
|
339
|
+
items.append((f"Final model ({self.project.model.sizes['component']} components)",
|
|
340
|
+
"final"))
|
|
341
|
+
if self.project.exploration is not None:
|
|
342
|
+
items += [(f"Exploratory, {r} components", r) for r in self.project.exploration.models]
|
|
343
|
+
self.ch_model.blockSignals(True)
|
|
344
|
+
self.ch_model.clear()
|
|
345
|
+
for text, key in items:
|
|
346
|
+
self.ch_model.addItem(text, key)
|
|
347
|
+
k = self.ch_model.findData(keep)
|
|
348
|
+
self.ch_model.setCurrentIndex(k if k >= 0 else 0)
|
|
349
|
+
self.ch_model.blockSignals(False)
|
|
350
|
+
self.draw_channels()
|
|
351
|
+
|
|
352
|
+
def draw_channels(self) -> None:
|
|
353
|
+
key = self.ch_model.currentData()
|
|
354
|
+
channels = self.project.settings.get("channels") or {}
|
|
355
|
+
if key is None:
|
|
356
|
+
self.ch_plot.clear("Fit the final model or run the exploratory models first.")
|
|
357
|
+
self.ch_shares_model.set_frame(pd.DataFrame())
|
|
358
|
+
return
|
|
359
|
+
if not channels:
|
|
360
|
+
self.ch_plot.clear("Add a channel: the LED wavelength and the filter band.")
|
|
361
|
+
self.ch_shares_model.set_frame(pd.DataFrame())
|
|
362
|
+
return
|
|
363
|
+
model = self.project.model if key == "final" else self.project.exploration.models[key]
|
|
364
|
+
try:
|
|
365
|
+
sig = pipeline.channel_signals(model, self.project.settings)
|
|
366
|
+
except SettingsError as exc:
|
|
367
|
+
self.ch_status.setText(str(exc))
|
|
368
|
+
self.ch_plot.clear("The channels do not fit the wavelength range of the model.")
|
|
369
|
+
self.ch_shares_model.set_frame(pd.DataFrame())
|
|
370
|
+
return
|
|
371
|
+
self.ch_status.setText("")
|
|
372
|
+
self.ch_plot.show_figure(plot.channel_signals(sig, model, width=9.0,
|
|
373
|
+
cmap=self.project.eem_colours))
|
|
374
|
+
share = 100 * sig["share"]
|
|
375
|
+
lo, mean, hi = (share.min("sample"), share.mean("sample"), share.max("sample"))
|
|
376
|
+
table = pd.DataFrame(
|
|
377
|
+
{f"C{c}": [f"{mean.values[i, j]:.0f} ({lo.values[i, j]:.0f}–{hi.values[i, j]:.0f})"
|
|
378
|
+
for i in range(sig.sizes["channel"])]
|
|
379
|
+
for j, c in enumerate(sig["component"].values)},
|
|
380
|
+
index=pd.Index([str(c) for c in sig["channel"].values], name="channel"))
|
|
381
|
+
self.ch_shares_model.set_frame(table)
|
|
219
382
|
|
|
220
383
|
def _exploration_settings(self) -> dict | None:
|
|
221
384
|
try:
|
|
@@ -344,6 +507,9 @@ class ParafacTab(QWidget):
|
|
|
344
507
|
self.draw_loadings()
|
|
345
508
|
if self.project.model is not None:
|
|
346
509
|
self.show_final()
|
|
510
|
+
if what in ("exploration", "final", "corrected", "settings", "display") \
|
|
511
|
+
and not (what == "settings" and self._editing_channels):
|
|
512
|
+
self._refresh_channel_models()
|
|
347
513
|
|
|
348
514
|
def show_exploration(self) -> None:
|
|
349
515
|
ex = self.project.exploration
|
|
@@ -112,6 +112,17 @@ class Project(QObject):
|
|
|
112
112
|
if invalidates:
|
|
113
113
|
self.invalidate(invalidates)
|
|
114
114
|
|
|
115
|
+
def set_channels(self, channels: dict) -> None:
|
|
116
|
+
"""Replace the filter-based channels (``set_settings`` would only add to them).
|
|
117
|
+
|
|
118
|
+
Channels do not change any computed result, so nothing is invalidated.
|
|
119
|
+
"""
|
|
120
|
+
if channels == (self.settings.get("channels") or {}):
|
|
121
|
+
return
|
|
122
|
+
self.settings["channels"] = channels
|
|
123
|
+
self.dirty = True
|
|
124
|
+
self.changed.emit("settings")
|
|
125
|
+
|
|
115
126
|
@property
|
|
116
127
|
def eem_colours(self) -> str:
|
|
117
128
|
"""Name of the EEM colour map (a key of :data:`eemkit.plot.COLORMAPS`)."""
|
|
@@ -22,9 +22,12 @@ Excitation wavelengths that are not on the measured grid (e.g. 254, 275 or
|
|
|
22
22
|
Emission values off the grid are linearly interpolated; emission areas are
|
|
23
23
|
trapezoidal integrals of the piecewise-linear spectrum between the exact
|
|
24
24
|
limits. A value that needs a NaN point (e.g. removed scatter) is NaN and
|
|
25
|
-
triggers a warning.
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
triggers a warning. In :func:`compute_indices`, an index the dataset cannot
|
|
26
|
+
give at all (a wavelength outside the measured range) is left empty with a
|
|
27
|
+
warning and its reason recorded, and the other indices are still computed.
|
|
28
|
+
Ratios are unit-free; peaks are in the units of ``intensity``. Indices
|
|
29
|
+
depend on instrument spectral response (Cory et al. 2010), so the
|
|
30
|
+
spectral-correction status travels with every result.
|
|
28
31
|
"""
|
|
29
32
|
|
|
30
33
|
from __future__ import annotations
|
|
@@ -42,6 +45,8 @@ from eemkit.core.history import get_history
|
|
|
42
45
|
from eemkit.errors import EEMKitWarning, IndexComputationError
|
|
43
46
|
|
|
44
47
|
EX_METHODS = ("linear", "nearest", "exact")
|
|
48
|
+
#: what :func:`compute_indices` does with an index it cannot compute
|
|
49
|
+
ON_ERROR = ("nan", "raise")
|
|
45
50
|
|
|
46
51
|
#: Coble (1996) peaks: name -> (ex nm, (em_min, em_max) nm)
|
|
47
52
|
COBLE_1996: dict[str, tuple[float, tuple[float, float]]] = {
|
|
@@ -203,23 +208,49 @@ def compute_indices(
|
|
|
203
208
|
hix: Mapping | None = None,
|
|
204
209
|
bix: Mapping | None = None,
|
|
205
210
|
peak_definitions: Mapping[str, tuple[float, tuple[float, float]]] | None = None,
|
|
211
|
+
on_error: str = "nan",
|
|
206
212
|
) -> pd.DataFrame:
|
|
207
213
|
"""All indices in one table (one row per sample) with the settings in ``df.attrs``.
|
|
208
214
|
|
|
209
215
|
``fi``, ``hix``, ``bix`` are keyword overrides for the respective
|
|
210
216
|
functions; ``peak_definitions`` defaults to :data:`COBLE_1996`.
|
|
211
217
|
``ex_method`` applies to every index and peak.
|
|
218
|
+
|
|
219
|
+
An index or peak that cannot be computed on this dataset (a wavelength
|
|
220
|
+
outside the measured range, or an excitation that was not measured when
|
|
221
|
+
``ex_method="exact"``) does not stop the table: with ``on_error="nan"``
|
|
222
|
+
(default) its column is left empty (NaN), an :class:`EEMKitWarning` says
|
|
223
|
+
why, and the reason is stored in ``df.attrs["settings"]["not_computed"]``
|
|
224
|
+
(and so in the JSON sidecar of :func:`export_indices`). With
|
|
225
|
+
``on_error="raise"`` the :class:`IndexComputationError` is raised instead.
|
|
212
226
|
"""
|
|
227
|
+
if on_error not in ON_ERROR:
|
|
228
|
+
raise ValueError(f"on_error must be one of {ON_ERROR}")
|
|
213
229
|
fi, hix, bix = dict(fi or {}), dict(hix or {}), dict(bix or {})
|
|
214
230
|
peak_definitions = dict(peak_definitions or COBLE_1996)
|
|
231
|
+
samples = pd.Index(ds["sample"].values, name="sample")
|
|
232
|
+
not_computed: dict[str, str] = {}
|
|
233
|
+
|
|
234
|
+
def attempt(name: str, compute) -> pd.Series:
|
|
235
|
+
try:
|
|
236
|
+
return compute().to_series()
|
|
237
|
+
except IndexComputationError as exc:
|
|
238
|
+
if on_error == "raise":
|
|
239
|
+
raise
|
|
240
|
+
not_computed[name] = str(exc)
|
|
241
|
+
warnings.warn(f"{name} not computed: {exc}", EEMKitWarning, stacklevel=3)
|
|
242
|
+
return pd.Series(np.nan, index=samples, name=name)
|
|
243
|
+
|
|
215
244
|
cols = {
|
|
216
|
-
"FI": fluorescence_index(ds, ex_method=ex_method, **fi),
|
|
217
|
-
"HIX": humification_index(ds, ex_method=ex_method, **hix),
|
|
218
|
-
"BIX": biological_index(ds, ex_method=ex_method, **bix),
|
|
245
|
+
"FI": attempt("FI", lambda: fluorescence_index(ds, ex_method=ex_method, **fi)),
|
|
246
|
+
"HIX": attempt("HIX", lambda: humification_index(ds, ex_method=ex_method, **hix)),
|
|
247
|
+
"BIX": attempt("BIX", lambda: biological_index(ds, ex_method=ex_method, **bix)),
|
|
219
248
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
249
|
+
for k, definition in peak_definitions.items():
|
|
250
|
+
cols[f"peak_{k}"] = attempt(
|
|
251
|
+
f"peak_{k}",
|
|
252
|
+
lambda k=k, d=definition: peaks(ds, {k: d}, ex_method=ex_method)[k])
|
|
253
|
+
df = pd.DataFrame(cols)
|
|
223
254
|
df.index.name = "sample"
|
|
224
255
|
df.attrs["settings"] = {
|
|
225
256
|
"ex_method": ex_method,
|
|
@@ -232,6 +263,7 @@ def compute_indices(
|
|
|
232
263
|
"definitions": {k: [v[0], list(v[1])] for k, v in peak_definitions.items()},
|
|
233
264
|
"units": ds["intensity"].attrs.get("units", "")},
|
|
234
265
|
"spectral_correction": ds.attrs.get("spectral_correction", "none"),
|
|
266
|
+
"not_computed": not_computed,
|
|
235
267
|
"processing_history": get_history(ds),
|
|
236
268
|
}
|
|
237
269
|
return df
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Non-negative PARAFAC with the diagnostics of Murphy et al. (2013)."""
|
|
2
2
|
|
|
3
3
|
from eemkit.parafac._cp import nn_parafac
|
|
4
|
+
from eemkit.parafac.channels import component_signals
|
|
4
5
|
from eemkit.parafac.compare import compare_models, compare_ranks, component_correlations
|
|
5
6
|
from eemkit.parafac.diagnostics import (
|
|
6
7
|
core_consistency,
|
|
@@ -26,6 +27,7 @@ __all__ = [
|
|
|
26
27
|
"compare_models",
|
|
27
28
|
"compare_ranks",
|
|
28
29
|
"component_correlations",
|
|
30
|
+
"component_signals",
|
|
29
31
|
"core_consistency",
|
|
30
32
|
"eemqual",
|
|
31
33
|
"fit_parafac",
|