From 1eebd21022cc13ea6abda48d0f4711019229d8d9 Mon Sep 17 00:00:00 2001 From: jupfi Date: Wed, 29 May 2024 10:25:47 +0200 Subject: [PATCH] Moved general methods to base class. --- src/quackseq/spectrometer/spectrometer.py | 22 ++----- .../spectrometer/spectrometer_controller.py | 57 +++++++++++++++++++ 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/src/quackseq/spectrometer/spectrometer.py b/src/quackseq/spectrometer/spectrometer.py index 3def7c3..fc1ba99 100644 --- a/src/quackseq/spectrometer/spectrometer.py +++ b/src/quackseq/spectrometer/spectrometer.py @@ -1,3 +1,6 @@ +from typing import Any + + class Spectrometer(): """Base class for spectrometers. @@ -19,21 +22,4 @@ class Spectrometer(): def set_averages(self, value : int): """Sets the number of averages.""" raise NotImplementedError - - @property - def controller(self): - """The controller of the spectrometer.""" - return self._controller - - @controller.setter - def controller(self, controller): - self._controller = controller - - @property - def model(self): - """The model of the spectrometer.""" - return self._model - - @model.setter - def model(self, model): - self._model = model \ No newline at end of file + \ No newline at end of file diff --git a/src/quackseq/spectrometer/spectrometer_controller.py b/src/quackseq/spectrometer/spectrometer_controller.py index 1f5e64d..9bc1927 100644 --- a/src/quackseq/spectrometer/spectrometer_controller.py +++ b/src/quackseq/spectrometer/spectrometer_controller.py @@ -1,5 +1,12 @@ """Base class for all spectrometer controllers.""" +import logging + +from quackseq.pulseparameters import RXReadout +from quackseq.pulsesequence import QuackSequence + +logger = logging.getLogger(__name__) + class SpectrometerController(): """The base class for all spectrometer controllers.""" @@ -17,3 +24,53 @@ class SpectrometerController(): def set_averages(self, value : int): """Sets the number of averages.""" raise NotImplementedError + + def translate_rx_event(self, sequence: QuackSequence) -> tuple: + """This method translates the RX event of the pulse sequence to the limr object. + + Returns: + tuple: A tuple containing the start and stop time of the RX event in µs + """ + # This is a correction factor for the RX event. The offset of the first pulse is 2.2µs longer than from the specified samples. + events = sequence.events + + previous_events_duration = 0 + # offset = 0 + rx_duration = 0 + for event in events: + logger.debug("Event %s has parameters: %s", event.name, event.parameters) + for parameter in event.parameters.values(): + logger.debug( + "Parameter %s has options: %s", parameter.name, parameter.options + ) + + if ( + parameter.name == sequence.RX_READOUT + and parameter.get_option_by_name(RXReadout.RX).value + ): + # Get the length of all previous events + previous_events = events[: events.index(event)] + previous_events_duration = sum( + [event.duration for event in previous_events] + ) + rx_duration = event.duration + + rx_begin = float(previous_events_duration) + if rx_duration: + rx_stop = rx_begin + float(rx_duration) + return rx_begin * 1e6, rx_stop * 1e6 + + else: + return None, None + + def calculate_simulation_length(self, sequence: QuackSequence) -> float: + """This method calculates the simulation length based on the settings and the pulse sequence. + + Returns: + float: The simulation length in seconds. + """ + events = sequence.events + simulation_length = 0 + for event in events: + simulation_length += event.duration + return simulation_length