ir-spectrum 1.0.2 → 2.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/CHANGELOG.md +37 -0
- package/README.md +0 -2
- package/lib/index.js +47 -19
- package/package.json +41 -16
- package/src/from/fromJcamp.js +12 -45
- package/src/from/fromSPC.js +31 -0
- package/src/from/utils/spectrumCallback.js +43 -0
- package/src/index.js +1 -0
- package/History.md +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
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
|
+
|
|
3
40
|
### [1.0.2](https://www.github.com/cheminfo/ir-spectrum/compare/v1.0.1...v1.0.2) (2021-04-14)
|
|
4
41
|
|
|
5
42
|
|
package/README.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var commonSpectrum = require('common-spectrum');
|
|
6
|
+
var spcParser = require('spc-parser');
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @typedef {Object} Peak
|
|
@@ -170,10 +171,6 @@ function annotationAbsorbance(annotation, peak, options = {}) {
|
|
|
170
171
|
];
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
function fromJcamp(jcamp, options) {
|
|
174
|
-
return commonSpectrum.fromJcamp(jcamp, { ...options, spectrumCallback });
|
|
175
|
-
}
|
|
176
|
-
|
|
177
174
|
function spectrumCallback(variables) {
|
|
178
175
|
// we add missing absorbance / transmittance
|
|
179
176
|
// variable a = absorbance
|
|
@@ -218,37 +215,68 @@ function spectrumCallback(variables) {
|
|
|
218
215
|
}
|
|
219
216
|
}
|
|
220
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Creates a new Analysis from a SPC buffer
|
|
220
|
+
* @param {ArrayBuffer|string} jcamp
|
|
221
|
+
* @param {object} [options={}]
|
|
222
|
+
* @param {string|number} [options.id=Math.random()]
|
|
223
|
+
* @param {string} [options.label=options.id] human redeable label
|
|
224
|
+
* @param {string} [options.spectrumCallback] a callback to apply on variables when creating spectrum. Default will add a and t
|
|
225
|
+
* @return {Analysis} - New class element with the given data
|
|
226
|
+
*/
|
|
227
|
+
function fromJcamp(jcamp, options = {}) {
|
|
228
|
+
return commonSpectrum.fromJcamp(jcamp, { ...options, spectrumCallback });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Creates a new Analysis from a SPC buffer
|
|
233
|
+
* @param {ArrayBuffer} buffer
|
|
234
|
+
* @param {object} [options={}]
|
|
235
|
+
* @param {object} [options.id=Math.random()]
|
|
236
|
+
* @param {string} [options.label=options.id] human redeable label
|
|
237
|
+
* @param {string} [options.spectrumCallback] a callback to apply on variables when creating spectrum. Default will add a and t
|
|
238
|
+
* @return {Analysis} - New class element with the given data
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
function fromSPC(buffer, options = {}) {
|
|
242
|
+
let analysis = new commonSpectrum.Analysis({ ...options, spectrumCallback });
|
|
243
|
+
let result = spcParser.parse(buffer);
|
|
244
|
+
|
|
245
|
+
if (result.meta) delete result.meta.parameters;
|
|
246
|
+
|
|
247
|
+
for (let spectrum of result.spectra) {
|
|
248
|
+
if (spectrum.meta) delete spectrum.meta.parameters;
|
|
249
|
+
analysis.pushSpectrum(spectrum.variables, {
|
|
250
|
+
dataType: 'IR SPECTRUM',
|
|
251
|
+
title: '',
|
|
252
|
+
meta: { ...result.meta, ...spectrum.meta },
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return analysis;
|
|
256
|
+
}
|
|
257
|
+
|
|
221
258
|
const JSGraph = { ...commonSpectrum.JSGraph, getAnnotations };
|
|
222
259
|
|
|
223
260
|
Object.defineProperty(exports, 'AnalysesManager', {
|
|
224
261
|
enumerable: true,
|
|
225
|
-
get: function () {
|
|
226
|
-
return commonSpectrum.AnalysesManager;
|
|
227
|
-
}
|
|
262
|
+
get: function () { return commonSpectrum.AnalysesManager; }
|
|
228
263
|
});
|
|
229
264
|
Object.defineProperty(exports, 'Analysis', {
|
|
230
265
|
enumerable: true,
|
|
231
|
-
get: function () {
|
|
232
|
-
return commonSpectrum.Analysis;
|
|
233
|
-
}
|
|
266
|
+
get: function () { return commonSpectrum.Analysis; }
|
|
234
267
|
});
|
|
235
268
|
Object.defineProperty(exports, 'autoPeakPicking', {
|
|
236
269
|
enumerable: true,
|
|
237
|
-
get: function () {
|
|
238
|
-
return commonSpectrum.autoPeakPicking;
|
|
239
|
-
}
|
|
270
|
+
get: function () { return commonSpectrum.autoPeakPicking; }
|
|
240
271
|
});
|
|
241
272
|
Object.defineProperty(exports, 'peakPicking', {
|
|
242
273
|
enumerable: true,
|
|
243
|
-
get: function () {
|
|
244
|
-
return commonSpectrum.peakPicking;
|
|
245
|
-
}
|
|
274
|
+
get: function () { return commonSpectrum.peakPicking; }
|
|
246
275
|
});
|
|
247
276
|
Object.defineProperty(exports, 'toJcamp', {
|
|
248
277
|
enumerable: true,
|
|
249
|
-
get: function () {
|
|
250
|
-
return commonSpectrum.toJcamp;
|
|
251
|
-
}
|
|
278
|
+
get: function () { return commonSpectrum.toJcamp; }
|
|
252
279
|
});
|
|
253
280
|
exports.JSGraph = JSGraph;
|
|
254
281
|
exports.fromJcamp = fromJcamp;
|
|
282
|
+
exports.fromSPC = fromSPC;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ir-spectrum",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"eslint": "eslint src",
|
|
15
15
|
"eslint-fix": "npm run eslint -- --fix",
|
|
16
16
|
"prepublishOnly": "rollup -c",
|
|
17
|
+
"prettier": "prettier --check src",
|
|
18
|
+
"prettier-write": "prettier --write src",
|
|
17
19
|
"test": "npm run test-coverage && npm run eslint",
|
|
18
20
|
"test-coverage": "jest --coverage",
|
|
19
21
|
"test-only": "jest"
|
|
@@ -33,23 +35,46 @@
|
|
|
33
35
|
"testEnvironment": "node"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
37
|
-
"@types/jest": "^
|
|
38
|
-
"cheminfo-build": "^1.1.
|
|
39
|
-
"codecov": "^3.8.
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"eslint-config-cheminfo": "^
|
|
42
|
-
"eslint-plugin-import": "^2.
|
|
43
|
-
"eslint-plugin-jest": "^
|
|
44
|
-
"eslint-plugin-prettier": "^
|
|
38
|
+
"@babel/plugin-transform-modules-commonjs": "^7.17.9",
|
|
39
|
+
"@types/jest": "^27.5.0",
|
|
40
|
+
"cheminfo-build": "^1.1.11",
|
|
41
|
+
"codecov": "^3.8.3",
|
|
42
|
+
"eslint": "^8.14.0",
|
|
43
|
+
"eslint-config-cheminfo": "^7.3.0",
|
|
44
|
+
"eslint-plugin-import": "^2.26.0",
|
|
45
|
+
"eslint-plugin-jest": "^26.1.5",
|
|
46
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
45
47
|
"esm": "^3.2.25",
|
|
46
|
-
"jest": "^
|
|
47
|
-
"jest-matcher-deep-close-to": "^
|
|
48
|
-
"prettier": "^2.2
|
|
49
|
-
"rollup": "^2.
|
|
48
|
+
"jest": "^28.0.3",
|
|
49
|
+
"jest-matcher-deep-close-to": "^3.0.2",
|
|
50
|
+
"prettier": "^2.6.2",
|
|
51
|
+
"rollup": "^2.72.0"
|
|
50
52
|
},
|
|
51
53
|
"dependencies": {
|
|
52
|
-
"common-spectrum": "0.
|
|
53
|
-
"ml-gsd": "^
|
|
54
|
+
"common-spectrum": "1.0.2",
|
|
55
|
+
"ml-gsd": "^11.2.0",
|
|
56
|
+
"spc-parser": "^0.5.2"
|
|
57
|
+
},
|
|
58
|
+
"info": {
|
|
59
|
+
"logo": "https://raw.githubusercontent.com/cheminfo/font/master/src/ir/assignment.svg",
|
|
60
|
+
"domain": [
|
|
61
|
+
"Physical Chemistry",
|
|
62
|
+
"Materials Science",
|
|
63
|
+
"Organic Chemistry"
|
|
64
|
+
],
|
|
65
|
+
"technique": {
|
|
66
|
+
"name": "IR",
|
|
67
|
+
"chmo": "0000630",
|
|
68
|
+
"iupac": "https://goldbook.iupac.org/terms/view/IT07399"
|
|
69
|
+
},
|
|
70
|
+
"functionality": {
|
|
71
|
+
"fileTypes": [
|
|
72
|
+
{
|
|
73
|
+
"extension": "jdx",
|
|
74
|
+
"manufacturer": "IUPAC",
|
|
75
|
+
"example": "https://raw.githubusercontent.com/cheminfo/ir-spectrum/master/testFiles/absorbance.jdx"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
54
79
|
}
|
|
55
80
|
}
|
package/src/from/fromJcamp.js
CHANGED
|
@@ -1,49 +1,16 @@
|
|
|
1
1
|
import { fromJcamp as commonFromJcamp } from 'common-spectrum';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
return commonFromJcamp(jcamp, { ...options, spectrumCallback });
|
|
5
|
-
}
|
|
3
|
+
import { spectrumCallback } from './utils/spectrumCallback';
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
variables.a = { ...yVariable };
|
|
19
|
-
variables.a.data = variables.a.data.slice();
|
|
20
|
-
variables.t = {
|
|
21
|
-
data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
|
|
22
|
-
label: 'Transmittance (%)',
|
|
23
|
-
units: '',
|
|
24
|
-
};
|
|
25
|
-
} else {
|
|
26
|
-
const factor =
|
|
27
|
-
yVariable.label.includes('%') ||
|
|
28
|
-
yVariable.label.toLowerCase().includes('percent')
|
|
29
|
-
? 100
|
|
30
|
-
: 1;
|
|
31
|
-
variables.a = {
|
|
32
|
-
data: yVariable.data.map(
|
|
33
|
-
(transmittance) => -Math.log10(transmittance / factor),
|
|
34
|
-
),
|
|
35
|
-
label: 'Absorbance',
|
|
36
|
-
units: '',
|
|
37
|
-
};
|
|
38
|
-
if (factor === 100) {
|
|
39
|
-
variables.t = { ...yVariable };
|
|
40
|
-
variables.t.data = variables.t.data.slice();
|
|
41
|
-
} else {
|
|
42
|
-
variables.t = {
|
|
43
|
-
units: '',
|
|
44
|
-
label: 'Transmittance (%)',
|
|
45
|
-
data: yVariable.data.map((transmittance) => transmittance * 100),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
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
|
+
* @return {Analysis} - New class element with the given data
|
|
13
|
+
*/
|
|
14
|
+
export function fromJcamp(jcamp, options = {}) {
|
|
15
|
+
return commonFromJcamp(jcamp, { ...options, spectrumCallback });
|
|
49
16
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Analysis } from 'common-spectrum';
|
|
2
|
+
import { parse } from 'spc-parser';
|
|
3
|
+
|
|
4
|
+
import { spectrumCallback } from './utils/spectrumCallback';
|
|
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
|
+
* @return {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
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
|
|
11
|
+
if (absorbance) {
|
|
12
|
+
variables.a = { ...yVariable };
|
|
13
|
+
variables.a.data = variables.a.data.slice();
|
|
14
|
+
variables.t = {
|
|
15
|
+
data: yVariable.data.map((absorbance) => 10 ** -absorbance * 100),
|
|
16
|
+
label: 'Transmittance (%)',
|
|
17
|
+
units: '',
|
|
18
|
+
};
|
|
19
|
+
} else {
|
|
20
|
+
const factor =
|
|
21
|
+
yVariable.label.includes('%') ||
|
|
22
|
+
yVariable.label.toLowerCase().includes('percent')
|
|
23
|
+
? 100
|
|
24
|
+
: 1;
|
|
25
|
+
variables.a = {
|
|
26
|
+
data: yVariable.data.map(
|
|
27
|
+
(transmittance) => -Math.log10(transmittance / factor),
|
|
28
|
+
),
|
|
29
|
+
label: 'Absorbance',
|
|
30
|
+
units: '',
|
|
31
|
+
};
|
|
32
|
+
if (factor === 100) {
|
|
33
|
+
variables.t = { ...yVariable };
|
|
34
|
+
variables.t.data = variables.t.data.slice();
|
|
35
|
+
} else {
|
|
36
|
+
variables.t = {
|
|
37
|
+
units: '',
|
|
38
|
+
label: 'Transmittance (%)',
|
|
39
|
+
data: yVariable.data.map((transmittance) => transmittance * 100),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.js
CHANGED
package/History.md
DELETED
|
File without changes
|