Skip to content

Commit

Permalink
feat(zones): add access to maxPercentCutOff option (#2963)
Browse files Browse the repository at this point in the history
  • Loading branch information
jobo322 committed Mar 18, 2024
1 parent 8bbce4e commit 544c2cc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/component/header/Zones2DOptionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const validationSchema = Yup.object().shape({

const initialValues = {
zonesNoiseFactor: 1,
zonesMinMaxRatio: 0.03,
};

function Zones2DOptionPanel() {
Expand Down Expand Up @@ -64,6 +65,22 @@ function Zones2DOptionPanel() {
step={1}
/>
</Label>
<Label
title="MinMaxRatio :"
htmlFor="livePreview"
style={headerLabelStyle}
>
<FormikInput
type="number"
name="zonesMinMaxRatio"
style={{
input: { width: '50px', textAlign: 'center' },
inputWrapper: { height: '100%' },
}}
min={0}
step={0.01}
/>
</Label>
<FormikOnChange
enableValidation
onChange={handleChangeNoiseFactory}
Expand Down
2 changes: 2 additions & 0 deletions src/component/reducer/Reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const getInitialState = (): State => ({
},
pivot: { value: 0, index: 0 },
zonesNoiseFactor: 1,
zonesMinMaxRatio: 0.03,
activeFilterID: null,
predictionIndex: 0,
},
Expand Down Expand Up @@ -347,6 +348,7 @@ export interface State {
*/
twoDimensionPhaseCorrection: TwoDimensionPhaseCorrection;
zonesNoiseFactor: number;
zonesMinMaxRatio: number;

/**
* The current active Filter
Expand Down
14 changes: 11 additions & 3 deletions src/component/reducer/actions/ZonesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ interface DeleteSignal2DProps {

type ChangeZonesFactorAction = ActionType<
'CHANGE_ZONES_NOISE_FACTOR',
{ zonesNoiseFactor: number }
{ zonesNoiseFactor: number; zonesMinMaxRatio: number }
>;

type Add2dZoneAction = ActionType<'ADD_2D_ZONE', ZoneBoundary>;

type AutoZonesDetectionAction = ActionType<
'AUTO_ZONES_DETECTION',
{ zonesNoiseFactor: number }
{ zonesNoiseFactor: number; zonesMinMaxRatio: number }
>;
type ChangeZoneSignalDeltaAction = ActionType<
'CHANGE_ZONE_SIGNAL_VALUE',
Expand Down Expand Up @@ -126,6 +127,7 @@ function handleChangeZonesFactor(
action: ChangeZonesFactorAction,
) {
draft.toolOptions.data.zonesNoiseFactor = action.payload.zonesNoiseFactor;
draft.toolOptions.data.zonesMinMaxRatio = action.payload.zonesMinMaxRatio;
}

//action
Expand All @@ -140,6 +142,7 @@ function handleAdd2dZone(draft: Draft<State>, action: Add2dZoneAction) {
const zones = detectZonesManual(original(datum), {
selectedZone: drawnZone,
thresholdFactor: draft.toolOptions.data.zonesNoiseFactor,
maxPercentCutOff: draft.toolOptions.data.zonesMinMaxRatio,
convolutionByFFT: false,
});

Expand All @@ -158,12 +161,16 @@ function handleAutoZonesDetection(

if (activeSpectrum?.id) {
const { index } = activeSpectrum;
const { zonesNoiseFactor: thresholdFactor } = action.payload;
const {
zonesNoiseFactor: thresholdFactor,
zonesMinMaxRatio: maxPercentCutOff,
} = action.payload;
const [fromX, toX] = draft.xDomain;
const [fromY, toY] = draft.yDomain;
const detectionOptions: DetectionZonesOptions = {
selectedZone: { fromX, toX, fromY, toY },
thresholdFactor,
maxPercentCutOff,
};
const datum = draft.data[index] as Spectrum2D;
const zones = detectZones(original(datum), detectionOptions);
Expand All @@ -181,6 +188,7 @@ function handleAutoSpectraZonesDetection(draft: Draft<State>) {
const detectionOptions = {
selectedZone: { fromX: minX, toX: maxX, fromY: minY, toY: maxY },
thresholdFactor: 1,
maxPercentCutOff: 0.03,
};

const zones = detectZones(original(datum), detectionOptions);
Expand Down
1 change: 1 addition & 0 deletions src/data/data2d/Spectrum2D/zones/getDetectionZones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface DetectionZonesOptions {
toY: number;
};
thresholdFactor: number;
maxPercentCutOff: number;
tolerances?: number[];
convolutionByFFT?: boolean;
enhanceSymmetry?: boolean;
Expand Down

0 comments on commit 544c2cc

Please sign in to comment.