Skip to content

Commit 79eb832

Browse files
authored
fix: fix new width in broad singlet peak (#117)
* fix: fix new width in broad singlet peak * chore: reduce code in gsd
1 parent 883b2fc commit 79eb832

File tree

3 files changed

+22
-46
lines changed

3 files changed

+22
-46
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@
8181
"ml-peak-shape-generator": "^4.1.2",
8282
"ml-savitzky-golay-generalized": "^4.0.1",
8383
"ml-spectra-fitting": "^4.2.1",
84-
"ml-spectra-processing": "^12.0.0"
84+
"ml-spectra-processing": "^14.0.0"
8585
}
8686
}

src/gsd.ts

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import { sgg, SGGOptions } from 'ml-savitzky-golay-generalized';
44
import {
55
xIsEquallySpaced,
66
xIsMonotonic,
7-
xMinValue,
8-
xMaxValue,
97
xNoiseStandardDeviation,
8+
xMinMaxValues,
109
} from 'ml-spectra-processing';
1110

1211
import { GSDPeak } from './GSDPeak';
@@ -79,7 +78,7 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] {
7978

8079
// If the max difference between delta x is less than 5%, then,
8180
// we can assume it to be equally spaced variable
82-
let equallySpaced = xIsEquallySpaced(x);
81+
const equallySpaced = xIsEquallySpaced(x);
8382

8483
if (noiseLevel === undefined) {
8584
if (equallySpaced) {
@@ -109,50 +108,25 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] {
109108
}
110109
}
111110

112-
let yData = y;
113-
let dY, ddY;
114-
const { windowSize, polynomial } = sgOptions;
111+
const xValue = equallySpaced ? x[1] - x[0] : x;
115112

116-
if (equallySpaced) {
117-
if (smoothY) {
118-
yData = sgg(y, x[1] - x[0], {
119-
windowSize,
120-
polynomial,
113+
const yData = smoothY
114+
? sgg(y, xValue, {
115+
...sgOptions,
121116
derivative: 0,
122-
});
123-
}
124-
dY = sgg(y, x[1] - x[0], {
125-
windowSize,
126-
polynomial,
127-
derivative: 1,
128-
});
129-
ddY = sgg(y, x[1] - x[0], {
130-
windowSize,
131-
polynomial,
132-
derivative: 2,
133-
});
134-
} else {
135-
if (smoothY) {
136-
yData = sgg(y, x, {
137-
windowSize,
138-
polynomial,
139-
derivative: 0,
140-
});
141-
}
142-
dY = sgg(y, x, {
143-
windowSize,
144-
polynomial,
145-
derivative: 1,
146-
});
147-
ddY = sgg(y, x, {
148-
windowSize,
149-
polynomial,
150-
derivative: 2,
151-
});
152-
}
117+
})
118+
: y;
119+
120+
const dY = sgg(y, xValue, {
121+
...sgOptions,
122+
derivative: 1,
123+
});
124+
const ddY = sgg(y, xValue, {
125+
...sgOptions,
126+
derivative: 2,
127+
});
153128

154-
const minY = xMinValue(yData);
155-
const maxY = xMaxValue(yData);
129+
const { min: minY, max: maxY } = xMinMaxValues(yData);
156130

157131
if (minY > maxY || minY === maxY) return [];
158132

src/post/joinBroadPeaks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ export function joinBroadPeaks<T extends GSDPeakOptionalShape>(
100100
id: generateID(),
101101
x: broadLines[maxI].x,
102102
y: max,
103-
width: candidates.x[0] - candidates.x[candidates.x.length - 1],
103+
width: Math.abs(
104+
candidates.x[candidates.x.length - 1] - candidates.x[0],
105+
),
104106
},
105107
],
106108
{ shape, optimization },

0 commit comments

Comments
 (0)