react-cheminfo 0.65.0 → 0.66.0

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 (237) hide show
  1. package/README.md +11 -6
  2. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  3. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  4. package/lib/ir/core/analysisSpectra.d.ts +23 -6
  5. package/lib/ir/core/analysisSpectra.d.ts.map +1 -1
  6. package/lib/ir/core/analysisSpectra.js.map +1 -1
  7. package/lib/ir/core/bandLabelPlan.d.ts.map +1 -1
  8. package/lib/ir/core/bandLabelPlan.js +11 -6
  9. package/lib/ir/core/bandLabelPlan.js.map +1 -1
  10. package/lib/ir/core/index.d.ts +13 -9
  11. package/lib/ir/core/index.d.ts.map +1 -1
  12. package/lib/ir/core/index.js +9 -6
  13. package/lib/ir/core/index.js.map +1 -1
  14. package/lib/ir/core/irBand.d.ts +45 -14
  15. package/lib/ir/core/irBand.d.ts.map +1 -1
  16. package/lib/ir/core/irBand.js +28 -6
  17. package/lib/ir/core/irBand.js.map +1 -1
  18. package/lib/ir/core/irCommands.d.ts +11 -0
  19. package/lib/ir/core/irCommands.d.ts.map +1 -1
  20. package/lib/ir/core/irCommands.js +11 -1
  21. package/lib/ir/core/irCommands.js.map +1 -1
  22. package/lib/ir/core/irDomain.d.ts +4 -3
  23. package/lib/ir/core/irDomain.d.ts.map +1 -1
  24. package/lib/ir/core/irDomain.js +10 -7
  25. package/lib/ir/core/irDomain.js.map +1 -1
  26. package/lib/ir/core/irFormat.d.ts +14 -2
  27. package/lib/ir/core/irFormat.d.ts.map +1 -1
  28. package/lib/ir/core/irFormat.js +33 -4
  29. package/lib/ir/core/irFormat.js.map +1 -1
  30. package/lib/ir/core/irMode.d.ts +35 -8
  31. package/lib/ir/core/irMode.d.ts.map +1 -1
  32. package/lib/ir/core/irMode.js +38 -10
  33. package/lib/ir/core/irMode.js.map +1 -1
  34. package/lib/ir/core/irReducer.d.ts +0 -28
  35. package/lib/ir/core/irReducer.d.ts.map +1 -1
  36. package/lib/ir/core/irReducer.js +1 -24
  37. package/lib/ir/core/irReducer.js.map +1 -1
  38. package/lib/ir/core/irSpectrum.d.ts +52 -26
  39. package/lib/ir/core/irSpectrum.d.ts.map +1 -1
  40. package/lib/ir/core/irSpectrum.js +21 -15
  41. package/lib/ir/core/irSpectrum.js.map +1 -1
  42. package/lib/ir/core/irState.d.ts +40 -2
  43. package/lib/ir/core/irState.d.ts.map +1 -1
  44. package/lib/ir/core/irState.js +38 -1
  45. package/lib/ir/core/irState.js.map +1 -1
  46. package/lib/ir/core/irTechnique.d.ts +94 -0
  47. package/lib/ir/core/irTechnique.d.ts.map +1 -0
  48. package/lib/ir/core/irTechnique.js +87 -0
  49. package/lib/ir/core/irTechnique.js.map +1 -0
  50. package/lib/ir/core/irTechniqueCommands.d.ts +26 -0
  51. package/lib/ir/core/irTechniqueCommands.d.ts.map +1 -0
  52. package/lib/ir/core/irTechniqueCommands.js +68 -0
  53. package/lib/ir/core/irTechniqueCommands.js.map +1 -0
  54. package/lib/ir/core/pickBands.d.ts +6 -5
  55. package/lib/ir/core/pickBands.d.ts.map +1 -1
  56. package/lib/ir/core/pickBands.js +49 -26
  57. package/lib/ir/core/pickBands.js.map +1 -1
  58. package/lib/ir/core/ramanBands.d.ts +30 -0
  59. package/lib/ir/core/ramanBands.d.ts.map +1 -0
  60. package/lib/ir/core/ramanBands.js +83 -0
  61. package/lib/ir/core/ramanBands.js.map +1 -0
  62. package/lib/ir/core/spectrumJcamp.d.ts +10 -5
  63. package/lib/ir/core/spectrumJcamp.d.ts.map +1 -1
  64. package/lib/ir/core/spectrumJcamp.js +63 -15
  65. package/lib/ir/core/spectrumJcamp.js.map +1 -1
  66. package/lib/ir/core/toIrSpectrum.d.ts.map +1 -1
  67. package/lib/ir/core/toIrSpectrum.js +17 -2
  68. package/lib/ir/core/toIrSpectrum.js.map +1 -1
  69. package/lib/ir/ui/BandRow.d.ts +30 -0
  70. package/lib/ir/ui/BandRow.d.ts.map +1 -0
  71. package/lib/ir/ui/BandRow.js +42 -0
  72. package/lib/ir/ui/BandRow.js.map +1 -0
  73. package/lib/ir/ui/BandsPanel.d.ts +4 -0
  74. package/lib/ir/ui/BandsPanel.d.ts.map +1 -1
  75. package/lib/ir/ui/BandsPanel.js +14 -59
  76. package/lib/ir/ui/BandsPanel.js.map +1 -1
  77. package/lib/ir/ui/IrAboutDialog.d.ts +7 -0
  78. package/lib/ir/ui/IrAboutDialog.d.ts.map +1 -1
  79. package/lib/ir/ui/IrAboutDialog.js +16 -3
  80. package/lib/ir/ui/IrAboutDialog.js.map +1 -1
  81. package/lib/ir/ui/IrCanvas.d.ts.map +1 -1
  82. package/lib/ir/ui/IrCanvas.js +2 -2
  83. package/lib/ir/ui/IrCanvas.js.map +1 -1
  84. package/lib/ir/ui/IrChart.d.ts +2 -1
  85. package/lib/ir/ui/IrChart.d.ts.map +1 -1
  86. package/lib/ir/ui/IrChart.js +18 -21
  87. package/lib/ir/ui/IrChart.js.map +1 -1
  88. package/lib/ir/ui/IrCommandProvider.d.ts +7 -0
  89. package/lib/ir/ui/IrCommandProvider.d.ts.map +1 -1
  90. package/lib/ir/ui/IrCommandProvider.js +2 -2
  91. package/lib/ir/ui/IrCommandProvider.js.map +1 -1
  92. package/lib/ir/ui/IrCommandTooltip.d.ts +7 -0
  93. package/lib/ir/ui/IrCommandTooltip.d.ts.map +1 -1
  94. package/lib/ir/ui/IrCommandTooltip.js +3 -2
  95. package/lib/ir/ui/IrCommandTooltip.js.map +1 -1
  96. package/lib/ir/ui/IrDocumentationDialog.d.ts +8 -1
  97. package/lib/ir/ui/IrDocumentationDialog.d.ts.map +1 -1
  98. package/lib/ir/ui/IrDocumentationDialog.js +30 -7
  99. package/lib/ir/ui/IrDocumentationDialog.js.map +1 -1
  100. package/lib/ir/ui/IrEditor.d.ts +3 -1
  101. package/lib/ir/ui/IrEditor.d.ts.map +1 -1
  102. package/lib/ir/ui/IrEditor.js +3 -20
  103. package/lib/ir/ui/IrEditor.js.map +1 -1
  104. package/lib/ir/ui/IrHeader.d.ts.map +1 -1
  105. package/lib/ir/ui/IrHeader.js +5 -1
  106. package/lib/ir/ui/IrHeader.js.map +1 -1
  107. package/lib/ir/ui/IrLogo.d.ts +11 -3
  108. package/lib/ir/ui/IrLogo.d.ts.map +1 -1
  109. package/lib/ir/ui/IrLogo.js +14 -5
  110. package/lib/ir/ui/IrLogo.js.map +1 -1
  111. package/lib/ir/ui/IrShell.d.ts.map +1 -1
  112. package/lib/ir/ui/IrShell.js +23 -56
  113. package/lib/ir/ui/IrShell.js.map +1 -1
  114. package/lib/ir/ui/IrStatusBar.d.ts +3 -2
  115. package/lib/ir/ui/IrStatusBar.d.ts.map +1 -1
  116. package/lib/ir/ui/IrStatusBar.js +14 -9
  117. package/lib/ir/ui/IrStatusBar.js.map +1 -1
  118. package/lib/ir/ui/IrToolbar.d.ts +3 -0
  119. package/lib/ir/ui/IrToolbar.d.ts.map +1 -1
  120. package/lib/ir/ui/IrToolbar.js +10 -3
  121. package/lib/ir/ui/IrToolbar.js.map +1 -1
  122. package/lib/ir/ui/IrTraces.d.ts +4 -1
  123. package/lib/ir/ui/IrTraces.d.ts.map +1 -1
  124. package/lib/ir/ui/IrTraces.js +2 -0
  125. package/lib/ir/ui/IrTraces.js.map +1 -1
  126. package/lib/ir/ui/RamanEditor.d.ts +46 -0
  127. package/lib/ir/ui/RamanEditor.d.ts.map +1 -0
  128. package/lib/ir/ui/RamanEditor.js +17 -0
  129. package/lib/ir/ui/RamanEditor.js.map +1 -0
  130. package/lib/ir/ui/SpectraPanel.d.ts.map +1 -1
  131. package/lib/ir/ui/SpectraPanel.js +2 -2
  132. package/lib/ir/ui/SpectraPanel.js.map +1 -1
  133. package/lib/ir/ui/SpectrumRow.d.ts +7 -0
  134. package/lib/ir/ui/SpectrumRow.d.ts.map +1 -1
  135. package/lib/ir/ui/SpectrumRow.js +4 -5
  136. package/lib/ir/ui/SpectrumRow.js.map +1 -1
  137. package/lib/ir/ui/VibrationalEditor.d.ts +48 -0
  138. package/lib/ir/ui/VibrationalEditor.d.ts.map +1 -0
  139. package/lib/ir/ui/VibrationalEditor.js +31 -0
  140. package/lib/ir/ui/VibrationalEditor.js.map +1 -0
  141. package/lib/ir/ui/bandsTsv.d.ts +19 -0
  142. package/lib/ir/ui/bandsTsv.d.ts.map +1 -0
  143. package/lib/ir/ui/bandsTsv.js +38 -0
  144. package/lib/ir/ui/bandsTsv.js.map +1 -0
  145. package/lib/ir/ui/irChartProps.d.ts +14 -4
  146. package/lib/ir/ui/irChartProps.d.ts.map +1 -1
  147. package/lib/ir/ui/irChartProps.js +3 -2
  148. package/lib/ir/ui/irChartProps.js.map +1 -1
  149. package/lib/ir/ui/irCommandContext.d.ts +8 -0
  150. package/lib/ir/ui/irCommandContext.d.ts.map +1 -1
  151. package/lib/ir/ui/irCommandContext.js +14 -3
  152. package/lib/ir/ui/irCommandContext.js.map +1 -1
  153. package/lib/ir/ui/useIrEditor.d.ts +3 -3
  154. package/lib/ir/ui/useIrEditor.d.ts.map +1 -1
  155. package/lib/ir/ui/useIrEditor.js +13 -4
  156. package/lib/ir/ui/useIrEditor.js.map +1 -1
  157. package/lib/ir/ui/useIrHandle.d.ts +14 -0
  158. package/lib/ir/ui/useIrHandle.d.ts.map +1 -0
  159. package/lib/ir/ui/useIrHandle.js +39 -0
  160. package/lib/ir/ui/useIrHandle.js.map +1 -0
  161. package/lib/ir/ui/useIrText.d.ts +40 -0
  162. package/lib/ir/ui/useIrText.d.ts.map +1 -0
  163. package/lib/ir/ui/useIrText.js +118 -0
  164. package/lib/ir/ui/useIrText.js.map +1 -0
  165. package/lib/ir/ui/useIrZoom.d.ts +7 -0
  166. package/lib/ir/ui/useIrZoom.d.ts.map +1 -1
  167. package/lib/ir/ui/useIrZoom.js +5 -4
  168. package/lib/ir/ui/useIrZoom.js.map +1 -1
  169. package/lib/ir/ui/useValueAxisZoom.d.ts +20 -0
  170. package/lib/ir/ui/useValueAxisZoom.d.ts.map +1 -0
  171. package/lib/ir/ui/useValueAxisZoom.js +54 -0
  172. package/lib/ir/ui/useValueAxisZoom.js.map +1 -0
  173. package/lib/ir.d.ts +3 -0
  174. package/lib/ir.d.ts.map +1 -1
  175. package/lib/ir.js +3 -0
  176. package/lib/ir.js.map +1 -1
  177. package/lib/locales/de.json +20 -1
  178. package/lib/locales/en.json +20 -1
  179. package/lib/locales/es.json +20 -1
  180. package/lib/locales/fr.json +20 -1
  181. package/lib/locales/it.json +20 -1
  182. package/lib/raman.d.ts +16 -0
  183. package/lib/raman.d.ts.map +1 -0
  184. package/lib/raman.js +12 -0
  185. package/lib/raman.js.map +1 -0
  186. package/package.json +2 -1
  187. package/src/ir/core/analysisSpectra.ts +26 -10
  188. package/src/ir/core/bandLabelPlan.ts +21 -10
  189. package/src/ir/core/index.ts +25 -5
  190. package/src/ir/core/irBand.ts +52 -14
  191. package/src/ir/core/irCommands.ts +15 -1
  192. package/src/ir/core/irDomain.ts +9 -7
  193. package/src/ir/core/irFormat.ts +39 -6
  194. package/src/ir/core/irMode.ts +42 -10
  195. package/src/ir/core/irReducer.ts +1 -49
  196. package/src/ir/core/irSpectrum.ts +59 -30
  197. package/src/ir/core/irState.ts +67 -2
  198. package/src/ir/core/irTechnique.ts +115 -0
  199. package/src/ir/core/irTechniqueCommands.ts +82 -0
  200. package/src/ir/core/pickBands.ts +63 -28
  201. package/src/ir/core/ramanBands.ts +105 -0
  202. package/src/ir/core/spectrumJcamp.ts +65 -16
  203. package/src/ir/core/toIrSpectrum.ts +20 -2
  204. package/src/ir/ui/BandRow.tsx +107 -0
  205. package/src/ir/ui/BandsPanel.tsx +32 -125
  206. package/src/ir/ui/IrAboutDialog.tsx +69 -28
  207. package/src/ir/ui/IrCanvas.tsx +2 -1
  208. package/src/ir/ui/IrChart.tsx +20 -24
  209. package/src/ir/ui/IrCommandProvider.tsx +10 -3
  210. package/src/ir/ui/IrCommandTooltip.tsx +11 -2
  211. package/src/ir/ui/IrDocumentationDialog.tsx +99 -55
  212. package/src/ir/ui/IrEditor.tsx +5 -36
  213. package/src/ir/ui/IrHeader.tsx +10 -3
  214. package/src/ir/ui/IrLogo.tsx +28 -9
  215. package/src/ir/ui/IrShell.tsx +27 -75
  216. package/src/ir/ui/IrStatusBar.tsx +17 -12
  217. package/src/ir/ui/IrToolbar.tsx +26 -15
  218. package/src/ir/ui/IrTraces.tsx +5 -1
  219. package/src/ir/ui/RamanEditor.tsx +53 -0
  220. package/src/ir/ui/SpectraPanel.tsx +2 -1
  221. package/src/ir/ui/SpectrumRow.tsx +14 -5
  222. package/src/ir/ui/VibrationalEditor.tsx +94 -0
  223. package/src/ir/ui/bandsTsv.ts +46 -0
  224. package/src/ir/ui/irChartProps.ts +14 -4
  225. package/src/ir/ui/irCommandContext.tsx +18 -3
  226. package/src/ir/ui/useIrEditor.ts +20 -8
  227. package/src/ir/ui/useIrHandle.ts +51 -0
  228. package/src/ir/ui/useIrText.ts +170 -0
  229. package/src/ir/ui/useIrZoom.ts +12 -3
  230. package/src/ir/ui/useValueAxisZoom.ts +67 -0
  231. package/src/ir.ts +3 -0
  232. package/src/locales/de.json +20 -1
  233. package/src/locales/en.json +20 -1
  234. package/src/locales/es.json +20 -1
  235. package/src/locales/fr.json +20 -1
  236. package/src/locales/it.json +20 -1
  237. package/src/raman.ts +19 -0
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Finding the bands of a Raman spectrum, with the picker infrared bands are
3
+ * found with.
4
+ *
5
+ * `autoPeakPicking` from `ir-spectrum` is `common-spectrum`'s, which runs
6
+ * `ml-gsd` over whichever variable it is pointed at — the picker
7
+ * `raman-spectrum` itself exports — and converts each peak to absorbance and
8
+ * transmittance on top. A Raman band is a maximum of intensity, so the picker is
9
+ * pointed at the intensity and only where each peak sits is read back: the
10
+ * conversion speaks two axes a Raman spectrum does not have.
11
+ *
12
+ * The strength letter follows the rule `ir-spectrum` applies to transmittance,
13
+ * applied to intensity: where the band's top sits between the spectrum's own
14
+ * lowest and highest intensity — below a third weak, below two thirds medium,
15
+ * strong above.
16
+ */
17
+
18
+ import type { MeasurementXY } from 'cheminfo-types';
19
+ import { autoPeakPicking } from 'ir-spectrum';
20
+ import { xFindClosestIndex, xMinMaxValues } from 'ml-spectra-processing';
21
+
22
+ import type { IrBand, IrBandStrength } from './irBand.ts';
23
+ import type { IrSpectrum } from './irSpectrum.ts';
24
+
25
+ /** What the picker is asked, whichever technique it picks for. */
26
+ export type PeakPickingOptions = NonNullable<
27
+ Parameters<typeof autoPeakPicking>[1]
28
+ >;
29
+
30
+ /**
31
+ * The bands of a Raman spectrum, picked on its intensity.
32
+ * @param spectrum - The spectrum to pick from.
33
+ * @param intensity - Its intensity, which the bands are maxima of.
34
+ * @param picking - Where to pick, and how finely.
35
+ * @returns The bands, in the order they were found.
36
+ */
37
+ export function ramanBands(
38
+ spectrum: IrSpectrum,
39
+ intensity: Float64Array,
40
+ picking: PeakPickingOptions,
41
+ ): IrBand[] {
42
+ const { id, wavenumber } = spectrum;
43
+ const picked = autoPeakPicking(measurementOf(wavenumber, intensity), {
44
+ ...picking,
45
+ yVariable: 'y',
46
+ });
47
+ const { min, max } = xMinMaxValues(intensity);
48
+
49
+ const bands: IrBand[] = [];
50
+ for (const peak of picked) {
51
+ if (!Number.isFinite(peak.wavenumber)) continue;
52
+ // The peak sits on a sample, so its intensity is read off that sample.
53
+ const value = intensity[xFindClosestIndex(wavenumber, peak.wavenumber)];
54
+ if (value === undefined) continue;
55
+ bands.push({
56
+ spectrumId: id,
57
+ wavenumber: peak.wavenumber,
58
+ intensity: value,
59
+ strength: strengthOf(value, min, max),
60
+ });
61
+ }
62
+ return bands;
63
+ }
64
+
65
+ /**
66
+ * How strong a band is, from where its top sits in the spectrum's range.
67
+ * @param value - The band's intensity.
68
+ * @param lowest - The spectrum's lowest intensity.
69
+ * @param highest - Its highest.
70
+ * @returns The letter a correlation table would use.
71
+ */
72
+ function strengthOf(
73
+ value: number,
74
+ lowest: number,
75
+ highest: number,
76
+ ): IrBandStrength {
77
+ const position = (value - lowest) / (highest - lowest);
78
+ if (position < WEAK_BELOW) return 'w';
79
+ if (position < MEDIUM_BELOW) return 'm';
80
+ return 'S';
81
+ }
82
+
83
+ /** Below this fraction of the spectrum's range a band is weak. */
84
+ const WEAK_BELOW = 0.33;
85
+
86
+ /** Below this one it is medium, and strong from here up. */
87
+ const MEDIUM_BELOW = 0.66;
88
+
89
+ /**
90
+ * The spectrum as `ir-spectrum` wants it: the shifts, and the intensity as `y`.
91
+ * @param shift - The Raman shifts, ascending.
92
+ * @param intensity - The intensity at each.
93
+ * @returns The measurement.
94
+ */
95
+ function measurementOf(
96
+ shift: Float64Array,
97
+ intensity: Float64Array,
98
+ ): MeasurementXY {
99
+ return {
100
+ variables: {
101
+ x: { label: 'Raman shift', units: '1/cm', symbol: 'x', data: shift },
102
+ y: { label: 'Intensity', units: '', symbol: 'y', data: intensity },
103
+ },
104
+ };
105
+ }
@@ -7,7 +7,8 @@
7
7
  * turned inside out, and a bare column of numbers leaves whoever opens it next
