ir-spectrum 3.2.1 → 4.0.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.
- package/lib/convertPeak.d.ts +22 -0
- package/lib/convertPeak.d.ts.map +1 -0
- package/lib/convertPeak.js +26 -0
- package/lib/convertPeak.js.map +1 -0
- package/lib/from/fromJcamp.d.ts +19 -0
- package/lib/from/fromJcamp.d.ts.map +1 -0
- package/lib/from/fromJcamp.js +13 -0
- package/lib/from/fromJcamp.js.map +1 -0
- package/lib/from/fromSPC.d.ts +20 -0
- package/lib/from/fromSPC.d.ts.map +1 -0
- package/lib/from/fromSPC.js +25 -0
- package/lib/from/fromSPC.js.map +1 -0
- package/lib/from/utils/spectrumCallback.d.ts +9 -0
- package/lib/from/utils/spectrumCallback.d.ts.map +1 -0
- package/lib/from/utils/spectrumCallback.js +55 -0
- package/lib/from/utils/spectrumCallback.js.map +1 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +33 -0
- package/lib/index.js.map +1 -0
- package/lib/jsgraph/getAnnotations.d.ts +59 -0
- package/lib/jsgraph/getAnnotations.d.ts.map +1 -0
- package/lib/jsgraph/getAnnotations.js +133 -0
- package/lib/jsgraph/getAnnotations.js.map +1 -0
- package/package.json +27 -20
- package/src/convertPeak.ts +49 -0
- package/src/from/fromJcamp.ts +30 -0
- package/src/from/fromSPC.ts +45 -0
- package/src/from/utils/spectrumCallback.ts +64 -0
- package/src/index.ts +64 -0
- package/src/jsgraph/{getAnnotations.js → getAnnotations.ts} +79 -28
- package/src/convertPeak.js +0 -23
- package/src/from/fromJcamp.js +0 -16
- package/src/from/fromSPC.js +0 -31
- package/src/from/utils/spectrumCallback.js +0 -45
- package/src/index.js +0 -27
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MeasurementXY } from 'cheminfo-types';
|
|
2
|
+
export interface ConvertedPeak {
|
|
3
|
+
wavenumber: number;
|
|
4
|
+
absorbance: number;
|
|
5
|
+
transmittance: number;
|
|
6
|
+
kind: string;
|
|
7
|
+
}
|
|
8
|
+
interface SpectrumPeak {
|
|
9
|
+
x: number;
|
|
10
|
+
a: number;
|
|
11
|
+
t: number;
|
|
12
|
+
[key: string]: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Converts a peak from common-spectrum format to IR-specific format.
|
|
16
|
+
* @param peak - Peak object with x, a, t properties.
|
|
17
|
+
* @param spectrum - Spectrum containing variable metadata.
|
|
18
|
+
* @returns Converted peak with wavenumber, absorbance, transmittance, and kind.
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertPeak(peak: SpectrumPeak, spectrum: MeasurementXY): ConvertedPeak;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=convertPeak.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertPeak.d.ts","sourceRoot":"","sources":["../src/convertPeak.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,YAAY;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,aAAa,GACtB,aAAa,CAQf"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a peak from common-spectrum format to IR-specific format.
|
|
3
|
+
* @param peak - Peak object with x, a, t properties.
|
|
4
|
+
* @param spectrum - Spectrum containing variable metadata.
|
|
5
|
+
* @returns Converted peak with wavenumber, absorbance, transmittance, and kind.
|
|
6
|
+
*/
|
|
7
|
+
export function convertPeak(peak, spectrum) {
|
|
8
|
+
const tVariable = spectrum.variables.t;
|
|
9
|
+
return {
|
|
10
|
+
wavenumber: peak.x,
|
|
11
|
+
absorbance: peak.a,
|
|
12
|
+
transmittance: peak.t / 100,
|
|
13
|
+
kind: getPeakKind(peak.t, tVariable?.min ?? 0, tVariable?.max ?? 100),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function getPeakKind(transmittance, minTransmittance, maxTransmittance) {
|
|
17
|
+
const position = (maxTransmittance - transmittance) / (maxTransmittance - minTransmittance);
|
|
18
|
+
if (position < 0.33) {
|
|
19
|
+
return 'w';
|
|
20
|
+
}
|
|
21
|
+
else if (position < 0.66) {
|
|
22
|
+
return 'm';
|
|
23
|
+
}
|
|
24
|
+
return 'S';
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=convertPeak.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertPeak.js","sourceRoot":"","sources":["../src/convertPeak.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,IAAkB,EAClB,QAAuB;IAEvB,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACvC,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,CAAC;QAClB,UAAU,EAAE,IAAI,CAAC,CAAC;QAClB,aAAa,EAAE,IAAI,CAAC,CAAC,GAAG,GAAG;QAC3B,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,EAAE,SAAS,EAAE,GAAG,IAAI,GAAG,CAAC;KACtE,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAClB,aAAqB,EACrB,gBAAwB,EACxB,gBAAwB;IAExB,MAAM,QAAQ,GACZ,CAAC,gBAAgB,GAAG,aAAa,CAAC,GAAG,CAAC,gBAAgB,GAAG,gBAAgB,CAAC,CAAC;IAC7E,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC;QACpB,OAAO,GAAG,CAAC;IACb,CAAC;SAAM,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC;QAC3B,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MeasurementXYVariables, TextData } from 'cheminfo-types';
|
|
2
|
+
import type { Analysis } from 'common-spectrum';
|
|
3
|
+
interface FromJcampOptions {
|
|
4
|
+
/** Unique identifier for the analysis. */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Human-readable label for the analysis. */
|
|
7
|
+
label?: string;
|
|
8
|
+
/** Custom callback to apply on variables when creating a spectrum. Defaults to adding absorbance/transmittance variables. */
|
|
9
|
+
spectrumCallback?: (variables: MeasurementXYVariables) => MeasurementXYVariables;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new Analysis from a JCAMP string or buffer.
|
|
13
|
+
* @param jcamp - JCAMP data as a string or ArrayBuffer.
|
|
14
|
+
* @param options - Options for the analysis.
|
|
15
|
+
* @returns New Analysis element with the given data.
|
|
16
|
+
*/
|
|
17
|
+
export declare function fromJcamp(jcamp: TextData, options?: FromJcampOptions): Analysis;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=fromJcamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromJcamp.d.ts","sourceRoot":"","sources":["../../src/from/fromJcamp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAKhD,UAAU,gBAAgB;IACxB,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6HAA6H;IAC7H,gBAAgB,CAAC,EAAE,CACjB,SAAS,EAAE,sBAAsB,KAC9B,sBAAsB,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,QAAQ,EACf,OAAO,GAAE,gBAAqB,GAC7B,QAAQ,CAGV"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fromJcamp as commonFromJcamp } from 'common-spectrum';
|
|
2
|
+
import { spectrumCallback as defaultSpectrumCallback } from "./utils/spectrumCallback.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Analysis from a JCAMP string or buffer.
|
|
5
|
+
* @param jcamp - JCAMP data as a string or ArrayBuffer.
|
|
6
|
+
* @param options - Options for the analysis.
|
|
7
|
+
* @returns New Analysis element with the given data.
|
|
8
|
+
*/
|
|
9
|
+
export function fromJcamp(jcamp, options = {}) {
|
|
10
|
+
const { spectrumCallback = defaultSpectrumCallback, ...rest } = options;
|
|
11
|
+
return commonFromJcamp(jcamp, { ...rest, spectrumCallback });
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=fromJcamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromJcamp.js","sourceRoot":"","sources":["../../src/from/fromJcamp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,gBAAgB,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAa1F;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,KAAe,EACf,UAA4B,EAAE;IAE9B,MAAM,EAAE,gBAAgB,GAAG,uBAAuB,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IACxE,OAAO,eAAe,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MeasurementXYVariables } from 'cheminfo-types';
|
|
2
|
+
import { Analysis } from 'common-spectrum';
|
|
3
|
+
import type { InputData } from 'spc-parser';
|
|
4
|
+
interface FromSPCOptions {
|
|
5
|
+
/** Unique identifier for the analysis. */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Human-readable label for the analysis. */
|
|
8
|
+
label?: string;
|
|
9
|
+
/** Custom callback to apply on variables when creating a spectrum. Defaults to adding absorbance/transmittance variables. */
|
|
10
|
+
spectrumCallback?: (variables: MeasurementXYVariables) => MeasurementXYVariables;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new Analysis from an SPC buffer.
|
|
14
|
+
* @param buffer - SPC file buffer.
|
|
15
|
+
* @param options - Options for the analysis.
|
|
16
|
+
* @returns New Analysis element with the given data.
|
|
17
|
+
*/
|
|
18
|
+
export declare function fromSPC(buffer: InputData, options?: FromSPCOptions): Analysis;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=fromSPC.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromSPC.d.ts","sourceRoot":"","sources":["../../src/from/fromSPC.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAK5C,UAAU,cAAc;IACtB,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6HAA6H;IAC7H,gBAAgB,CAAC,EAAE,CACjB,SAAS,EAAE,sBAAsB,KAC9B,sBAAsB,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,SAAS,EACjB,OAAO,GAAE,cAAmB,GAC3B,QAAQ,CAiBV"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Analysis } from 'common-spectrum';
|
|
2
|
+
import { parse } from 'spc-parser';
|
|
3
|
+
import { spectrumCallback as defaultSpectrumCallback } from "./utils/spectrumCallback.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new Analysis from an SPC buffer.
|
|
6
|
+
* @param buffer - SPC file buffer.
|
|
7
|
+
* @param options - Options for the analysis.
|
|
8
|
+
* @returns New Analysis element with the given data.
|
|
9
|
+
*/
|
|
10
|
+
export function fromSPC(buffer, options = {}) {
|
|
11
|
+
const { spectrumCallback = defaultSpectrumCallback, ...rest } = options;
|
|
12
|
+
const analysis = new Analysis({ ...rest, spectrumCallback });
|
|
13
|
+
const result = parse(buffer);
|
|
14
|
+
const { parameters: _resultParameters, ...resultMeta } = result.meta;
|
|
15
|
+
for (const spectrum of result.spectra) {
|
|
16
|
+
const { parameters: _spectrumParameters, ...spectrumMeta } = spectrum.meta ?? {};
|
|
17
|
+
analysis.pushSpectrum(spectrum.variables, {
|
|
18
|
+
dataType: 'IR SPECTRUM',
|
|
19
|
+
title: '',
|
|
20
|
+
meta: { ...resultMeta, ...spectrumMeta },
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return analysis;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=fromSPC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromSPC.js","sourceRoot":"","sources":["../../src/from/fromSPC.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,gBAAgB,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAa1F;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CACrB,MAAiB,EACjB,UAA0B,EAAE;IAE5B,MAAM,EAAE,gBAAgB,GAAG,uBAAuB,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IACxE,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAE7B,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;IAErE,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACtC,MAAM,EAAE,UAAU,EAAE,mBAAmB,EAAE,GAAG,YAAY,EAAE,GACxD,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;QACtB,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE;YACxC,QAAQ,EAAE,aAAa;YACvB,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,EAAE,GAAG,UAAU,EAAE,GAAG,YAAY,EAAE;SACzC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MeasurementXYVariables } from 'cheminfo-types';
|
|
2
|
+
/**
|
|
3
|
+
* Callback that adds absorbance (a) and transmittance (t) variables to the spectrum.
|
|
4
|
+
* If the y variable is absorbance, transmittance is computed and vice versa.
|
|
5
|
+
* @param variables - Spectrum variables with at least x and y defined.
|
|
6
|
+
* @returns The modified variables with a and t added.
|
|
7
|
+
*/
|
|
8
|
+
export declare function spectrumCallback(variables: MeasurementXYVariables): MeasurementXYVariables;
|
|
9
|
+
//# sourceMappingURL=spectrumCallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spectrumCallback.d.ts","sourceRoot":"","sources":["../../../src/from/utils/spectrumCallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,sBAAsB,GAChC,sBAAsB,CAqDxB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback that adds absorbance (a) and transmittance (t) variables to the spectrum.
|
|
3
|
+
* If the y variable is absorbance, transmittance is computed and vice versa.
|
|
4
|
+
* @param variables - Spectrum variables with at least x and y defined.
|
|
5
|
+
* @returns The modified variables with a and t added.
|
|
6
|
+
*/
|
|
7
|
+
export function spectrumCallback(variables) {
|
|
8
|
+
// we add missing absorbance / transmittance
|
|
9
|
+
// variable a = absorbance
|
|
10
|
+
// variable t = transmittance
|
|
11
|
+
const yVariable = variables.y;
|
|
12
|
+
let isAbsorbance = true;
|
|
13
|
+
if (yVariable.label.toLowerCase().includes('trans')) {
|
|
14
|
+
isAbsorbance = false;
|
|
15
|
+
}
|
|
16
|
+
if (isAbsorbance) {
|
|
17
|
+
variables.a = {
|
|
18
|
+
...yVariable,
|
|
19
|
+
symbol: 'a',
|
|
20
|
+
data: yVariable.data.slice(),
|
|
21
|
+
};
|
|
22
|
+
variables.t = {
|
|
23
|
+
data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
|
|
24
|
+
label: 'Transmittance (%)',
|
|
25
|
+
symbol: 't',
|
|
26
|
+
units: '',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const factor = yVariable.label.includes('%') ||
|
|
31
|
+
yVariable.label.toLowerCase().includes('percent')
|
|
32
|
+
? 100
|
|
33
|
+
: 1;
|
|
34
|
+
variables.a = {
|
|
35
|
+
data: yVariable.data.map((transmittance) => -Math.log10(transmittance / factor)),
|
|
36
|
+
symbol: 'a',
|
|
37
|
+
label: 'Absorbance',
|
|
38
|
+
units: '',
|
|
39
|
+
};
|
|
40
|
+
if (factor === 100) {
|
|
41
|
+
variables.t = { ...yVariable, symbol: 't' };
|
|
42
|
+
variables.t.data = variables.t.data.slice();
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
variables.t = {
|
|
46
|
+
units: '',
|
|
47
|
+
label: 'Transmittance (%)',
|
|
48
|
+
symbol: 't',
|
|
49
|
+
data: yVariable.data.map((transmittance) => transmittance * 100),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return variables;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=spectrumCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spectrumCallback.js","sourceRoot":"","sources":["../../../src/from/utils/spectrumCallback.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAAiC;IAEjC,4CAA4C;IAC5C,0BAA0B;IAC1B,6BAA6B;IAC7B,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC;IAC9B,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,YAAY,GAAG,KAAK,CAAC;IACvB,CAAC;IACD,IAAI,YAAY,EAAE,CAAC;QACjB,SAAS,CAAC,CAAC,GAAG;YACZ,GAAG,SAAS;YACZ,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,KAAK,EAAc;SACzC,CAAC;QACF,SAAS,CAAC,CAAC,GAAG;YACZ,IAAI,EAAG,SAAS,CAAC,IAAiB,CAAC,GAAG,CACpC,CAAC,UAAkB,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,GAAG,GAAG,CAChD;YACD,KAAK,EAAE,mBAAmB;YAC1B,MAAM,EAAE,GAAG;YACX,KAAK,EAAE,EAAE;SACV,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,MAAM,GACV,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC7B,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;YAC/C,CAAC,CAAC,GAAG;YACL,CAAC,CAAC,CAAC,CAAC;QAER,SAAS,CAAC,CAAC,GAAG;YACZ,IAAI,EAAG,SAAS,CAAC,IAAiB,CAAC,GAAG,CACpC,CAAC,aAAqB,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC,CAC/D;YACD,MAAM,EAAE,GAAG;YACX,KAAK,EAAE,YAAY;YACnB,KAAK,EAAE,EAAE;SACV,CAAC;QACF,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC5C,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAc,CAAC;QAC1D,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,CAAC,GAAG;gBACZ,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,mBAAmB;gBAC1B,MAAM,EAAE,GAAG;gBACX,IAAI,EAAG,SAAS,CAAC,IAAiB,CAAC,GAAG,CACpC,CAAC,aAAqB,EAAE,EAAE,CAAC,aAAa,GAAG,GAAG,CAC/C;aACF,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MeasurementXY } from 'cheminfo-types';
|
|
2
|
+
import type { AutoPeakPickingOptions, PeakPickingOptions } from 'common-spectrum';
|
|
3
|
+
import { JSGraph as OriginalJSGraph } from 'common-spectrum';
|
|
4
|
+
import type { ConvertedPeak } from './convertPeak.ts';
|
|
5
|
+
import { getAnnotations } from './jsgraph/getAnnotations.ts';
|
|
6
|
+
export type { ConvertedPeak } from './convertPeak.ts';
|
|
7
|
+
export { AnalysesManager, Analysis, toJcamp } from 'common-spectrum';
|
|
8
|
+
/**
|
|
9
|
+
* Picks a single peak closest to the given target wavenumber.
|
|
10
|
+
* @param spectrum - The spectrum to pick from.
|
|
11
|
+
* @param target - Target wavenumber value.
|
|
12
|
+
* @param options - Peak picking options.
|
|
13
|
+
* @returns The converted peak or undefined if no peak is found.
|
|
14
|
+
*/
|
|
15
|
+
export declare function peakPicking(spectrum: MeasurementXY, target: number, options?: PeakPickingOptions): ConvertedPeak | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Automatically picks all peaks in the spectrum.
|
|
18
|
+
* @param spectrum - The spectrum to pick from.
|
|
19
|
+
* @param options - Auto peak picking options.
|
|
20
|
+
* @returns Array of converted peaks.
|
|
21
|
+
*/
|
|
22
|
+
export declare function autoPeakPicking(spectrum: MeasurementXY, options?: AutoPeakPickingOptions): ConvertedPeak[];
|
|
23
|
+
export { fromJcamp } from './from/fromJcamp.ts';
|
|
24
|
+
export { fromSPC } from './from/fromSPC.ts';
|
|
25
|
+
export declare const JSGraph: typeof OriginalJSGraph & {
|
|
26
|
+
getAnnotations: typeof getAnnotations;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,OAAO,IAAI,eAAe,EAG3B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAErE;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,kBAAkB,GAC3B,aAAa,GAAG,SAAS,CAO3B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,aAAa,EAAE,CASjB;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,eAAO,MAAM,OAAO,EAAE,OAAO,eAAe,GAAG;IAC7C,cAAc,EAAE,OAAO,cAAc,CAAC;CACE,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { JSGraph as OriginalJSGraph, autoPeakPicking as originalAutoPeakPicking, peakPicking as originalPeakPicking, } from 'common-spectrum';
|
|
2
|
+
import { convertPeak } from "./convertPeak.js";
|
|
3
|
+
import { getAnnotations } from "./jsgraph/getAnnotations.js";
|
|
4
|
+
export { AnalysesManager, Analysis, toJcamp } from 'common-spectrum';
|
|
5
|
+
/**
|
|
6
|
+
* Picks a single peak closest to the given target wavenumber.
|
|
7
|
+
* @param spectrum - The spectrum to pick from.
|
|
8
|
+
* @param target - Target wavenumber value.
|
|
9
|
+
* @param options - Peak picking options.
|
|
10
|
+
* @returns The converted peak or undefined if no peak is found.
|
|
11
|
+
*/
|
|
12
|
+
export function peakPicking(spectrum, target, options) {
|
|
13
|
+
const peak = originalPeakPicking(spectrum, target, options);
|
|
14
|
+
if (!peak)
|
|
15
|
+
return undefined;
|
|
16
|
+
return convertPeak(peak, spectrum);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Automatically picks all peaks in the spectrum.
|
|
20
|
+
* @param spectrum - The spectrum to pick from.
|
|
21
|
+
* @param options - Auto peak picking options.
|
|
22
|
+
* @returns Array of converted peaks.
|
|
23
|
+
*/
|
|
24
|
+
export function autoPeakPicking(spectrum, options) {
|
|
25
|
+
const peaks = originalAutoPeakPicking(spectrum, options);
|
|
26
|
+
if (!peaks)
|
|
27
|
+
return [];
|
|
28
|
+
return peaks.map((peak) => convertPeak(peak, spectrum));
|
|
29
|
+
}
|
|
30
|
+
export { fromJcamp } from "./from/fromJcamp.js";
|
|
31
|
+
export { fromSPC } from "./from/fromSPC.js";
|
|
32
|
+
export const JSGraph = { ...OriginalJSGraph, getAnnotations };
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,OAAO,IAAI,eAAe,EAC1B,eAAe,IAAI,uBAAuB,EAC1C,WAAW,IAAI,mBAAmB,GACnC,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,QAAuB,EACvB,MAAc,EACd,OAA4B;IAE5B,MAAM,IAAI,GAAG,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5D,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,WAAW,CAChB,IAAkE,EAClE,QAAQ,CACT,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAuB,EACvB,OAAgC;IAEhC,MAAM,KAAK,GAAG,uBAAuB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACxB,WAAW,CACT,IAAkE,EAClE,QAAQ,CACT,CACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,MAAM,CAAC,MAAM,OAAO,GAEhB,EAAE,GAAG,eAAe,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
interface AnnotationPeak {
|
|
2
|
+
wavenumber: number;
|
|
3
|
+
transmittance: number;
|
|
4
|
+
absorbance: number;
|
|
5
|
+
kind: string;
|
|
6
|
+
assignment?: string;
|
|
7
|
+
}
|
|
8
|
+
interface AnnotationLabel {
|
|
9
|
+
text: string;
|
|
10
|
+
size: string;
|
|
11
|
+
anchor: string;
|
|
12
|
+
color: string;
|
|
13
|
+
angle?: number;
|
|
14
|
+
position: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
dy: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
interface AnnotationPosition {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
dy: string;
|
|
24
|
+
dx: string;
|
|
25
|
+
}
|
|
26
|
+
interface Annotation {
|
|
27
|
+
line: number;
|
|
28
|
+
type: string;
|
|
29
|
+
strokeColor: string;
|
|
30
|
+
strokeWidth: number;
|
|
31
|
+
fillColor: string;
|
|
32
|
+
labels?: AnnotationLabel[];
|
|
33
|
+
position?: AnnotationPosition[];
|
|
34
|
+
}
|
|
35
|
+
interface GetAnnotationsOptions {
|
|
36
|
+
/** Fill color for annotation rectangles. */
|
|
37
|
+
fillColor?: string;
|
|
38
|
+
/** Stroke color for annotation rectangles. */
|
|
39
|
+
strokeColor?: string;
|
|
40
|
+
/** Display the kind ('m', 'w', 'S'). */
|
|
41
|
+
showKind?: boolean;
|
|
42
|
+
/** Display the assignment. */
|
|
43
|
+
showAssignment?: boolean;
|
|
44
|
+
/** Callback allowing to add properties to an annotation. */
|
|
45
|
+
creationFct?: (annotation: Annotation, peak: AnnotationPeak) => void;
|
|
46
|
+
/** 't100'=transmittance in %, 't'=transmittance, 'a'=absorbance. */
|
|
47
|
+
mode?: 'a' | 't' | 't100';
|
|
48
|
+
/** Angle for assignment labels in absorbance mode. */
|
|
49
|
+
assignmentAngle?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates annotations for jsgraph that allows to display the result of peak picking.
|
|
53
|
+
* @param peaks - Array of peaks with wavenumber, transmittance, absorbance, kind.
|
|
54
|
+
* @param options - Display options for the annotations.
|
|
55
|
+
* @returns Array of annotation objects for jsgraph.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getAnnotations(peaks: AnnotationPeak[], options?: GetAnnotationsOptions): Annotation[];
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=getAnnotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAnnotations.d.ts","sourceRoot":"","sources":["../../src/jsgraph/getAnnotations.ts"],"names":[],"mappings":"AAAA,UAAU,cAAc;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE;QACR,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC;CACH;AAED,UAAU,kBAAkB;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACjC;AAED,UAAU,qBAAqB;IAC7B,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8BAA8B;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;IACrE,oEAAoE;IACpE,IAAI,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC;IAC1B,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,GAAE,qBAA0B,GAClC,UAAU,EAAE,CAiCd"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates annotations for jsgraph that allows to display the result of peak picking.
|
|
3
|
+
* @param peaks - Array of peaks with wavenumber, transmittance, absorbance, kind.
|
|
4
|
+
* @param options - Display options for the annotations.
|
|
5
|
+
* @returns Array of annotation objects for jsgraph.
|
|
6
|
+
*/
|
|
7
|
+
export function getAnnotations(peaks, options = {}) {
|
|
8
|
+
const { fillColor = 'green', strokeColor = 'red', creationFct, mode = 't100', } = options;
|
|
9
|
+
const annotations = peaks.map((peak) => {
|
|
10
|
+
const annotation = {
|
|
11
|
+
line: 1,
|
|
12
|
+
type: 'rect',
|
|
13
|
+
strokeColor,
|
|
14
|
+
strokeWidth: 0,
|
|
15
|
+
fillColor,
|
|
16
|
+
};
|
|
17
|
+
if (creationFct) {
|
|
18
|
+
creationFct(annotation, peak);
|
|
19
|
+
}
|
|
20
|
+
switch (mode) {
|
|
21
|
+
case 'a':
|
|
22
|
+
annotationAbsorbance(annotation, peak, options);
|
|
23
|
+
break;
|
|
24
|
+
case 't':
|
|
25
|
+
annotationTransmittance(annotation, peak, 1, options);
|
|
26
|
+
break;
|
|
27
|
+
case 't100':
|
|
28
|
+
annotationTransmittance(annotation, peak, 100, options);
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
}
|
|
32
|
+
return annotation;
|
|
33
|
+
});
|
|
34
|
+
return annotations;
|
|
35
|
+
}
|
|
36
|
+
function annotationTransmittance(annotation, peak, factor = 1, options = {}) {
|
|
37
|
+
const { showKind = true, showAssignment = true } = options;
|
|
38
|
+
const labels = [];
|
|
39
|
+
let line = 0;
|
|
40
|
+
if (showKind) {
|
|
41
|
+
labels.push({
|
|
42
|
+
text: peak.kind,
|
|
43
|
+
size: '18px',
|
|
44
|
+
anchor: 'middle',
|
|
45
|
+
color: 'red',
|
|
46
|
+
position: {
|
|
47
|
+
x: peak.wavenumber,
|
|
48
|
+
y: peak.transmittance * factor,
|
|
49
|
+
dy: `${23 + line * 14}px`,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
line++;
|
|
53
|
+
}
|
|
54
|
+
if (showAssignment) {
|
|
55
|
+
labels.push({
|
|
56
|
+
text: peak.assignment ?? '',
|
|
57
|
+
size: '18px',
|
|
58
|
+
anchor: 'middle',
|
|
59
|
+
color: 'darkred',
|
|
60
|
+
position: {
|
|
61
|
+
x: peak.wavenumber,
|
|
62
|
+
y: peak.transmittance * factor,
|
|
63
|
+
dy: `${23 + line * 14}px`,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
line++;
|
|
67
|
+
}
|
|
68
|
+
annotation.labels = labels;
|
|
69
|
+
annotation.position = [
|
|
70
|
+
{
|
|
71
|
+
x: peak.wavenumber,
|
|
72
|
+
y: peak.transmittance * factor,
|
|
73
|
+
dy: '10px',
|
|
74
|
+
dx: '-1px',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
x: peak.wavenumber,
|
|
78
|
+
y: peak.transmittance * factor,
|
|
79
|
+
dy: '5px',
|
|
80
|
+
dx: '1px',
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
function annotationAbsorbance(annotation, peak, options = {}) {
|
|
85
|
+
const { showKind = true, showAssignment = true, assignmentAngle = -45, } = options;
|
|
86
|
+
const labels = [];
|
|
87
|
+
let line = 0;
|
|
88
|
+
if (showKind) {
|
|
89
|
+
labels.push({
|
|
90
|
+
text: peak.kind,
|
|
91
|
+
size: '18px',
|
|
92
|
+
anchor: 'middle',
|
|
93
|
+
color: 'red',
|
|
94
|
+
position: {
|
|
95
|
+
x: peak.wavenumber,
|
|
96
|
+
y: peak.absorbance,
|
|
97
|
+
dy: `${-15 - line * 14}px`,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
line++;
|
|
101
|
+
}
|
|
102
|
+
if (showAssignment) {
|
|
103
|
+
labels.push({
|
|
104
|
+
text: peak.assignment ?? '',
|
|
105
|
+
size: '18px',
|
|
106
|
+
angle: assignmentAngle,
|
|
107
|
+
anchor: 'left',
|
|
108
|
+
color: 'darkred',
|
|
109
|
+
position: {
|
|
110
|
+
x: peak.wavenumber,
|
|
111
|
+
y: peak.absorbance,
|
|
112
|
+
dy: `${-15 - line * 14}px`,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
line++;
|
|
116
|
+
}
|
|
117
|
+
annotation.labels = labels;
|
|
118
|
+
annotation.position = [
|
|
119
|
+
{
|
|
120
|
+
x: peak.wavenumber,
|
|
121
|
+
y: peak.absorbance,
|
|
122
|
+
dy: '-10px',
|
|
123
|
+
dx: '-1px',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
x: peak.wavenumber,
|
|
127
|
+
y: peak.absorbance,
|
|
128
|
+
dy: '-5px',
|
|
129
|
+
dx: '1px',
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=getAnnotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAnnotations.js","sourceRoot":"","sources":["../../src/jsgraph/getAnnotations.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ir-spectrum",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Package used to handle IR spectra in SciPeaks.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"exports":
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./lib/index.js"
|
|
8
|
+
},
|
|
7
9
|
"files": [
|
|
10
|
+
"lib",
|
|
8
11
|
"src"
|
|
9
12
|
],
|
|
10
13
|
"scripts": {
|
|
11
|
-
"build": "cheminfo-build
|
|
12
|
-
"
|
|
14
|
+
"build": "npm run tsc && cheminfo-build --entry lib/index.js --root IRSpectrum",
|
|
15
|
+
"check-types": "tsc --noEmit",
|
|
16
|
+
"clean": "rimraf lib",
|
|
13
17
|
"eslint": "eslint src",
|
|
14
18
|
"eslint-fix": "npm run eslint -- --fix",
|
|
19
|
+
"prepack": "npm run tsc",
|
|
15
20
|
"prettier": "prettier --check src",
|
|
16
21
|
"prettier-write": "prettier --write src",
|
|
17
|
-
"test": "npm run test-only && npm run eslint && npm run prettier",
|
|
22
|
+
"test": "npm run test-only && npm run check-types && npm run eslint && npm run prettier",
|
|
18
23
|
"test-only": "vitest run --coverage",
|
|
19
|
-
"
|
|
24
|
+
"tsc": "npm run clean && npm run tsc-build",
|
|
25
|
+
"tsc-build": "tsc --project tsconfig.build.json"
|
|
20
26
|
},
|
|
21
27
|
"repository": {
|
|
22
28
|
"type": "git",
|
|
@@ -29,22 +35,23 @@
|
|
|
29
35
|
"url": "https://github.com/cheminfo/ir-spectrum/issues"
|
|
30
36
|
},
|
|
31
37
|
"homepage": "https://github.com/cheminfo/ir-spectrum#readme",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"common-spectrum": "3.1.0",
|
|
40
|
+
"ml-gsd": "^13.1.1",
|
|
41
|
+
"spc-parser": "^1.0.0"
|
|
42
|
+
},
|
|
32
43
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@vitest/coverage-v8": "^
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"eslint
|
|
38
|
-
"
|
|
44
|
+
"@types/node": "^25.3.0",
|
|
45
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
46
|
+
"@zakodium/tsconfig": "^1.0.2",
|
|
47
|
+
"cheminfo-build": "^1.3.2",
|
|
48
|
+
"eslint": "^9.39.2",
|
|
49
|
+
"eslint-config-cheminfo-typescript": "^21.1.0",
|
|
39
50
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
40
|
-
"prettier": "^3.
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"common-spectrum": "2.12.0",
|
|
45
|
-
"ml-gsd": "^13.0.1",
|
|
46
|
-
"spc-parser": "^1.0.0",
|
|
47
|
-
"uninstall": "^0.0.0"
|
|
51
|
+
"prettier": "^3.8.1",
|
|
52
|
+
"rimraf": "^6.1.3",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"vitest": "^4.0.18"
|
|
48
55
|
},
|
|
49
56
|
"info": {
|
|
50
57
|
"logo": "https://raw.githubusercontent.com/cheminfo/font/master/src/ir/assignment.svg",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { MeasurementXY } from 'cheminfo-types';
|
|
2
|
+
|
|
3
|
+
export interface ConvertedPeak {
|
|
4
|
+
wavenumber: number;
|
|
5
|
+
absorbance: number;
|
|
6
|
+
transmittance: number;
|
|
7
|
+
kind: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface SpectrumPeak {
|
|
11
|
+
x: number;
|
|
12
|
+
a: number;
|
|
13
|
+
t: number;
|
|
14
|
+
[key: string]: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Converts a peak from common-spectrum format to IR-specific format.
|
|
19
|
+
* @param peak - Peak object with x, a, t properties.
|
|
20
|
+
* @param spectrum - Spectrum containing variable metadata.
|
|
21
|
+
* @returns Converted peak with wavenumber, absorbance, transmittance, and kind.
|
|
22
|
+
*/
|
|
23
|
+
export function convertPeak(
|
|
24
|
+
peak: SpectrumPeak,
|
|
25
|
+
spectrum: MeasurementXY,
|
|
26
|
+
): ConvertedPeak {
|
|
27
|
+
const tVariable = spectrum.variables.t;
|
|
28
|
+
return {
|
|
29
|
+
wavenumber: peak.x,
|
|
30
|
+
absorbance: peak.a,
|
|
31
|
+
transmittance: peak.t / 100,
|
|
32
|
+
kind: getPeakKind(peak.t, tVariable?.min ?? 0, tVariable?.max ?? 100),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getPeakKind(
|
|
37
|
+
transmittance: number,
|
|
38
|
+
minTransmittance: number,
|
|
39
|
+
maxTransmittance: number,
|
|
40
|
+
): string {
|
|
41
|
+
const position =
|
|
42
|
+
(maxTransmittance - transmittance) / (maxTransmittance - minTransmittance);
|
|
43
|
+
if (position < 0.33) {
|
|
44
|
+
return 'w';
|
|
45
|
+
} else if (position < 0.66) {
|
|
46
|
+
return 'm';
|
|
47
|
+
}
|
|
48
|
+
return 'S';
|
|
49
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MeasurementXYVariables, TextData } from 'cheminfo-types';
|
|
2
|
+
import type { Analysis } from 'common-spectrum';
|
|
3
|
+
import { fromJcamp as commonFromJcamp } from 'common-spectrum';
|
|
4
|
+
|
|
5
|
+
import { spectrumCallback as defaultSpectrumCallback } from './utils/spectrumCallback.ts';
|
|
6
|
+
|
|
7
|
+
interface FromJcampOptions {
|
|
8
|
+
/** Unique identifier for the analysis. */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Human-readable label for the analysis. */
|
|
11
|
+
label?: string;
|
|
12
|
+
/** Custom callback to apply on variables when creating a spectrum. Defaults to adding absorbance/transmittance variables. */
|
|
13
|
+
spectrumCallback?: (
|
|
14
|
+
variables: MeasurementXYVariables,
|
|
15
|
+
) => MeasurementXYVariables;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new Analysis from a JCAMP string or buffer.
|
|
20
|
+
* @param jcamp - JCAMP data as a string or ArrayBuffer.
|
|
21
|
+
* @param options - Options for the analysis.
|
|
22
|
+
* @returns New Analysis element with the given data.
|
|
23
|
+
*/
|
|
24
|
+
export function fromJcamp(
|
|
25
|
+
jcamp: TextData,
|
|
26
|
+
options: FromJcampOptions = {},
|
|
27
|
+
): Analysis {
|
|
28
|
+
const { spectrumCallback = defaultSpectrumCallback, ...rest } = options;
|
|
29
|
+
return commonFromJcamp(jcamp, { ...rest, spectrumCallback });
|
|
30
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MeasurementXYVariables } from 'cheminfo-types';
|
|
2
|
+
import { Analysis } from 'common-spectrum';
|
|
3
|
+
import type { InputData } from 'spc-parser';
|
|
4
|
+
import { parse } from 'spc-parser';
|
|
5
|
+
|
|
6
|
+
import { spectrumCallback as defaultSpectrumCallback } from './utils/spectrumCallback.ts';
|
|
7
|
+
|
|
8
|
+
interface FromSPCOptions {
|
|
9
|
+
/** Unique identifier for the analysis. */
|
|
10
|
+
id?: string;
|
|
11
|
+
/** Human-readable label for the analysis. */
|
|
12
|
+
label?: string;
|
|
13
|
+
/** Custom callback to apply on variables when creating a spectrum. Defaults to adding absorbance/transmittance variables. */
|
|
14
|
+
spectrumCallback?: (
|
|
15
|
+
variables: MeasurementXYVariables,
|
|
16
|
+
) => MeasurementXYVariables;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new Analysis from an SPC buffer.
|
|
21
|
+
* @param buffer - SPC file buffer.
|
|
22
|
+
* @param options - Options for the analysis.
|
|
23
|
+
* @returns New Analysis element with the given data.
|
|
24
|
+
*/
|
|
25
|
+
export function fromSPC(
|
|
26
|
+
buffer: InputData,
|
|
27
|
+
options: FromSPCOptions = {},
|
|
28
|
+
): Analysis {
|
|
29
|
+
const { spectrumCallback = defaultSpectrumCallback, ...rest } = options;
|
|
30
|
+
const analysis = new Analysis({ ...rest, spectrumCallback });
|
|
31
|
+
const result = parse(buffer);
|
|
32
|
+
|
|
33
|
+
const { parameters: _resultParameters, ...resultMeta } = result.meta;
|
|
34
|
+
|
|
35
|
+
for (const spectrum of result.spectra) {
|
|
36
|
+
const { parameters: _spectrumParameters, ...spectrumMeta } =
|
|
37
|
+
spectrum.meta ?? {};
|
|
38
|
+
analysis.pushSpectrum(spectrum.variables, {
|
|
39
|
+
dataType: 'IR SPECTRUM',
|
|
40
|
+
title: '',
|
|
41
|
+
meta: { ...resultMeta, ...spectrumMeta },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return analysis;
|
|
45
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { MeasurementXYVariables } from 'cheminfo-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Callback that adds absorbance (a) and transmittance (t) variables to the spectrum.
|
|
5
|
+
* If the y variable is absorbance, transmittance is computed and vice versa.
|
|
6
|
+
* @param variables - Spectrum variables with at least x and y defined.
|
|
7
|
+
* @returns The modified variables with a and t added.
|
|
8
|
+
*/
|
|
9
|
+
export function spectrumCallback(
|
|
10
|
+
variables: MeasurementXYVariables,
|
|
11
|
+
): MeasurementXYVariables {
|
|
12
|
+
// we add missing absorbance / transmittance
|
|
13
|
+
// variable a = absorbance
|
|
14
|
+
// variable t = transmittance
|
|
15
|
+
const yVariable = variables.y;
|
|
16
|
+
let isAbsorbance = true;
|
|
17
|
+
if (yVariable.label.toLowerCase().includes('trans')) {
|
|
18
|
+
isAbsorbance = false;
|
|
19
|
+
}
|
|
20
|
+
if (isAbsorbance) {
|
|
21
|
+
variables.a = {
|
|
22
|
+
...yVariable,
|
|
23
|
+
symbol: 'a',
|
|
24
|
+
data: yVariable.data.slice() as number[],
|
|
25
|
+
};
|
|
26
|
+
variables.t = {
|
|
27
|
+
data: (yVariable.data as number[]).map(
|
|
28
|
+
(absorbance: number) => 10 ** -absorbance * 100,
|
|
29
|
+
),
|
|
30
|
+
label: 'Transmittance (%)',
|
|
31
|
+
symbol: 't',
|
|
32
|
+
units: '',
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
const factor =
|
|
36
|
+
yVariable.label.includes('%') ||
|
|
37
|
+
yVariable.label.toLowerCase().includes('percent')
|
|
38
|
+
? 100
|
|
39
|
+
: 1;
|
|
40
|
+
|
|
41
|
+
variables.a = {
|
|
42
|
+
data: (yVariable.data as number[]).map(
|
|
43
|
+
(transmittance: number) => -Math.log10(transmittance / factor),
|
|
44
|
+
),
|
|
45
|
+
symbol: 'a',
|
|
46
|
+
label: 'Absorbance',
|
|
47
|
+
units: '',
|
|
48
|
+
};
|
|
49
|
+
if (factor === 100) {
|
|
50
|
+
variables.t = { ...yVariable, symbol: 't' };
|
|
51
|
+
variables.t.data = variables.t.data.slice() as number[];
|
|
52
|
+
} else {
|
|
53
|
+
variables.t = {
|
|
54
|
+
units: '',
|
|
55
|
+
label: 'Transmittance (%)',
|
|
56
|
+
symbol: 't',
|
|
57
|
+
data: (yVariable.data as number[]).map(
|
|
58
|
+
(transmittance: number) => transmittance * 100,
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return variables;
|
|
64
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { MeasurementXY } from 'cheminfo-types';
|
|
2
|
+
import type {
|
|
3
|
+
AutoPeakPickingOptions,
|
|
4
|
+
PeakPickingOptions,
|
|
5
|
+
} from 'common-spectrum';
|
|
6
|
+
import {
|
|
7
|
+
JSGraph as OriginalJSGraph,
|
|
8
|
+
autoPeakPicking as originalAutoPeakPicking,
|
|
9
|
+
peakPicking as originalPeakPicking,
|
|
10
|
+
} from 'common-spectrum';
|
|
11
|
+
|
|
12
|
+
import type { ConvertedPeak } from './convertPeak.ts';
|
|
13
|
+
import { convertPeak } from './convertPeak.ts';
|
|
14
|
+
import { getAnnotations } from './jsgraph/getAnnotations.ts';
|
|
15
|
+
|
|
16
|
+
export type { ConvertedPeak } from './convertPeak.ts';
|
|
17
|
+
export { AnalysesManager, Analysis, toJcamp } from 'common-spectrum';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Picks a single peak closest to the given target wavenumber.
|
|
21
|
+
* @param spectrum - The spectrum to pick from.
|
|
22
|
+
* @param target - Target wavenumber value.
|
|
23
|
+
* @param options - Peak picking options.
|
|
24
|
+
* @returns The converted peak or undefined if no peak is found.
|
|
25
|
+
*/
|
|
26
|
+
export function peakPicking(
|
|
27
|
+
spectrum: MeasurementXY,
|
|
28
|
+
target: number,
|
|
29
|
+
options?: PeakPickingOptions,
|
|
30
|
+
): ConvertedPeak | undefined {
|
|
31
|
+
const peak = originalPeakPicking(spectrum, target, options);
|
|
32
|
+
if (!peak) return undefined;
|
|
33
|
+
return convertPeak(
|
|
34
|
+
peak as { x: number; a: number; t: number; [key: string]: number },
|
|
35
|
+
spectrum,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Automatically picks all peaks in the spectrum.
|
|
41
|
+
* @param spectrum - The spectrum to pick from.
|
|
42
|
+
* @param options - Auto peak picking options.
|
|
43
|
+
* @returns Array of converted peaks.
|
|
44
|
+
*/
|
|
45
|
+
export function autoPeakPicking(
|
|
46
|
+
spectrum: MeasurementXY,
|
|
47
|
+
options?: AutoPeakPickingOptions,
|
|
48
|
+
): ConvertedPeak[] {
|
|
49
|
+
const peaks = originalAutoPeakPicking(spectrum, options);
|
|
50
|
+
if (!peaks) return [];
|
|
51
|
+
return peaks.map((peak) =>
|
|
52
|
+
convertPeak(
|
|
53
|
+
peak as { x: number; a: number; t: number; [key: string]: number },
|
|
54
|
+
spectrum,
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { fromJcamp } from './from/fromJcamp.ts';
|
|
60
|
+
export { fromSPC } from './from/fromSPC.ts';
|
|
61
|
+
|
|
62
|
+
export const JSGraph: typeof OriginalJSGraph & {
|
|
63
|
+
getAnnotations: typeof getAnnotations;
|
|
64
|
+
} = { ...OriginalJSGraph, getAnnotations };
|
|
@@ -1,34 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
interface AnnotationPeak {
|
|
2
|
+
wavenumber: number;
|
|
3
|
+
transmittance: number;
|
|
4
|
+
absorbance: number;
|
|
5
|
+
kind: string;
|
|
6
|
+
assignment?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface AnnotationLabel {
|
|
10
|
+
text: string;
|
|
11
|
+
size: string;
|
|
12
|
+
anchor: string;
|
|
13
|
+
color: string;
|
|
14
|
+
angle?: number;
|
|
15
|
+
position: {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
dy: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface AnnotationPosition {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
dy: string;
|
|
26
|
+
dx: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface Annotation {
|
|
30
|
+
line: number;
|
|
31
|
+
type: string;
|
|
32
|
+
strokeColor: string;
|
|
33
|
+
strokeWidth: number;
|
|
34
|
+
fillColor: string;
|
|
35
|
+
labels?: AnnotationLabel[];
|
|
36
|
+
position?: AnnotationPosition[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface GetAnnotationsOptions {
|
|
40
|
+
/** Fill color for annotation rectangles. */
|
|
41
|
+
fillColor?: string;
|
|
42
|
+
/** Stroke color for annotation rectangles. */
|
|
43
|
+
strokeColor?: string;
|
|
44
|
+
/** Display the kind ('m', 'w', 'S'). */
|
|
45
|
+
showKind?: boolean;
|
|
46
|
+
/** Display the assignment. */
|
|
47
|
+
showAssignment?: boolean;
|
|
48
|
+
/** Callback allowing to add properties to an annotation. */
|
|
49
|
+
creationFct?: (annotation: Annotation, peak: AnnotationPeak) => void;
|
|
50
|
+
/** 't100'=transmittance in %, 't'=transmittance, 'a'=absorbance. */
|
|
51
|
+
mode?: 'a' | 't' | 't100';
|
|
52
|
+
/** Angle for assignment labels in absorbance mode. */
|
|
53
|
+
assignmentAngle?: number;
|
|
54
|
+
}
|
|
9
55
|
|
|
10
56
|
/**
|
|
11
|
-
* Creates annotations for jsgraph that allows to display the result of peak picking
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
15
|
-
* @param {string} [options.strokeColor='red']
|
|
16
|
-
* @param {string} [options.showKind=true] - Display the kind, 'm', 'w', 'S'
|
|
17
|
-
* @param {string} [options.showAssignment=true] - Display the assignment
|
|
18
|
-
* @param {Function} [options.createFct] - (annotation, peak) => {}: callback allowing to add properties
|
|
19
|
-
* @param {string} [options.mode='t100'] - 't100'=transmittance in %, 't'=transmittance, 'a'=absorbance
|
|
20
|
-
* @returns array
|
|
57
|
+
* Creates annotations for jsgraph that allows to display the result of peak picking.
|
|
58
|
+
* @param peaks - Array of peaks with wavenumber, transmittance, absorbance, kind.
|
|
59
|
+
* @param options - Display options for the annotations.
|
|
60
|
+
* @returns Array of annotation objects for jsgraph.
|
|
21
61
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
62
|
+
export function getAnnotations(
|
|
63
|
+
peaks: AnnotationPeak[],
|
|
64
|
+
options: GetAnnotationsOptions = {},
|
|
65
|
+
): Annotation[] {
|
|
24
66
|
const {
|
|
25
67
|
fillColor = 'green',
|
|
26
68
|
strokeColor = 'red',
|
|
27
69
|
creationFct,
|
|
28
70
|
mode = 't100',
|
|
29
71
|
} = options;
|
|
30
|
-
|
|
31
|
-
|
|
72
|
+
const annotations = peaks.map((peak) => {
|
|
73
|
+
const annotation: Annotation = {
|
|
32
74
|
line: 1,
|
|
33
75
|
type: 'rect',
|
|
34
76
|
strokeColor,
|
|
@@ -55,9 +97,14 @@ export function getAnnotations(peaks, options = {}) {
|
|
|
55
97
|
return annotations;
|
|
56
98
|
}
|
|
57
99
|
|
|
58
|
-
function annotationTransmittance(
|
|
100
|
+
function annotationTransmittance(
|
|
101
|
+
annotation: Annotation,
|
|
102
|
+
peak: AnnotationPeak,
|
|
103
|
+
factor = 1,
|
|
104
|
+
options: GetAnnotationsOptions = {},
|
|
105
|
+
): void {
|
|
59
106
|
const { showKind = true, showAssignment = true } = options;
|
|
60
|
-
|
|
107
|
+
const labels: AnnotationLabel[] = [];
|
|
61
108
|
let line = 0;
|
|
62
109
|
|
|
63
110
|
if (showKind) {
|
|
@@ -77,7 +124,7 @@ function annotationTransmittance(annotation, peak, factor = 1, options = {}) {
|
|
|
77
124
|
|
|
78
125
|
if (showAssignment) {
|
|
79
126
|
labels.push({
|
|
80
|
-
text: peak.assignment,
|
|
127
|
+
text: peak.assignment ?? '',
|
|
81
128
|
size: '18px',
|
|
82
129
|
anchor: 'middle',
|
|
83
130
|
color: 'darkred',
|
|
@@ -107,13 +154,17 @@ function annotationTransmittance(annotation, peak, factor = 1, options = {}) {
|
|
|
107
154
|
];
|
|
108
155
|
}
|
|
109
156
|
|
|
110
|
-
function annotationAbsorbance(
|
|
157
|
+
function annotationAbsorbance(
|
|
158
|
+
annotation: Annotation,
|
|
159
|
+
peak: AnnotationPeak,
|
|
160
|
+
options: GetAnnotationsOptions = {},
|
|
161
|
+
): void {
|
|
111
162
|
const {
|
|
112
163
|
showKind = true,
|
|
113
164
|
showAssignment = true,
|
|
114
165
|
assignmentAngle = -45,
|
|
115
166
|
} = options;
|
|
116
|
-
|
|
167
|
+
const labels: AnnotationLabel[] = [];
|
|
117
168
|
let line = 0;
|
|
118
169
|
|
|
119
170
|
if (showKind) {
|
|
@@ -133,7 +184,7 @@ function annotationAbsorbance(annotation, peak, options = {}) {
|
|
|
133
184
|
|
|
134
185
|
if (showAssignment) {
|
|
135
186
|
labels.push({
|
|
136
|
-
text: peak.assignment,
|
|
187
|
+
text: peak.assignment ?? '',
|
|
137
188
|
size: '18px',
|
|
138
189
|
angle: assignmentAngle,
|
|
139
190
|
anchor: 'left',
|
package/src/convertPeak.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function convertPeak(peak, spectrum) {
|
|
2
|
-
return {
|
|
3
|
-
wavenumber: peak.x,
|
|
4
|
-
absorbance: peak.a,
|
|
5
|
-
transmittance: peak.t / 100,
|
|
6
|
-
kind: getPeakKind(
|
|
7
|
-
peak.t,
|
|
8
|
-
spectrum.variables.t.min,
|
|
9
|
-
spectrum.variables.t.max,
|
|
10
|
-
),
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function getPeakKind(transmittance, minTransmittance, maxTransmittance) {
|
|
15
|
-
let position =
|
|
16
|
-
(maxTransmittance - transmittance) / (maxTransmittance - minTransmittance);
|
|
17
|
-
if (position < 0.33) {
|
|
18
|
-
return 'w';
|
|
19
|
-
} else if (position < 0.66) {
|
|
20
|
-
return 'm';
|
|
21
|
-
}
|
|
22
|
-
return 'S';
|
|
23
|
-
}
|
package/src/from/fromJcamp.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { fromJcamp as commonFromJcamp } from 'common-spectrum';
|
|
2
|
-
|
|
3
|
-
import { spectrumCallback } from './utils/spectrumCallback.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a new Analysis from a SPC buffer
|
|
7
|
-
* @param {ArrayBuffer|string} jcamp
|
|
8
|
-
* @param {object} [options={}]
|
|
9
|
-
* @param {string|number} [options.id=Math.random()]
|
|
10
|
-
* @param {string} [options.label=options.id] - human redeable label
|
|
11
|
-
* @param {string} [options.spectrumCallback] - a callback to apply on variables when creating spectrum. Default will add a and t
|
|
12
|
-
* @returns {Analysis} - New class element with the given data
|
|
13
|
-
*/
|
|
14
|
-
export function fromJcamp(jcamp, options = {}) {
|
|
15
|
-
return commonFromJcamp(jcamp, { ...options, spectrumCallback });
|
|
16
|
-
}
|
package/src/from/fromSPC.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Analysis } from 'common-spectrum';
|
|
2
|
-
import { parse } from 'spc-parser';
|
|
3
|
-
|
|
4
|
-
import { spectrumCallback } from './utils/spectrumCallback.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new Analysis from a SPC buffer
|
|
8
|
-
* @param {ArrayBuffer} buffer
|
|
9
|
-
* @param {object} [options={}]
|
|
10
|
-
* @param {object} [options.id=Math.random()]
|
|
11
|
-
* @param {string} [options.label=options.id] - human redeable label
|
|
12
|
-
* @param {string} [options.spectrumCallback] - a callback to apply on variables when creating spectrum. Default will add a and t
|
|
13
|
-
* @returns {Analysis} - New class element with the given data
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export function fromSPC(buffer, options = {}) {
|
|
17
|
-
let analysis = new Analysis({ ...options, spectrumCallback });
|
|
18
|
-
let result = parse(buffer);
|
|
19
|
-
|
|
20
|
-
if (result.meta) delete result.meta.parameters;
|
|
21
|
-
|
|
22
|
-
for (let spectrum of result.spectra) {
|
|
23
|
-
if (spectrum.meta) delete spectrum.meta.parameters;
|
|
24
|
-
analysis.pushSpectrum(spectrum.variables, {
|
|
25
|
-
dataType: 'IR SPECTRUM',
|
|
26
|
-
title: '',
|
|
27
|
-
meta: { ...result.meta, ...spectrum.meta },
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return analysis;
|
|
31
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export function spectrumCallback(variables) {
|
|
2
|
-
// we add missing absorbance / transmittance
|
|
3
|
-
// variable a = absorbance
|
|
4
|
-
// variable t = transmittance
|
|
5
|
-
let yVariable = variables.y;
|
|
6
|
-
let absorbance = true;
|
|
7
|
-
if (yVariable.label.toLowerCase().includes('trans')) {
|
|
8
|
-
absorbance = false;
|
|
9
|
-
}
|
|
10
|
-
if (absorbance) {
|
|
11
|
-
variables.a = { ...yVariable, symbol: 'a', data: yVariable.data.slice() };
|
|
12
|
-
variables.t = {
|
|
13
|
-
data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
|
|
14
|
-
label: 'Transmittance (%)',
|
|
15
|
-
symbol: 't',
|
|
16
|
-
units: '',
|
|
17
|
-
};
|
|
18
|
-
} else {
|
|
19
|
-
const factor =
|
|
20
|
-
yVariable.label.includes('%') ||
|
|
21
|
-
yVariable.label.toLowerCase().includes('percent')
|
|
22
|
-
? 100
|
|
23
|
-
: 1;
|
|
24
|
-
|
|
25
|
-
variables.a = {
|
|
26
|
-
data: yVariable.data.map(
|
|
27
|
-
(transmittance) => -Math.log10(transmittance / factor),
|
|
28
|
-
),
|
|
29
|
-
symbol: 'a',
|
|
30
|
-
label: 'Absorbance',
|
|
31
|
-
units: '',
|
|
32
|
-
};
|
|
33
|
-
if (factor === 100) {
|
|
34
|
-
variables.t = { ...yVariable, symbol: 't' };
|
|
35
|
-
variables.t.data = variables.t.data.slice();
|
|
36
|
-
} else {
|
|
37
|
-
variables.t = {
|
|
38
|
-
units: '',
|
|
39
|
-
label: 'Transmittance (%)',
|
|
40
|
-
symbol: 't',
|
|
41
|
-
data: yVariable.data.map((transmittance) => transmittance * 100),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
JSGraph as OriginalJSGraph,
|
|
3
|
-
autoPeakPicking as originalAutoPeakPicking,
|
|
4
|
-
peakPicking as originalPeakPicking,
|
|
5
|
-
} from 'common-spectrum';
|
|
6
|
-
|
|
7
|
-
import { convertPeak } from './convertPeak.js';
|
|
8
|
-
import { getAnnotations } from './jsgraph/getAnnotations.js';
|
|
9
|
-
|
|
10
|
-
export { AnalysesManager, Analysis, toJcamp } from 'common-spectrum';
|
|
11
|
-
|
|
12
|
-
export function peakPicking(spectrum, target, options) {
|
|
13
|
-
const peak = originalPeakPicking(spectrum, target, options);
|
|
14
|
-
if (!peak) return undefined;
|
|
15
|
-
return convertPeak(peak, spectrum);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function autoPeakPicking(spectrum, options) {
|
|
19
|
-
const peaks = originalAutoPeakPicking(spectrum, options);
|
|
20
|
-
if (!peaks) return [];
|
|
21
|
-
return peaks.map((peak) => convertPeak(peak, spectrum));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { fromJcamp } from './from/fromJcamp.js';
|
|
25
|
-
export { fromSPC } from './from/fromSPC.js';
|
|
26
|
-
|
|
27
|
-
export const JSGraph = { ...OriginalJSGraph, getAnnotations };
|