Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix new width in broad singlet peak #117

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
62 changes: 18 additions & 44 deletions src/gsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -109,50 +108,25 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] {
}
}

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

if (equallySpaced) {
if (smoothY) {
yData = sgg(y, x[1] - x[0], {
windowSize,
polynomial,
const yData = smoothY
? sgg(y, xValue, {
...sgOptions,
Copy link
Member

@lpatiny lpatiny Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we send other parameters that just windowSize and polynomial ?

If sgg does not change the options (like adding a new parameter) and this would be a bug in sgg I think, you don't need to create a new object with destructuring sgOptions. You can directly send sgOptions.

derivative: 0,
});
}
dY = sgg(y, x[1] - x[0], {
windowSize,
polynomial,
derivative: 1,
});
ddY = sgg(y, x[1] - x[0], {
windowSize,
polynomial,
derivative: 2,
});
} else {
if (smoothY) {
yData = sgg(y, x, {
windowSize,
polynomial,
derivative: 0,
});
}
dY = sgg(y, x, {
windowSize,
polynomial,
derivative: 1,
});
ddY = sgg(y, x, {
windowSize,
polynomial,
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 [];

Expand Down
4 changes: 3 additions & 1 deletion src/post/joinBroadPeaks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export function joinBroadPeaks<T extends GSDPeakOptionalShape>(
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 },
Expand Down
Loading