Added methods for event creation and deletion.

This commit is contained in:
jupfi 2024-05-28 16:48:20 +02:00
parent bd40004dd3
commit b77ba30085
2 changed files with 56 additions and 4 deletions

View file

@ -8,6 +8,7 @@ from __future__ import annotations
import logging
from numpy.core.multiarray import array as array
from PyQt6.QtCore import pyqtSignal
from nqrduck.assets.icons import PulseParamters
from nqrduck.helpers.functions import (
@ -37,6 +38,7 @@ class Option:
"""
subclasses = []
value_changed = pyqtSignal()
def __init_subclass__(cls, **kwargs):
"""Adds the subclass to the list of subclasses."""
@ -98,13 +100,20 @@ class BooleanOption(Option):
def set_value(self, value):
"""Sets the value of the option."""
self.value = value
self.value_changed.emit()
class NumericOption(Option):
"""Defines a numeric option for a pulse parameter option."""
def __init__(
self, name: str, value, is_float=True, min_value=None, max_value=None
self,
name: str,
value,
is_float=True,
min_value=None,
max_value=None,
slider=False,
) -> None:
"""Initializes the NumericOption.
@ -114,18 +123,22 @@ class NumericOption(Option):
is_float (bool): If the value is a float.
min_value: The minimum value of the option.
max_value: The maximum value of the option.
slider (bool): If the option should be displayed as a slider.
"""
super().__init__(name, value)
self.is_float = is_float
self.min_value = min_value
self.max_value = max_value
self.slider = slider
def set_value(self, value):
"""Sets the value of the option."""
if value < self.min_value:
self.value = self.min_value
self.value_changed.emit()
elif value >= self.max_value:
self.value = self.max_value
self.value_changed.emit()
else:
raise ValueError(
f"Value {value} is not in the range of {self.min_value} to {self.max_value}. This should have been cought earlier."
@ -192,6 +205,7 @@ class FunctionOption(Option):
value: The value of the option.
"""
self.value = value
self.value_changed.emit()
def get_function_by_name(self, name):
"""Returns the function with the given name.
@ -316,6 +330,8 @@ class TXPulse(BaseSpectrometerModel.PulseParameter):
RELATIVE_AMPLITUDE = "Relative TX Amplitude (%)"
TX_PHASE = "TX Phase"
TX_PULSE_SHAPE = "TX Pulse Shape"
N_PHASE_CYCLES = "Number of Phase Cycles"
PHASE_CYCLE_LEVEL = "Phase Cycle Level"
def __init__(self, name: str) -> None:
"""Initializes the TX Pulse Parameter.
@ -325,10 +341,25 @@ class TXPulse(BaseSpectrometerModel.PulseParameter):
super().__init__(name)
self.add_option(
NumericOption(
self.RELATIVE_AMPLITUDE, 0, is_float=False, min_value=0, max_value=100
self.RELATIVE_AMPLITUDE,
0,
is_float=False,
min_value=0,
max_value=100,
slider=True,
)
)
self.add_option(NumericOption(self.TX_PHASE, 0))
self.add_option(
NumericOption(
self.N_PHASE_CYCLES, 1, is_float=False, min_value=1, max_value=360
)
)
self.add_option(
NumericOption(
self.PHASE_CYCLE_LEVEL, 0, is_float=False, min_value=0, max_value=10
)
)
self.add_option(
FunctionOption(
self.TX_PULSE_SHAPE,

View file

@ -38,6 +38,27 @@ class PulseSequence:
"""
return [event.name for event in self.events]
def add_event(self, event_name: str, duration: float) -> None:
"""Add a new event to the pulse sequence.
Args:
event_name (str): The name of the event
duration (float): The duration of the event
"""
self.events.append(self.Event(event_name, f"{float(duration):.16g}u"))
def delete_event(self, event_name: str) -> None:
"""Deletes an event from the pulse sequence.
Args:
event_name (str): The name of the event to delete
"""
for event in self.events:
if event.name == event_name:
self.events.remove(event)
break
class Event:
"""An event is a part of a pulse sequence. It has a name and a duration and different parameters that have to be set.