Skip to content

Commit

Permalink
feat: 2d apodization
Browse files Browse the repository at this point in the history
refactor: hide the 2D apodization feature behind the experimental flag
  • Loading branch information
hamed-musallam committed Nov 25, 2024
1 parent 40c01bb commit 450d0e6
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 34 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"ml-tree-similarity": "^2.2.0",
"multiplet-analysis": "^2.1.2",
"nmr-correlation": "^2.3.3",
"nmr-load-save": "^2.0.4",
"nmr-load-save": "^2.1.0",
"nmr-processing": "^14.0.3",
"nmredata": "^0.9.11",
"numeral": "^2.0.6",
Expand Down
6 changes: 6 additions & 0 deletions src/component/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { options } from '../toolbar/ToolTypes.js';
import { AutoPeakPickingOptionPanel } from './AutoPeakPickingOptionPanel.js';
import { HeaderWrapper } from './HeaderWrapper.js';
import RangesPickingOptionPanel from './RangesPickingOptionPanel.js';
import { SimpleApodizationDimensionOneOptionsPanel } from './SimpleApodizationDimensionOneOptionsPanel.js';
import { SimpleApodizationDimensionTwoOptionsPanel } from './SimpleApodizationDimensionTwoOptionsPanel.js';
import { SimpleApodizationOptionsPanel } from './SimpleApodizationOptionsPanel.js';
import { SimpleBaseLineCorrectionOptionsPanel } from './SimpleBaseLineCorrectionOptionsPanel.js';
import { SimplePhaseCorrectionOptionsPanel } from './SimplePhaseCorrectionOptionsPanel.js';
Expand Down Expand Up @@ -104,6 +106,10 @@ function HeaderInner(props: HeaderInnerProps) {
switch (selectedOptionPanel) {
case options.apodization.id:
return <SimpleApodizationOptionsPanel />;
case options.apodizationDimension1.id:
return <SimpleApodizationDimensionOneOptionsPanel />;
case options.apodizationDimension2.id:
return <SimpleApodizationDimensionTwoOptionsPanel />;
case options.zeroFilling.id:
return <SimpleZeroFillingOptionsPanel />;
case options.phaseCorrection.id:
Expand Down
54 changes: 54 additions & 0 deletions src/component/header/SimpleApodizationDimensionOneOptionsPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { memo, useCallback } from 'react';

import type { ExtractFilterEntry } from '../../data/types/common/ExtractFilterEntry.js';
import { useDispatch } from '../context/DispatchContext.js';
import { useFilter } from '../hooks/useFilter.js';

import { BaseSimpleApodizationOptionsPanel } from './BaseSimpleApodizationOptionsPanel.js';

interface ApodizationOptionsInnerPanelProps {
filter: ExtractFilterEntry<'apodizationDimension1'> | null;
}

function ApodizationOptionsInnerPanel(
props: ApodizationOptionsInnerPanelProps,
) {
const dispatch = useDispatch();

const applyHandler = useCallback(
(data) => {
const { options } = data;
dispatch({
type: 'APPLY_APODIZATION_DIMENSION_ONE_FILTER',
payload: { options },
});
},
[dispatch],
);
const changeHandler = useCallback(
(data) => {
const { livePreview, options } = data;

dispatch({
type: 'CALCULATE_APODIZATION_DIMENSION_ONE_FILTER',
payload: { livePreview, options: structuredClone(options) },
});
},
[dispatch],
);

return (
<BaseSimpleApodizationOptionsPanel
filter={props.filter}
onApplyDispatch={applyHandler}
onChangeDispatch={changeHandler}
/>
);
}

const MemoizedApodizationPanel = memo(ApodizationOptionsInnerPanel);

export function SimpleApodizationDimensionOneOptionsPanel() {
const filter = useFilter('apodizationDimension1');
return <MemoizedApodizationPanel filter={filter} />;
}
54 changes: 54 additions & 0 deletions src/component/header/SimpleApodizationDimensionTwoOptionsPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { memo, useCallback } from 'react';

import type { ExtractFilterEntry } from '../../data/types/common/ExtractFilterEntry.js';
import { useDispatch } from '../context/DispatchContext.js';
import { useFilter } from '../hooks/useFilter.js';

import { BaseSimpleApodizationOptionsPanel } from './BaseSimpleApodizationOptionsPanel.js';

interface ApodizationOptionsInnerPanelProps {
filter: ExtractFilterEntry<'apodizationDimension2'> | null;
}

function ApodizationOptionsInnerPanel(
props: ApodizationOptionsInnerPanelProps,
) {
const dispatch = useDispatch();

const applyHandler = useCallback(
(data) => {
const { options } = data;
dispatch({
type: 'APPLY_APODIZATION_DIMENSION_TWO_FILTER',
payload: { options },
});
},
[dispatch],
);
const changeHandler = useCallback(
(data) => {
const { livePreview, options } = data;

dispatch({
type: 'CALCULATE_APODIZATION_DIMENSION_TWO_FILTER',
payload: { livePreview, options: structuredClone(options) },
});
},
[dispatch],
);

return (
<BaseSimpleApodizationOptionsPanel
filter={props.filter}
onApplyDispatch={applyHandler}
onChangeDispatch={changeHandler}
/>
);
}

const MemoizedApodizationPanel = memo(ApodizationOptionsInnerPanel);

export function SimpleApodizationDimensionTwoOptionsPanel() {
const filter = useFilter('apodizationDimension2');
return <MemoizedApodizationPanel filter={filter} />;
}
8 changes: 8 additions & 0 deletions src/component/modal/setting/settings-tabs/ToolsTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ const LIST: ListItem[] = [
label: 'Apodization',
name: 'apodization',
},
{
label: 'Apodization dimension one',
name: 'apodizationDimension1',
},
{
label: 'Apodization dimension two',
name: 'apodizationDimension2',
},
{
label: 'Zero filling',
name: 'zeroFilling',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useCallback } from 'react';

import type { ExtractFilterEntry } from '../../../../data/types/common/ExtractFilterEntry.js';
import { useDispatch } from '../../../context/DispatchContext.js';

import { BaseApodizationOptions } from './apodization/BaseApodizationOptions.js';

import type { BaseFilterOptionsPanelProps } from './index.js';

export default function ApodizationDimensionOneOptionsPanel(
props: BaseFilterOptionsPanelProps<
ExtractFilterEntry<'apodizationDimension1'>
>,
) {
const dispatch = useDispatch();

const { filter, enableEdit = true, onCancel, onConfirm } = props;

const applyHandler = useCallback(
(data) => {
const { options } = data;
dispatch({
type: 'APPLY_APODIZATION_DIMENSION_ONE_FILTER',
payload: { options },
});
},
[dispatch],
);
const changeHandler = useCallback(
(data) => {
const { livePreview, options } = data;

dispatch({
type: 'CALCULATE_APODIZATION_DIMENSION_ONE_FILTER',
payload: { livePreview, options: structuredClone(options) },
});
},
[dispatch],
);

return (
<BaseApodizationOptions
enableEdit={enableEdit}
filter={filter}
onCancel={onCancel}
onConfirm={onConfirm}
onApplyDispatch={applyHandler}
onChangeDispatch={changeHandler}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useCallback } from 'react';

import type { ExtractFilterEntry } from '../../../../data/types/common/ExtractFilterEntry.js';
import { useDispatch } from '../../../context/DispatchContext.js';

import { BaseApodizationOptions } from './apodization/BaseApodizationOptions.js';

import type { BaseFilterOptionsPanelProps } from './index.js';

export default function ApodizationDimensionTwoOptionsPanel(
props: BaseFilterOptionsPanelProps<
ExtractFilterEntry<'apodizationDimension2'>
>,
) {
const dispatch = useDispatch();

const { filter, enableEdit = true, onCancel, onConfirm } = props;

const applyHandler = useCallback(
(data) => {
const { options } = data;
dispatch({
type: 'APPLY_APODIZATION_DIMENSION_TWO_FILTER',
payload: { options },
});
},
[dispatch],
);
const changeHandler = useCallback(
(data) => {
const { livePreview, options } = data;

dispatch({
type: 'CALCULATE_APODIZATION_DIMENSION_TWO_FILTER',
payload: { livePreview, options: structuredClone(options) },
});
},
[dispatch],
);

return (
<BaseApodizationOptions
enableEdit={enableEdit}
filter={filter}
onCancel={onCancel}
onConfirm={onConfirm}
onApplyDispatch={applyHandler}
onChangeDispatch={changeHandler}
/>
);
}
12 changes: 11 additions & 1 deletion src/component/panels/filtersPanel/Filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Filters1D, Filters2D } from 'nmr-processing';

import type { LabelStyle } from '../../../elements/Label.js';

import ApodizationDimensionOneOptionsPanel from './ApodizationDimensionOneOptionsPanel.js';
import ApodizationDimensionTwoOptionsPanel from './ApodizationDimensionTwoOptionsPanel.js';
import ApodizationOptionsPanel from './ApodizationOptionsPanel.js';
import BaseLineCorrectionOptionsPanel from './BaseLineCorrectionOptionsPanel.js';
import ExclusionZonesOptionsPanel from './ExclusionZonesOptionsPanel.js';
Expand All @@ -20,10 +22,18 @@ const {
exclusionZones,
} = Filters1D;

const { shift2DX, shift2DY, phaseCorrectionTwoDimensions } = Filters2D;
const {
shift2DX,
shift2DY,
phaseCorrectionTwoDimensions,
apodizationDimension1,
apodizationDimension2,
} = Filters2D;

export const filterOptionPanels = {
[apodization.name]: ApodizationOptionsPanel,
[apodizationDimension1.name]: ApodizationDimensionOneOptionsPanel,
[apodizationDimension2.name]: ApodizationDimensionTwoOptionsPanel,
[phaseCorrection.name]: PhaseCorrectionOptionsPanel,
[zeroFilling.name]: ZeroFillingOptionsPanel,
[phaseCorrectionTwoDimensions.name]: PhaseCorrectionTwoDimensionsOptionsPanel,
Expand Down
27 changes: 21 additions & 6 deletions src/component/reducer/Reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { produce, original } from 'immer';
import type { CorrelationData } from 'nmr-correlation';
import { buildCorrelationData } from 'nmr-correlation';
import type { Spectrum, ViewState } from 'nmr-load-save';
import type {
BaselineCorrectionZone,
Apodization1DOptions,
} from 'nmr-processing';
import type { BaselineCorrectionZone } from 'nmr-processing';
import type { Reducer } from 'react';

import type { StateMoleculeExtended } from '../../data/molecules/Molecule.js';
Expand Down Expand Up @@ -169,7 +166,6 @@ export const getInitialState = (): State => ({
zones: [],
livePreview: true,
},
apodizationOptions: {} as Apodization1DOptions,
twoDimensionPhaseCorrection: {
activeTraceDirection: 'horizontal',
addTracesToBothDirections: true,
Expand Down Expand Up @@ -347,7 +343,6 @@ export interface State {
options: any;
livePreview: boolean;
};
apodizationOptions: Apodization1DOptions;
/**
* pivot point for manual phase correction
* @default {value:0,index:0}
Expand Down Expand Up @@ -463,8 +458,28 @@ function innerSpectrumReducer(draft: Draft<State>, action: Action) {
return FiltersActions.handleShiftSpectrumAlongXAxis(draft, action);
case 'APPLY_APODIZATION_FILTER':
return FiltersActions.handleApplyApodizationFilter(draft, action);
case 'APPLY_APODIZATION_DIMENSION_ONE_FILTER':
return FiltersActions.handleApplyApodizationDimensionOneFilter(
draft,
action,
);
case 'APPLY_APODIZATION_DIMENSION_TWO_FILTER':
return FiltersActions.handleApplyApodizationDimensionTwoFilter(
draft,
action,
);
case 'CALCULATE_APODIZATION_FILTER':
return FiltersActions.handleCalculateApodizationFilter(draft, action);
case 'CALCULATE_APODIZATION_DIMENSION_ONE_FILTER':
return FiltersActions.handleCalculateApodizationDimensionOneFilter(
draft,
action,
);
case 'CALCULATE_APODIZATION_DIMENSION_TWO_FILTER':
return FiltersActions.handleCalculateApodizationDimensionTwoFilter(
draft,
action,
);
case 'APPLY_ZERO_FILLING_FILTER':
return FiltersActions.handleApplyZeroFillingFilter(draft, action);
case 'CALCULATE_ZERO_FILLING_FILTER':
Expand Down
Loading

0 comments on commit 450d0e6

Please sign in to comment.