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 numpy as np
from nqrduck_spectrometer.base_spectrometer_controller import BaseSpectrometerController
@ -11,11 +13,15 @@ logger = logging.getLogger(__name__)
class SimulatorController(BaseSpectrometerController):
"""The controller class for the nqrduck simulator module."""
def __init__(self, module):
"""Initializes the SimulatorController."""
super().__init__(module)
def start_measurement(self):
"""This method is called when the start_measurement signal is received from the core.
It will becalled if the simulator is the active spectrometer.
This will start the simulation based on the settings and the pulse sequence.
"""
@ -31,7 +37,8 @@ class SimulatorController(BaseSpectrometerController):
except ValueError:
logger.warning("Could not translate pulse sequence")
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
@ -206,7 +213,7 @@ class SimulatorController(BaseSpectrometerController):
"""
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(
sample=sample,
pulse=pulse_array,
@ -276,7 +283,7 @@ class SimulatorController(BaseSpectrometerController):
events = self.module.model.pulse_programmer.model.pulse_sequence.events
previous_events_duration = 0
offset = 0
# offset = 0
rx_duration = 0
for event in events:
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:
"""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.
Args:
value (str) : The new frequency in MHz.
"""
logger.debug("Setting frequency to: %s", value)
try:
@ -321,6 +332,7 @@ class SimulatorController(BaseSpectrometerController):
def set_averages(self, value: str) -> None:
"""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.
Args:

View file

@ -1,3 +1,5 @@
"""The model module for the simulator spectrometer."""
import logging
from nqrduck_spectrometer.base_spectrometer_model import BaseSpectrometerModel
from nqrduck_spectrometer.pulseparameters import TXPulse, RXReadout
@ -11,6 +13,8 @@ logger = logging.getLogger(__name__)
class SimulatorModel(BaseSpectrometerModel):
"""Model class for the simulator spectrometer."""
# Simulation settings
NUMBER_POINTS = "N. simulation points"
NUMBER_ISOCHROMATS = "N. of isochromats"
@ -61,6 +65,7 @@ class SimulatorModel(BaseSpectrometerModel):
RX = "RX"
def __init__(self, module):
"""Initializes the SimulatorModel."""
super().__init__(module)
# 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.",
min_value=0.1,
)
self.add_setting(
power_amplifier_power_setting, self.HARDWARE
)
self.add_setting(power_amplifier_power_setting, self.HARDWARE)
gain_setting = FloatSetting(
self.GAIN,
@ -171,9 +174,7 @@ class SimulatorModel(BaseSpectrometerModel):
"The amplification factor of the receiver chain, impacting the final measured signal amplitude.",
min_value=0.1,
)
self.add_setting(
gain_setting, self.HARDWARE
)
self.add_setting(gain_setting, self.HARDWARE)
temperature_setting = FloatSetting(
self.TEMPERATURE,
@ -245,9 +246,7 @@ class SimulatorModel(BaseSpectrometerModel):
"The resonant frequency of the observed transition.",
min_value=1e5,
)
self.add_setting(
resonant_frequency_setting, self.SAMPLE
)
self.add_setting(resonant_frequency_setting, self.SAMPLE)
gamma_setting = FloatSetting(
self.GAMMA,
@ -263,7 +262,6 @@ class SimulatorModel(BaseSpectrometerModel):
9 / 2,
"The nuclear spin of the samples nuclei.",
min_value=0,
)
self.add_setting(nuclear_spin_setting, self.SAMPLE)
@ -339,6 +337,10 @@ class SimulatorModel(BaseSpectrometerModel):
@property
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
@averages.setter
@ -347,9 +349,12 @@ class SimulatorModel(BaseSpectrometerModel):
@property
def target_frequency(self):
"""The target frequency for the simulation.
Doesn't do anything at the moment.
"""
return self._target_frequency
@target_frequency.setter
def target_frequency(self, value):
self._target_frequency = value

View file

@ -1,3 +1,5 @@
"""Creation of the Simulator Spectrometer."""
from nqrduck_spectrometer.base_spectrometer import BaseSpectrometer
from .model import SimulatorModel
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
class SimulatorView(BaseSpectrometerView):
"""The View class for the simulator module."""
def __init__(self, module):
"""Initializes the SimulatorView."""
super().__init__(module)
# This automatically generates the settings widget based on the settings in the model
self.widget = self.load_settings_ui()