use crate::processing::contracts::polarity::PolarityState;
use crate::processing::contracts::profile::NormalizedAcmeV1;
use super::{
BaselineProfile, DigitalFilterCorrection, FourierTransform, FrequencyFrame, PhaseCorrection,
PhaseFailurePolicy, PhaseMethod, Projection, RealBaseline, SpectrumOperation, Window, ZeroFill,
};
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq)]
pub enum ProcessingOperation {
Spectrum {
axis: usize,
operation: SpectrumOperation,
},
Window {
axis: usize,
window: Window,
},
ZeroFill {
axis: usize,
zero_fill: ZeroFill,
},
StandardZeroFill {
axis: usize,
},
FourierTransform {
axis: usize,
transform: FourierTransform,
},
DigitalFilterCorrection {
axis: usize,
correction: DigitalFilterCorrection,
},
PhaseCorrection {
axis: usize,
correction: PhaseCorrection,
},
BaselineCorrection {
axis: usize,
profile: BaselineProfile,
},
ComponentTransform {
axis: usize,
},
Projection {
projection: Projection,
polarity: PolarityState,
},
ResolveFrequencyFrame {
axis: usize,
frame: FrequencyFrame,
},
ReverseAxis {
axis: usize,
},
}
impl ProcessingOperation {
pub fn target(&self) -> OperationTarget {
match self.axis() {
Some(axis) => OperationTarget::Axis(axis),
None => OperationTarget::Dataset,
}
}
pub(crate) fn axis(&self) -> Option<usize> {
match self {
Self::Spectrum { axis, .. }
| Self::Window { axis, .. }
| Self::ZeroFill { axis, .. }
| Self::StandardZeroFill { axis }
| Self::FourierTransform { axis, .. }
| Self::DigitalFilterCorrection { axis, .. }
| Self::PhaseCorrection { axis, .. }
| Self::BaselineCorrection { axis, .. }
| Self::ComponentTransform { axis }
| Self::ResolveFrequencyFrame { axis, .. }
| Self::ReverseAxis { axis } => Some(*axis),
Self::Projection { .. } => None,
}
}
pub(crate) fn name(&self) -> &'static str {
match self {
Self::Spectrum { .. } => "spectrum operation",
Self::Window { .. } => "window",
Self::ZeroFill { .. } => "zero fill",
Self::StandardZeroFill { .. } => "standard zero fill",
Self::FourierTransform { .. } => "Fourier transform",
Self::DigitalFilterCorrection {
correction: DigitalFilterCorrection::AcknowledgeZeroDelayV1,
..
} => "zero-delay acknowledgement",
Self::DigitalFilterCorrection {
correction: DigitalFilterCorrection::FrequencyDomainPhaseRampV1(_),
..
} => "delay phase ramp",
Self::DigitalFilterCorrection {
correction: DigitalFilterCorrection::TimeDomainShiftFoldV1 { .. },
..
} => "time-domain shift/fold correction",
Self::PhaseCorrection { .. } => "phase correction",
Self::BaselineCorrection { .. } => "baseline correction",
Self::ComponentTransform { .. } => "component transform",
Self::Projection { .. } => "scalar projection",
Self::ResolveFrequencyFrame { .. } => "frequency-frame resolution",
Self::ReverseAxis { .. } => "axis reversal",
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OperationTarget {
Axis(usize),
Axes(Vec<usize>),
Dataset,
}
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq)]
pub enum ProcessingRequest {
BaselineEstimate {
axis: usize,
method: RealBaseline,
},
PhaseMethod {
axis: usize,
method: PhaseMethod,
},
Explicit(ProcessingOperation),
#[non_exhaustive]
AutoPhase {
axis: usize,
profile: NormalizedAcmeV1,
polarity: PolarityState,
failure_policy: PhaseFailurePolicy,
},
}
impl ProcessingRequest {
pub fn target(&self) -> OperationTarget {
match self {
Self::Explicit(operation) => operation.target(),
Self::AutoPhase { axis, .. }
| Self::PhaseMethod { axis, .. }
| Self::BaselineEstimate { axis, .. } => OperationTarget::Axis(*axis),
}
}
pub fn explicit(&self) -> Option<&ProcessingOperation> {
match self {
Self::Explicit(operation) => Some(operation),
Self::AutoPhase { .. } | Self::PhaseMethod { .. } | Self::BaselineEstimate { .. } => {
None
}
}
}
}
impl From<ProcessingOperation> for ProcessingRequest {
fn from(value: ProcessingOperation) -> Self {
Self::Explicit(value)
}
}