ml-spectra-fitting
Advanced tools
Comparing version 4.1.0 to 4.1.1
@@ -16,2 +16,3 @@ import { DataXY, DoubleArray } from 'cheminfo-types'; | ||
export interface Peak { | ||
id?: string; | ||
x: number; | ||
@@ -32,2 +33,7 @@ y: number; | ||
} | ||
declare type OptimizedPeakIDOrNot<T extends Peak> = T extends { | ||
id: string; | ||
} ? OptimizedPeak & { | ||
id: string; | ||
} : OptimizedPeak; | ||
declare type OptimizationParameter = number | ((peak: Peak) => number); | ||
@@ -86,5 +92,5 @@ export interface OptimizationOptions { | ||
*/ | ||
export declare function optimize(data: DataXY<DoubleArray>, peaks: Peak[], options?: OptimizeOptions): { | ||
export declare function optimize<T extends Peak>(data: DataXY<DoubleArray>, peaks: T[], options?: OptimizeOptions): { | ||
error: number; | ||
peaks: OptimizedPeak[]; | ||
peaks: OptimizedPeakIDOrNot<T>[]; | ||
iterations: number; | ||
@@ -91,0 +97,0 @@ }; |
@@ -51,12 +51,12 @@ import { xMinMaxValues } from 'ml-spectra-processing'; | ||
for (let peak of internalPeaks) { | ||
const newPeak = { | ||
x: 0, | ||
y: 0, | ||
shape: peak.shape, | ||
}; | ||
newPeak.x = fittedValues[peak.fromIndex]; | ||
newPeak.y = fittedValues[peak.fromIndex + 1] * minMaxY.range + shiftValue; | ||
for (let i = 2; i < peak.parameters.length; i++) { | ||
const { id, shape, parameters, fromIndex } = peak; | ||
let newPeak = { x: 0, y: 0, shape }; | ||
if (id) { | ||
newPeak = { ...newPeak, id }; | ||
} | ||
newPeak.x = fittedValues[fromIndex]; | ||
newPeak.y = fittedValues[fromIndex + 1] * minMaxY.range + shiftValue; | ||
for (let i = 2; i < parameters.length; i++) { | ||
//@ts-expect-error should be fixed once | ||
newPeak.shape[peak.parameters[i]] = fittedValues[peak.fromIndex + i]; | ||
newPeak.shape[parameters[i]] = fittedValues[fromIndex + i]; | ||
} | ||
@@ -63,0 +63,0 @@ newPeaks.push(newPeak); |
@@ -6,2 +6,3 @@ import { Shape1D, Shape1DInstance } from 'ml-peak-shape-generator'; | ||
export interface InternalPeak { | ||
id?: string; | ||
shape: Shape1D; | ||
@@ -8,0 +9,0 @@ shapeFct: Shape1DInstance; |
@@ -22,9 +22,4 @@ import { getShape1D } from 'ml-peak-shape-generator'; | ||
for (const peak of normalizedPeaks) { | ||
const shape = peak.shape | ||
? peak.shape | ||
: options.shape | ||
? options.shape | ||
: { kind: 'gaussian' }; | ||
const { id, shape = options.shape ? options.shape : { kind: 'gaussian' } } = peak; | ||
const shapeFct = getShape1D(shape); | ||
//@ts-expect-error Should disappear with next release of peak-shape-generator | ||
const parameters = ['x', 'y', ...shapeFct.getParameters()]; | ||
@@ -72,2 +67,3 @@ const propertiesValues = { | ||
internalPeaks.push({ | ||
id, | ||
shape, | ||
@@ -74,0 +70,0 @@ shapeFct, |
@@ -16,2 +16,3 @@ import { DataXY, DoubleArray } from 'cheminfo-types'; | ||
export interface Peak { | ||
id?: string; | ||
x: number; | ||
@@ -32,2 +33,7 @@ y: number; | ||
} | ||
declare type OptimizedPeakIDOrNot<T extends Peak> = T extends { | ||
id: string; | ||
} ? OptimizedPeak & { | ||
id: string; | ||
} : OptimizedPeak; | ||
declare type OptimizationParameter = number | ((peak: Peak) => number); | ||
@@ -86,5 +92,5 @@ export interface OptimizationOptions { | ||
*/ | ||
export declare function optimize(data: DataXY<DoubleArray>, peaks: Peak[], options?: OptimizeOptions): { | ||
export declare function optimize<T extends Peak>(data: DataXY<DoubleArray>, peaks: T[], options?: OptimizeOptions): { | ||
error: number; | ||
peaks: OptimizedPeak[]; | ||
peaks: OptimizedPeakIDOrNot<T>[]; | ||
iterations: number; | ||
@@ -91,0 +97,0 @@ }; |
@@ -54,12 +54,12 @@ "use strict"; | ||
for (let peak of internalPeaks) { | ||
const newPeak = { | ||
x: 0, | ||
y: 0, | ||
shape: peak.shape, | ||
}; | ||
newPeak.x = fittedValues[peak.fromIndex]; | ||
newPeak.y = fittedValues[peak.fromIndex + 1] * minMaxY.range + shiftValue; | ||
for (let i = 2; i < peak.parameters.length; i++) { | ||
const { id, shape, parameters, fromIndex } = peak; | ||
let newPeak = { x: 0, y: 0, shape }; | ||
if (id) { | ||
newPeak = { ...newPeak, id }; | ||
} | ||
newPeak.x = fittedValues[fromIndex]; | ||
newPeak.y = fittedValues[fromIndex + 1] * minMaxY.range + shiftValue; | ||
for (let i = 2; i < parameters.length; i++) { | ||
//@ts-expect-error should be fixed once | ||
newPeak.shape[peak.parameters[i]] = fittedValues[peak.fromIndex + i]; | ||
newPeak.shape[parameters[i]] = fittedValues[fromIndex + i]; | ||
} | ||
@@ -66,0 +66,0 @@ newPeaks.push(newPeak); |
@@ -6,2 +6,3 @@ import { Shape1D, Shape1DInstance } from 'ml-peak-shape-generator'; | ||
export interface InternalPeak { | ||
id?: string; | ||
shape: Shape1D; | ||
@@ -8,0 +9,0 @@ shapeFct: Shape1DInstance; |
@@ -25,9 +25,4 @@ "use strict"; | ||
for (const peak of normalizedPeaks) { | ||
const shape = peak.shape | ||
? peak.shape | ||
: options.shape | ||
? options.shape | ||
: { kind: 'gaussian' }; | ||
const { id, shape = options.shape ? options.shape : { kind: 'gaussian' } } = peak; | ||
const shapeFct = (0, ml_peak_shape_generator_1.getShape1D)(shape); | ||
//@ts-expect-error Should disappear with next release of peak-shape-generator | ||
const parameters = ['x', 'y', ...shapeFct.getParameters()]; | ||
@@ -75,2 +70,3 @@ const propertiesValues = { | ||
internalPeaks.push({ | ||
id, | ||
shape, | ||
@@ -77,0 +73,0 @@ shapeFct, |
{ | ||
"name": "ml-spectra-fitting", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Fit spectra using gaussian or lorentzian", | ||
@@ -65,5 +65,5 @@ "main": "./lib/index.js", | ||
"ml-levenberg-marquardt": "^4.1.0", | ||
"ml-peak-shape-generator": "^4.1.1", | ||
"ml-peak-shape-generator": "^4.1.2", | ||
"ml-spectra-processing": "^11.5.0" | ||
} | ||
} |
@@ -12,4 +12,14 @@ import type { DataXY } from 'cheminfo-types'; | ||
const peaks = [ | ||
{ x: -0.5, y: 1, shape: { kind: 'gaussian' as const, fwhm: 0.05 } }, | ||
{ x: 0.5, y: 1, shape: { kind: 'gaussian' as const, fwhm: 0.05 } }, | ||
{ | ||
id: 'first', | ||
x: -0.5, | ||
y: 1, | ||
shape: { kind: 'gaussian' as const, fwhm: 0.05 }, | ||
}, | ||
{ | ||
id: 'second', | ||
x: 0.5, | ||
y: 1, | ||
shape: { kind: 'gaussian' as const, fwhm: 0.05 }, | ||
}, | ||
]; | ||
@@ -27,4 +37,14 @@ | ||
let result = optimize(data, [ | ||
{ x: -0.55, y: 0.9, shape: { kind: 'gaussian' as const, fwhm: 0.08 } }, | ||
{ x: 0.55, y: 0.9, shape: { kind: 'gaussian' as const, fwhm: 0.08 } }, | ||
{ | ||
id: 'first', | ||
x: -0.55, | ||
y: 0.9, | ||
shape: { kind: 'gaussian' as const, fwhm: 0.08 }, | ||
}, | ||
{ | ||
id: 'second', | ||
x: 0.55, | ||
y: 0.9, | ||
shape: { kind: 'gaussian' as const, fwhm: 0.08 }, | ||
}, | ||
]); | ||
@@ -31,0 +51,0 @@ |
@@ -23,2 +23,3 @@ import { DataXY, DoubleArray } from 'cheminfo-types'; | ||
export interface Peak { | ||
id?: string; | ||
x: number; | ||
@@ -39,2 +40,6 @@ y: number; | ||
type OptimizedPeakIDOrNot<T extends Peak> = T extends { id: string } | ||
? OptimizedPeak & { id: string } | ||
: OptimizedPeak; | ||
type OptimizationParameter = number | ((peak: Peak) => number); | ||
@@ -97,9 +102,9 @@ | ||
*/ | ||
export function optimize( | ||
export function optimize<T extends Peak>( | ||
data: DataXY<DoubleArray>, | ||
peaks: Peak[], | ||
peaks: T[], | ||
options: OptimizeOptions = {}, | ||
): { | ||
error: number; | ||
peaks: OptimizedPeak[]; | ||
peaks: OptimizedPeakIDOrNot<T>[]; | ||
iterations: number; | ||
@@ -148,16 +153,18 @@ } { | ||
let newPeaks: OptimizedPeak[] = []; | ||
let newPeaks = []; | ||
for (let peak of internalPeaks) { | ||
const newPeak = { | ||
x: 0, | ||
y: 0, | ||
shape: peak.shape, | ||
}; | ||
newPeak.x = fittedValues[peak.fromIndex]; | ||
newPeak.y = fittedValues[peak.fromIndex + 1] * minMaxY.range + shiftValue; | ||
for (let i = 2; i < peak.parameters.length; i++) { | ||
const { id, shape, parameters, fromIndex } = peak; | ||
let newPeak = { x: 0, y: 0, shape } as OptimizedPeakIDOrNot<T>; | ||
if (id) { | ||
newPeak = { ...newPeak, id } as OptimizedPeakIDOrNot<T>; | ||
} | ||
newPeak.x = fittedValues[fromIndex]; | ||
newPeak.y = fittedValues[fromIndex + 1] * minMaxY.range + shiftValue; | ||
for (let i = 2; i < parameters.length; i++) { | ||
//@ts-expect-error should be fixed once | ||
newPeak.shape[peak.parameters[i]] = fittedValues[peak.fromIndex + i]; | ||
newPeak.shape[parameters[i]] = fittedValues[fromIndex + i]; | ||
} | ||
newPeaks.push(newPeak); | ||
@@ -164,0 +171,0 @@ } |
@@ -13,2 +13,3 @@ import { getShape1D, Shape1D, Shape1DInstance } from 'ml-peak-shape-generator'; | ||
export interface InternalPeak { | ||
id?: string; | ||
shape: Shape1D; | ||
@@ -45,11 +46,7 @@ shapeFct: Shape1DInstance; | ||
for (const peak of normalizedPeaks) { | ||
const shape: Shape1D = peak.shape | ||
? peak.shape | ||
: options.shape | ||
? options.shape | ||
: { kind: 'gaussian' }; | ||
const { id, shape = options.shape ? options.shape : { kind: 'gaussian' } } = | ||
peak; | ||
const shapeFct: Shape1DInstance = getShape1D(shape); | ||
//@ts-expect-error Should disappear with next release of peak-shape-generator | ||
const parameters: Parameter[] = ['x', 'y', ...shapeFct.getParameters()]; | ||
@@ -125,2 +122,3 @@ | ||
internalPeaks.push({ | ||
id, | ||
shape, | ||
@@ -127,0 +125,0 @@ shapeFct, |
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
103410
2034