This commit is contained in:
jupfi 2024-04-29 19:40:37 +02:00
parent 8bd826c49f
commit 1ebda98a0b
5 changed files with 45 additions and 19 deletions

View file

@ -0,0 +1 @@
"""Init file for the nqrduck_spectrometer_simulator package."""

View file

@ -1,3 +1,5 @@
"""The controller module for the simulator spectrometer."""
import logging import logging
import numpy as np import numpy as np
from nqrduck_spectrometer.base_spectrometer_controller import BaseSpectrometerController from nqrduck_spectrometer.base_spectrometer_controller import BaseSpectrometerController
@ -11,11 +13,15 @@ logger = logging.getLogger(__name__)
class SimulatorController(BaseSpectrometerController): class SimulatorController(BaseSpectrometerController):
"""The controller class for the nqrduck simulator module."""
def __init__(self, module): def __init__(self, module):
"""Initializes the SimulatorController."""
super().__init__(module) super().__init__(module)
def start_measurement(self): def start_measurement(self):
"""This method is called when the start_measurement signal is received from the core. """This method is called when the start_measurement signal is received from the core.
It will becalled if the simulator is the active spectrometer. It will becalled if the simulator is the active spectrometer.
This will start the simulation based on the settings and the pulse sequence. This will start the simulation based on the settings and the pulse sequence.
""" """
@ -31,7 +37,8 @@ class SimulatorController(BaseSpectrometerController):
except ValueError: except ValueError:
logger.warning("Could not translate pulse sequence") logger.warning("Could not translate pulse sequence")
self.module.nqrduck_signal.emit( self.module.nqrduck_signal.emit(
"measurement_error", "Could not translate pulse sequence. Did you configure one?" "measurement_error",
"Could not translate pulse sequence. Did you configure one?",
) )
return return
@ -206,7 +213,7 @@ class SimulatorController(BaseSpectrometerController):
""" """
model = self.module.model model = self.module.model
noise = float(model.get_setting_by_name(model.NOISE).value) # noise = float(model.get_setting_by_name(model.NOISE).value)
simulation = Simulation( simulation = Simulation(
sample=sample, sample=sample,
pulse=pulse_array, pulse=pulse_array,
@ -276,7 +283,7 @@ class SimulatorController(BaseSpectrometerController):
events = self.module.model.pulse_programmer.model.pulse_sequence.events events = self.module.model.pulse_programmer.model.pulse_sequence.events
previous_events_duration = 0 previous_events_duration = 0
offset = 0 # offset = 0
rx_duration = 0 rx_duration = 0
for event in events: for event in events:
logger.debug("Event %s has parameters: %s", event.name, event.parameters) logger.debug("Event %s has parameters: %s", event.name, event.parameters)
@ -306,7 +313,11 @@ class SimulatorController(BaseSpectrometerController):
def set_frequency(self, value: str) -> None: def set_frequency(self, value: str) -> None:
"""This method is called when the set_frequency signal is received from the core. """This method is called when the set_frequency signal is received from the core.
For the simulator this just prints a warning that the simulator is selected. For the simulator this just prints a warning that the simulator is selected.
Args:
value (str) : The new frequency in MHz.
""" """
logger.debug("Setting frequency to: %s", value) logger.debug("Setting frequency to: %s", value)
try: try:
@ -321,6 +332,7 @@ class SimulatorController(BaseSpectrometerController):
def set_averages(self, value: str) -> None: def set_averages(self, value: str) -> None:
"""This method is called when the set_averages signal is received from the core. """This method is called when the set_averages signal is received from the core.
It sets the averages in the model used for the simulation. It sets the averages in the model used for the simulation.
Args: Args:

View file

@ -1,3 +1,5 @@
"""The model module for the simulator spectrometer."""
import logging import logging
from nqrduck_spectrometer.base_spectrometer_model import BaseSpectrometerModel from nqrduck_spectrometer.base_spectrometer_model import BaseSpectrometerModel
from nqrduck_spectrometer.pulseparameters import TXPulse, RXReadout from nqrduck_spectrometer.pulseparameters import TXPulse, RXReadout
@ -11,6 +13,8 @@ logger = logging.getLogger(__name__)
class SimulatorModel(BaseSpectrometerModel): class SimulatorModel(BaseSpectrometerModel):
"""Model class for the simulator spectrometer."""
# Simulation settings # Simulation settings
NUMBER_POINTS = "N. simulation points" NUMBER_POINTS = "N. simulation points"
NUMBER_ISOCHROMATS = "N. of isochromats" NUMBER_ISOCHROMATS = "N. of isochromats"
@ -61,6 +65,7 @@ class SimulatorModel(BaseSpectrometerModel):
RX = "RX" RX = "RX"
def __init__(self, module): def __init__(self, module):
"""Initializes the SimulatorModel."""
super().__init__(module) super().__init__(module)
# Simulation settings # Simulation settings
@ -161,9 +166,7 @@ class SimulatorModel(BaseSpectrometerModel):
"The power output capability of the power amplifier, determines the strength of pulses that can be generated.", "The power output capability of the power amplifier, determines the strength of pulses that can be generated.",
min_value=0.1, min_value=0.1,
) )
self.add_setting( self.add_setting(power_amplifier_power_setting, self.HARDWARE)
power_amplifier_power_setting, self.HARDWARE
)
gain_setting = FloatSetting( gain_setting = FloatSetting(
self.GAIN, self.GAIN,
@ -171,9 +174,7 @@ class SimulatorModel(BaseSpectrometerModel):
"The amplification factor of the receiver chain, impacting the final measured signal amplitude.", "The amplification factor of the receiver chain, impacting the final measured signal amplitude.",
min_value=0.1, min_value=0.1,
) )
self.add_setting( self.add_setting(gain_setting, self.HARDWARE)
gain_setting, self.HARDWARE
)
temperature_setting = FloatSetting( temperature_setting = FloatSetting(
self.TEMPERATURE, self.TEMPERATURE,
@ -245,9 +246,7 @@ class SimulatorModel(BaseSpectrometerModel):
"The resonant frequency of the observed transition.", "The resonant frequency of the observed transition.",
min_value=1e5, min_value=1e5,
) )
self.add_setting( self.add_setting(resonant_frequency_setting, self.SAMPLE)
resonant_frequency_setting, self.SAMPLE
)
gamma_setting = FloatSetting( gamma_setting = FloatSetting(
self.GAMMA, self.GAMMA,
@ -263,7 +262,6 @@ class SimulatorModel(BaseSpectrometerModel):
9 / 2, 9 / 2,
"The nuclear spin of the samples nuclei.", "The nuclear spin of the samples nuclei.",
min_value=0, min_value=0,
) )
self.add_setting(nuclear_spin_setting, self.SAMPLE) self.add_setting(nuclear_spin_setting, self.SAMPLE)
@ -325,7 +323,7 @@ class SimulatorModel(BaseSpectrometerModel):
self.add_pulse_parameter_option(self.RX, RXReadout) self.add_pulse_parameter_option(self.RX, RXReadout)
self.averages = 1 self.averages = 1
self.target_frequency = 100e6 self.target_frequency = 100e6
# Try to load the pulse programmer module # Try to load the pulse programmer module
try: try:
@ -339,6 +337,10 @@ class SimulatorModel(BaseSpectrometerModel):
@property @property
def averages(self): def averages(self):
"""The number of averages used for the simulation.
More averages improve the signal-to-noise ratio of the simulated signal.
"""
return self._averages return self._averages
@averages.setter @averages.setter
@ -347,9 +349,12 @@ class SimulatorModel(BaseSpectrometerModel):
@property @property
def target_frequency(self): def target_frequency(self):
"""The target frequency for the simulation.
Doesn't do anything at the moment.
"""
return self._target_frequency return self._target_frequency
@target_frequency.setter @target_frequency.setter
def target_frequency(self, value): def target_frequency(self, value):
self._target_frequency = value self._target_frequency = value

View file

@ -1,3 +1,5 @@
"""Creation of the Simulator Spectrometer."""
from nqrduck_spectrometer.base_spectrometer import BaseSpectrometer from nqrduck_spectrometer.base_spectrometer import BaseSpectrometer
from .model import SimulatorModel from .model import SimulatorModel
from .view import SimulatorView from .view import SimulatorView

View file

@ -1,7 +1,13 @@
"""The View class for the simulator module."""
from nqrduck_spectrometer.base_spectrometer_view import BaseSpectrometerView from nqrduck_spectrometer.base_spectrometer_view import BaseSpectrometerView
class SimulatorView(BaseSpectrometerView): class SimulatorView(BaseSpectrometerView):
"""The View class for the simulator module."""
def __init__(self, module): def __init__(self, module):
"""Initializes the SimulatorView."""
super().__init__(module) super().__init__(module)
# This automatically generates the settings widget based on the settings in the model # This automatically generates the settings widget based on the settings in the model
self.widget = self.load_settings_ui() self.widget = self.load_settings_ui()