eemkit 0.5.0__tar.gz → 0.6.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.
Files changed (129) hide show
  1. {eemkit-0.5.0 → eemkit-0.6.0}/CHANGELOG.md +17 -0
  2. {eemkit-0.5.0 → eemkit-0.6.0}/CITATION.cff +2 -2
  3. {eemkit-0.5.0 → eemkit-0.6.0}/PKG-INFO +1 -1
  4. {eemkit-0.5.0 → eemkit-0.6.0}/docs/api.md +1 -0
  5. {eemkit-0.5.0 → eemkit-0.6.0}/docs/app-guide.md +1 -1
  6. {eemkit-0.5.0 → eemkit-0.6.0}/docs/corrections.md +27 -0
  7. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/__init__.py +1 -1
  8. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/cli.py +14 -1
  9. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/__init__.py +4 -2
  10. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/inner_filter.py +32 -0
  11. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/corrections_tab.py +46 -6
  12. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/pipeline.py +35 -5
  13. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_cli.py +19 -0
  14. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_corrections.py +24 -0
  15. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_gui.py +35 -0
  16. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_pipeline.py +41 -1
  17. {eemkit-0.5.0 → eemkit-0.6.0}/.gitignore +0 -0
  18. {eemkit-0.5.0 → eemkit-0.6.0}/LICENSE +0 -0
  19. {eemkit-0.5.0 → eemkit-0.6.0}/README.md +0 -0
  20. {eemkit-0.5.0 → eemkit-0.6.0}/docs/absorbance.md +0 -0
  21. {eemkit-0.5.0 → eemkit-0.6.0}/docs/campaigns.md +0 -0
  22. {eemkit-0.5.0 → eemkit-0.6.0}/docs/cli.md +0 -0
  23. {eemkit-0.5.0 → eemkit-0.6.0}/docs/data_model.md +0 -0
  24. {eemkit-0.5.0 → eemkit-0.6.0}/docs/download.md +0 -0
  25. {eemkit-0.5.0 → eemkit-0.6.0}/docs/gui.md +0 -0
  26. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/0_readme_parafac_app.png +0 -0
  27. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/1_project.png +0 -0
  28. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/2_corrections.png +0 -0
  29. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/3_indices.png +0 -0
  30. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/4a_parafac_ranks.png +0 -0
  31. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/4b_parafac_outliers.png +0 -0
  32. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/4c_parafac_final.png +0 -0
  33. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/4d_parafac_by_model.png +0 -0
  34. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/5a_rivers_time.png +0 -0
  35. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/5b_rivers_composition.png +0 -0
  36. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/5c_rivers_tests.png +0 -0
  37. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/app/6_export.png +0 -0
  38. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/logo-256.png +0 -0
  39. {eemkit-0.5.0 → eemkit-0.6.0}/docs/img/logo.svg +0 -0
  40. {eemkit-0.5.0 → eemkit-0.6.0}/docs/index.md +0 -0
  41. {eemkit-0.5.0 → eemkit-0.6.0}/docs/indices.md +0 -0
  42. {eemkit-0.5.0 → eemkit-0.6.0}/docs/instruments.md +0 -0
  43. {eemkit-0.5.0 → eemkit-0.6.0}/docs/parafac.md +0 -0
  44. {eemkit-0.5.0 → eemkit-0.6.0}/docs/plotting.md +0 -0
  45. {eemkit-0.5.0 → eemkit-0.6.0}/docs/quickstart.md +0 -0
  46. {eemkit-0.5.0 → eemkit-0.6.0}/pyproject.toml +0 -0
  47. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/__main__.py +0 -0
  48. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/absorbance.py +0 -0
  49. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/campaigns.py +0 -0
  50. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/core/__init__.py +0 -0
  51. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/core/dataset.py +0 -0
  52. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/core/grid.py +0 -0
  53. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/core/history.py +0 -0
  54. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/_common.py +0 -0
  55. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/blank.py +0 -0
  56. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/crop.py +0 -0
  57. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/dilution.py +0 -0
  58. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/instrument.py +0 -0
  59. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/raman.py +0 -0
  60. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/scatter.py +0 -0
  61. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/spectral.py +0 -0
  62. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/corrections/zap.py +0 -0
  63. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/errors.py +0 -0
  64. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/__init__.py +0 -0
  65. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/__main__.py +0 -0
  66. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/campaigns_tab.py +0 -0
  67. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/common.py +0 -0
  68. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/export_tab.py +0 -0
  69. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/icons/eemkit-128.png +0 -0
  70. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/icons/eemkit-16.png +0 -0
  71. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/icons/eemkit-24.png +0 -0
  72. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/icons/eemkit-256.png +0 -0
  73. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/icons/eemkit-32.png +0 -0
  74. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/icons/eemkit-48.png +0 -0
  75. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/icons/eemkit-64.png +0 -0
  76. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/indices_tab.py +0 -0
  77. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/main_window.py +0 -0
  78. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/parafac_tab.py +0 -0
  79. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/project_tab.py +0 -0
  80. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/splash.py +0 -0
  81. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/state.py +0 -0
  82. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/gui/theme.py +0 -0
  83. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/indices.py +0 -0
  84. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/io/__init__.py +0 -0
  85. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/io/_cary_csv.py +0 -0
  86. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/io/cary60.py +0 -0
  87. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/io/cary_eclipse.py +0 -0
  88. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/io/discover.py +0 -0
  89. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/io/instruments.py +0 -0
  90. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/io/loader.py +0 -0
  91. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/io/pairing.py +0 -0
  92. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/__init__.py +0 -0
  93. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/_cp.py +0 -0
  94. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/channels.py +0 -0
  95. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/compare.py +0 -0
  96. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/diagnostics.py +0 -0
  97. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/export.py +0 -0
  98. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/model.py +0 -0
  99. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/outliers.py +0 -0
  100. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/parafac/validation.py +0 -0
  101. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/plot.py +0 -0
  102. {eemkit-0.5.0 → eemkit-0.6.0}/src/eemkit/report.py +0 -0
  103. {eemkit-0.5.0 → eemkit-0.6.0}/tests/conftest.py +0 -0
  104. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/README.md +0 -0
  105. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/aqualog/sample4.dat +0 -0
  106. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/eemR_DESCRIPTION.txt +0 -0
  107. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/fluoromax4/f1.dat +0 -0
  108. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/fluoromax4/f2.dat +0 -0
  109. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/fluoromax4/f3.dat +0 -0
  110. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/hitachi-f7000-fl/hitachi1.TXT +0 -0
  111. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/hitachi-f7000-fl/hitachi2.TXT +0 -0
  112. {eemkit-0.5.0 → eemkit-0.6.0}/tests/data/eemR/shimadzu/shimadzu.TXT +0 -0
  113. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_absorbance.py +0 -0
  114. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_campaigns.py +0 -0
  115. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_cary60.py +0 -0
  116. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_cary_eclipse.py +0 -0
  117. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_channels.py +0 -0
  118. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_dataset.py +0 -0
  119. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_dilution_zap.py +0 -0
  120. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_grid.py +0 -0
  121. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_indices.py +0 -0
  122. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_instruments.py +0 -0
  123. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_outliers_report.py +0 -0
  124. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_package.py +0 -0
  125. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_pairing.py +0 -0
  126. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_parafac.py +0 -0
  127. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_parafac_compare.py +0 -0
  128. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_plot.py +0 -0
  129. {eemkit-0.5.0 → eemkit-0.6.0}/tests/test_real_data.py +0 -0
