mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-11-09 12:30:01 +00:00
Implemented loading and saving of pulse sequences
This commit is contained in:
parent
0611569b57
commit
9bb5696b9d
3 changed files with 45 additions and 13 deletions
|
@ -43,6 +43,7 @@ class BaseSpectrometerModel(ModuleModel):
|
|||
|
||||
def get_options(self):
|
||||
return self.options
|
||||
|
||||
|
||||
def __init__(self, module):
|
||||
super().__init__(module)
|
||||
|
|
|
@ -8,18 +8,19 @@ class Option():
|
|||
def set_value(self):
|
||||
raise NotImplementedError
|
||||
|
||||
class BooleanOption(Option):
|
||||
"""Defines a boolean option for a pulse parameter.
|
||||
"""
|
||||
def __init__(self, state) -> None:
|
||||
super().__init__()
|
||||
self.state = state
|
||||
|
||||
def set_value(self, state):
|
||||
self.state = state
|
||||
class BooleanOption(Option):
|
||||
"""Defines a boolean option for a pulse parameter option.
|
||||
"""
|
||||
def __init__(self, value) -> None:
|
||||
super().__init__()
|
||||
self.value = value
|
||||
|
||||
def set_value(self, value):
|
||||
self.value = value
|
||||
|
||||
class NumericOption(Option):
|
||||
"""Defines a numeric option for a pulse parameter.
|
||||
"""Defines a numeric option for a pulse parameter option.
|
||||
"""
|
||||
def __init__(self, value) -> None:
|
||||
super().__init__()
|
||||
|
@ -29,7 +30,7 @@ class NumericOption(Option):
|
|||
self.value = float(value)
|
||||
|
||||
class WidgetSelectionOption(Option):
|
||||
"""Defines a widget selection option for a pulse parameter.
|
||||
"""Defines a widget selection option for a pulse parameter option.
|
||||
"""
|
||||
def __init__(self, widgets) -> None:
|
||||
super().__init__()
|
||||
|
@ -69,7 +70,7 @@ class RXReadout(BaseSpectrometerModel.PulseParameter):
|
|||
|
||||
def get_pixmap(self):
|
||||
self_path = Path(__file__).parent
|
||||
if self.options["RX"].state == False:
|
||||
if self.options["RX"].value == False:
|
||||
image_path = self_path / "resources/pulseparameter/RXOff.png"
|
||||
else:
|
||||
image_path = self_path / "resources/pulseparameter/RXOn.png"
|
||||
|
|
|
@ -27,6 +27,22 @@ class PulseSequence:
|
|||
logger.debug("Duration of event %s changed to %s", self.name, duration)
|
||||
self.duration = duration
|
||||
|
||||
@classmethod
|
||||
def load_event(cls, event, pulse_parameter_options):
|
||||
"""Loads an event from a dict. The pulse paramter options are needed to load the parameters
|
||||
and determine if the correct spectrometer is active."""
|
||||
obj = cls(event["name"], event["duration"])
|
||||
for parameter in event["parameters"]:
|
||||
for pulse_parameter_option in pulse_parameter_options.keys():
|
||||
# This checks if the pulse paramter options are the same as the ones in the pulse sequence
|
||||
if pulse_parameter_option == parameter["name"]:
|
||||
pulse_paramter_class = pulse_parameter_options[pulse_parameter_option]
|
||||
obj.parameters[pulse_parameter_option] = pulse_paramter_class(parameter["name"])
|
||||
for option in parameter["value"]:
|
||||
obj.parameters[pulse_parameter_option].options[option["name"]].value = option["value"]
|
||||
|
||||
return obj
|
||||
|
||||
def dump_sequence_data(self):
|
||||
"""Returns a dict with all the data in the pulse sequence"""
|
||||
data = {
|
||||
|
@ -42,7 +58,21 @@ class PulseSequence:
|
|||
for parameter in event.parameters.keys():
|
||||
event_data["parameters"].append({
|
||||
"name": parameter,
|
||||
"value": event.parameters[parameter].get_options()
|
||||
"value": []
|
||||
})
|
||||
for option in event.parameters[parameter].options.keys():
|
||||
event_data["parameters"][-1]["value"].append({
|
||||
"name": option,
|
||||
"value": event.parameters[parameter].options[option].value
|
||||
})
|
||||
data["events"].append(event_data)
|
||||
return data
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def load_sequence(cls, sequence, pulse_parameter_options):
|
||||
obj = cls(sequence["name"])
|
||||
for event_data in sequence["events"]:
|
||||
obj.events.append(cls.Event.load_event(event_data, pulse_parameter_options))
|
||||
|
||||
return obj
|
||||
|
||||
|
|
Loading…
Reference in a new issue