-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename function maxValue to maxAbsoluteValue
- Loading branch information
1 parent
f57d93a
commit 5763ab0
Showing
6 changed files
with
72 additions
and
74 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
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,32 @@ | ||
import { Spectrum1D } from 'nmr-load-save'; | ||
|
||
import { get1DDataXY } from '../../data/data1d/Spectrum1D'; | ||
|
||
import { maxAbsoluteValue } from './maxAbsoluteValue'; | ||
|
||
interface PeakPosition { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export function getClosePeak( | ||
spectrum: Spectrum1D, | ||
lookRange: { | ||
from: number; | ||
to: number; | ||
}, | ||
): PeakPosition | null { | ||
const { from, to } = lookRange; | ||
const datum = get1DDataXY(spectrum); | ||
const maxIndex = datum.x.findIndex((number) => number >= to) - 1; | ||
const minIndex = datum.x.findIndex((number) => number >= from); | ||
|
||
const yDataRange = datum.y.slice(minIndex, maxIndex); | ||
if (!yDataRange || yDataRange.length === 0) return null; | ||
|
||
const y = maxAbsoluteValue(yDataRange); | ||
const xIndex = minIndex + yDataRange.indexOf(y); | ||
const x = datum.x[xIndex]; | ||
|
||
return { x, y }; | ||
} | ||
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,31 @@ | ||
import { NumberArray } from 'cheminfo-types'; | ||
import { | ||
XGetFromToIndexOptions, | ||
xCheck, | ||
xGetFromToIndex, | ||
} from 'ml-spectra-processing'; | ||
|
||
//This function is an adapted version of the xMaxAbsoluteValue function from ml-spectra-processing. It identifies the maximum absolute value and returns the corresponding maximum value along with its sign | ||
export function maxAbsoluteValue( | ||
array: NumberArray, | ||
options: XGetFromToIndexOptions = {}, | ||
): number { | ||
xCheck(array); | ||
|
||
const { fromIndex, toIndex } = xGetFromToIndex(array, options); | ||
let maxValue = array[fromIndex]; | ||
let sign = 1; | ||
|
||
for (let i = fromIndex + 1; i <= toIndex; i++) { | ||
if (array[i] >= 0) { | ||
if (array[i] > maxValue) { | ||
maxValue = array[i]; | ||
sign = 1; | ||
} | ||
} else if (-array[i] > maxValue) { | ||
maxValue = -array[i]; | ||
sign = Math.sign(array[i]); | ||
} | ||
} | ||
return maxValue * sign; | ||
} | ||
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 was deleted.
Oops, something went wrong.