Skip to content

Commit 0064f6e

Browse files
committed
Feat(GSD): Option smoothY
1 parent c0d3bf9 commit 0064f6e

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ml-gsd",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Global Spectra Deconvolution",
55
"main": "src/index.js",
66
"directories": {
@@ -13,7 +13,7 @@
1313
},
1414
"repository": {
1515
"type": "git",
16-
"url": "https://github.com/mljs/global-spectra-deconvolution.git"
16+
"url": "https://github.com/mljs/global-spectral-deconvolution.git"
1717
},
1818
"keywords": [
1919
"Global Spectra Deconvolution",
@@ -25,23 +25,21 @@
2525
"author": "Andres Castillo",
2626
"license": "MIT",
2727
"bugs": {
28-
"url": "https://github.com/mljs/global-spectra-deconvolution/issues"
28+
"url": "https://github.com/mljs/global-spectral-deconvolution/issues"
2929
},
30-
"homepage": "https://github.com/mljs/global-spectra-deconvolution",
30+
"homepage": "https://github.com/mljs/global-spectral-deconvolution",
3131
"devDependencies": {
3232
"cheminfo-tools": "^1.0.2",
3333
"mocha": "^2.2.5",
3434
"mocha-better-spec-reporter": "^2.1.1",
3535
"should": "^7.0.2",
36-
"xy-parser": "^1.0.0",
37-
"chemcalc": "^3.0.1",
38-
"ml-stat": "^1.0.1"
36+
"chemcalc": "^3.0.1"
3937
},
4038
"dependencies": {
4139
"ml-optimize-lorentzian": "0.0.2",
4240
"ml-stat": "^1.0.1",
4341
"xy-parser": "^1.1.0",
44-
"ml-savitzky-golay-generalized": "1.0.0",
42+
"ml-savitzky-golay-generalized": "1.0.3",
4543
"extend": "3.0.0"
4644
}
4745
}

src/gsd.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var extend = require('extend');
44
var SG = require('ml-savitzky-golay-generalized');
55

66
var sgDefOptions = {
7-
windowSize: 5,
7+
windowSize: 9,
88
polynomial: 3
99
};
1010

@@ -53,13 +53,16 @@ function gsd(x, y, options){
5353
}
5454
}
5555
//If the max difference between delta x is less than 5%, then, we can assume it to be equally spaced variable
56+
var Y = y;
5657
if((maxDx-minDx)/maxDx<0.05){
57-
var Y = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:0});
58+
if(options.smoothY)
59+
Y = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:0});
5860
var dY = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:1});
5961
var ddY = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:2});
6062
}
6163
else{
62-
var Y = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:0});
64+
if(options.smoothY)
65+
Y = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:0});
6366
var dY = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:1});
6467
var ddY = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:2});
6568
}
@@ -171,6 +174,9 @@ function gsd(x, y, options){
171174
}
172175

173176
function realTopDetection(peakList, x, y){
177+
//console.log(peakList);
178+
//console.log(x);
179+
//console.log(y);
174180
var listP = [];
175181
var alpha, beta, gamma, p,currentPoint;
176182
for(var j=0;j<peakList.length;j++){

test/ethylvinylether.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ describe('Global spectra deconvolution NMR spectra', function () {
88
// Test case obtained from Pag 443, Chap 8.
99
it('Ethylvinylether should have 21 peaks', function () {
1010
var spectrum=JSON.parse(fs.readFileSync('./test//ethylvinylether.json', 'utf-8'));
11-
var result = peakPicking.gsd(spectrum[0],spectrum[1], {noiseLevel: 1049200.537996172, minMaxRatio:0.03});
12-
//console.log(result)
11+
var result = peakPicking.gsd(spectrum[0],spectrum[1],
12+
{noiseLevel: 1049200.537996172,
13+
minMaxRatio: 0.03,
14+
smoothY:false,
15+
sgOptions:{windowSize:5, polynomial:3}
16+
});
1317
result.length.should.equal(21);
1418
});
1519
});

test/test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ describe('Global spectra deconvolution simple simulated spectrum', function () {
88
// Test case obtained from Pag 443, Chap 8.
99
it('Should provide the right result ...', function () {
1010
var spectrum=JSON.parse(fs.readFileSync('./test//C2.json', 'utf-8'));
11-
var result = peakPicking.gsd(spectrum[0],spectrum[1], {noiseLevel: 0.001, minMaxRatio:0,realTopDetection:true});
11+
var result = peakPicking.gsd(spectrum[0],spectrum[1], {noiseLevel: 0.001,
12+
minMaxRatio:0,
13+
realTopDetection:true,
14+
smoothY:false
15+
});
1216

1317
result[0].x.should.approximately(24,0.02);
14-
result[0].y.should.approximately(0.09394372786996513,0.0005);
18+
result[0].y.should.approximately(0.09394372786996513,0.00005);
1519
//result[0].width.should.approximately(0.008,5e-4);
1620

1721
result[1].x.should.approximately(25,0.02);
18-
result[1].y.should.approximately(0.0020321396708958394,0.0005);
22+
result[1].y.should.approximately(0.0020321396708958394,0.00005);
1923
//result[1].width.should.approximately(0.006,5e-4);
2024

2125
});

0 commit comments

Comments
 (0)