ml-gsd
Version:
Global Spectral Deconvolution
26 lines • 909 B
JavaScript
import { getShape1D } from 'ml-peak-shape-generator';
/**
* add missing property if it does not exist in the peak,
* if shape exists but fwhm doesn't, it will be calculated from peak.width
*/
export function addMissingShape(peaks, options = {}) {
const { shape = { kind: 'gaussian' }, output = structuredClone(peaks) } = options;
const shapeInstance = getShape1D(shape);
return output.map((peak) => {
if (hasShape(peak)) {
if (!('fwhm' in peak.shape)) {
const shapeInstance = getShape1D(peak.shape);
peak.shape.fwhm = shapeInstance.widthToFWHM(peak.width);
}
return peak;
}
return {
...peak,
shape: { fwhm: shapeInstance.widthToFWHM(peak.width), ...shape },
};
});
}
function hasShape(peak) {
return 'shape' in peak;
}
//# sourceMappingURL=addMissingShape.js.map