8
8
  * to guess which. `##YUNITS=` states it, and `ir-spectrum` reads it back and
9
9
  * derives the other axis from it, so a spectrum written here returns carrying
10
- * both.
10
+ * both. A Raman spectrum is written as its intensity, under a `##DATA TYPE=`
11
+ * that says it is Raman.
11
12
  *
12
13
  * The points are written as an `##PEAK TABLE=` of explicit `x y` pairs rather
13
14
  * than as a compressed `##XYDATA=` record. An XYDATA record states a first
@@ -20,6 +21,7 @@
20
21
  import { fromJSON } from 'convert-to-jcamp';
21
22
 
22
23
  import type { IrMode, IrSpectrum } from './irSpectrum.ts';
24
+ import { IR_TECHNIQUE_RULES, irModeTechnique } from './irTechnique.ts';
23
25
 
24
26
  /** The extension a written spectrum is saved under. */
25
27
  export const JCAMP_EXTENSION = '.jdx';
@@ -27,8 +29,8 @@ export const JCAMP_EXTENSION = '.jdx';
27
29
  /** What a JCAMP-DX file is served as. */
28
30
  export const JCAMP_MIME_TYPE = 'chemical/x-jcamp-dx';
29
31
 
30
- /** How the technique is named when the file that was read named nothing. */
31
- export const DEFAULT_DATA_TYPE = 'INFRARED SPECTRUM';
32
+ /** The infrared data type, written when the file that was read named none. */
33
+ export const DEFAULT_DATA_TYPE = IR_TECHNIQUE_RULES.infrared.dataType;
32
34
 