@@ -3,6 +3,23 @@
3
3
  All notable changes are listed here. Versions follow
4
4
  [semantic versioning](https://semver.org/).
5
5
 
6
+ ## 0.6.0 (2026-11-30)
7
+
8
+ Fluorescence data without absorbance spectra. Projects that correct the
9
+ inner filter give the same results as in 0.5.0.
10
+
11
+ * **Data without absorbance spectra.** A fluorometer used on its own (e.g. a
12
+ Cary Eclipse without a UV-Vis spectrophotometer) gives no absorbance, and
13
+ until now the inner-filter step stopped the corrections. With
14
+ `inner_filter.apply = false` and a `skip_reason`, or in the application by
15
+ unticking `Correct with the absorbance spectra` and saying why, the step is
16
+ left out and the reason is recorded in the processing history, the
17
+ processing record and the report (new function
18
+ `corrections.skip_inner_filter`). A reason is required: the correction is
19
+ never left out silently. The fluorescence path length is then not needed.
20
+ `eemkit check` reports the choice. Projects that correct the inner filter
21
+ do not change.
22
+
6
23
  ## 0.5.0 (2026-11-26)
7
24
 
8
25
  The application for macOS and Linux, and a logo. Results do not change.
@@ -6,8 +6,8 @@ authors:
6
6
  - family-names: Cirrone
7
7
  given-names: Riccardo Gaetano
8
8
  affiliation: University of Siena
9
- version: 0.5.0
10
- date-released: "2026-11-26"
9
+ version: 0.6.0
10
+ date-released: "2026-11-30"
11
11
  doi: 10.5281/zenodo.23982732
12
12
  identifiers:
13
13
  - type: doi
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: eemkit
3
- Version: 0.5.0
3
+ Version: 0.6.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/
@@ -46,6 +46,7 @@
46
46
  - subtract_absorbance_blank
47
47
  - match_absorbance_dilution
48
48
  - correct_inner_filter
49
+ - skip_inner_filter
49
50
  - subtract_blank
50
51
  - normalize_raman
51
52
  - correct_dilution
@@ -140,7 +140,7 @@ Parameters on the left, preview on the right. The order of the steps is fixed: i
140
140
  | Box | Contents | Ombrone |
141
141
  | --- | --- | --- |
142
142
  | `Instrument spectral correction` | Excitation and emission correction factor files of the instrument (optional, see [below](#instrument-spectral-correction)). Empty = not applied. | not applied |
143
- | `Inner filter` | Path length of the two cuvettes in cm. **Required**, with no default: while they are empty (red) the corrections do not run. Kothawala et al. 2013. | 1 and 1 |
143
+ | `Inner filter` | Path length of the two cuvettes in cm. **Required**, with no default: while they are empty (red) the corrections do not run. Kothawala et al. 2013. Without absorbance spectra, untick `Correct with the absorbance spectra` and say why in `Why not corrected`: the reason is written in the processing record (see [Corrections](corrections.md#without-absorbance-spectra)). | 1 and 1 |
144
144
  | `Raman units` | Excitation and emission range of the Raman area of the blank; optional baseline subtraction. Lawaetz & Stedmon 2009. | Ex 350, Em 381–426, no |
145
145
  | `Scatter removal` | Water Raman shift and width (below/above, in nm) of the four bands: first- and second-order Rayleigh and Raman. `Zeros below Rayleigh` sets to zero the region where emission is below excitation minus the offset (Thygesen et al. 2004). `Interpolate removed bands`: `no` keeps the bands as missing data, as PARAFAC needs; `em`, `ex` or `both` interpolate them. | 3400 cm⁻¹; 10/10, 8/8, 12/12, 10/10; zeros at 10 nm; no |
146
146
  | `Crop` | Excitation and emission limits to keep. Empty = no limit. | Ex ≥ 240 |
@@ -13,6 +13,7 @@ always passed explicitly.
13
13
  | 2 | `subtract_absorbance_blank` | `absorbance - blank_absorbance` | |
14
14
  | 2b | `match_absorbance_dilution` | diluted samples only: absorbance rescaled to the EEM's dilution | Beer–Lambert |
15
15
  | 3 | `correct_inner_filter` | `F * 10**((A_ex + A_em) / 2)`, path lengths required | Kothawala et al. 2013; Lakowicz 2006 |
16
+ | 3* | `skip_inner_filter` | no absorbance spectra: nothing computed, the reason recorded ([below](#without-absorbance-spectra)) | |
16
17
  | 4 | `subtract_blank` | `intensity - blank_intensity` | |
17
18
  | 5 | `normalize_raman` | divides by the blank's water Raman area | Lawaetz & Stedmon 2009 |
18
19
  | 5b | `correct_dilution` | diluted samples only: `intensity * dilution_factor` | staRdom `eem_dilution` |
@@ -32,6 +33,32 @@ Samples lacking an input (blank, absorbance) make a correction fail unless
32
33
  `missing="keep"` (leave them uncorrected, flagged in a coordinate) or
33
34
  `missing="drop"` is passed.
34
35
 
36
+ ## Without absorbance spectra
37
+
38
+ A fluorometer used on its own (a Cary Eclipse without a UV-Vis
39
+ spectrophotometer, for example) gives no absorbance, so the inner filter
40
+ cannot be corrected. eemkit does not skip the step silently:
41
+ `skip_inner_filter(ds, reason=...)` takes its place in the order, changes
42
+ nothing and records the reason in the history (and so in
43
+ `processing_record.json` and the report); `ife_corrected` is False for every
44
+ sample. In a project file:
45
+
46
+ ```toml
47
+ [inner_filter]
48
+ apply = false
49
+ skip_reason = "no absorbance measured; samples diluted to A254 < 0.05"
50
+ ```
51
+
52
+ The fluorescence path length is then not needed; the absorbance one is
53
+ still needed if absorbance files are paired (for the CDOM metrics).
54
+ Uncorrected fluorescence is too low where the sample absorbs, and more so
55
+ for the most concentrated samples, which can distort PARAFAC scores and
56
+ components. The correction is commonly left out only for samples of low
57
+ absorbance or diluted to it (Kothawala et al. 2013); the reason should say
58
+ which. The pairing table still pairs each EEM with its water blank, needed
59
+ for the blank subtraction and the Raman units; the absorbance columns stay
60
+ empty.
61
+
35
62
  ## Spectral correction
36
63
 
37
64
  `ds.attrs["spectral_correction"]` is `"none"` until
@@ -1,6 +1,6 @@
1
1
  """eemkit: EEM processing and PARAFAC modelling of dissolved organic matter fluorescence."""
2
2
 
3
- __version__ = "0.5.0"
3
+ __version__ = "0.6.0"
4
4
 
5
5
  import importlib
6
6
  from typing import TYPE_CHECKING
@@ -81,6 +81,7 @@ def check(args: argparse.Namespace) -> int:
81
81
  settings, base = _project(args.project)
82
82
  problems: list[str] = []
83
83
  notes: list[str] = []
84
+ table = None
84
85
  proj = settings["project"]
85
86
  for key in ("data_root", "pairing"):
86
87
  if not proj.get(key):
@@ -106,7 +107,19 @@ def check(args: argparse.Namespace) -> int:
106
107
  notes.append(f"pairing table: {len(table)} rows, {n_in} included")
107
108
  if n_in == 0:
108
109
  problems.append("no row of the pairing table is included")
109
- for key in ("absorbance_path_length_cm", "fluorescence_path_length_cm"):
110
+ try:
111
+ skip = pipeline.inner_filter_skip_reason(settings)
112
+ except EEMKitError as e:
113
+ problems.append(str(e))
114
+ skip = ""
115
+ keys = ["absorbance_path_length_cm", "fluorescence_path_length_cm"]
116
+ if skip is not None:
117
+ if skip:
118
+ notes.append(f"inner filter: not corrected ({skip})")
119
+ paired_abs = table is not None and bool((table.loc[table["include"], "abs_file"]
120
+ != "").any())
121
+ keys = ["absorbance_path_length_cm"] if paired_abs else []
122
+ for key in keys:
110
123
  if settings["inner_filter"].get(key) in (None, ""):
111
124
  problems.append(f"inner_filter.{key} is not set (it depends on your cuvettes)")
112
125
  try:
@@ -4,7 +4,8 @@ Recommended order (each function refuses to run after a step that must follow it
4
4
 
5
5
  1. :func:`apply_spectral_correction` (instrument response; optional)
6
6
  2. :func:`subtract_absorbance_blank`
7
- 3. :func:`correct_inner_filter`
7
+ 3. :func:`correct_inner_filter` (or :func:`skip_inner_filter`, with the reason, when
8
+ there are no absorbance spectra)
8
9
  4. :func:`subtract_blank`
9
10
  5. :func:`normalize_raman`, then :func:`correct_dilution` (diluted samples) and
10
11
  :func:`zap` (regions removed by hand)
@@ -17,7 +18,7 @@ With diluted samples, :func:`match_absorbance_dilution` goes between steps 2 and
17
18
  from eemkit.corrections.blank import subtract_absorbance_blank, subtract_blank
18
19
  from eemkit.corrections.crop import crop
19
20
  from eemkit.corrections.dilution import correct_dilution, match_absorbance_dilution
20
- from eemkit.corrections.inner_filter import correct_inner_filter
21
+ from eemkit.corrections.inner_filter import correct_inner_filter, skip_inner_filter
21
22
  from eemkit.corrections.raman import normalize_raman, raman_area
22
23
  from eemkit.corrections.scatter import (
23
24
  interpolate_missing,
@@ -45,6 +46,7 @@ __all__ = [
45
46
  "read_correction_file",
46
47
  "remove_scatter",
47
48
  "scatter_mask",
49
+ "skip_inner_filter",
48
50
  "spectral_correction_status",
49
51
  "subtract_absorbance_blank",
50
52
  "subtract_blank",
@@ -31,6 +31,8 @@ from eemkit.corrections._common import (
31
31
  from eemkit.errors import CorrectionError, EEMKitWarning
32
32
 
33
33
  KOTHAWALA_MAX_A254 = 1.5
34
+ #: History step written when the correction is deliberately not applied.
35
+ SKIP_STEP = "skip_inner_filter"
34
36
 
35
37
 
36
38
  def correct_inner_filter(
@@ -65,6 +67,7 @@ def correct_inner_filter(
65
67
  step = "correct_inner_filter"
66
68
  require_vars(ds, "intensity", "absorbance", step=step)
67
69
  require_not_done(ds, step)
70
+ require_not_done(ds, SKIP_STEP)
68
71
  # The water Raman signal inside the sample is attenuated like the DOM
69
72
  # fluorescence, so IFE must be corrected before the blank is subtracted.
70
73
  for later in ("subtract_blank", "normalize_raman", "remove_scatter"):
@@ -110,6 +113,35 @@ def correct_inner_filter(
110
113
  )
111
114
 
112
115
 
116
+ def skip_inner_filter(ds: xr.Dataset, *, reason: str) -> xr.Dataset:
117
+ """Record that the inner-filter correction is not applied, and why.
118
+
119
+ For data without absorbance spectra, e.g. from a fluorometer used on its
120
+ own. The intensities are not changed: the step only writes a history entry
121
+ with ``reason`` (so the processing record says the correction is missing),
122
+ sets ``ife_corrected`` to False for every sample and prevents a later
123
+ :func:`correct_inner_filter`. Without the correction, fluorescence is
124
+ underestimated where the sample absorbs; it is commonly neglected only for
125
+ samples of low absorbance or diluted to it (Kothawala et al. 2013), which
126
+ is what ``reason`` should state.
127
+ """
128
+ step = SKIP_STEP
129
+ require_vars(ds, "intensity", step=step)
130
+ require_not_done(ds, step)
131
+ require_not_done(ds, "correct_inner_filter")
132
+ for later in ("subtract_blank", "normalize_raman", "remove_scatter"):
133
+ require_not_after(ds, step, later, allow_instrument=later == "subtract_blank")
134
+ reason = str(reason or "").strip()
135
+ if not reason:
136
+ raise CorrectionError(f"{step}: give the reason why the inner-filter correction is not "
137
+ "applied (it is written in the processing record)")
138
+ flags = xr.DataArray(np.zeros(ds.sizes[SAMPLE_DIM], dtype=bool), dims=SAMPLE_DIM)
139
+ out = ds.assign_coords(ife_corrected=flags)
140
+ n_abs = int(has_data(ds["absorbance"]).sum()) if "absorbance" in ds else 0
141
+ return with_history(out, step, reason=reason, n_samples=int(ds.sizes[SAMPLE_DIM]),
142
+ n_with_absorbance=n_abs)
143
+
144
+
113
145
  def _at(a: xr.DataArray, wavelengths: xr.DataArray) -> xr.DataArray:
114
146
  """Absorbance at the given wavelengths, linear interpolation, renamed to their dim."""
115
147
  dim = wavelengths.dims[0]
@@ -67,11 +67,24 @@ class CorrectionsTab(QWidget):
67
67
 
68
68
  self.l_abs = OptionalFloat(required=True, placeholder="required, e.g. 1")
69
69
  self.l_fl = OptionalFloat(required=True, placeholder="required, e.g. 1")
70
+ self.ife_apply = QCheckBox("Correct with the absorbance spectra")
71
+ self.ife_apply.setChecked(True)
72
+ self.ife_reason = QLineEdit()
73
+ self.ife_reason.setPlaceholderText("required, e.g. no absorbance; samples diluted "
74
+ "to A254 < 0.05")
75
+ self.ife_apply.toggled.connect(self._ife_toggled)
70
76
  g_ife = QGroupBox("Inner filter (Kothawala et al. 2013)")
71
77
  f = QFormLayout(g_ife)
78
+ f.addRow(self.ife_apply)
72
79
  f.addRow("Absorbance cuvette (cm)", self.l_abs)
73
80
  f.addRow("Fluorescence cuvette (cm)", self.l_fl)
74
- f.addRow(note("Path lengths depend on your cuvettes and have no default."))
81
+ f.addRow("Why not corrected", self.ife_reason)
82
+ f.addRow(note("Path lengths depend on your cuvettes and have no default. Without "
83
+ "absorbance spectra (e.g. a fluorometer used alone), untick the box and "
84
+ "give the reason: it is written in the processing record. Uncorrected "
85
+ "fluorescence is too low where the sample absorbs, so this suits only "
86
+ "samples of low absorbance."))
87
+ self._ife_toggled(True)
75
88
 
76
89
  r = s["raman"]
77
90
  self.r_ex = spin(r["ex"], 200, 600, 1, 0, " nm")
@@ -168,6 +181,9 @@ class CorrectionsTab(QWidget):
168
181
  self.convention.setCurrentText(CONVENTIONS[s["spectral"].get("convention", "multiply")])
169
182
  self.l_abs.set_value(s["inner_filter"].get("absorbance_path_length_cm"))
170
183
  self.l_fl.set_value(s["inner_filter"].get("fluorescence_path_length_cm"))
184
+ self.ife_reason.setText(str(s["inner_filter"].get("skip_reason") or ""))
185
+ self.ife_apply.setChecked(s["inner_filter"].get("apply", True) is not False)
186
+ self._ife_toggled(self.ife_apply.isChecked())
171
187
  r = s["raman"]
172
188
  self.r_ex.setValue(float(r["ex"]))
173
189
  self.r_lo.setValue(float(r["em_range"][0]))
@@ -185,11 +201,30 @@ class CorrectionsTab(QWidget):
185
201
  w.set_value(s["crop"].get(k))
186
202
  self.missing.setCurrentText(s["missing"]["policy"])
187
203
 
204
+ def _ife_toggled(self, apply: bool) -> None:
205
+ """Path lengths are required only with the correction; the reason only without it."""
206
+ self.l_fl.setEnabled(apply)
207
+ self.ife_reason.setEnabled(not apply)
208
+ for w, required in ((self.l_abs, apply), (self.l_fl, apply)):
209
+ w.required = required
210
+ w._validate()
211
+
188
212
  def store_settings(self) -> bool:
189
- if not (self.l_abs.is_valid() and self.l_fl.is_valid()):
213
+ apply = self.ife_apply.isChecked()
214
+ reason = self.ife_reason.text().strip()
215
+ if apply and not (self.l_abs.is_valid() and self.l_fl.is_valid()):
190
216
  QMessageBox.information(self, "eemkit", "Enter both cuvette path lengths (cm). "
191
217
  "They depend on your measurement and have no default.")
192
218
  return False
219
+ if not apply and not reason:
220
+ QMessageBox.information(self, "eemkit", "Say why the inner filter is not "
221
+ "corrected; the reason is written in the processing "
222
+ "record.")
223
+ return False
224
+ if not self.l_abs.is_valid():
225
+ QMessageBox.information(self, "eemkit", "The absorbance cuvette path length is "
226
+ "not a number.")
227
+ return False
193
228
  files = {k: e.text() for k, e in self.factor_files.items()}
194
229
  if bool(files["ex_factors"]) != bool(files["em_factors"]):
195
230
  QMessageBox.information(self, "eemkit", "Spectral correction needs both the "
@@ -200,7 +235,8 @@ class CorrectionsTab(QWidget):
200
235
  sections = {
201
236
  "spectral": {**{k: self.project.relative(v) for k, v in files.items()},
202
237
  "convention": convention},
203
- "inner_filter": {"absorbance_path_length_cm": self.l_abs.value(),
238
+ "inner_filter": {"apply": apply, "skip_reason": "" if apply else reason,
239
+ "absorbance_path_length_cm": self.l_abs.value(),
204
240
  "fluorescence_path_length_cm": self.l_fl.value()},
205
241
  "raman": {"ex": self.r_ex.value(), "em_range": [self.r_lo.value(), self.r_hi.value()],
206
242
  "baseline": self.r_base.isChecked()},
@@ -289,11 +325,15 @@ class CorrectionsTab(QWidget):
289
325
  lines.append(f"{p.raw.sizes['sample']} samples loaded. Spectral correction: "
290
326
  f"{C.spectral_correction_status(done)}.")
291
327
  if p.corrected is not None:
292
- ife = p.corrected["ife_factor"]
328
+ if "ife_factor" in p.corrected:
329
+ ife = p.corrected["ife_factor"]
330
+ ife_text = (f"Inner-filter factor over all cells: median "
331
+ f"{float(ife.median()):.3f}, max {float(ife.max()):.3f}.")
332
+ else:
333
+ ife_text = "Inner filter not corrected."
293
334
  ra = p.corrected["raman_area"].values
294
335
  miss = float(np.isnan(p.corrected["intensity"]).mean()) * 100
295
- lines.append(f"Inner-filter factor over all cells: median {float(ife.median()):.3f}, "
296
- f"max {float(ife.max()):.3f}. Raman area of the blanks: "
336
+ lines.append(f"{ife_text} Raman area of the blanks: "
297
337
  f"{np.nanmin(ra):.4g}-{np.nanmax(ra):.4g} (CV "
298
338
  f"{np.nanstd(ra) / np.nanmean(ra) * 100:.1f} %). Corrected grid: ex "
299
339
  f"{p.corrected.ex.min().item():g}-{p.corrected.ex.max().item():g}, em "
@@ -71,8 +71,10 @@ DEFAULTS: dict = {
71
71
  # Instrument-specific factor files (wavelength, factor); empty = not applied.
72
72
  # convention: "multiply" (correction factors) or "divide" (response spectra).
73
73
  "spectral": {"ex_factors": "", "em_factors": "", "convention": "multiply"},
74
- # Kothawala et al. (2013): absorbance-based inner-filter correction
75
- "inner_filter": {"absorbance_path_length_cm": None, "fluorescence_path_length_cm": None},
74
+ # Kothawala et al. (2013): absorbance-based inner-filter correction. apply = false (no
75
+ # absorbance spectra) needs skip_reason, written in the processing record.
76
+ "inner_filter": {"apply": True, "skip_reason": "",
77
+ "absorbance_path_length_cm": None, "fluorescence_path_length_cm": None},
76
78
  # Lawaetz & Stedmon (2009): Raman area of the blank at ex 350, em 381-426 nm
77
79
  "raman": {"ex": 350.0, "em_range": [381.0, 426.0], "baseline": False},
78
80
  # Band widths (below, above) in nm. 10 nm is the eemR/staRdom default width;
@@ -225,10 +227,31 @@ def reader_options(settings: dict) -> dict:
225
227
  return {}
226
228
 
227
229
 
230
+ def inner_filter_skip_reason(settings: dict) -> str | None:
231
+ """``None`` if the inner-filter correction is applied, else the reason it is not.
232
+
233
+ Raises :class:`~eemkit.errors.SettingsError` when ``inner_filter.apply`` is
234
+ false without a ``skip_reason``: the correction is never left out silently.
235
+ """
236
+ s = settings.get("inner_filter", {})
237
+ apply = s.get("apply", True)
238
+ if not isinstance(apply, bool):
239
+ raise SettingsError(f"inner_filter.apply must be true or false, got {apply!r}")
240
+ if apply:
241
+ return None
242
+ reason = str(s.get("skip_reason") or "").strip()
243
+ if not reason:
244
+ raise SettingsError("inner_filter.apply is false: say why in inner_filter.skip_reason "
245
+ "(e.g. 'no absorbance measured; samples diluted to A254 < 0.05'); "
246
+ "it is written in the processing record")
247
+ return reason
248
+
249
+
228
250
  def correct_until_raman(ds: xr.Dataset, settings: dict,
229
251
  base: str | Path | None = None) -> xr.Dataset:
230
252
  """Spectral correction (if factor files are set), absorbance blank, inner
231
- filter, EEM blank and Raman units; then dilution (when the pairing table
253
+ filter (or, with ``inner_filter.apply = false``, a history entry with the
254
+ reason it is not applied), EEM blank and Raman units; then dilution (when the pairing table
232
255
  has dilution columns) and the regions of ``zap.regions``. Factor files are
233
256
  relative to ``base``. Steps listed in ``project.already_done`` were done by
234
257
  the instrument software: they are recorded, not repeated, and must agree
@@ -236,9 +259,14 @@ def correct_until_raman(ds: xr.Dataset, settings: dict,
236
259
  done = list(settings["project"].get("already_done") or [])
237
260
  check_declared(ds, done)
238
261
  has_abs = "absorbance" in ds
239
- if "inner_filter" not in done or has_abs:
262
+ skip_reason = inner_filter_skip_reason(settings)
263
+ correct_ife = "inner_filter" not in done and skip_reason is None
264
+ if skip_reason is not None and "inner_filter" in done:
265
+ raise SettingsError("inner_filter.apply is false, but project.already_done says the "
266
+ "instrument software corrected the inner filter: keep only one")
267
+ if correct_ife or has_abs:
240
268
  l_abs = _required(settings, "inner_filter", "absorbance_path_length_cm")
241
- if "inner_filter" not in done:
269
+ if correct_ife:
242
270
  l_fl = _required(settings, "inner_filter", "fluorescence_path_length_cm")
243
271
  missing = settings["missing"]["policy"]
244
272
  sp = settings["spectral"]
@@ -258,6 +286,8 @@ def correct_until_raman(ds: xr.Dataset, settings: dict,
258
286
  ds = C.match_absorbance_dilution(ds)
259
287
  if "inner_filter" in done:
260
288
  ds = mark_done(ds, "inner_filter")
289
+ elif skip_reason is not None:
290
+ ds = C.skip_inner_filter(ds, reason=skip_reason)
261
291
  else:
262
292
  if "blank" in done:
263
293
  warnings.warn("the instrument subtracted the blank before eemkit's inner-filter "
@@ -44,6 +44,25 @@ def test_check_lists_missing_settings(project, capsys):
44
44
  assert "inner_filter.absorbance_path_length_cm is not set" in capsys.readouterr().out
45
45
 
46
46
 
47
+ def test_check_without_inner_filter_correction(project, capsys):
48
+ s = pipeline.load_settings(project)
49
+ s["inner_filter"].update(apply=False, absorbance_path_length_cm=None,
50
+ fluorescence_path_length_cm=None)
51
+ pipeline.save_settings(s, project)
52
+ assert main(["check", str(project)]) == 1
53
+ out = capsys.readouterr().out
54
+ assert "skip_reason" in out
55
+ assert "absorbance_path_length_cm is not set" in out # absorbance files are still paired
56
+ assert "fluorescence_path_length_cm" not in out
57
+ table = pd.read_csv(project.parent / "pairing.csv", dtype=str, keep_default_na=False)
58
+ table[["abs_file", "abs_blank_file"]] = ""
59
+ table.to_csv(project.parent / "pairing.csv", index=False)
60
+ s["inner_filter"]["skip_reason"] = "no absorbance measured"
61
+ pipeline.save_settings(s, project)
62
+ assert main(["check", str(project)]) == 0
63
+ assert "inner filter: not corrected (no absorbance measured)" in capsys.readouterr().out
64
+
65
+
47
66
  def test_run_writes_the_results_next_to_the_project(project, capsys):
48
67
  with warnings.catch_warnings():
49
68
  warnings.simplefilter("ignore")
@@ -119,6 +119,30 @@ def test_inner_filter_missing_absorbance():
119
119
  assert not bool(out["ife_corrected"].sel(sample="s0"))
120
120
 
121
121
 
122
+ def test_skip_inner_filter_records_the_reason():
123
+ ds = make_ds().drop_vars(["absorbance", "blank_absorbance", "wavelength"])
124
+ with pytest.raises(CorrectionError, match="reason"):
125
+ C.skip_inner_filter(ds, reason=" ")
126
+ out = C.skip_inner_filter(ds, reason="no absorbance; diluted")
127
+ # nothing computed: only the ife_corrected flag is added
128
+ xr.testing.assert_identical(out["intensity"].drop_vars("ife_corrected"), ds["intensity"])
129
+ assert not out["ife_corrected"].any()
130
+ entry = get_history(out)[-1]
131
+ assert entry["step"] == "skip_inner_filter"
132
+ assert entry["params"]["reason"] == "no absorbance; diluted"
133
+ assert entry["params"]["n_with_absorbance"] == 0
134
+ # the rest of the chain runs; neither the skip nor the correction can follow it
135
+ later = C.normalize_raman(C.subtract_blank(out), ex=350, em_range=(381, 426))
136
+ assert steps(later)[-3:] == ["skip_inner_filter", "subtract_blank", "normalize_raman"]
137
+ with pytest.raises(CorrectionError, match="already"):
138
+ C.skip_inner_filter(out, reason="again")
139
+ with pytest.raises(CorrectionError, match="skip_inner_filter"):
140
+ C.correct_inner_filter(C.subtract_absorbance_blank(C.skip_inner_filter(
141
+ make_ds(), reason="r")), absorbance_path_length_cm=1, fluorescence_path_length_cm=1)
142
+ with pytest.raises(CorrectionError, match="before subtract_blank"):
143
+ C.skip_inner_filter(C.subtract_blank(ds), reason="r")
144
+
145
+
122
146
  # --- Raman ---------------------------------------------------------------------
123
147
 
124
148
  def test_raman_area_exact_for_piecewise_linear_and_off_grid_limits():
@@ -267,6 +267,41 @@ def test_instrument_box(qtbot, window, dialogs, tmp_path):
267
267
  assert tab.instrument.currentData() == "fluoromax"
268
268
 
269
269
 
270
+ def test_inner_filter_not_corrected(qtbot, window, dialogs, tmp_path):
271
+ """Without absorbance spectra the box is unticked and the reason given."""
272
+ w, p, tab = window, window.project, window.corrections_tab
273
+ data = make_project(tmp_path)
274
+ p.set_path_setting("data_root", data)
275
+ p.set_path_setting("pairing", tmp_path / "pairing.csv")
276
+ p.set_path_setting("output_dir", tmp_path / "results")
277
+ p.changed.emit("settings")
278
+ w.project_tab.scan()
279
+ _idle(qtbot, w)
280
+ w.project_tab.suggest()
281
+ w.project_tab.pairing_view.selectAll()
282
+ w.project_tab.set_include(True)
283
+ p.pairing[["abs_file", "abs_blank_file"]] = ""
284
+ w.project_tab.load_data()
285
+ _idle(qtbot, w)
286
+ assert "absorbance" not in p.raw
287
+
288
+ assert tab.ife_apply.isChecked() and not tab.ife_reason.isEnabled()
289
+ tab.ife_apply.setChecked(False)
290
+ assert not tab.l_fl.isEnabled() and tab.ife_reason.isEnabled()
291
+ tab.apply() # no reason: refused
292
+ assert dialogs[-1][0] == "information" and "why" in dialogs[-1][1]
293
+ assert p.corrected is None
294
+ tab.ife_reason.setText("no absorbance measured")
295
+ tab.apply()
296
+ _idle(qtbot, w)
297
+ assert p.corrected is not None and not p.corrected["ife_corrected"].any()
298
+ assert p.settings["inner_filter"]["apply"] is False
299
+ assert p.settings["inner_filter"]["skip_reason"] == "no absorbance measured"
300
+ assert "Inner filter not corrected" in tab.summary.text()
301
+ tab.load_settings() # the form shows what the project says
302
+ assert not tab.ife_apply.isChecked() and tab.ife_reason.text() == "no absorbance measured"
303
+
304
+
270
305
  def test_output_inside_data_folder_is_refused(window, tmp_path):
271
306
  p = window.project
272
307
  p.set_path_setting("data_root", tmp_path / "data")
@@ -10,7 +10,7 @@ import pandas as pd
10
10
  import pytest
11
11
  from conftest import cary60_text, eclipse_text
12
12
 
13
- from eemkit import load_dataset, pipeline, read_pairing
13
+ from eemkit import get_history, load_dataset, pipeline, read_pairing
14
14
  from eemkit.errors import Cancelled, SettingsError
15
15
  from eemkit.io.discover import classify, scan_folder, suggest_pairing
16
16
 
@@ -185,6 +185,46 @@ def test_full_chain_recovers_components_and_exports(data_root, tmp_path):
185
185
  assert fmax.shape == (8, 2)
186
186
 
187
187
 
188
+ def test_inner_filter_skipped_without_absorbance(data_root, tmp_path):
189
+ """A fluorometer alone (no absorbance): the correction is left out only with a reason."""
190
+ s = _settings(data_root, tmp_path)
191
+ table = pd.read_csv(tmp_path / "pairing.csv", dtype=str, keep_default_na=False)
192
+ table = table.drop(columns=["abs_file", "abs_blank_file"])
193
+ table.to_csv(tmp_path / "pairing.csv", index=False)
194
+ s["inner_filter"].update(absorbance_path_length_cm=None, fluorescence_path_length_cm=None)
195
+ raw = pipeline.load(s)
196
+ assert "absorbance" not in raw
197
+ with pytest.raises(SettingsError, match="path_length_cm"):
198
+ pipeline.correct_until_raman(raw, s)
199
+ s["inner_filter"]["apply"] = False
200
+ with pytest.raises(SettingsError, match="skip_reason"):
201
+ pipeline.correct_until_raman(raw, s)
202
+ s["inner_filter"]["skip_reason"] = "no absorbance measured; samples diluted"
203
+ s["project"]["already_done"] = ["inner_filter"]
204
+ with pytest.raises(SettingsError, match="only one"):
205
+ pipeline.correct_until_raman(raw, s)
206
+ s["project"]["already_done"] = []
207
+
208
+ with warnings.catch_warnings():
209
+ warnings.simplefilter("ignore")
210
+ after = pipeline.correct_until_raman(raw, s)
211
+ cor = pipeline.finish_corrections(after, s)
212
+ idx = pipeline.compute_indices(after, s)
213
+ names = [h["step"] for h in get_history(after)]
214
+ assert "skip_inner_filter" in names and "correct_inner_filter" not in names
215
+ assert names.index("skip_inner_filter") < names.index("subtract_blank")
216
+ assert not after["ife_corrected"].any() and "ife_factor" not in after
217
+ assert set(idx.columns) >= {"FI", "HIX", "BIX"}
218
+
219
+ out = Path(s["project"]["output_dir"])
220
+ pipeline.export_results(out, s, corrected=cor, indices=idx, figures=False)
221
+ assert "no absorbance measured; samples diluted" in \
222
+ (out / "processing_record.json").read_text(encoding="utf-8")
223
+ back = pipeline.load_settings(out / "settings.toml")
224
+ assert back["inner_filter"]["apply"] is False
225
+ assert back["inner_filter"]["skip_reason"] == "no absorbance measured; samples diluted"
226
+
227
+
188
228
  def test_spectral_correction_from_settings(data_root, tmp_path):
189
229
  s = _settings(data_root, tmp_path)
190
230
  _write(tmp_path / "factors" / "ex.csv", "nm,factor\r\n200,2\r\n500,2\r\n")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes