"""
The ska_oso_pdm.sb_definition.csp.pst module defines a Python
representation of a PST Configuration.
"""
from pydantic import model_validator
from typing_extensions import Self
from ska_oso_pdm._shared import PdmObject, TerseStrEnum
from .df import PSTDetectedFilterbankParams
from .ft import PSTFlowThroughParams
from .pt import PSTPulsarTimingParams
[docs]
class PSTProcessingMode(TerseStrEnum):
"""
Enumeration of PST processing modes.
"""
VOLTAGE_RECORDER = "VOLTAGE_RECORDER"
FLOW_THROUGH = "FLOW_THROUGH"
DETECTED_FILTERBANK = "DETECTED_FILTERBANK"
PULSAR_TIMING = "PULSAR_TIMING"
[docs]
class PSTConfiguration(PdmObject):
"""
Class to hold PST configurations.
:param pst_processing_mode:
:param ft: Parameters for flow-through mode
:param df: Parameters for detected-filterbank mode
:param pt: Parameters for pulsar-timing mode
"""
pst_processing_mode: PSTProcessingMode = PSTProcessingMode.VOLTAGE_RECORDER
ft: PSTFlowThroughParams | None = None
df: PSTDetectedFilterbankParams | None = None
pt: PSTPulsarTimingParams | None = None
@model_validator(mode="after")
def check_params_match_mode(self) -> Self:
params_tuple = (self.ft, self.df, self.pt)
num_not_nones = len(list(filter(lambda x: x is not None, params_tuple)))
if self.pst_processing_mode == "VOLTAGE_RECORDER" and num_not_nones != 0:
raise ValueError(
"No parameters should be defined for VOLTAGE_RECORDER mode"
)
elif self.pst_processing_mode == "FLOW_THROUGH" and self.ft is None:
raise ValueError("FLOW_THROUGH parameters have not been defined")
elif self.pst_processing_mode == "DETECTED_FILTERBANK" and self.df is None:
raise ValueError("DETECTED_FILTERBANK parameters have not been defined")
elif self.pst_processing_mode == "PULSAR_TIMING" and self.pt is None:
raise ValueError("PULSAR_TIMING parameters have not been defined")
elif self.pst_processing_mode != "VOLTAGE_RECORDER" and num_not_nones > 1:
raise ValueError("Parameters of more than one mode have been defined")
return self