ir-spectrum 2.0.0 → 3.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/README.md +1 -0
- package/lib/index.js +46 -16
- package/package.json +13 -16
- package/src/convertPeak.js +23 -0
- package/src/from/utils/spectrumCallback.js +6 -4
- package/src/index.js +19 -8
- package/src/jsgraph/getAnnotations.js +2 -2
- package/CHANGELOG.md +0 -61
package/README.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var commonSpectrum = require('common-spectrum');
|
|
6
4
|
var spcParser = require('spc-parser');
|
|
7
5
|
|
|
6
|
+
function convertPeak(peak, spectrum) {
|
|
7
|
+
return {
|
|
8
|
+
wavenumber: peak.x,
|
|
9
|
+
absorbance: peak.a,
|
|
10
|
+
transmittance: peak.t / 100,
|
|
11
|
+
kind: getPeakKind(
|
|
12
|
+
peak.t,
|
|
13
|
+
spectrum.variables.t.min,
|
|
14
|
+
spectrum.variables.t.max,
|
|
15
|
+
),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getPeakKind(transmittance, minTransmittance, maxTransmittance) {
|
|
20
|
+
let position =
|
|
21
|
+
(maxTransmittance - transmittance) / (maxTransmittance - minTransmittance);
|
|
22
|
+
if (position < 0.33) {
|
|
23
|
+
return 'w';
|
|
24
|
+
} else if (position < 0.66) {
|
|
25
|
+
return 'm';
|
|
26
|
+
}
|
|
27
|
+
return 'S';
|
|
28
|
+
}
|
|
29
|
+
|
|
8
30
|
/**
|
|
9
31
|
* @typedef {Object} Peak
|
|
10
32
|
* @property {number} wavenumber
|
|
@@ -38,9 +60,9 @@ function getAnnotations(peaks, options = {}) {
|
|
|
38
60
|
let annotation = {
|
|
39
61
|
line: 1,
|
|
40
62
|
type: 'rect',
|
|
41
|
-
strokeColor
|
|
63
|
+
strokeColor,
|
|
42
64
|
strokeWidth: 0,
|
|
43
|
-
fillColor
|
|
65
|
+
fillColor,
|
|
44
66
|
};
|
|
45
67
|
if (creationFct) {
|
|
46
68
|
creationFct(annotation, peak);
|
|
@@ -180,13 +202,12 @@ function spectrumCallback(variables) {
|
|
|
180
202
|
if (yVariable.label.toLowerCase().includes('trans')) {
|
|
181
203
|
absorbance = false;
|
|
182
204
|
}
|
|
183
|
-
|
|
184
205
|
if (absorbance) {
|
|
185
|
-
variables.a = { ...yVariable };
|
|
186
|
-
variables.a.data = variables.a.data.slice();
|
|
206
|
+
variables.a = { ...yVariable, symbol: 'a', data: yVariable.data.slice() };
|
|
187
207
|
variables.t = {
|
|
188
208
|
data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
|
|
189
209
|
label: 'Transmittance (%)',
|
|
210
|
+
symbol: 't',
|
|
190
211
|
units: '',
|
|
191
212
|
};
|
|
192
213
|
} else {
|
|
@@ -195,20 +216,23 @@ function spectrumCallback(variables) {
|
|
|
195
216
|
yVariable.label.toLowerCase().includes('percent')
|
|
196
217
|
? 100
|
|
197
218
|
: 1;
|
|
219
|
+
|
|
198
220
|
variables.a = {
|
|
199
221
|
data: yVariable.data.map(
|
|
200
222
|
(transmittance) => -Math.log10(transmittance / factor),
|
|
201
223
|
),
|
|
224
|
+
symbol: 'a',
|
|
202
225
|
label: 'Absorbance',
|
|
203
226
|
units: '',
|
|
204
227
|
};
|
|
205
228
|
if (factor === 100) {
|
|
206
|
-
variables.t = { ...yVariable };
|
|
229
|
+
variables.t = { ...yVariable, symbol: 't' };
|
|
207
230
|
variables.t.data = variables.t.data.slice();
|
|
208
231
|
} else {
|
|
209
232
|
variables.t = {
|
|
210
233
|
units: '',
|
|
211
234
|
label: 'Transmittance (%)',
|
|
235
|
+
symbol: 't',
|
|
212
236
|
data: yVariable.data.map((transmittance) => transmittance * 100),
|
|
213
237
|
};
|
|
214
238
|
}
|
|
@@ -255,6 +279,18 @@ function fromSPC(buffer, options = {}) {
|
|
|
255
279
|
return analysis;
|
|
256
280
|
}
|
|
257
281
|
|
|
282
|
+
function peakPicking(spectrum, target, options) {
|
|
283
|
+
const peak = commonSpectrum.peakPicking(spectrum, target, options);
|
|
284
|
+
if (!peak) return undefined;
|
|
285
|
+
return convertPeak(peak, spectrum);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function autoPeakPicking(spectrum, options) {
|
|
289
|
+
const peaks = commonSpectrum.autoPeakPicking(spectrum, options);
|
|
290
|
+
if (!peaks) return [];
|
|
291
|
+
return peaks.map((peak) => convertPeak(peak, spectrum));
|
|
292
|
+
}
|
|
293
|
+
|
|
258
294
|
const JSGraph = { ...commonSpectrum.JSGraph, getAnnotations };
|
|
259
295
|
|
|
260
296
|
Object.defineProperty(exports, 'AnalysesManager', {
|
|
@@ -265,18 +301,12 @@ Object.defineProperty(exports, 'Analysis', {
|
|
|
265
301
|
enumerable: true,
|
|
266
302
|
get: function () { return commonSpectrum.Analysis; }
|
|
267
303
|
});
|
|
268
|
-
Object.defineProperty(exports, 'autoPeakPicking', {
|
|
269
|
-
enumerable: true,
|
|
270
|
-
get: function () { return commonSpectrum.autoPeakPicking; }
|
|
271
|
-
});
|
|
272
|
-
Object.defineProperty(exports, 'peakPicking', {
|
|
273
|
-
enumerable: true,
|
|
274
|
-
get: function () { return commonSpectrum.peakPicking; }
|
|
275
|
-
});
|
|
276
304
|
Object.defineProperty(exports, 'toJcamp', {
|
|
277
305
|
enumerable: true,
|
|
278
306
|
get: function () { return commonSpectrum.toJcamp; }
|
|
279
307
|
});
|
|
280
308
|
exports.JSGraph = JSGraph;
|
|
309
|
+
exports.autoPeakPicking = autoPeakPicking;
|
|
281
310
|
exports.fromJcamp = fromJcamp;
|
|
282
311
|
exports.fromSPC = fromSPC;
|
|
312
|
+
exports.peakPicking = peakPicking;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ir-spectrum",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build-doc": "cheminfo doc",
|
|
14
14
|
"eslint": "eslint src",
|
|
15
15
|
"eslint-fix": "npm run eslint -- --fix",
|
|
16
|
-
"
|
|
16
|
+
"prepack": "rollup -c",
|
|
17
17
|
"prettier": "prettier --check src",
|
|
18
18
|
"prettier-write": "prettier --write src",
|
|
19
19
|
"test": "npm run test-coverage && npm run eslint",
|
|
@@ -35,25 +35,22 @@
|
|
|
35
35
|
"testEnvironment": "node"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
39
|
-
"@types/jest": "^
|
|
40
|
-
"cheminfo-build": "^1.
|
|
38
|
+
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
|
|
39
|
+
"@types/jest": "^29.5.3",
|
|
40
|
+
"cheminfo-build": "^1.2.0",
|
|
41
41
|
"codecov": "^3.8.3",
|
|
42
|
-
"eslint": "^8.
|
|
43
|
-
"eslint-config-cheminfo": "^
|
|
44
|
-
"eslint-plugin-import": "^2.26.0",
|
|
45
|
-
"eslint-plugin-jest": "^26.1.5",
|
|
46
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
42
|
+
"eslint": "^8.47.0",
|
|
43
|
+
"eslint-config-cheminfo": "^9.0.2",
|
|
47
44
|
"esm": "^3.2.25",
|
|
48
|
-
"jest": "^
|
|
45
|
+
"jest": "^29.6.3",
|
|
49
46
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
50
|
-
"prettier": "^
|
|
51
|
-
"rollup": "^
|
|
47
|
+
"prettier": "^3.0.2",
|
|
48
|
+
"rollup": "^3.28.1"
|
|
52
49
|
},
|
|
53
50
|
"dependencies": {
|
|
54
|
-
"common-spectrum": "
|
|
55
|
-
"ml-gsd": "^
|
|
56
|
-
"spc-parser": "^0.
|
|
51
|
+
"common-spectrum": "2.2.1",
|
|
52
|
+
"ml-gsd": "^12.1.3",
|
|
53
|
+
"spc-parser": "^0.7.2"
|
|
57
54
|
},
|
|
58
55
|
"info": {
|
|
59
56
|
"logo": "https://raw.githubusercontent.com/cheminfo/font/master/src/ir/assignment.svg",
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -7,13 +7,12 @@ export function spectrumCallback(variables) {
|
|
|
7
7
|
if (yVariable.label.toLowerCase().includes('trans')) {
|
|
8
8
|
absorbance = false;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
10
|
if (absorbance) {
|
|
12
|
-
variables.a = { ...yVariable };
|
|
13
|
-
variables.a.data = variables.a.data.slice();
|
|
11
|
+
variables.a = { ...yVariable, symbol: 'a', data: yVariable.data.slice() };
|
|
14
12
|
variables.t = {
|
|
15
13
|
data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
|
|
16
14
|
label: 'Transmittance (%)',
|
|
15
|
+
symbol: 't',
|
|
17
16
|
units: '',
|
|
18
17
|
};
|
|
19
18
|
} else {
|
|
@@ -22,20 +21,23 @@ export function spectrumCallback(variables) {
|
|
|
22
21
|
yVariable.label.toLowerCase().includes('percent')
|
|
23
22
|
? 100
|
|
24
23
|
: 1;
|
|
24
|
+
|
|
25
25
|
variables.a = {
|
|
26
26
|
data: yVariable.data.map(
|
|
27
27
|
(transmittance) => -Math.log10(transmittance / factor),
|
|
28
28
|
),
|
|
29
|
+
symbol: 'a',
|
|
29
30
|
label: 'Absorbance',
|
|
30
31
|
units: '',
|
|
31
32
|
};
|
|
32
33
|
if (factor === 100) {
|
|
33
|
-
variables.t = { ...yVariable };
|
|
34
|
+
variables.t = { ...yVariable, symbol: 't' };
|
|
34
35
|
variables.t.data = variables.t.data.slice();
|
|
35
36
|
} else {
|
|
36
37
|
variables.t = {
|
|
37
38
|
units: '',
|
|
38
39
|
label: 'Transmittance (%)',
|
|
40
|
+
symbol: 't',
|
|
39
41
|
data: yVariable.data.map((transmittance) => transmittance * 100),
|
|
40
42
|
};
|
|
41
43
|
}
|
package/src/index.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
JSGraph as OriginalJSGraph,
|
|
3
|
+
autoPeakPicking as originalAutoPeakPicking,
|
|
4
|
+
peakPicking as originalPeakPicking,
|
|
5
|
+
} from 'common-spectrum';
|
|
2
6
|
|
|
7
|
+
import { convertPeak } from './convertPeak.js';
|
|
3
8
|
import { getAnnotations } from './jsgraph/getAnnotations';
|
|
4
9
|
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
10
|
+
export { Analysis, AnalysesManager, 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
|
+
}
|
|
12
23
|
|
|
13
24
|
export { fromJcamp } from './from/fromJcamp';
|
|
14
25
|
export { fromSPC } from './from/fromSPC';
|
|
@@ -31,9 +31,9 @@ export function getAnnotations(peaks, options = {}) {
|
|
|
31
31
|
let annotation = {
|
|
32
32
|
line: 1,
|
|
33
33
|
type: 'rect',
|
|
34
|
-
strokeColor
|
|
34
|
+
strokeColor,
|
|
35
35
|
strokeWidth: 0,
|
|
36
|
-
fillColor
|
|
36
|
+
fillColor,
|
|
37
37
|
};
|
|
38
38
|
if (creationFct) {
|
|
39
39
|
creationFct(annotation, peak);
|
package/CHANGELOG.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [2.0.0](https://www.github.com/cheminfo/ir-spectrum/compare/v1.1.0...v2.0.0) (2022-05-05)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
### ⚠ BREAKING CHANGES
|
|
7
|
-
|
|
8
|
-
* remove node 12 compatibility
|
|
9
|
-
* update dependencies to use new ml-signal-processing package
|
|
10
|
-
|
|
11
|
-
### Features
|
|
12
|
-
|
|
13
|
-
* update dependencies to use new ml-signal-processing package ([41e89c2](https://www.github.com/cheminfo/ir-spectrum/commit/41e89c29fec7d228fd9c65828b471cde15af5a9c))
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### Miscellaneous Chores
|
|
17
|
-
|
|
18
|
-
* remove node 12 compatibility ([fd426fc](https://www.github.com/cheminfo/ir-spectrum/commit/fd426fce70fcf8260de58a49224e6b66b07641e8))
|
|
19
|
-
|
|
20
|
-
## [1.1.0](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.3...v1.1.0) (2021-09-07)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
### Features
|
|
24
|
-
|
|
25
|
-
* add fromSPC ([d9eacf4](https://www.github.com/cheminfo/ir-spectrum/commit/d9eacf4cc3d4338ad630f7ee4798c3a168ead34f))
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Bug Fixes
|
|
29
|
-
|
|
30
|
-
* remove compatibility with node 10.x ([08ed76c](https://www.github.com/cheminfo/ir-spectrum/commit/08ed76c47905625822272eb6e9831ba57f6b777f))
|
|
31
|
-
|
|
32
|
-
### [1.0.3](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.2...v1.0.3) (2021-07-06)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
### Bug Fixes
|
|
36
|
-
|
|
37
|
-
* dot in README ([dac6c63](https://www.github.com/cheminfo/ir-spectrum/commit/dac6c63f88399c1e87f10dd6dbb163b9c149e9b9))
|
|
38
|
-
* iupac link for technique ([b67a76d](https://www.github.com/cheminfo/ir-spectrum/commit/b67a76d98e494655f037a43915aea29ad00eb5ff))
|
|
39
|
-
|
|
40
|
-
### [1.0.2](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.1...v1.0.2) (2021-04-14)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Bug Fixes
|
|
44
|
-
|
|
45
|
-
* double reverse because same variable (pointer) ([208bcf9](https://www.github.com/cheminfo/ir-spectrum/commit/208bcf9c04d1dcd5f9875d773f5bb201f26d2c56))
|
|
46
|
-
|
|
47
|
-
### [1.0.1](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.0...v1.0.1) (2021-03-29)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
### Bug Fixes
|
|
51
|
-
|
|
52
|
-
* use wavenumber and not wavelength ([66b6b51](https://www.github.com/cheminfo/ir-spectrum/commit/66b6b51a7c92c424183c4b34865bd21d0d714848))
|
|
53
|
-
|
|
54
|
-
## 1.0.0 (2021-03-26)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### Features
|
|
58
|
-
|
|
59
|
-
* add getAnnotations ([e3f8b63](https://www.github.com/cheminfo/ir-spectrum/commit/e3f8b631f74fbb4bcdcebab7f1b6666e9695b722))
|
|
60
|
-
* add peakPicking and autoPeakPicking ([a950e2d](https://www.github.com/cheminfo/ir-spectrum/commit/a950e2d7a4c02009f6b3c5c82f9f264193f25345))
|
|
61
|
-
* fromJcamp adds a and t ([b3c8d77](https://www.github.com/cheminfo/ir-spectrum/commit/b3c8d77404d49415f594ec94ba92009877fc81a4))
|