Moved general methods to base class.

This commit is contained in:
jupfi 2024-05-29 10:25:47 +02:00
parent 0ec31e541d
commit 1eebd21022
2 changed files with 61 additions and 18 deletions

View file

@ -1,3 +1,6 @@
from typing import Any
class Spectrometer():
"""Base class for spectrometers.
@ -20,20 +23,3 @@ class Spectrometer():
"""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

View file

@ -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