33
35
  /**
34
36
  * Write one spectrum as a JCAMP-DX block.
@@ -37,15 +39,20 @@ export const DEFAULT_DATA_TYPE = 'INFRARED SPECTRUM';
37
39
  * which that was, and only otherwise the one being read. Writing what is on
38
40
  * screen instead would export a spectrum that had been through a logarithm it
39
41
  * was never measured with — and, where a band bottoms out at zero transmittance,
40
- * an absorbance of infinity that no reader can take back.
42
+ * an absorbance of infinity that no reader can take back. A spectrum carrying
43
+ * neither falls back on whichever axis it does carry, so a Raman spectrum is
44
+ * written as its intensity.
41
45
  * @param spectrum - The spectrum.
42
46
  * @param mode - The axis being read, used when the file named none.
43
47
  * @returns The block, `##TITLE=` through `##END=`.
48
+ * @throws {Error} When the spectrum carries no value axis at all.
44
49
  */
45
50
  export function irSpectrumToJcamp(spectrum: IrSpectrum, mode: IrMode): string {
46
- const written = spectrum.origin.recorded ?? mode;
47
- const values =
48
- written === 'absorbance' ? spectrum.absorbance : spectrum.transmittance;
51
+ const written = writtenAxis(spectrum, mode);
52
+ const values = spectrum[written];
53
+ if (values === undefined) {
54
+ throw new Error(`${spectrum.name} carries no value axis to write.`);
55
+ }
49
56
  return fromJSON(
50
57
  { x: spectrum.wavenumber, y: values },
51
58
  { info: infoRecords(spectrum, written), meta: metaRecords(spectrum) },
@@ -67,13 +74,14 @@ export function irSpectrumToJcamp(spectrum: IrSpectrum, mode: IrMode): string {
67
74
  * spectrum would have written.
68
75
  * @param spectra - The spectra, in the order the list holds them.
69
76
  * @param mode - The axis being read, used for a spectrum whose file named none.
70
- * @param title - What to call the file's own outer block.
77
+ * @param title - What to call the file's own outer block. Defaults to the
78
+ * count and the technique that reads `mode`: `2 infrared spectra`.
71
79
  * @returns The file.
72
80
  */
73
81
  export function irSpectraToJcamp(
74
82
  spectra: readonly IrSpectrum[],
75
83
  mode: IrMode,
76
- title = `${spectra.length} infrared spectra`,
84
+ title = `${spectra.length} ${IR_TECHNIQUE_RULES[irModeTechnique(mode)].name} spectra`,
77
85
  ): string {
78
86
  const only = spectra.length === 1 ? spectra[0] : undefined;
79
87
  if (only !== undefined) return irSpectrumToJcamp(only, mode);
@@ -91,6 +99,32 @@ ${blocks.join('\n')}
91
99
  `;
92
100
  }
93
101
 
102
+ /**
103
+ * Which axis of a spectrum is written.
104
+ * @param spectrum - The spectrum.
105
+ * @param mode - The axis being read.
106
+ * @returns The axis its file recorded, else the one being read, else the first
107
+ * it carries; `mode` when it carries none, which the caller refuses.
108
+ */
109
+ function writtenAxis(spectrum: IrSpectrum, mode: IrMode): IrMode {
110
+ const { recorded } = spectrum.origin;
111
+ if (recorded !== undefined && spectrum[recorded] !== undefined) {
112
+ return recorded;
113
+ }
114
+ if (spectrum[mode] !== undefined) return mode;
115
+ for (const axis of WRITTEN_AXES) {
116
+ if (spectrum[axis] !== undefined) return axis;
117
+ }
118
+ return mode;
119
+ }
120
+
121
+ /** The axes a spectrum may carry, in the order one is looked for. */
122
+ const WRITTEN_AXES: readonly IrMode[] = [
123
+ 'transmittance',
124
+ 'absorbance',
125
+ 'intensity',
126
+ ];
127
+
94
128
  /**
95
129
  * The standard records of a block: what it is called, and what its axes are.
96
130
  * @param spectrum - The spectrum.
@@ -103,17 +137,32 @@ function infoRecords(
103
137
  ): Record<string, string> {
104
138
  return {
105
139
  title: recordValue(spectrum.name),
106
- // The technique as the file stated it, so a Raman spectrum that was opened
107
- // here is not written back out claiming to be infrared.
108
- dataType: technique(spectrum) ?? DEFAULT_DATA_TYPE,
140
+ // The technique as the file stated it, and otherwise the one the written
141
+ // axis belongs to, so a Raman spectrum is never written out claiming to be
142
+ // infrared.
143
+ dataType:
144
+ technique(spectrum) ??
145
+ IR_TECHNIQUE_RULES[irModeTechnique(written)].dataType,
109
146
  xUnits: '1/CM',
110
- // Spelled the way `ir-spectrum` reads it: it takes the axis to be
111
- // transmittance when the label says `trans`, and to be a percentage rather
112
- // than a fraction when it carries a `%`.
113
- yUnits: written === 'absorbance' ? 'ABSORBANCE' : 'Transmittance (%)',
147
+ yUnits: Y_UNITS[written],
114
148
  };
115
149
  }
116
150
 
151
+ /**
152
+ * What each axis is called in `##YUNITS=`.
153
+ *
154
+ * Spelled the way `ir-spectrum` reads them: it takes the axis to be
155
+ * transmittance when the label says `trans`, and to be a percentage rather than
156
+ * a fraction when it carries a `%`. A Raman intensity has no unit of its own —
157
+ * counts on one instrument, a fraction of the strongest band on another — so it
158
+ * is named, as Raman instruments write it.
159
+ */
160
+ const Y_UNITS: Record<IrMode, string> = {
161
+ transmittance: 'Transmittance (%)',
162
+ absorbance: 'ABSORBANCE',
163
+ intensity: 'INTENSITY',
164
+ };
165
+
117
166
  /**
118
167
  * The `$`-prefixed records of a block: the acquisition, as the file stated it.
119
168
  *
@@ -64,8 +64,7 @@ export function toIrSpectrum(
64
64
  name: name ?? loaded.name ?? loaded.origin.fileName ?? 'spectrum',
65
65
  color,
66
66
  wavenumber: loaded.wavenumber,
67
- absorbance: loaded.absorbance,
68
- transmittance: loaded.transmittance,
67
+ ...valueAxes(loaded),
69
68
  meta: loaded.meta,
70
69
  origin: loaded.origin,
71
70
  visible,
@@ -100,3 +99,22 @@ export function toIrSpectra(
100
99
  }
101
100
  return spectra;
102
101
  }
102
+
103
+ /**
104
+ * The value axes a loaded spectrum carries, and only those.
105
+ *
106
+ * An absent axis is an absent key, never a key holding `undefined`: the two
107
+ * read the same in a debugger and differently in every structural comparison.
108
+ * @param loaded - What the reader produced.
109
+ * @returns Its absorbance and transmittance, or its intensity.
110
+ */
111
+ function valueAxes(
112
+ loaded: LoadedIrSpectrum,
113
+ ): Pick<IrSpectrum, 'absorbance' | 'transmittance' | 'intensity'> {
114
+ const { absorbance, transmittance, intensity } = loaded;
115
+ return {
116
+ ...(absorbance === undefined ? {} : { absorbance }),
117
+ ...(transmittance === undefined ? {} : { transmittance }),
118
+ ...(intensity === undefined ? {} : { intensity }),
119
+ };
120
+ }
@@ -0,0 +1,107 @@
1
+ import { Icon } from '@blueprintjs/core';
2
+
3
+ import {
4
+ panelCellStyle,
5
+ panelNumberCellStyle,
6
+ } from '../../panel/core/panelStyles.ts';
7
+ import type { AssignedBand } from '../core/assignBands.ts';
8
+ import type { IrBand } from '../core/irBand.ts';
9
+ import { bandValue } from '../core/irBand.ts';
10
+ import { formatIrValue, formatWavenumber } from '../core/irFormat.ts';
11
+ import type { IrMode } from '../core/irSpectrum.ts';
12
+
13
+ export interface BandRowProps {
14
+ /** The band and everything it might be. */
15
+ entry: AssignedBand;
16
+ /** Which value axis is being read. */
17
+ mode: IrMode;
18
+ /** Whether the row has a column for what the band could be. */
19
+ assignments: boolean;
20
+ /** Whether the pointer is on this band, here or on the chart. */
21
+ lit: boolean;
22
+ /**
23
+ * Told when the pointer arrives on this row, and when it leaves.
24
+ * @default undefined
25
+ */
26
+ onHighlight?: (band: IrBand | null) => void;
27
+ }
28
+
29
+ /**
30
+ * One band: where it is, how strong, and every vibration it could be.
31
+ *
32
+ * The candidates are written as one line rather than a list, so a strong band
33
+ * with four of them stays one row of the table and the wavenumbers keep reading
34
+ * down the column. The `title` carries them again with each one's note, which is
35
+ * where the reason to prefer one lives.
36
+ * @param props - Component props.
37
+ * @returns The row.
38
+ */
39
+ export function BandRow(props: BandRowProps) {
40
+ const { entry, mode, assignments, lit, onHighlight } = props;
41
+ const { band } = entry;
42
+
43
+ return (
44
+ <tr
45
+ style={lit ? litRowStyle : undefined}
46
+ onPointerEnter={() => onHighlight?.(band)}
47
+ onPointerLeave={() => onHighlight?.(null)}
48
+ >
49
+ <td style={panelNumberCellStyle}>{formatWavenumber(band.wavenumber)}</td>
50
+ <td style={panelCellStyle} title={STRENGTH_TITLES[band.strength]}>
51
+ {band.strength}
52
+ </td>
53
+ <td style={panelNumberCellStyle}>
54
+ {formatIrValue(bandValue(band, mode) ?? Number.NaN, mode)}
55
+ </td>
56
+ {assignments ? <CandidatesCell entry={entry} /> : null}
57
+ </tr>
58
+ );
59
+ }
60
+
61
+ interface CandidatesCellProps {
62
+ /** The band and everything it might be. */
63
+ entry: AssignedBand;
64
+ }
65
+
66
+ /**
67
+ * What a band could be: the narrowest candidate, and how many more there are.
68
+ * @param props - Component props.
69
+ * @returns The cell.
70
+ */
71
+ function CandidatesCell(props: CandidatesCellProps) {
72
+ const { candidates } = props.entry;
73
+ const detail = candidates
74
+ .map((candidate) =>
75
+ candidate.note === undefined
76
+ ? `${candidate.group} ${candidate.vibration}`
77
+ : `${candidate.group} ${candidate.vibration} — ${candidate.note}`,
78
+ )
79
+ .join('\n');
80
+
81
+ return (
82
+ <td style={panelCellStyle} title={detail}>
83
+ {candidates.length === 0 ? (
84
+ <span style={{ opacity: 0.5 }}>—</span>
85
+ ) : (
86
+ <span style={{ whiteSpace: 'normal' }}>
87
+ {candidates[0]?.group} {candidates[0]?.vibration}
88
+ {candidates.length > 1 ? (
89
+ <span style={{ opacity: 0.6 }}>
90
+ {' '}
91
+ <Icon icon="more" size={10} /> {candidates.length - 1} more
92
+ </span>
93
+ ) : null}
94
+ </span>
95
+ )}
96
+ </td>
97
+ );
98
+ }
99
+
100
+ /** What each strength letter means, for the column that shows only the letter. */
101
+ const STRENGTH_TITLES = {
102
+ w: 'weak, relative to this spectrum',
103
+ m: 'medium, relative to this spectrum',
104
+ S: 'strong, relative to this spectrum',
105
+ } as const;
106
+
107
+ const litRowStyle = { background: '#fff3e0' } as const;
@@ -1,22 +1,21 @@
1
- import { Icon } from '@blueprintjs/core';
2
1
  import { useMemo } from 'react';
3
2
  import { Button, Toolbar } from 'react-science/ui';
4
3
 
5
4
  import {
6
5
  panelBodyStyle,
7
- panelCellStyle,
8
6
  panelEmptyStyle,
9
7
  panelHeaderCellStyle,
10
- panelNumberCellStyle,
11
8
  panelStyle,
12
9
  panelTableStyle,
13
10
  panelToolbarStyle,
14
11
  } from '../../panel/core/panelStyles.ts';
15
- import type { AssignedBand } from '../core/assignBands.ts';
16
12
  import type { IrBand } from '../core/irBand.ts';
17
13
  import { sameIrBand } from '../core/irBand.ts';
18
- import { formatIrValue, formatWavenumber } from '../core/irFormat.ts';
14
+ import { shortModeLabel } from '../core/irFormat.ts';
15
+ import { IR_TECHNIQUE_RULES } from '../core/irTechnique.ts';
19
16
 
17
+ import { BandRow } from './BandRow.tsx';
18
+ import { bandsToTsv } from './bandsTsv.ts';
20
19
  import { useIrActions, useIrEditorState } from './irStateContext.ts';
21
20
 
22
21
  export interface BandsPanelProps {
@@ -45,6 +44,10 @@ export interface BandsPanelProps {
45
44
  * Hovering a row marks the band on the chart and hovering the chart lights the
46
45
  * row, which is the whole reason the highlight is threaded through the shell
47
46
  * rather than held here: the two views are of one thing.
47
+ *
48
+ * For a technique the correlation table does not cover — Raman — the column of
49
+ * candidates and the button naming them are left out, and the table is the
50
+ * bands themselves.
48
51
  * @param props - Component props.
49
52
  * @returns The panel.
50
53
  */
@@ -52,11 +55,16 @@ export function BandsPanel(props: BandsPanelProps) {
52
55
  const { highlight = null, onHighlight } = props;
53
56
  const { state, selectedSpectrum, assigned } = useIrEditorState();
54
57
  const actions = useIrActions();
55
- const { mode, pickBands, showAssignments, picking } = state.settings;
58
+ const { mode, pickBands, showAssignments, picking, technique } =
59
+ state.settings;
60
+ const { assignments } = IR_TECHNIQUE_RULES[technique];
56
61
 
57
62
  const rows = useMemo(() => assigned, [assigned]);
58
63
 
59
- const tsv = useMemo(() => bandsToTsv(rows, mode), [rows, mode]);
64
+ const tsv = useMemo(
65
+ () => bandsToTsv(rows, mode, assignments),
66
+ [rows, mode, assignments],
67
+ );
60
68
 
61
69
  return (
62
70
  <div style={panelStyle}>
@@ -69,16 +77,18 @@ export function BandsPanel(props: BandsPanelProps) {
69
77
  aria-label="Pick the bands"
70
78
  onClick={() => actions.setSettings({ pickBands: !pickBands })}
71
79
  />
72
- <Toolbar.Item
73
- icon="label"
74
- active={showAssignments}
75
- tooltip="Name the assignments on the chart"
76
- aria-label="Name the assignments on the chart"
77
- disabled={!pickBands}
78
- onClick={() =>
79
- actions.setSettings({ showAssignments: !showAssignments })
80
- }
81
- />
80
+ {assignments ? (
81
+ <Toolbar.Item
82
+ icon="label"
83
+ active={showAssignments}
84
+ tooltip="Name the assignments on the chart"
85
+ aria-label="Name the assignments on the chart"
86
+ disabled={!pickBands}
87
+ onClick={() =>
88
+ actions.setSettings({ showAssignments: !showAssignments })
89
+ }
90
+ />
91
+ ) : null}
82
92
  </Toolbar>
83
93
 
84
94
  {/* The threshold is the one picking setting worth reaching for while
@@ -134,9 +144,11 @@ export function BandsPanel(props: BandsPanelProps) {
134
144
  <th style={panelHeaderCellStyle}>cm⁻¹</th>
135
145
  <th style={panelHeaderCellStyle} />
136
146
  <th style={{ ...panelHeaderCellStyle, textAlign: 'right' }}>
137
- {mode === 'absorbance' ? 'A' : '%T'}
147
+ {shortModeLabel(mode)}
138
148
  </th>
139
- <th style={panelHeaderCellStyle}>could be</th>
149
+ {assignments ? (
150
+ <th style={panelHeaderCellStyle}>could be</th>
151
+ ) : null}
140
152
  </tr>
141
153
  </thead>
142
154
  <tbody>
@@ -145,6 +157,7 @@ export function BandsPanel(props: BandsPanelProps) {
145
157
  key={`${entry.band.spectrumId} ${entry.band.wavenumber}`}
146
158
  entry={entry}
147
159
  mode={mode}
160
+ assignments={assignments}
148
161
  lit={sameIrBand(entry.band, highlight)}
149
162
  onHighlight={onHighlight}
150
163
  />
@@ -157,112 +170,6 @@ export function BandsPanel(props: BandsPanelProps) {
157
170
  );
158
171
  }
159
172
 
160
- interface BandRowProps {
161
- /** The band and everything it might be. */
162
- entry: AssignedBand;
163
- /** Which value axis is being read. */
164
- mode: 'absorbance' | 'transmittance';
165
- /** Whether the pointer is on this band, here or on the chart. */
166
- lit: boolean;
167
- /** Told when the pointer arrives on this row, and when it leaves. */
168
- onHighlight?: (band: IrBand | null) => void;
169
- }
170
-
171
- /**
172
- * One band: where it is, how strong, and every vibration it could be.
173
- *
174
- * The candidates are written as one line rather than a list, so a strong band
175
- * with four of them stays one row of the table and the wavenumbers keep reading
176
- * down the column. The `title` carries them again with each one's note, which is
177
- * where the reason to prefer one lives.
178
- * @param props - Component props.
179
- * @returns The row.
180
- */
181
- function BandRow(props: BandRowProps) {
182
- const { entry, mode, lit, onHighlight } = props;
183
- const { band, candidates } = entry;
184
-
185
- const value = mode === 'absorbance' ? band.absorbance : band.transmittance;
186
- const detail = candidates
187
- .map((candidate) =>
188
- candidate.note === undefined
189
- ? `${candidate.group} ${candidate.vibration}`
190
- : `${candidate.group} ${candidate.vibration} — ${candidate.note}`,
191
- )
192
- .join('\n');
193
-
194
- return (
195
- <tr
196
- style={lit ? litRowStyle : undefined}
197
- onPointerEnter={() => onHighlight?.(band)}
198
- onPointerLeave={() => onHighlight?.(null)}
199
- >
200
- <td style={panelNumberCellStyle}>{formatWavenumber(band.wavenumber)}</td>
201
- <td style={panelCellStyle} title={STRENGTH_TITLES[band.strength]}>
202
- {band.strength}
203
- </td>
204
- <td style={panelNumberCellStyle}>{formatIrValue(value, mode)}</td>
205
- <td style={panelCellStyle} title={detail}>
206
- {candidates.length === 0 ? (
207
- <span style={{ opacity: 0.5 }}>—</span>
208
- ) : (
209
- <span style={{ whiteSpace: 'normal' }}>
210
- {candidates[0]?.group} {candidates[0]?.vibration}
211
- {candidates.length > 1 ? (
212
- <span style={{ opacity: 0.6 }}>
213
- {' '}
214
- <Icon icon="more" size={10} /> {candidates.length - 1} more
215
- </span>
216
- ) : null}
217
- </span>
218
- )}
219
- </td>
220
- </tr>
221
- );
222
- }
223
-
224
- /** What each strength letter means, for the column that shows only the letter. */
225
- const STRENGTH_TITLES = {
226
- w: 'weak, relative to this spectrum',
227
- m: 'medium, relative to this spectrum',
228
- S: 'strong, relative to this spectrum',
229
- } as const;
230
-
231
- /**
232
- * The table as text, for pasting into a notebook.
233
- *
234
- * Tab separated with every candidate on the row, because the reason to copy a
235
- * band table is to put it beside a structure and argue about it — and the
236
- * argument is over the candidates rather than over the wavenumbers.
237
- * @param rows - The bands, as they are shown.
238
- * @param mode - Which value axis is being read.
239
- * @returns The table, one line per band, with a heading.
240
- */
241
- function bandsToTsv(
242
- rows: readonly AssignedBand[],
243
- mode: 'absorbance' | 'transmittance',
244
- ): string {
245
- const heading = ['wavenumber', 'strength', mode, 'could be'].join('\t');
246
- const lines = rows.map((entry) =>
247
- [
248
- formatWavenumber(entry.band.wavenumber),
249
- entry.band.strength,
250
- formatIrValue(
251
- mode === 'absorbance'
252
- ? entry.band.absorbance
253
- : entry.band.transmittance,
254
- mode,
255
- ),
256
- entry.candidates
257
- .map((candidate) => `${candidate.group} ${candidate.vibration}`)
258
- .join('; '),
259
- ].join('\t'),
260
- );
261
- return [heading, ...lines].join('\n');
262
- }
263
-
264
- const litRowStyle = { background: '#fff3e0' } as const;
265
-
266
173
  const thresholdStyle = {
267
174
  display: 'inline-flex',
268
175
  alignItems: 'center',