Basic implementation of single freq. measurements.

This commit is contained in:
jupfi 2023-07-17 11:28:57 +02:00
parent 896048ab39
commit fb002d0745
3 changed files with 55 additions and 3 deletions

View file

@ -1,8 +1,18 @@
import logging import logging
from nqrduck.module.module_controller import ModuleController from nqrduck.module.module_controller import ModuleController
from nqrduck_spectrometer.measurement import Measurement
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class MeasurementController(ModuleController): class MeasurementController(ModuleController):
def __init__(self, module): def __init__(self, module):
super().__init__(module) super().__init__(module)
def start_measurement(self):
logger.debug("Start measurement clicked")
self.module.nqrduck_signal.emit("start_measurement", None)
def process_signals(self, key: str, value: Measurement):
if key == "single_measurement":
logger.debug("Received single measurement.")
self.module.model.single_measurement = value

View file

@ -1,8 +1,23 @@
import logging import logging
from PyQt6.QtCore import pyqtSignal
from nqrduck_spectrometer.measurement import Measurement
from nqrduck.module.module_model import ModuleModel from nqrduck.module.module_model import ModuleModel
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class MeasurementModel(ModuleModel): class MeasurementModel(ModuleModel):
single_measurement_changed = pyqtSignal(Measurement)
def __init__(self, module) -> None: def __init__(self, module) -> None:
super().__init__(module) super().__init__(module)
@property
def single_measurement(self):
"""Single measurement data."""
return self._single_measurement
@single_measurement.setter
def single_measurement(self, value : Measurement):
self._single_measurement = value
self.single_measurement_changed.emit(value)

View file

@ -1,5 +1,7 @@
import logging import logging
import numpy as np
from PyQt6.QtWidgets import QWidget from PyQt6.QtWidgets import QWidget
from PyQt6.QtCore import pyqtSlot
from .widget import Ui_Form from .widget import Ui_Form
from nqrduck.module.module_view import ModuleView from nqrduck.module.module_view import ModuleView
@ -13,3 +15,28 @@ class MeasurementView(ModuleView):
self._ui_form = Ui_Form() self._ui_form = Ui_Form()
self._ui_form.setupUi(self) self._ui_form.setupUi(self)
self.widget = widget self.widget = widget
# Connect signals
self.module.model.single_measurement_changed.connect(self.update_single_measurement)
self._ui_form.buttonStart.clicked.connect(self.on_measurement_start_button_clicked)
@pyqtSlot()
def update_single_measurement(self):
logger.debug("Updating single measurement view.")
# Set the x data
tdx = self.module.model.single_measurement.tdx
tdy = self.module.model.single_measurement.tdy
#correcting a offset in the time domain by subtracting the mean
tdy_mean = tdy[:,0]-np.mean(tdy)
self._ui_form.plotter.canvas.ax.clear() # Clear the axes for the new plot
self._ui_form.plotter.canvas.ax.plot(tdx, tdy_mean)
self._ui_form.plotter.canvas.ax.set_xlabel("Time (µs)")
self._ui_form.plotter.canvas.ax.set_ylabel("Amplitude (a.u.)")
self._ui_form.plotter.canvas.ax.set_title("Single measurement")
self._ui_form.plotter.canvas.ax.grid()
self._ui_form.plotter.canvas.draw()
@pyqtSlot()
def on_measurement_start_button_clicked(self):
logger.debug("Measurement start button clicked.")
self.module.controller.start_measurement()