-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: nmrium crash when some keys not exists
check and map ranges, signals, peaks and integrals when import data close #1404
- Loading branch information
1 parent
6b4d4cd
commit 450decd
Showing
8 changed files
with
129 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Datum1D } from "../../types/data1d/Datum1D"; | ||
|
||
export function getSpectrumErrorValue(datum: Datum1D) { | ||
const { x } = datum.data; | ||
return (x[x.length - 1] - x[0]) / 10000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import merge from 'lodash/merge'; | ||
|
||
import { Integrals } from '../../../types/data1d'; | ||
|
||
export function initiateIntegrals(options: Partial<{ integrals: Integrals }>) { | ||
return merge( | ||
{ | ||
values: [], | ||
options: { | ||
sum: undefined, | ||
isSumConstant: true, | ||
sumAuto: true, | ||
}, | ||
}, | ||
options.integrals, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import merge from 'lodash/merge'; | ||
|
||
import { Datum1D, Peaks } from '../../../types/data1d'; | ||
|
||
import { mapPeaks } from './mapPeaks'; | ||
|
||
export function initiatePeaks( | ||
options: Partial<{ peaks: Peaks }>, | ||
datum: Datum1D, | ||
) { | ||
return merge( | ||
{ values: [], options: {} }, | ||
options.peaks, | ||
{ | ||
values: mapPeaks(options?.peaks?.values || [], datum), | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Peak, Datum1D } from '../../../types/data1d'; | ||
import generateID from '../../../utilities/generateID'; | ||
import { getSpectrumErrorValue } from '../getSpectrumErrorValue'; | ||
import { getShiftX } from '../shift/getShiftX'; | ||
|
||
function checkPeak(peak: Peak, datum: Datum1D, error) { | ||
// check if the Peak is already exists | ||
for (const { x } of datum.peaks?.values || []) { | ||
if (Math.abs(peak.x - x) < error) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
export function mapPeaks(peaks: Peak[], datum: Datum1D) { | ||
const shiftX = getShiftX(datum); | ||
|
||
const error = getSpectrumErrorValue(datum); | ||
|
||
return peaks.reduce<Peak[]>((acc, newPeak) => { | ||
// check if the peak is already exists | ||
if (checkPeak(newPeak, datum, error)) return acc; | ||
|
||
acc.push({ | ||
id: newPeak?.id || generateID(), | ||
originalX: newPeak.x - shiftX, | ||
x: newPeak.x, | ||
y: newPeak.y, | ||
width: newPeak.width, | ||
}); | ||
|
||
return acc; | ||
}, []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import merge from 'lodash/merge'; | ||
|
||
import { Datum1D, Ranges } from '../../../types/data1d'; | ||
|
||
import { mapRanges } from './mapRanges'; | ||
|
||
export function initiateRanges( | ||
options: Partial<{ ranges: Ranges }>, | ||
datum: Datum1D, | ||
) { | ||
return merge( | ||
{ | ||
values: [], | ||
options: { | ||
sum: undefined, | ||
isSumConstant: true, | ||
sumAuto: true, | ||
}, | ||
}, | ||
options.ranges, | ||
{ | ||
values: mapRanges(options?.ranges?.values || [], datum), | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters