mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-11-09 20:40:02 +00:00
Added docstrings.
This commit is contained in:
parent
8d90f89092
commit
de7f966afd
5 changed files with 104 additions and 10 deletions
|
@ -1,16 +1,19 @@
|
||||||
from nqrduck.module.module_controller import ModuleController
|
from nqrduck.module.module_controller import ModuleController
|
||||||
|
|
||||||
class BaseSpectrometerController(ModuleController):
|
class BaseSpectrometerController(ModuleController):
|
||||||
|
"""The base class for all spectrometer controllers."""
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
super().__init__(module)
|
super().__init__(module)
|
||||||
|
|
||||||
def start_measurement(self):
|
def start_measurement(self):
|
||||||
"""Starts the measurement.
|
"""Starts the measurement.
|
||||||
|
This method should be called when the measurement is started.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def set_frequency(self, value):
|
def set_frequency(self, value):
|
||||||
|
"""Sets the frequency of the spectrometer."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def set_averages(self, value):
|
def set_averages(self, value):
|
||||||
|
|
|
@ -6,15 +6,33 @@ from nqrduck.module.module_model import ModuleModel
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class BaseSpectrometerModel(ModuleModel):
|
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
|
settings : OrderedDict
|
||||||
pulse_parameter_options : OrderedDict
|
pulse_parameter_options : OrderedDict
|
||||||
|
|
||||||
class Setting(QObject):
|
class Setting(QObject):
|
||||||
"""A setting for the spectrometer is a value that is the same for all events in a pulse sequence.
|
"""A setting for the spectrometer is a value that is the same for all events in a pulse sequence.
|
||||||
E.g. the number of averages or the number of points in a spectrum."""
|
E.g. the number of averages or the number of points in a spectrum.
|
||||||
|
"""
|
||||||
settings_changed = pyqtSignal()
|
settings_changed = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, name, default, description) -> None:
|
def __init__(self, name : str, default : str, description : str) -> None:
|
||||||
|
"""Initializes the setting.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
name (str) -- The name of the setting
|
||||||
|
default (str) -- The default value of the setting
|
||||||
|
description (str) -- The description of the setting
|
||||||
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.name = name
|
self.name = name
|
||||||
self.value = default
|
self.value = default
|
||||||
|
@ -28,6 +46,7 @@ class BaseSpectrometerModel(ModuleModel):
|
||||||
|
|
||||||
def get_setting(self):
|
def get_setting(self):
|
||||||
return float(self.value)
|
return float(self.value)
|
||||||
|
|
||||||
class PulseParameter:
|
class PulseParameter:
|
||||||
"""A pulse parameter is a value that can be different for each event in a pulse sequence.
|
"""A pulse parameter is a value that can be different for each event in a pulse sequence.
|
||||||
E.g. the transmit pulse power or the phase of the transmit pulse.
|
E.g. the transmit pulse power or the phase of the transmit pulse.
|
||||||
|
@ -39,20 +58,47 @@ class BaseSpectrometerModel(ModuleModel):
|
||||||
name (str) -- The name of the pulse parameter
|
name (str) -- The name of the pulse parameter
|
||||||
options (OrderedDict) -- The options 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.name = name
|
||||||
self.options = list()
|
self.options = list()
|
||||||
|
|
||||||
def get_pixmap(self):
|
def get_pixmap(self):
|
||||||
raise NotImplementedError
|
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)
|
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
|
return self.options
|
||||||
|
|
||||||
def get_option_by_name(self, name : str) -> "Option":
|
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:
|
for option in self.options:
|
||||||
if option.name == name:
|
if option.name == name:
|
||||||
return option
|
return option
|
||||||
|
@ -60,27 +106,57 @@ class BaseSpectrometerModel(ModuleModel):
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
|
"""Initializes the spectrometer model.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
module (Module) -- The module that the spectrometer is connected to
|
||||||
|
"""
|
||||||
super().__init__(module)
|
super().__init__(module)
|
||||||
self.settings = OrderedDict()
|
self.settings = OrderedDict()
|
||||||
self.pulse_parameter_options = OrderedDict()
|
self.pulse_parameter_options = OrderedDict()
|
||||||
|
|
||||||
def add_setting(self, name, value, description, category) -> None:
|
def add_setting(self, name : str, value: str, description : str, category : str) -> None:
|
||||||
|
"""Adds a setting to the spectrometer.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
name (str) -- The name of the setting
|
||||||
|
value (str) -- The default value of the setting
|
||||||
|
description (str) -- The description of the setting
|
||||||
|
category (str) -- The category of the setting
|
||||||
|
"""
|
||||||
if category not in self.settings.keys():
|
if category not in self.settings.keys():
|
||||||
self.settings[category] = []
|
self.settings[category] = []
|
||||||
self.settings[category].append(self.Setting(name, value, description))
|
self.settings[category].append(self.Setting(name, value, description))
|
||||||
|
|
||||||
def get_setting_by_name(self, name : str) -> 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 category in self.settings.keys():
|
||||||
for setting in self.settings[category]:
|
for setting in self.settings[category]:
|
||||||
if setting.name == name:
|
if setting.name == name:
|
||||||
return setting
|
return setting
|
||||||
raise ValueError("Setting with name %s not found" % name)
|
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
|
self.pulse_parameter_options[name] = pulse_parameter_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_frequency(self):
|
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
|
raise NotImplementedError
|
||||||
|
|
||||||
@target_frequency.setter
|
@target_frequency.setter
|
||||||
|
@ -89,6 +165,7 @@ class BaseSpectrometerModel(ModuleModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def averages(self):
|
def averages(self):
|
||||||
|
""" The number of averages for the spectrometer."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@averages.setter
|
@averages.setter
|
||||||
|
|
|
@ -10,11 +10,12 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BaseSpectrometerView(ModuleView):
|
class BaseSpectrometerView(ModuleView):
|
||||||
|
"""The View Class for all Spectrometers."""
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
super().__init__(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.
|
"""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."""
|
If there is a widget file that has been generated by Qt Designer, it will be used. Otherwise, a default view will be generated."""
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,11 @@ class Measurement():
|
||||||
# Data saving and loading
|
# Data saving and loading
|
||||||
|
|
||||||
def to_json(self):
|
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 {
|
return {
|
||||||
"tdx": self.tdx.tolist(),
|
"tdx": self.tdx.tolist(),
|
||||||
"tdy": [[x.real, x.imag] for x in self.tdy], # Convert complex numbers to list
|
"tdy": [[x.real, x.imag] for x in self.tdy], # Convert complex numbers to list
|
||||||
|
@ -39,7 +43,14 @@ class Measurement():
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, json):
|
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"]])
|
tdy = np.array([complex(y[0], y[1]) for y in json["tdy"]])
|
||||||
return cls(
|
return cls(
|
||||||
np.array(json["tdx"]),
|
np.array(json["tdx"]),
|
||||||
|
|
|
@ -436,6 +436,7 @@ class FunctionOption(Option):
|
||||||
|
|
||||||
|
|
||||||
class TXPulse(BaseSpectrometerModel.PulseParameter):
|
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"
|
RELATIVE_AMPLITUDE = "Relative TX Amplitude"
|
||||||
TX_PHASE = "TX Phase"
|
TX_PHASE = "TX Phase"
|
||||||
TX_PULSE_SHAPE = "TX Pulse Shape"
|
TX_PULSE_SHAPE = "TX Pulse Shape"
|
||||||
|
@ -460,6 +461,7 @@ class TXPulse(BaseSpectrometerModel.PulseParameter):
|
||||||
|
|
||||||
|
|
||||||
class RXReadout(BaseSpectrometerModel.PulseParameter):
|
class RXReadout(BaseSpectrometerModel.PulseParameter):
|
||||||
|
"""Basic PulseParameter for the RX Readout. It includes an option for the RX Readout state."""
|
||||||
RX = "RX"
|
RX = "RX"
|
||||||
|
|
||||||
def __init__(self, name) -> None:
|
def __init__(self, name) -> None:
|
||||||
|
|
Loading…
Reference in a new issue