Comparing version 12.0.0-pre.1661396593 to 12.0.0-pre.1661543950
@@ -5,2 +5,4 @@ import type { DataXY } from 'cheminfo-types'; | ||
import { GSDPeak } from './GSDPeak'; | ||
import { MakeMandatory } from './utils/MakeMandatory'; | ||
import { MakeOptional } from './utils/MakeOptional'; | ||
export interface GSDOptions { | ||
@@ -45,2 +47,4 @@ /** | ||
} | ||
export declare type GSDPeakID = MakeMandatory<GSDPeak, 'id'>; | ||
export declare type GSDPeakIDOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
/** | ||
@@ -53,3 +57,3 @@ * Global spectra deconvolution | ||
*/ | ||
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeak[]; | ||
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeakID[]; | ||
//# sourceMappingURL=gsd.d.ts.map |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { sgg } from 'ml-savitzky-golay-generalized'; | ||
@@ -164,2 +165,3 @@ import { xIsEquallySpaced, xIsMonotoneIncreasing, xMinValue, xMaxValue, xNoiseStandardDeviation, } from 'ml-spectra-processing'; | ||
peaks.push({ | ||
id: generateID(), | ||
x: deltaX, | ||
@@ -166,0 +168,0 @@ y: yData[minddYIndex], |
@@ -0,5 +1,8 @@ | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDBroadenPeak { | ||
id?: string; | ||
x: number; | ||
y: number; | ||
width: number; | ||
shape?: Shape1D; | ||
index: number; | ||
@@ -6,0 +9,0 @@ from: { |
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDPeak { | ||
id?: string; | ||
x: number; | ||
@@ -4,0 +5,0 @@ y: number; |
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDPeakOptimized { | ||
id?: string; | ||
x: number; | ||
@@ -4,0 +5,0 @@ y: number; |
@@ -0,3 +1,19 @@ | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
import { GSDBroadenPeak } from '../GSDBroadenPeak'; | ||
import { GSDPeak } from '../GSDPeak'; | ||
import { MakeOptional } from '../utils/MakeOptional'; | ||
declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
declare type GSDBroadenPeakWithID = GSDBroadenPeak & { | ||
id: string; | ||
}; | ||
declare type GSDBroadenPeakWithShape = GSDBroadenPeak & { | ||
shape: Shape1D; | ||
}; | ||
declare type GSDBroadenPeakWithShapeID = GSDBroadenPeakWithID & { | ||
shape: Shape1D; | ||
}; | ||
export declare type WithOrWithout<T, ToExtends, TrueType, FalseType> = T extends ToExtends ? TrueType : FalseType; | ||
export declare type WithIDOrShape<T> = T extends { | ||
id: string; | ||
} ? WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShapeID, GSDBroadenPeakWithID> : WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShape, GSDBroadenPeak>; | ||
/** | ||
@@ -10,3 +26,3 @@ * This method will allow to enlarge peaks while preventing overlap between peaks | ||
*/ | ||
export declare function broadenPeaks(peakList: Omit<GSDPeak, 'shape'>[], options?: { | ||
export declare function broadenPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: { | ||
/** | ||
@@ -21,3 +37,4 @@ * @default 2 | ||
overlap?: boolean; | ||
}): GSDBroadenPeak[]; | ||
}): WithIDOrShape<T>[]; | ||
export {}; | ||
//# sourceMappingURL=broadenPeaks.d.ts.map |
@@ -0,1 +1,2 @@ | ||
import { getShape1D } from 'ml-peak-shape-generator'; | ||
/** | ||
@@ -10,14 +11,3 @@ * This method will allow to enlarge peaks while preventing overlap between peaks | ||
const { factor = 2, overlap = false } = options; | ||
const peaks = peakList.map((peak) => { | ||
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor; | ||
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor; | ||
return { | ||
x: peak.x, | ||
y: peak.y, | ||
index: peak.index, | ||
width: xTo - xFrom, | ||
from: { x: xFrom }, | ||
to: { x: xTo }, | ||
}; | ||
}); | ||
const peaks = mapPeaks(peakList, factor); | ||
if (!overlap) { | ||
@@ -35,7 +25,36 @@ for (let i = 0; i < peaks.length - 1; i++) { | ||
} | ||
for (let peak of peaks) { | ||
for (const peak of peaks) { | ||
peak.width = peak.to.x - peak.from.x; | ||
if (peak.shape) { | ||
const { shape, width } = peak; | ||
if (shape.fwhm !== undefined) { | ||
const shapeFct = getShape1D(shape); | ||
peak.shape.fwhm = shapeFct.widthToFWHM(width); | ||
} | ||
} | ||
} | ||
return peaks; | ||
} | ||
function mapPeaks(peaks, factor) { | ||
return peaks.map((peak) => { | ||
const { id, shape } = peak; | ||
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor; | ||
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor; | ||
let result = { | ||
x: peak.x, | ||
y: peak.y, | ||
index: peak.index, | ||
width: xTo - xFrom, | ||
from: { x: xFrom }, | ||
to: { x: xTo }, | ||
}; | ||
if (id) { | ||
result = { ...result, id }; | ||
} | ||
if (shape) { | ||
result = { ...result, shape }; | ||
} | ||
return result; | ||
}); | ||
} | ||
//# sourceMappingURL=broadenPeaks.js.map |
import type { Shape1D } from 'ml-peak-shape-generator'; | ||
import { OptimizationOptions } from 'ml-spectra-fitting'; | ||
import { GSDPeak } from '../GSDPeak'; | ||
import { MakeOptional } from '../utils/MakeOptional'; | ||
import { GSDPeakOptimizedID } from './optimizePeaksWithLogs'; | ||
export interface JoinBroadPeaksOptions { | ||
@@ -27,6 +29,4 @@ /** | ||
*/ | ||
export interface GSDPeakWithOptionalShape extends Omit<GSDPeak, 'shape'> { | ||
shape?: Shape1D; | ||
} | ||
export declare function joinBroadPeaks(peakList: GSDPeakWithOptionalShape[], options?: JoinBroadPeaksOptions): GSDPeak[]; | ||
export declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
export declare function joinBroadPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: JoinBroadPeaksOptions): GSDPeakOptimizedID[]; | ||
//# sourceMappingURL=joinBroadPeaks.d.ts.map |
@@ -0,1 +1,3 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import { addMissingIDs } from '../utils/addMissingIDs'; | ||
import { addMissingShape } from '../utils/addMissingShape'; | ||
@@ -9,5 +11,5 @@ import { optimizePeaks } from './optimizePeaks'; | ||
const broadLines = []; | ||
const peaks = addMissingShape(peakList, { shape }); | ||
if (peaks.length < 2) | ||
return peaks; | ||
if (peakList.length < 2) { | ||
return addMissingIDs(addMissingShape(peakList.map(getGSDPeakOptimizedStructure), { shape })); | ||
} | ||
let maxDdy = peakList[0].ddY; | ||
@@ -18,6 +20,10 @@ for (let i = 1; i < peakList.length; i++) { | ||
} | ||
for (let i = peaks.length - 1; i >= 0; i--) { | ||
if (Math.abs(peaks[i].ddY) <= broadRatio * maxDdy) { | ||
broadLines.push(peaks.splice(i, 1)[0]); | ||
const newPeaks = []; | ||
for (const peak of peakList) { | ||
if (Math.abs(peak.ddY) <= broadRatio * maxDdy) { | ||
broadLines.push(peak); | ||
} | ||
else { | ||
newPeaks.push(getGSDPeakOptimizedStructure(peak)); | ||
} | ||
} | ||
@@ -46,2 +52,3 @@ //@ts-expect-error Push a feke peak | ||
{ | ||
id: generateID(), | ||
x: broadLines[maxI].x, | ||
@@ -52,11 +59,9 @@ y: max, | ||
], { shape, optimization }); | ||
//@ts-expect-error type is equal as expected | ||
peaks.push(fitted[0]); | ||
newPeaks.push(fitted[0]); | ||
} | ||
else { | ||
// Put back the candidates to the peak list | ||
indexes.forEach((index) => { | ||
// @ts-expect-error todo 2 | ||
peaks.push(broadLines[index]); | ||
}); | ||
for (const index of indexes) { | ||
newPeaks.push(getGSDPeakOptimizedStructure(broadLines[index])); | ||
} | ||
} | ||
@@ -70,7 +75,19 @@ candidates = { x: [broadLines[i].x], y: [broadLines[i].y] }; | ||
} | ||
peaks.sort((a, b) => { | ||
newPeaks.sort((a, b) => { | ||
return a.x - b.x; | ||
}); | ||
return peaks; | ||
return addMissingIDs(newPeaks, { output: newPeaks }); | ||
} | ||
function getGSDPeakOptimizedStructure(peak) { | ||
const { id, shape, x, y, width } = peak; | ||
let newPeak = { | ||
x, | ||
y, | ||
width, | ||
shape, | ||
}; | ||
if (id) | ||
newPeak.id = id; | ||
return newPeak; | ||
} | ||
//# sourceMappingURL=joinBroadPeaks.js.map |
@@ -1,6 +0,6 @@ | ||
import type { DataXY, PeakXYWidth } from 'cheminfo-types'; | ||
import type { DataXY } from 'cheminfo-types'; | ||
import { FromTo } from 'cheminfo-types'; | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
import type { OptimizationOptions } from 'ml-spectra-fitting'; | ||
import { GSDPeakOptimized } from '../GSDPeakOptimized'; | ||
import { Peak } from './optimizePeaksWithLogs'; | ||
export interface OptimizePeaksOptions { | ||
@@ -41,3 +41,5 @@ /** | ||
*/ | ||
export declare function optimizePeaks(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): GSDPeakOptimized[]; | ||
export declare function optimizePeaks<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): (T extends { | ||
id: string; | ||
} ? import("./optimizePeaksWithLogs").GSDPeakOptimizedID : import("..").GSDPeakOptimized)[]; | ||
//# sourceMappingURL=optimizePeaks.d.ts.map |
import type { DataXY, PeakXYWidth } from 'cheminfo-types'; | ||
import { GSDPeakOptimized } from '../GSDPeakOptimized'; | ||
import { MakeMandatory } from '../utils/MakeMandatory'; | ||
import { OptimizePeaksOptions } from './optimizePeaks'; | ||
export interface Peak extends PeakXYWidth { | ||
id?: string; | ||
} | ||
export declare type GSDPeakOptimizedID = MakeMandatory<GSDPeakOptimized, 'id'>; | ||
declare type GSDPeakOptimizedIDOrNot<T extends Peak> = T extends { | ||
id: string; | ||
} ? GSDPeakOptimizedID : GSDPeakOptimized; | ||
/** | ||
@@ -10,6 +18,7 @@ * Optimize the position (x), max intensity (y), full width at half maximum (fwhm) | ||
*/ | ||
export declare function optimizePeaksWithLogs(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): { | ||
export declare function optimizePeaksWithLogs<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): { | ||
logs: any[]; | ||
optimizedPeaks: GSDPeakOptimized[]; | ||
optimizedPeaks: GSDPeakOptimizedIDOrNot<T>[]; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=optimizePeaksWithLogs.d.ts.map |
@@ -67,3 +67,3 @@ import { getShape1D } from 'ml-peak-shape-generator'; | ||
else { | ||
results = results.concat(peaks); | ||
results.push(...peaks); | ||
logs.push({ | ||
@@ -70,0 +70,0 @@ ...log, |
@@ -8,5 +8,5 @@ import { Shape1D } from 'ml-peak-shape-generator'; | ||
width: number; | ||
shape?: Shape1D; | ||
}>(peaks: T[], options?: { | ||
shape?: Shape1D; | ||
output?: T[]; | ||
}): (T & { | ||
@@ -13,0 +13,0 @@ shape: Shape1D; |
import { getShape1D } from 'ml-peak-shape-generator'; | ||
const { parse, stringify } = JSON; | ||
/** | ||
@@ -7,5 +8,5 @@ * add missing property if it does not exist in the peak, | ||
export function addMissingShape(peaks, options = {}) { | ||
const { shape = { kind: 'gaussian' } } = options; | ||
const { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)) } = options; | ||
let shapeInstance = getShape1D(shape); | ||
return peaks.map((peak) => { | ||
return output.map((peak) => { | ||
if (hasShape(peak)) { | ||
@@ -12,0 +13,0 @@ if (!('fwhm' in peak.shape)) { |
@@ -13,16 +13,6 @@ import { Shape1D } from 'ml-peak-shape-generator'; | ||
shape?: Shape1D; | ||
output?: T[]; | ||
}): (T & { | ||
shape: { | ||
kind: "gaussian"; | ||
fwhm: number; | ||
sd?: number | undefined; | ||
} | { | ||
kind: "lorentzian"; | ||
fwhm: number; | ||
} | { | ||
kind: "pseudoVoigt"; | ||
fwhm: number; | ||
mu?: number | undefined; | ||
}; | ||
shape: Shape1D; | ||
})[]; | ||
//# sourceMappingURL=setShape.d.ts.map |
import { getShape1D } from 'ml-peak-shape-generator'; | ||
const { parse, stringify } = JSON; | ||
/** | ||
@@ -6,5 +7,5 @@ * Append 2 properties to the peaks, shape and fwhm | ||
export function setShape(peaks, options = {}) { | ||
let { shape = { kind: 'gaussian' } } = options; | ||
let { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)), } = options; | ||
let shapeInstance = getShape1D(shape); | ||
return peaks.map((peak) => ({ | ||
return output.map((peak) => ({ | ||
...peak, | ||
@@ -11,0 +12,0 @@ shape: { fwhm: shapeInstance.widthToFWHM(peak.width), ...shape }, |
@@ -5,2 +5,4 @@ import type { DataXY } from 'cheminfo-types'; | ||
import { GSDPeak } from './GSDPeak'; | ||
import { MakeMandatory } from './utils/MakeMandatory'; | ||
import { MakeOptional } from './utils/MakeOptional'; | ||
export interface GSDOptions { | ||
@@ -45,2 +47,4 @@ /** | ||
} | ||
export declare type GSDPeakID = MakeMandatory<GSDPeak, 'id'>; | ||
export declare type GSDPeakIDOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
/** | ||
@@ -53,3 +57,3 @@ * Global spectra deconvolution | ||
*/ | ||
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeak[]; | ||
export declare function gsd(data: DataXY, options?: GSDOptions): GSDPeakID[]; | ||
//# sourceMappingURL=gsd.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.gsd = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const ml_savitzky_golay_generalized_1 = require("ml-savitzky-golay-generalized"); | ||
@@ -167,2 +168,3 @@ const ml_spectra_processing_1 = require("ml-spectra-processing"); | ||
peaks.push({ | ||
id: (0, uuid_1.v4)(), | ||
x: deltaX, | ||
@@ -169,0 +171,0 @@ y: yData[minddYIndex], |
@@ -0,5 +1,8 @@ | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDBroadenPeak { | ||
id?: string; | ||
x: number; | ||
y: number; | ||
width: number; | ||
shape?: Shape1D; | ||
index: number; | ||
@@ -6,0 +9,0 @@ from: { |
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDPeak { | ||
id?: string; | ||
x: number; | ||
@@ -4,0 +5,0 @@ y: number; |
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDPeakOptimized { | ||
id?: string; | ||
x: number; | ||
@@ -4,0 +5,0 @@ y: number; |
@@ -0,3 +1,19 @@ | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
import { GSDBroadenPeak } from '../GSDBroadenPeak'; | ||
import { GSDPeak } from '../GSDPeak'; | ||
import { MakeOptional } from '../utils/MakeOptional'; | ||
declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
declare type GSDBroadenPeakWithID = GSDBroadenPeak & { | ||
id: string; | ||
}; | ||
declare type GSDBroadenPeakWithShape = GSDBroadenPeak & { | ||
shape: Shape1D; | ||
}; | ||
declare type GSDBroadenPeakWithShapeID = GSDBroadenPeakWithID & { | ||
shape: Shape1D; | ||
}; | ||
export declare type WithOrWithout<T, ToExtends, TrueType, FalseType> = T extends ToExtends ? TrueType : FalseType; | ||
export declare type WithIDOrShape<T> = T extends { | ||
id: string; | ||
} ? WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShapeID, GSDBroadenPeakWithID> : WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShape, GSDBroadenPeak>; | ||
/** | ||
@@ -10,3 +26,3 @@ * This method will allow to enlarge peaks while preventing overlap between peaks | ||
*/ | ||
export declare function broadenPeaks(peakList: Omit<GSDPeak, 'shape'>[], options?: { | ||
export declare function broadenPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: { | ||
/** | ||
@@ -21,3 +37,4 @@ * @default 2 | ||
overlap?: boolean; | ||
}): GSDBroadenPeak[]; | ||
}): WithIDOrShape<T>[]; | ||
export {}; | ||
//# sourceMappingURL=broadenPeaks.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.broadenPeaks = void 0; | ||
const ml_peak_shape_generator_1 = require("ml-peak-shape-generator"); | ||
/** | ||
@@ -13,14 +14,3 @@ * This method will allow to enlarge peaks while preventing overlap between peaks | ||
const { factor = 2, overlap = false } = options; | ||
const peaks = peakList.map((peak) => { | ||
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor; | ||
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor; | ||
return { | ||
x: peak.x, | ||
y: peak.y, | ||
index: peak.index, | ||
width: xTo - xFrom, | ||
from: { x: xFrom }, | ||
to: { x: xTo }, | ||
}; | ||
}); | ||
const peaks = mapPeaks(peakList, factor); | ||
if (!overlap) { | ||
@@ -38,4 +28,11 @@ for (let i = 0; i < peaks.length - 1; i++) { | ||
} | ||
for (let peak of peaks) { | ||
for (const peak of peaks) { | ||
peak.width = peak.to.x - peak.from.x; | ||
if (peak.shape) { | ||
const { shape, width } = peak; | ||
if (shape.fwhm !== undefined) { | ||
const shapeFct = (0, ml_peak_shape_generator_1.getShape1D)(shape); | ||
peak.shape.fwhm = shapeFct.widthToFWHM(width); | ||
} | ||
} | ||
} | ||
@@ -45,2 +42,24 @@ return peaks; | ||
exports.broadenPeaks = broadenPeaks; | ||
function mapPeaks(peaks, factor) { | ||
return peaks.map((peak) => { | ||
const { id, shape } = peak; | ||
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor; | ||
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor; | ||
let result = { | ||
x: peak.x, | ||
y: peak.y, | ||
index: peak.index, | ||
width: xTo - xFrom, | ||
from: { x: xFrom }, | ||
to: { x: xTo }, | ||
}; | ||
if (id) { | ||
result = { ...result, id }; | ||
} | ||
if (shape) { | ||
result = { ...result, shape }; | ||
} | ||
return result; | ||
}); | ||
} | ||
//# sourceMappingURL=broadenPeaks.js.map |
import type { Shape1D } from 'ml-peak-shape-generator'; | ||
import { OptimizationOptions } from 'ml-spectra-fitting'; | ||
import { GSDPeak } from '../GSDPeak'; | ||
import { MakeOptional } from '../utils/MakeOptional'; | ||
import { GSDPeakOptimizedID } from './optimizePeaksWithLogs'; | ||
export interface JoinBroadPeaksOptions { | ||
@@ -27,6 +29,4 @@ /** | ||
*/ | ||
export interface GSDPeakWithOptionalShape extends Omit<GSDPeak, 'shape'> { | ||
shape?: Shape1D; | ||
} | ||
export declare function joinBroadPeaks(peakList: GSDPeakWithOptionalShape[], options?: JoinBroadPeaksOptions): GSDPeak[]; | ||
export declare type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
export declare function joinBroadPeaks<T extends GSDPeakOptionalShape>(peakList: T[], options?: JoinBroadPeaksOptions): GSDPeakOptimizedID[]; | ||
//# sourceMappingURL=joinBroadPeaks.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.joinBroadPeaks = void 0; | ||
const uuid_1 = require("@lukeed/uuid"); | ||
const addMissingIDs_1 = require("../utils/addMissingIDs"); | ||
const addMissingShape_1 = require("../utils/addMissingShape"); | ||
@@ -12,5 +14,5 @@ const optimizePeaks_1 = require("./optimizePeaks"); | ||
const broadLines = []; | ||
const peaks = (0, addMissingShape_1.addMissingShape)(peakList, { shape }); | ||
if (peaks.length < 2) | ||
return peaks; | ||
if (peakList.length < 2) { | ||
return (0, addMissingIDs_1.addMissingIDs)((0, addMissingShape_1.addMissingShape)(peakList.map(getGSDPeakOptimizedStructure), { shape })); | ||
} | ||
let maxDdy = peakList[0].ddY; | ||
@@ -21,6 +23,10 @@ for (let i = 1; i < peakList.length; i++) { | ||
} | ||
for (let i = peaks.length - 1; i >= 0; i--) { | ||
if (Math.abs(peaks[i].ddY) <= broadRatio * maxDdy) { | ||
broadLines.push(peaks.splice(i, 1)[0]); | ||
const newPeaks = []; | ||
for (const peak of peakList) { | ||
if (Math.abs(peak.ddY) <= broadRatio * maxDdy) { | ||
broadLines.push(peak); | ||
} | ||
else { | ||
newPeaks.push(getGSDPeakOptimizedStructure(peak)); | ||
} | ||
} | ||
@@ -49,2 +55,3 @@ //@ts-expect-error Push a feke peak | ||
{ | ||
id: (0, uuid_1.v4)(), | ||
x: broadLines[maxI].x, | ||
@@ -55,11 +62,9 @@ y: max, | ||
], { shape, optimization }); | ||
//@ts-expect-error type is equal as expected | ||
peaks.push(fitted[0]); | ||
newPeaks.push(fitted[0]); | ||
} | ||
else { | ||
// Put back the candidates to the peak list | ||
indexes.forEach((index) => { | ||
// @ts-expect-error todo 2 | ||
peaks.push(broadLines[index]); | ||
}); | ||
for (const index of indexes) { | ||
newPeaks.push(getGSDPeakOptimizedStructure(broadLines[index])); | ||
} | ||
} | ||
@@ -73,8 +78,20 @@ candidates = { x: [broadLines[i].x], y: [broadLines[i].y] }; | ||
} | ||
peaks.sort((a, b) => { | ||
newPeaks.sort((a, b) => { | ||
return a.x - b.x; | ||
}); | ||
return peaks; | ||
return (0, addMissingIDs_1.addMissingIDs)(newPeaks, { output: newPeaks }); | ||
} | ||
exports.joinBroadPeaks = joinBroadPeaks; | ||
function getGSDPeakOptimizedStructure(peak) { | ||
const { id, shape, x, y, width } = peak; | ||
let newPeak = { | ||
x, | ||
y, | ||
width, | ||
shape, | ||
}; | ||
if (id) | ||
newPeak.id = id; | ||
return newPeak; | ||
} | ||
//# sourceMappingURL=joinBroadPeaks.js.map |
@@ -1,6 +0,6 @@ | ||
import type { DataXY, PeakXYWidth } from 'cheminfo-types'; | ||
import type { DataXY } from 'cheminfo-types'; | ||
import { FromTo } from 'cheminfo-types'; | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
import type { OptimizationOptions } from 'ml-spectra-fitting'; | ||
import { GSDPeakOptimized } from '../GSDPeakOptimized'; | ||
import { Peak } from './optimizePeaksWithLogs'; | ||
export interface OptimizePeaksOptions { | ||
@@ -41,3 +41,5 @@ /** | ||
*/ | ||
export declare function optimizePeaks(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): GSDPeakOptimized[]; | ||
export declare function optimizePeaks<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): (T extends { | ||
id: string; | ||
} ? import("./optimizePeaksWithLogs").GSDPeakOptimizedID : import("..").GSDPeakOptimized)[]; | ||
//# sourceMappingURL=optimizePeaks.d.ts.map |
import type { DataXY, PeakXYWidth } from 'cheminfo-types'; | ||
import { GSDPeakOptimized } from '../GSDPeakOptimized'; | ||
import { MakeMandatory } from '../utils/MakeMandatory'; | ||
import { OptimizePeaksOptions } from './optimizePeaks'; | ||
export interface Peak extends PeakXYWidth { | ||
id?: string; | ||
} | ||
export declare type GSDPeakOptimizedID = MakeMandatory<GSDPeakOptimized, 'id'>; | ||
declare type GSDPeakOptimizedIDOrNot<T extends Peak> = T extends { | ||
id: string; | ||
} ? GSDPeakOptimizedID : GSDPeakOptimized; | ||
/** | ||
@@ -10,6 +18,7 @@ * Optimize the position (x), max intensity (y), full width at half maximum (fwhm) | ||
*/ | ||
export declare function optimizePeaksWithLogs(data: DataXY, peakList: PeakXYWidth[], options?: OptimizePeaksOptions): { | ||
export declare function optimizePeaksWithLogs<T extends Peak>(data: DataXY, peakList: T[], options?: OptimizePeaksOptions): { | ||
logs: any[]; | ||
optimizedPeaks: GSDPeakOptimized[]; | ||
optimizedPeaks: GSDPeakOptimizedIDOrNot<T>[]; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=optimizePeaksWithLogs.d.ts.map |
@@ -70,3 +70,3 @@ "use strict"; | ||
else { | ||
results = results.concat(peaks); | ||
results.push(...peaks); | ||
logs.push({ | ||
@@ -73,0 +73,0 @@ ...log, |
@@ -8,5 +8,5 @@ import { Shape1D } from 'ml-peak-shape-generator'; | ||
width: number; | ||
shape?: Shape1D; | ||
}>(peaks: T[], options?: { | ||
shape?: Shape1D; | ||
output?: T[]; | ||
}): (T & { | ||
@@ -13,0 +13,0 @@ shape: Shape1D; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const ml_peak_shape_generator_1 = require("ml-peak-shape-generator"); | ||
const { parse, stringify } = JSON; | ||
/** | ||
@@ -11,5 +12,5 @@ * add missing property if it does not exist in the peak, | ||
function addMissingShape(peaks, options = {}) { | ||
const { shape = { kind: 'gaussian' } } = options; | ||
const { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)) } = options; | ||
let shapeInstance = (0, ml_peak_shape_generator_1.getShape1D)(shape); | ||
return peaks.map((peak) => { | ||
return output.map((peak) => { | ||
if (hasShape(peak)) { | ||
@@ -16,0 +17,0 @@ if (!('fwhm' in peak.shape)) { |
@@ -13,16 +13,6 @@ import { Shape1D } from 'ml-peak-shape-generator'; | ||
shape?: Shape1D; | ||
output?: T[]; | ||
}): (T & { | ||
shape: { | ||
kind: "gaussian"; | ||
fwhm: number; | ||
sd?: number | undefined; | ||
} | { | ||
kind: "lorentzian"; | ||
fwhm: number; | ||
} | { | ||
kind: "pseudoVoigt"; | ||
fwhm: number; | ||
mu?: number | undefined; | ||
}; | ||
shape: Shape1D; | ||
})[]; | ||
//# sourceMappingURL=setShape.d.ts.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
const ml_peak_shape_generator_1 = require("ml-peak-shape-generator"); | ||
const { parse, stringify } = JSON; | ||
/** | ||
@@ -10,5 +11,5 @@ * Append 2 properties to the peaks, shape and fwhm | ||
function setShape(peaks, options = {}) { | ||
let { shape = { kind: 'gaussian' } } = options; | ||
let { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)), } = options; | ||
let shapeInstance = (0, ml_peak_shape_generator_1.getShape1D)(shape); | ||
return peaks.map((peak) => ({ | ||
return output.map((peak) => ({ | ||
...peak, | ||
@@ -15,0 +16,0 @@ shape: { fwhm: shapeInstance.widthToFWHM(peak.width), ...shape }, |
{ | ||
"name": "ml-gsd", | ||
"version": "12.0.0-pre.1661396593", | ||
"version": "12.0.0-pre.1661543950", | ||
"description": "Global Spectra Deconvolution", | ||
@@ -82,8 +82,9 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@lukeed/uuid": "^2.0.0", | ||
"cheminfo-types": "^1.1.0", | ||
"ml-peak-shape-generator": "^4.1.1", | ||
"ml-savitzky-golay-generalized": "^4.0.1", | ||
"ml-spectra-fitting": "^4.1.0", | ||
"ml-spectra-fitting": "^4.1.1", | ||
"ml-spectra-processing": "^11.6.0" | ||
} | ||
} |
@@ -36,2 +36,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
{ | ||
id: peakList[0].id, | ||
x: -0.5, | ||
@@ -52,2 +53,3 @@ y: 0.6945098953985852, | ||
{ | ||
id: peakList[1].id, | ||
x: 0.5, | ||
@@ -54,0 +56,0 @@ y: 0.6945098953985852, |
@@ -66,3 +66,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
]; | ||
expect(peakList).toBeDeepCloseTo(expected); | ||
expect(peakList).toBeDeepCloseTo(addMissingID(peakList, expected)); | ||
}); | ||
@@ -105,3 +105,3 @@ | ||
]; | ||
expect(peakList).toBeDeepCloseTo(expected); | ||
expect(peakList).toBeDeepCloseTo(addMissingID(peakList, expected)); | ||
}); | ||
@@ -148,3 +148,3 @@ | ||
expect(peakList).toBeDeepCloseTo(expected); | ||
expect(peakList).toBeDeepCloseTo(addMissingID(peakList, expected)); | ||
}); | ||
@@ -191,3 +191,3 @@ | ||
expect(peakList).toBeDeepCloseTo(expected); | ||
expect(peakList).toBeDeepCloseTo(addMissingID(peakList, expected)); | ||
}); | ||
@@ -203,1 +203,8 @@ | ||
}); | ||
function addMissingID(peaks, expected) { | ||
for (let i = 0; i < expected.length; i++) { | ||
expected[i].id = peaks[i].id; | ||
} | ||
return expected; | ||
} |
@@ -54,2 +54,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
{ | ||
id: peakList[0].id, | ||
x: 5, | ||
@@ -81,2 +82,3 @@ y: 10000, | ||
{ | ||
id: peakList[0].id, | ||
x: 4.45, | ||
@@ -97,2 +99,3 @@ y: 7921, | ||
{ | ||
id: peakList[1].id, | ||
x: 5, | ||
@@ -113,2 +116,3 @@ y: 10000, | ||
{ | ||
id: peakList[2].id, | ||
x: 5.55, | ||
@@ -115,0 +119,0 @@ y: 7921, |
@@ -25,3 +25,5 @@ import { readFileSync } from 'fs'; | ||
}); | ||
expect(peaks[0]).toBeDeepCloseTo({ | ||
id: peaks[0].id, | ||
x: 200.05527917306466, | ||
@@ -28,0 +30,0 @@ y: 28.795378784444413, |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import type { DataXY } from 'cheminfo-types'; | ||
@@ -13,2 +14,4 @@ import { Shape1D } from 'ml-peak-shape-generator'; | ||
import { GSDPeak } from './GSDPeak'; | ||
import { MakeMandatory } from './utils/MakeMandatory'; | ||
import { MakeOptional } from './utils/MakeOptional'; | ||
import { optimizeTop } from './utils/optimizeTop'; | ||
@@ -56,3 +59,4 @@ import { setShape } from './utils/setShape'; | ||
} | ||
export type GSDPeakID = MakeMandatory<GSDPeak, 'id'>; | ||
export type GSDPeakIDOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
/** | ||
@@ -66,3 +70,3 @@ * Global spectra deconvolution | ||
export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeak[] { | ||
export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] { | ||
let { | ||
@@ -223,3 +227,3 @@ sgOptions = { | ||
const peaks: GSDPeak[] = []; | ||
const peaks: GSDPeakIDOptionalShape[] = []; | ||
for (const minddYIndex of minddY) { | ||
@@ -252,2 +256,3 @@ let deltaX = x[minddYIndex]; | ||
peaks.push({ | ||
id: generateID(), | ||
x: deltaX, | ||
@@ -262,3 +267,3 @@ y: yData[minddYIndex], | ||
}, | ||
} as GSDPeak); | ||
}); | ||
} | ||
@@ -283,3 +288,3 @@ } | ||
return setShape(peaks, { shape }); | ||
return setShape(peaks, { shape }) as GSDPeakID[]; | ||
} |
@@ -0,5 +1,9 @@ | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDBroadenPeak { | ||
id?: string; | ||
x: number; | ||
y: number; | ||
width: number; | ||
shape?: Shape1D; | ||
index: number; | ||
@@ -6,0 +10,0 @@ from: { x: number }; |
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDPeak { | ||
id?: string; | ||
x: number; | ||
@@ -5,0 +6,0 @@ y: number; |
import { Shape1D } from 'ml-peak-shape-generator'; | ||
export interface GSDPeakOptimized { | ||
id?: string; | ||
x: number; | ||
@@ -5,0 +6,0 @@ y: number; |
@@ -303,2 +303,3 @@ import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to'; | ||
{ | ||
id: '1', | ||
x: -0.5, | ||
@@ -331,2 +332,3 @@ y: 1, | ||
index: 575, | ||
shape: { kind: 'gaussian' }, | ||
inflectionPoints: { | ||
@@ -340,29 +342,34 @@ from: { index: 573, x: 10.46 }, | ||
); | ||
expect(result).toBeDeepCloseTo([ | ||
{ | ||
x: -0.5, | ||
y: 1, | ||
index: 25, | ||
width: 1.3, | ||
from: { x: -1.3 }, | ||
to: { x: 0 }, | ||
}, | ||
{ | ||
x: 0.5, | ||
y: 1, | ||
index: 75, | ||
width: 1.3, | ||
from: { x: 0 }, | ||
to: { x: 1.3 }, | ||
}, | ||
{ | ||
x: 10.5, | ||
y: 1, | ||
index: 575, | ||
width: 1.6, | ||
from: { x: 9.7 }, | ||
to: { x: 11.3 }, | ||
}, | ||
]); | ||
expect(result).toBeDeepCloseTo( | ||
[ | ||
{ | ||
id: '1', | ||
x: -0.5, | ||
y: 1, | ||
index: 25, | ||
width: 1.3, | ||
from: { x: -1.3 }, | ||
to: { x: 0 }, | ||
}, | ||
{ | ||
x: 0.5, | ||
y: 1, | ||
index: 75, | ||
width: 1.3, | ||
from: { x: 0 }, | ||
to: { x: 1.3 }, | ||
}, | ||
{ | ||
x: 10.5, | ||
y: 1, | ||
index: 575, | ||
shape: { kind: 'gaussian' }, | ||
width: 1.6, | ||
from: { x: 9.7 }, | ||
to: { x: 11.3 }, | ||
}, | ||
], | ||
1, | ||
); | ||
}); | ||
}); |
@@ -29,3 +29,2 @@ import { generateSpectrum } from 'spectrum-generator'; | ||
}); | ||
expect(peaks.length).toBeGreaterThan(3); | ||
@@ -32,0 +31,0 @@ expect(newPeaks).toHaveLength(3); |
@@ -0,4 +1,20 @@ | ||
import { getShape1D, Shape1D } from 'ml-peak-shape-generator'; | ||
import { GSDBroadenPeak } from '../GSDBroadenPeak'; | ||
import { GSDPeak } from '../GSDPeak'; | ||
import { MakeOptional } from '../utils/MakeOptional'; | ||
type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
type GSDBroadenPeakWithID = GSDBroadenPeak & { id: string }; | ||
type GSDBroadenPeakWithShape = GSDBroadenPeak & { shape: Shape1D }; | ||
type GSDBroadenPeakWithShapeID = GSDBroadenPeakWithID & { shape: Shape1D }; | ||
export type WithOrWithout<T, ToExtends, TrueType, FalseType> = | ||
T extends ToExtends ? TrueType : FalseType; | ||
export type WithIDOrShape<T> = T extends { id: string } | ||
? WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShapeID, GSDBroadenPeakWithID> | ||
: WithOrWithout<T, GSDPeak, GSDBroadenPeakWithShape, GSDBroadenPeak>; | ||
/** | ||
@@ -12,4 +28,4 @@ * This method will allow to enlarge peaks while preventing overlap between peaks | ||
export function broadenPeaks( | ||
peakList: Omit<GSDPeak, 'shape'>[], | ||
export function broadenPeaks<T extends GSDPeakOptionalShape>( | ||
peakList: T[], | ||
options: { | ||
@@ -26,17 +42,6 @@ /** | ||
} = {}, | ||
): GSDBroadenPeak[] { | ||
) { | ||
const { factor = 2, overlap = false } = options; | ||
const peaks = peakList.map((peak) => { | ||
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor; | ||
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor; | ||
return { | ||
x: peak.x, | ||
y: peak.y, | ||
index: peak.index, | ||
width: xTo - xFrom, | ||
from: { x: xFrom }, | ||
to: { x: xTo }, | ||
}; | ||
}); | ||
const peaks = mapPeaks(peakList, factor); | ||
@@ -56,4 +61,11 @@ if (!overlap) { | ||
for (let peak of peaks) { | ||
for (const peak of peaks) { | ||
peak.width = peak.to.x - peak.from.x; | ||
if (peak.shape) { | ||
const { shape, width } = peak; | ||
if (shape.fwhm !== undefined) { | ||
const shapeFct = getShape1D(shape); | ||
peak.shape.fwhm = shapeFct.widthToFWHM(width); | ||
} | ||
} | ||
} | ||
@@ -63,1 +75,33 @@ | ||
} | ||
function mapPeaks<T extends GSDPeakOptionalShape>( | ||
peaks: T[], | ||
factor: number, | ||
): WithIDOrShape<T>[] { | ||
return peaks.map((peak) => { | ||
const { id, shape } = peak; | ||
const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor; | ||
const xTo = peak.x + (peak.inflectionPoints.to.x - peak.x) * factor; | ||
let result = { | ||
x: peak.x, | ||
y: peak.y, | ||
index: peak.index, | ||
width: xTo - xFrom, | ||
from: { x: xFrom }, | ||
to: { x: xTo }, | ||
} as GSDBroadenPeak; | ||
if (id) { | ||
result = { ...result, id } as GSDBroadenPeakWithID; | ||
} | ||
if (shape) { | ||
result = { ...result, shape } as T extends { id: string } | ||
? GSDBroadenPeakWithShapeID | ||
: GSDBroadenPeakWithShape; | ||
} | ||
return result as WithIDOrShape<T>; | ||
}); | ||
} |
@@ -0,1 +1,2 @@ | ||
import { v4 as generateID } from '@lukeed/uuid'; | ||
import type { Shape1D } from 'ml-peak-shape-generator'; | ||
@@ -6,5 +7,8 @@ import { OptimizationOptions } from 'ml-spectra-fitting'; | ||
import { GSDPeakOptimized } from '../GSDPeakOptimized'; | ||
import { MakeOptional } from '../utils/MakeOptional'; | ||
import { addMissingIDs } from '../utils/addMissingIDs'; | ||
import { addMissingShape } from '../utils/addMissingShape'; | ||
import { optimizePeaks } from './optimizePeaks'; | ||
import { GSDPeakOptimizedID } from './optimizePeaksWithLogs'; | ||
@@ -36,9 +40,8 @@ export interface JoinBroadPeaksOptions { | ||
export interface GSDPeakWithOptionalShape extends Omit<GSDPeak, 'shape'> { | ||
shape?: Shape1D; | ||
} | ||
export function joinBroadPeaks( | ||
peakList: GSDPeakWithOptionalShape[], | ||
export type GSDPeakOptionalShape = MakeOptional<GSDPeak, 'shape'>; | ||
export function joinBroadPeaks<T extends GSDPeakOptionalShape>( | ||
peakList: T[], | ||
options: JoinBroadPeaksOptions = {}, | ||
): GSDPeak[] { | ||
): GSDPeakOptimizedID[] { | ||
let { | ||
@@ -54,6 +57,9 @@ shape = { kind: 'gaussian' }, | ||
let count = 1; | ||
const broadLines: GSDPeakOptimized[] = []; | ||
const peaks = addMissingShape(peakList, { shape }); | ||
const broadLines: T[] = []; | ||
if (peaks.length < 2) return peaks; | ||
if (peakList.length < 2) { | ||
return addMissingIDs( | ||
addMissingShape(peakList.map(getGSDPeakOptimizedStructure), { shape }), | ||
); | ||
} | ||
@@ -65,5 +71,8 @@ let maxDdy = peakList[0].ddY; | ||
for (let i: number = peaks.length - 1; i >= 0; i--) { | ||
if (Math.abs(peaks[i].ddY) <= broadRatio * maxDdy) { | ||
broadLines.push(peaks.splice(i, 1)[0]); | ||
const newPeaks: GSDPeakOptimized[] = []; | ||
for (const peak of peakList) { | ||
if (Math.abs(peak.ddY) <= broadRatio * maxDdy) { | ||
broadLines.push(peak); | ||
} else { | ||
newPeaks.push(getGSDPeakOptimizedStructure(peak)); | ||
} | ||
@@ -96,2 +105,3 @@ } | ||
{ | ||
id: generateID(), | ||
x: broadLines[maxI].x, | ||
@@ -104,10 +114,8 @@ y: max, | ||
); | ||
//@ts-expect-error type is equal as expected | ||
peaks.push(fitted[0]); | ||
newPeaks.push(fitted[0]); | ||
} else { | ||
// Put back the candidates to the peak list | ||
indexes.forEach((index) => { | ||
// @ts-expect-error todo 2 | ||
peaks.push(broadLines[index]); | ||
}); | ||
for (const index of indexes) { | ||
newPeaks.push(getGSDPeakOptimizedStructure(broadLines[index])); | ||
} | ||
} | ||
@@ -122,7 +130,22 @@ | ||
} | ||
peaks.sort((a, b) => { | ||
newPeaks.sort((a, b) => { | ||
return a.x - b.x; | ||
}); | ||
return peaks; | ||
return addMissingIDs(newPeaks, { output: newPeaks }); | ||
} | ||
function getGSDPeakOptimizedStructure<T extends GSDPeakOptionalShape>(peak: T) { | ||
const { id, shape, x, y, width } = peak; | ||
let newPeak = { | ||
x, | ||
y, | ||
width, | ||
shape, | ||
} as GSDPeakOptimized; | ||
if (id) newPeak.id = id; | ||
return newPeak; | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { DataXY, PeakXYWidth } from 'cheminfo-types'; | ||
import type { DataXY } from 'cheminfo-types'; | ||
import { FromTo } from 'cheminfo-types'; | ||
@@ -6,6 +6,4 @@ import { Shape1D } from 'ml-peak-shape-generator'; | ||
import { GSDPeakOptimized } from '../GSDPeakOptimized'; | ||
import { Peak, optimizePeaksWithLogs } from './optimizePeaksWithLogs'; | ||
import { optimizePeaksWithLogs } from './optimizePeaksWithLogs'; | ||
export interface OptimizePeaksOptions { | ||
@@ -47,8 +45,8 @@ /** | ||
*/ | ||
export function optimizePeaks( | ||
export function optimizePeaks<T extends Peak>( | ||
data: DataXY, | ||
peakList: PeakXYWidth[], | ||
peakList: T[], | ||
options: OptimizePeaksOptions = {}, | ||
): GSDPeakOptimized[] { | ||
) { | ||
return optimizePeaksWithLogs(data, peakList, options).optimizedPeaks; | ||
} |
@@ -7,2 +7,3 @@ import type { DataXY, PeakXYWidth } from 'cheminfo-types'; | ||
import { GSDPeakOptimized } from '../GSDPeakOptimized'; | ||
import { MakeMandatory } from '../utils/MakeMandatory'; | ||
import { addMissingShape } from '../utils/addMissingShape'; | ||
@@ -13,2 +14,14 @@ import { groupPeaks } from '../utils/groupPeaks'; | ||
export interface Peak extends PeakXYWidth { | ||
id?: string; | ||
} | ||
export type GSDPeakOptimizedID = MakeMandatory<GSDPeakOptimized, 'id'>; | ||
type GSDPeakOptimizedIDOrNot<T extends Peak> = T extends { | ||
id: string; | ||
} | ||
? GSDPeakOptimizedID | ||
: GSDPeakOptimized; | ||
/** | ||
@@ -20,7 +33,7 @@ * Optimize the position (x), max intensity (y), full width at half maximum (fwhm) | ||
*/ | ||
export function optimizePeaksWithLogs( | ||
export function optimizePeaksWithLogs<T extends Peak>( | ||
data: DataXY, | ||
peakList: PeakXYWidth[], | ||
peakList: T[], | ||
options: OptimizePeaksOptions = {}, | ||
): { logs: any[]; optimizedPeaks: GSDPeakOptimized[] } { | ||
): { logs: any[]; optimizedPeaks: GSDPeakOptimizedIDOrNot<T>[] } { | ||
const { | ||
@@ -47,3 +60,3 @@ fromTo = {}, | ||
let logs: any[] = []; | ||
let results: GSDPeakOptimized[] = []; | ||
let results: GSDPeakOptimizedIDOrNot<T>[] = []; | ||
groups.forEach((peakGroup) => { | ||
@@ -97,3 +110,3 @@ const start = Date.now(); | ||
), | ||
}); | ||
} as GSDPeakOptimizedIDOrNot<T>); | ||
} | ||
@@ -107,3 +120,3 @@ logs.push({ | ||
} else { | ||
results = results.concat(peaks); | ||
results.push(...(peaks as GSDPeakOptimizedIDOrNot<T>[])); | ||
logs.push({ | ||
@@ -110,0 +123,0 @@ ...log, |
import { getShape1D, Shape1D } from 'ml-peak-shape-generator'; | ||
const { parse, stringify } = JSON; | ||
/** | ||
@@ -8,9 +9,10 @@ * add missing property if it does not exist in the peak, | ||
export function addMissingShape<T extends { width: number; shape?: Shape1D }>( | ||
export function addMissingShape<T extends { width: number }>( | ||
peaks: T[], | ||
options: { shape?: Shape1D } = {}, | ||
options: { shape?: Shape1D; output?: T[] } = {}, | ||
): (T & { shape: Shape1D })[] { | ||
const { shape = { kind: 'gaussian' } } = options; | ||
const { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)) } = | ||
options; | ||
let shapeInstance = getShape1D(shape); | ||
return peaks.map((peak) => { | ||
return output.map((peak) => { | ||
if (hasShape(peak)) { | ||
@@ -17,0 +19,0 @@ if (!('fwhm' in peak.shape)) { |
import { getShape1D, Shape1D } from 'ml-peak-shape-generator'; | ||
const { parse, stringify } = JSON; | ||
/** | ||
@@ -15,7 +17,12 @@ * Append 2 properties to the peaks, shape and fwhm | ||
shape?: Shape1D; | ||
output?: T[]; | ||
} = {}, | ||
) { | ||
let { shape = { kind: 'gaussian' } } = options; | ||
): (T & { shape: Shape1D })[] { | ||
let { | ||
shape = { kind: 'gaussian' }, | ||
output = parse(stringify(peaks)) as T[], | ||
} = options; | ||
let shapeInstance = getShape1D(shape); | ||
return peaks.map((peak) => ({ | ||
return output.map((peak) => ({ | ||
...peak, | ||
@@ -22,0 +29,0 @@ shape: { fwhm: shapeInstance.widthToFWHM(peak.width), ...shape }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2651463
167
10728
6
+ Added@lukeed/uuid@^2.0.0
+ Added@lukeed/csprng@1.1.0(transitive)
+ Added@lukeed/uuid@2.0.1(transitive)
Updatedml-spectra-fitting@^4.1.1