Skip to content

Commit

Permalink
feat: auto ranges detection based on window zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Apr 13, 2021
1 parent b7592b3 commit 792ea3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/component/reducer/actions/RangesActions.ts
@@ -1,5 +1,6 @@
import { Draft, original } from 'immer';
import cloneDeep from 'lodash/cloneDeep';
import { xFindClosestIndex } from 'ml-spectra-processing';

import { Filters } from '../../../data/Filters';
import * as FiltersManager from '../../../data/FiltersManager';
Expand Down Expand Up @@ -33,7 +34,17 @@ import { setDomain } from './DomainActions';
function handleAutoRangesDetection(draft: Draft<State>, detectionOptions) {
if (draft.activeSpectrum?.id) {
const { index } = draft.activeSpectrum;
detectRanges(draft.data[index], detectionOptions);
const datum = draft.data[index] as Datum1D;

const [from, to] = draft.xDomain;
const windowFromIndex = xFindClosestIndex(datum.data.x, from);
const windowToIndex = xFindClosestIndex(datum.data.x, to);

detectRanges(datum, {
...detectionOptions,
windowFromIndex,
windowToIndex,
});
handleOnChangeRangesData(draft);
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/data/data1d/autoRangesDetection.js
Expand Up @@ -18,12 +18,15 @@ export default function autoRangesDetection(datum1D, options = {}) {
// we calculate the noise but this could be improved
let noiseLevel = xAbsoluteMedian(datum1D.data.re);

const { re, x } = datum1D.data;
let { re, x } = datum1D.data;

const { originFrequency, nucleus } = datum1D.info;

const { windowFromIndex, windowToIndex, peakPicking } = options;

const peakPickingOptions = {
...defaultPeakPickingOptions,
...options.peakPicking,
...peakPicking,
};

const rangesOptions = {
Expand All @@ -32,6 +35,11 @@ export default function autoRangesDetection(datum1D, options = {}) {
noiseLevel: 3 * noiseLevel,
};

if (windowFromIndex !== undefined && windowToIndex !== undefined) {
x = x.slice(windowFromIndex, windowToIndex);
re = re.slice(windowFromIndex, windowToIndex);
}

const ranges = xyAutoRangesPicking(
{ x, y: re },
{
Expand Down

0 comments on commit 792ea3f

Please sign in to comment.