Merge branch 'main' into category-settings

This commit is contained in:
Julia P 2024-03-02 21:01:04 +01:00 committed by GitHub
commit 236b5cb30d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 86 additions and 8 deletions

View file

@ -1,16 +1,19 @@
from nqrduck.module.module_controller import ModuleController
class BaseSpectrometerController(ModuleController):
"""The base class for all spectrometer controllers."""
def __init__(self, module):
super().__init__(module)
def start_measurement(self):
"""Starts the measurement.
This method should be called when the measurement is started.
"""
raise NotImplementedError
def set_frequency(self, value):
"""Sets the frequency of the spectrometer."""
raise NotImplementedError
def set_averages(self, value):

View file

@ -7,6 +7,16 @@ from.settings import Setting
logger = logging.getLogger(__name__)
class BaseSpectrometerModel(ModuleModel):
"""The base class for all spectrometer models.
It contains the settings and pulse parameters of the spectrometer.
Arguments:
module (Module) -- The module that the spectrometer is connected to
Attributes:
settings (OrderedDict) -- The settings of the spectrometer
pulse_parameter_options (OrderedDict) -- The pulse parameter options of the spectrometer
"""
settings : OrderedDict
pulse_parameter_options : OrderedDict
@ -21,20 +31,47 @@ class BaseSpectrometerModel(ModuleModel):
name (str) -- The name of the pulse parameter
options (OrderedDict) -- The options of the pulse parameter
"""
def __init__(self, name):
def __init__(self, name : str):
"""Initializes the pulse parameter.
Arguments:
name (str) -- The name of the pulse parameter
"""
self.name = name
self.options = list()
def get_pixmap(self):
raise NotImplementedError
def add_option(self, option):
def add_option(self, option : "Option") -> None:
"""Adds an option to the pulse parameter.
Arguments:
option (Option) -- The option to add
"""
self.options.append(option)
def get_options(self):
def get_options(self) -> list:
""" Gets the options of the pulse parameter.
Returns:
list -- The options of the pulse parameter
"""
return self.options
def get_option_by_name(self, name : str) -> "Option":
"""Gets an option by its name.
Arguments:
name (str) -- The name of the option
Returns:
Option -- The option with the specified name
Raises:
ValueError -- If no option with the specified name is found
"""
for option in self.options:
if option.name == name:
return option
@ -42,27 +79,50 @@ class BaseSpectrometerModel(ModuleModel):
def __init__(self, module):
"""Initializes the spectrometer model.
Arguments:
module (Module) -- The module that the spectrometer is connected to
"""
super().__init__(module)
self.settings = OrderedDict()
self.pulse_parameter_options = OrderedDict()
def add_setting(self, setting : Setting, category : str) -> None:
if category not in self.settings.keys():
self.settings[category] = []
self.settings[category].append(setting)
def get_setting_by_name(self, name : str) -> Setting:
"""Gets a setting by its name.
Arguments:
name (str) -- The name of the setting
Returns:
Setting -- The setting with the specified name
Raises:
ValueError -- If no setting with the specified name is found
"""
for category in self.settings.keys():
for setting in self.settings[category]:
if setting.name == name:
return setting
raise ValueError("Setting with name %s not found" % name)
def add_pulse_parameter_option(self, name, pulse_parameter_class) -> None:
def add_pulse_parameter_option(self, name : str, pulse_parameter_class : PulseParameter) -> None:
""" Adds a pulse parameter option to the spectrometer.
Arguments:
name (str) -- The name of the pulse parameter
pulse_parameter_class (PulseParameter) -- The pulse parameter class"""
self.pulse_parameter_options[name] = pulse_parameter_class
@property
def target_frequency(self):
""" The target frequency of the spectrometer in Hz. This is the frequency where the magnetic resonance experiment is performed. """
raise NotImplementedError
@target_frequency.setter
@ -71,6 +131,7 @@ class BaseSpectrometerModel(ModuleModel):
@property
def averages(self):
""" The number of averages for the spectrometer."""
raise NotImplementedError
@averages.setter

View file

@ -11,11 +11,12 @@ logger = logging.getLogger(__name__)
class BaseSpectrometerView(ModuleView):
"""The View Class for all Spectrometers."""
def __init__(self, module):
super().__init__(module)
def load_settings_ui(self):
def load_settings_ui(self) -> None:
"""This method automatically generates a view for the settings of the module.
If there is a widget file that has been generated by Qt Designer, it will be used. Otherwise, a default view will be generated."""

View file

@ -29,7 +29,11 @@ class Measurement():
# Data saving and loading
def to_json(self):
"""Converts the measurement to a json-compatible format."""
"""Converts the measurement to a json-compatible format.
Returns:
dict -- The measurement in json-compatible format.
"""
return {
"tdx": self.tdx.tolist(),
"tdy": [[x.real, x.imag] for x in self.tdy], # Convert complex numbers to list
@ -39,7 +43,14 @@ class Measurement():
@classmethod
def from_json(cls, json):
"""Converts the json format to a measurement."""
"""Converts the json format to a measurement.
Arguments:
json (dict) -- The measurement in json-compatible format.
Returns:
Measurement -- The measurement.
"""
tdy = np.array([complex(y[0], y[1]) for y in json["tdy"]])
return cls(
np.array(json["tdx"]),

View file

@ -436,6 +436,7 @@ class FunctionOption(Option):
class TXPulse(BaseSpectrometerModel.PulseParameter):
""" Basic TX Pulse Parameter. It includes options for the relative amplitude, the phase and the pulse shape."""
RELATIVE_AMPLITUDE = "Relative TX Amplitude"
TX_PHASE = "TX Phase"
TX_PULSE_SHAPE = "TX Pulse Shape"
@ -460,6 +461,7 @@ class TXPulse(BaseSpectrometerModel.PulseParameter):
class RXReadout(BaseSpectrometerModel.PulseParameter):
"""Basic PulseParameter for the RX Readout. It includes an option for the RX Readout state."""
RX = "RX"
def __init__(self, name) -> None: