diff --git a/src/nqrduck_measurement/controller.py b/src/nqrduck_measurement/controller.py index dcf8137..5270d04 100644 --- a/src/nqrduck_measurement/controller.py +++ b/src/nqrduck_measurement/controller.py @@ -1,8 +1,18 @@ import logging from nqrduck.module.module_controller import ModuleController +from nqrduck_spectrometer.measurement import Measurement logger = logging.getLogger(__name__) class MeasurementController(ModuleController): def __init__(self, module): - super().__init__(module) \ No newline at end of file + 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 diff --git a/src/nqrduck_measurement/model.py b/src/nqrduck_measurement/model.py index ba7e885..803987d 100644 --- a/src/nqrduck_measurement/model.py +++ b/src/nqrduck_measurement/model.py @@ -1,8 +1,23 @@ import logging +from PyQt6.QtCore import pyqtSignal +from nqrduck_spectrometer.measurement import Measurement from nqrduck.module.module_model import ModuleModel logger = logging.getLogger(__name__) class MeasurementModel(ModuleModel): + + single_measurement_changed = pyqtSignal(Measurement) + def __init__(self, module) -> None: - super().__init__(module) \ No newline at end of file + 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) diff --git a/src/nqrduck_measurement/view.py b/src/nqrduck_measurement/view.py index a10f8ab..429a7e2 100644 --- a/src/nqrduck_measurement/view.py +++ b/src/nqrduck_measurement/view.py @@ -1,5 +1,7 @@ import logging +import numpy as np from PyQt6.QtWidgets import QWidget +from PyQt6.QtCore import pyqtSlot from .widget import Ui_Form from nqrduck.module.module_view import ModuleView @@ -12,4 +14,29 @@ class MeasurementView(ModuleView): widget = QWidget() self._ui_form = Ui_Form() self._ui_form.setupUi(self) - self.widget = widget \ No newline at end of file + 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() \ No newline at end of file