@@ -4,9 +4,8 @@ import { sgg, SGGOptions } from 'ml-savitzky-golay-generalized';
44import {
55 xIsEquallySpaced ,
66 xIsMonotonic ,
7- xMinValue ,
8- xMaxValue ,
97 xNoiseStandardDeviation ,
8+ xMinMaxValues ,
109} from 'ml-spectra-processing' ;
1110
1211import { 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
0 commit comments