From 4e12f0edf0dac8aca58d5edea5018044f794d3d2 Mon Sep 17 00:00:00 2001 From: jobo322 Date: Tue, 5 Mar 2024 09:52:45 -0500 Subject: [PATCH 1/2] fix: fix new width in broad singlet peak --- package.json | 2 +- src/gsd.ts | 19 ++++++------------- src/post/joinBroadPeaks.ts | 4 +++- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index c45e5ee..81708c4 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,6 @@ "ml-peak-shape-generator": "^4.1.2", "ml-savitzky-golay-generalized": "^4.0.1", "ml-spectra-fitting": "^4.2.1", - "ml-spectra-processing": "^12.0.0" + "ml-spectra-processing": "^14.0.0" } } diff --git a/src/gsd.ts b/src/gsd.ts index dd08104..171c925 100644 --- a/src/gsd.ts +++ b/src/gsd.ts @@ -111,42 +111,35 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] { let yData = y; let dY, ddY; - const { windowSize, polynomial } = sgOptions; if (equallySpaced) { if (smoothY) { yData = sgg(y, x[1] - x[0], { - windowSize, - polynomial, + ...sgOptions, derivative: 0, }); } dY = sgg(y, x[1] - x[0], { - windowSize, - polynomial, + ...sgOptions, derivative: 1, }); ddY = sgg(y, x[1] - x[0], { - windowSize, - polynomial, + ...sgOptions, derivative: 2, }); } else { if (smoothY) { yData = sgg(y, x, { - windowSize, - polynomial, + ...sgOptions, derivative: 0, }); } dY = sgg(y, x, { - windowSize, - polynomial, + ...sgOptions, derivative: 1, }); ddY = sgg(y, x, { - windowSize, - polynomial, + ...sgOptions, derivative: 2, }); } diff --git a/src/post/joinBroadPeaks.ts b/src/post/joinBroadPeaks.ts index 714e97b..fe0aa80 100644 --- a/src/post/joinBroadPeaks.ts +++ b/src/post/joinBroadPeaks.ts @@ -100,7 +100,9 @@ export function joinBroadPeaks( id: generateID(), x: broadLines[maxI].x, y: max, - width: candidates.x[0] - candidates.x[candidates.x.length - 1], + width: Math.abs( + candidates.x[candidates.x.length - 1] - candidates.x[0], + ), }, ], { shape, optimization }, From b95aafe9da80d87cf3f1568114f055eded3d3dce Mon Sep 17 00:00:00 2001 From: jobo322 Date: Tue, 5 Mar 2024 22:19:38 -0500 Subject: [PATCH 2/2] chore: reduce code in gsd --- src/gsd.ts | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/src/gsd.ts b/src/gsd.ts index 171c925..c8a1ab1 100644 --- a/src/gsd.ts +++ b/src/gsd.ts @@ -4,9 +4,8 @@ import { sgg, SGGOptions } from 'ml-savitzky-golay-generalized'; import { xIsEquallySpaced, xIsMonotonic, - xMinValue, - xMaxValue, xNoiseStandardDeviation, + xMinMaxValues, } from 'ml-spectra-processing'; import { GSDPeak } from './GSDPeak'; @@ -79,7 +78,7 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] { // If the max difference between delta x is less than 5%, then, // we can assume it to be equally spaced variable - let equallySpaced = xIsEquallySpaced(x); + const equallySpaced = xIsEquallySpaced(x); if (noiseLevel === undefined) { if (equallySpaced) { @@ -109,43 +108,25 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] { } } - let yData = y; - let dY, ddY; + const xValue = equallySpaced ? x[1] - x[0] : x; - if (equallySpaced) { - if (smoothY) { - yData = sgg(y, x[1] - x[0], { + const yData = smoothY + ? sgg(y, xValue, { ...sgOptions, derivative: 0, - }); - } - dY = sgg(y, x[1] - x[0], { - ...sgOptions, - derivative: 1, - }); - ddY = sgg(y, x[1] - x[0], { - ...sgOptions, - derivative: 2, - }); - } else { - if (smoothY) { - yData = sgg(y, x, { - ...sgOptions, - derivative: 0, - }); - } - dY = sgg(y, x, { - ...sgOptions, - derivative: 1, - }); - ddY = sgg(y, x, { - ...sgOptions, - derivative: 2, - }); - } + }) + : y; + + const dY = sgg(y, xValue, { + ...sgOptions, + derivative: 1, + }); + const ddY = sgg(y, xValue, { + ...sgOptions, + derivative: 2, + }); - const minY = xMinValue(yData); - const maxY = xMaxValue(yData); + const { min: minY, max: maxY } = xMinMaxValues(yData); if (minY > maxY || minY === maxY) return [];