Skip to content

Commit 4653e16

Browse files
committed
feat: change parameters
BREAKING CHANGES The function now use the `DataXY` input (an object with x:[] and y:[] properties). The width of the peaks after gsd is the width between the 2 inflection points. The width of the peaks after optimizePeaks is always FWHM
1 parent 82f46d9 commit 4653e16

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

README.md

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# global-spectral-deconvolution
22

33
[![NPM version][npm-image]][npm-url]
4-
[![build status][travis-image]][travis-url]
54
[![David deps][david-image]][david-url]
65
[![npm download][download-image]][download-url]
76

87
Global Spectra Deconvolution + Peak optimizer
98

9+
`gsd`is using an algorithm that is searching for inflection points to determine the position of peaks and the width of the peaks are between the 2 inflection points. The result of GSD yield to an array of object containing {x, y and width}. However this width is based on the inflection point and may be different from the 'fwhm' (Full Width Half Maximum).
10+
11+
The second algorithm (`optimize`) will optimize the width as a FWHM to match the original peak. After optimization the width with therefore be always FWHM whichever is the function used.
12+
1013
## [API documentation](http://mljs.github.io/global-spectral-deconvolution/)
1114

1215
## Parameters
@@ -61,39 +64,28 @@ By default we enlarge of a factor 2 and we don't allow overlap.
6164
## Example
6265

6366
```js
64-
var CC = require('chemcalc');
65-
var Stat = require('ml-stat');
66-
var peakPicking = require('ml-gsd');
67-
68-
var spectrum = CC.analyseMF('Cl2.Br2', {
69-
isotopomers: 'arrayXXYY',
70-
fwhm: 0.01,
71-
gaussianWidth: 11,
72-
});
73-
var xy = spectrum.arrayXXYY;
74-
var x = xy[0];
75-
var y = xy[1];
76-
//Just a fake noiseLevel
77-
var noiseLevel =
78-
Stat.array.median(
79-
y.filter(function (a) {
80-
return a > 0;
81-
}),
82-
) * 3;
83-
84-
var options = {
85-
noiseLevel: noiseLevel,
86-
minMaxRatio: 0,
87-
broadRatio: 0,
88-
smoothY: false,
89-
realTopDetection: true,
90-
};
91-
var result = peakPicking.gsd(x, y, options);
67+
import { IsotopicDistribution } from 'mf-global';
68+
import { gsd, optimizePeaks } from '../src';
69+
70+
// generate a sample spectrum of the form {x:[], y:[]}
71+
const data = new IsotopicDistribution('C').getGaussian();
9272

93-
result = peakPicking.optimizePeaks(result, x, y, {
94-
factorWidth: 1,
95-
functionName: 'gaussian',
73+
let peaks = gsd(data, {
74+
noiseLevel: 0,
75+
minMaxRatio: 0.00025, // Threshold to determine if a given peak should be considered as a noise
76+
realTopDetection: true,
77+
maxCriteria: true, // inverted:false
78+
smoothY: false,
79+
sgOptions: { windowSize: 7, polynomial: 3 },
9680
});
81+
console.log(peaks); // array of peaks {x,y,width}, width = distance between inflection points
82+
// GSD
83+
84+
let optimized = optimizePeaks(data, peaks);
85+
console.log(optimized); // array of peaks {x,y,width}, width = FWHM
86+
87+
88+
9789
```
9890

9991
## License
@@ -102,8 +94,6 @@ result = peakPicking.optimizePeaks(result, x, y, {
10294

10395
[npm-image]: https://img.shields.io/npm/v/ml-gsd.svg?style=flat-square
10496
[npm-url]: https://npmjs.org/package/ml-gsd
105-
[travis-image]: https://img.shields.io/travis/mljs/global-spectral-deconvolution/master.svg?style=flat-square
106-
[travis-url]: https://travis-ci.org/mljs/global-spectral-deconvolution
10797
[david-image]: https://img.shields.io/david/mljs/global-spectral-deconvolution.svg?style=flat-square
10898
[david-url]: https://david-dm.org/mljs/global-spectral-deconvolution
10999
[download-image]: https://img.shields.io/npm/dm/ml-gsd.svg?style=flat-square

examples/example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var gsd = require('../src/gsd');
1+
const gsd = require('../src/gsd');
22

33
let X = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
44
let Y = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0];
@@ -8,6 +8,6 @@ let peaks = gsd(X, Y, {
88
realTopDetection: true,
99
maxCriteria: true, // inverted:false
1010
smoothY: false,
11-
sgOptions: { windowSize: 7, polynomial: 3 }
11+
sgOptions: { windowSize: 7, polynomial: 3 },
1212
});
1313
console.log(peaks);

examples/mf.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// to execute with `node -r esm ./mf.js`
2+
3+
import { IsotopicDistribution } from 'mf-global';
4+
import { gsd, optimizePeaks } from '../src';
5+
6+
// generate a sample spectrum of the form {x:[], y:[]}
7+
const data = new IsotopicDistribution('C').getGaussian();
8+
9+
let peaks = gsd(data, {
10+
noiseLevel: 0,
11+
minMaxRatio: 0.00025, // Threshold to determine if a given peak should be considered as a noise
12+
realTopDetection: true,
13+
maxCriteria: true, // inverted:false
14+
smoothY: false,
15+
sgOptions: { windowSize: 7, polynomial: 3 },
16+
});
17+
18+
let optimized = optimizePeaks(data, peaks);
19+
console.log(optimized);

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
"eslint-plugin-import": "^2.22.1",
6060
"eslint-plugin-jest": "^24.1.0",
6161
"eslint-plugin-prettier": "^3.1.4",
62+
"esm": "^3.2.25",
6263
"jest": "^26.6.3",
64+
"mf-global": "^1.3.0",
6365
"ml-stat": "^1.3.3",
6466
"prettier": "^2.1.2",
6567
"rollup": "^2.33.1",

0 commit comments

Comments
 (0)