Skip to content

Commit cedb1c9

Browse files
authored
feat: remove peak limit for optimization and adjust autoPeakPicking parameters (#4241)
1 parent 2424fef commit cedb1c9

7 files changed

Lines changed: 51 additions & 50 deletions

File tree

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"@tanstack/react-table": "^8.21.3",
7272
"@zakodium/nmr-types": "^0.5.18",
7373
"@zakodium/nmrium-core": "^0.7.37",
74-
"@zakodium/nmrium-core-plugins": "^0.7.48",
74+
"@zakodium/nmrium-core-plugins": "^0.7.50",
7575
"@zakodium/pdnd-esm": "^1.1.0",
7676
"@zakodium/utils": "^0.2.0",
7777
"@zip.js/zip.js": "^2.8.26",
@@ -98,7 +98,7 @@
9898
"ml-spectra-processing": "^14.29.2",
9999
"ml-tree-similarity": "^2.2.0",
100100
"nmr-correlation": "2.3.3",
101-
"nmr-processing": "^22.18.0",
101+
"nmr-processing": "^22.19.0",
102102
"numeral": "^2.0.6",
103103
"openchemlib": "^9.24.0",
104104
"openchemlib-utils": "^8.17.1",

src/component/panels/PeaksPanel/PeaksPanel.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,7 @@ function PeaksPanelInner(props: PeaksPanelInnerProps) {
111111
const filterPeaks = peaks.values.filter((peak) =>
112112
isInRange(peak.x, { from, to }),
113113
);
114-
if (filterPeaks.length <= 15) {
115-
dispatch({ type: 'OPTIMIZE_PEAKS', payload: { peaks: filterPeaks } });
116-
} else {
117-
toaster.show({
118-
message: 'optimization can be done on no more than 15 peaks',
119-
intent: 'danger',
120-
});
121-
}
114+
dispatch({ type: 'OPTIMIZE_PEAKS', payload: { peaks: filterPeaks } });
122115
};
123116

124117
function toggleViewProperty(key: keyof FilterType<PeaksViewState, boolean>) {

src/component/reducer/actions/RangesActions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ function handleAutoRangesDetection(
243243
broadWidth: 0.05,
244244
thresholdFactor: 8,
245245
minMaxRatio,
246+
maxAbsoluteRatio: minMaxRatio,
246247
direction: lookNegative ? 'both' : 'positive',
247248
},
248249
};

src/data/data1d/Spectrum1D/peaks/autoPeakPicking.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function autoPeakPicking(
4848
sensitivity: 100,
4949
shape: defaultPeakShape,
5050
noiseLevel: noise * noiseFactor,
51+
maxAbsoluteRatio: minMaxRatio, // Threshold to determine if a given peak should be considered as a noise
5152
minMaxRatio, // Threshold to determine if a given peak should be considered as a noise
5253
realTopDetection: true,
5354
smoothY: false,

src/data/data1d/Spectrum1D/peaks/optimizePeaks.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,105 +36,110 @@ export function optimizePeaks(
3636
groupingFactor: 10,
3737
stages: [
3838
{
39+
// Stage 1: local stabilization
40+
factorLimits: 2,
41+
maxNumberOfPeaks: 40,
3942
optimization: {
4043
kind: 'lm',
4144
options: { maxIterations: 20, errorTolerance: 1e-3 },
4245
},
4346
parameters: {
4447
fwhm: {
4548
optimize: true,
46-
min: (peak: any) => (peak.shape?.fwhm ?? 0) / 2,
49+
min: (peak: any) => (peak.shape?.fwhm ?? 0) * 0.5,
4750
max: (peak: any) => (peak.shape?.fwhm ?? 0) * 2,
4851
},
4952
mu: { optimize: false },
5053
x: { optimize: false },
5154
y: {
5255
optimize: true,
53-
init: (peak: any) => peak.y * 0.8,
56+
init: (peak: any) => peak.y,
5457
},
5558
},
5659
},
5760
{
61+
factorLimits: 2,
62+
maxNumberOfPeaks: 40,
5863
optimization: {
5964
kind: 'lm',
60-
options: { maxIterations: 20, errorTolerance: 5e-4 },
65+
options: { maxIterations: 20, errorTolerance: 1e-3 },
6166
},
6267
parameters: {
6368
fwhm: {
6469
optimize: true,
65-
min: (peak: any) => (peak.shape?.fwhm ?? 0) / 2,
70+
min: (peak: any) => (peak.shape?.fwhm ?? 0) * 0.5,
6671
max: (peak: any) => (peak.shape?.fwhm ?? 0) * 2,
6772
},
6873
mu: { optimize: false },
6974
x: { optimize: false },
7075
y: {
7176
optimize: true,
77+
init: (peak: any) => peak.y,
7278
},
7379
},
7480
},
7581
{
82+
// Stage 2: regroup into the real overlapping cluster
83+
factorLimits: 2,
84+
maxNumberOfPeaks: 40,
7685
optimization: {
7786
kind: 'lm',
78-
options: { maxIterations: 20, errorTolerance: 1e-5 },
87+
options: { maxIterations: 25, errorTolerance: 1e-4 },
7988
},
8089
parameters: {
8190
fwhm: {
8291
optimize: true,
83-
min: (peak: any) => (peak.shape?.fwhm ?? 0) / 2,
92+
min: (peak: any) => (peak.shape?.fwhm ?? 0) * 0.5,
8493
max: (peak: any) => (peak.shape?.fwhm ?? 0) * 2,
8594
},
8695
mu: { optimize: true },
8796
x: { optimize: false },
88-
y: {
89-
optimize: true,
90-
},
97+
y: { optimize: true },
9198
},
9299
},
93100
{
101+
// Stage 3: final polish
102+
factorLimits: 2,
103+
maxNumberOfPeaks: 40,
94104
optimization: {
95105
kind: 'lm',
96-
options: { maxIterations: 20, errorTolerance: 5e-4 },
106+
options: { maxIterations: 30, errorTolerance: 1e-5 },
97107
},
98108
parameters: {
99109
fwhm: {
100110
optimize: true,
101-
min: (peak: any) => (peak.shape?.fwhm ?? 0) / 3,
102-
max: (peak: any) => (peak.shape?.fwhm ?? 0) * 3,
111+
min: (peak: any) => (peak.shape?.fwhm ?? 0) * 0.5,
112+
max: (peak: any) => (peak.shape?.fwhm ?? 0) * 2,
103113
},
104114
mu: { optimize: true },
105-
x: { optimize: true },
106-
y: { optimize: true },
107-
},
108-
},
109-
{
110-
optimization: {
111-
kind: 'lm',
112-
options: { maxIterations: 20, errorTolerance: 1e-4 },
113-
},
114-
parameters: {
115-
fwhm: {
115+
x: {
116116
optimize: true,
117-
min: (peak: any) => (peak.shape?.fwhm ?? 0) / 2,
118-
max: (peak: any) => (peak.shape?.fwhm ?? 0) * 2,
117+
min: (peak: any) => peak.x - (peak.shape?.fwhm ?? 0) / 4,
118+
max: (peak: any) => peak.x + (peak.shape?.fwhm ?? 0) / 4,
119119
},
120-
mu: { optimize: false },
121-
x: { optimize: true },
122120
y: { optimize: true },
123121
},
124122
},
125123
{
124+
// Stage 3: final polish
125+
factorLimits: 2,
126+
maxNumberOfPeaks: 40,
126127
optimization: {
127128
kind: 'lm',
128-
options: { maxIterations: 20, errorTolerance: 1e-8 },
129+
options: { maxIterations: 30, errorTolerance: 1e-5 },
129130
},
130131
parameters: {
131132
fwhm: {
132133
optimize: true,
133-
min: (peak: any) => (peak.shape?.fwhm ?? 0) / 2,
134+
min: (peak: any) => (peak.shape?.fwhm ?? 0) * 0.5,
134135
max: (peak: any) => (peak.shape?.fwhm ?? 0) * 2,
135136
},
136137
mu: { optimize: true },
137-
x: { optimize: true },
138+
x: {
139+
optimize: true,
140+
min: (peak: any) => peak.x - (peak.shape?.fwhm ?? 0) / 4,
141+
max: (peak: any) => peak.x + (peak.shape?.fwhm ?? 0) / 4,
142+
},
138143
y: { optimize: true },
139144
},
140145
},

src/data/data1d/Spectrum1D/ranges/detectSignalsByMultipletAnalysis.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function detectSignalsByMultipletAnalysis(
3535
to,
3636
frequency,
3737
minMaxRatio: 0.1,
38+
maxAbsoluteRatio: 0.1,
3839
broadWidth: 0.25,
3940
broadRatio: 0.0025,
4041
optimize: true,

0 commit comments

Comments
 (0)