mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-11-09 12:30:01 +00:00
Added saving of version to pulsesequence.
This commit is contained in:
parent
27b43fc494
commit
9d1b0fb3ac
1 changed files with 10 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""Contains the PulseSequence class that is used to store a pulse sequence and its events."""
|
"""Contains the PulseSequence class that is used to store a pulse sequence and its events."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import importlib.metadata
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from nqrduck.helpers.unitconverter import UnitConverter
|
from nqrduck.helpers.unitconverter import UnitConverter
|
||||||
from nqrduck_spectrometer.pulseparameters import Option
|
from nqrduck_spectrometer.pulseparameters import Option
|
||||||
|
@ -19,9 +20,14 @@ class PulseSequence:
|
||||||
events (list): The events of the pulse sequence
|
events (list): The events of the pulse sequence
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name) -> None:
|
def __init__(self, name, version = None) -> None:
|
||||||
"""Initializes the pulse sequence."""
|
"""Initializes the pulse sequence."""
|
||||||
self.name = name
|
self.name = name
|
||||||
|
# Saving version to check for compatability of saved sequence
|
||||||
|
if version is not None:
|
||||||
|
self.version = version
|
||||||
|
else:
|
||||||
|
self.version = importlib.metadata.version("nqrduck_spectrometer")
|
||||||
self.events = list()
|
self.events = list()
|
||||||
|
|
||||||
def get_event_names(self) -> list:
|
def get_event_names(self) -> list:
|
||||||
|
@ -125,7 +131,8 @@ class PulseSequence:
|
||||||
Returns:
|
Returns:
|
||||||
dict: The dict with the sequence data
|
dict: The dict with the sequence data
|
||||||
"""
|
"""
|
||||||
data = {"name": self.name, "events": []}
|
# Get the versions of this package
|
||||||
|
data = {"name": self.name, "version" : self.version, "events": []}
|
||||||
for event in self.events:
|
for event in self.events:
|
||||||
event_data = {
|
event_data = {
|
||||||
"name": event.name,
|
"name": event.name,
|
||||||
|
@ -156,7 +163,7 @@ class PulseSequence:
|
||||||
Raises:
|
Raises:
|
||||||
KeyError: If the pulse parameter options are not the same as the ones in the pulse sequence
|
KeyError: If the pulse parameter options are not the same as the ones in the pulse sequence
|
||||||
"""
|
"""
|
||||||
obj = cls(sequence["name"])
|
obj = cls(sequence["name"], version = sequence["version"])
|
||||||
for event_data in sequence["events"]:
|
for event_data in sequence["events"]:
|
||||||
obj.events.append(cls.Event.load_event(event_data, pulse_parameter_options))
|
obj.events.append(cls.Event.load_event(event_data, pulse_parameter_options))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue