Added multidimensional dataset display.

This commit is contained in:
jupfi 2024-06-21 17:32:37 +02:00
parent 1b4160afda
commit a4885926b5
3 changed files with 57 additions and 46 deletions

View file

@ -133,7 +133,6 @@ class MeasurementController(ModuleController):
and self.module.view.measurement_dialog.isVisible() and self.module.view.measurement_dialog.isVisible()
): ):
logger.debug("Received single measurement.") logger.debug("Received single measurement.")
self.module.model.displayed_measurement = value
self.module.model.add_measurement(value) self.module.model.add_measurement(value)
self.module.view.measurement_dialog.hide() self.module.view.measurement_dialog.hide()
@ -264,31 +263,48 @@ class MeasurementController(ModuleController):
dialog.deleteLater() dialog.deleteLater()
@pyqtSlot() @pyqtSlot(Measurement)
def change_displayed_measurement(self, measurement=None) -> None: def change_displayed_measurement(self, measurement) -> None:
"""Change the displayed measurement. """Change the displayed measurement.
If no measurement is provided, the displayed measurement is changed to the selected measurement in the selection box. If no measurement is provided, the displayed measurement is changed to the selected measurement in the selection box.
Args: Args:
measurement (Measurement, optional): The measurement to display. Defaults to None. measurement (Measurement, optional): The measurement to display.
""" """
logger.debug("Changing displayed measurement.")
if not self.module.model.measurements: if not self.module.model.measurements:
logger.debug("No measurements to display.") logger.debug("No measurements to display.")
return return
if not measurement:
index = self.module.view._ui_form.selectionBox.value()
self.module.model.displayed_measurement = self.module.model.measurements[
index
]
logger.debug(
f"Changing displayed measurement to {self.module.model.displayed_measurement.name}."
)
else:
logger.debug(f"Changing displayed measurement to {measurement.name}.")
self.module.model.displayed_measurement = measurement self.module.model.displayed_measurement = measurement
# Adjust the min and max value of the selection box
n_datasets = len(measurement.tdx)
self.module.view._ui_form.selectionBox.setRange(0, n_datasets - 1)
logger.debug(f"Number of datasets: {n_datasets}")
self.module.model.dataset_index = n_datasets - 1
self.module.view.update_displayed_measurement()
@pyqtSlot()
def change_displayed_dataset(self) -> None:
"""Change the displayed dataset.
If no dataset is provided, the displayed dataset is changed to the selected dataset in the selection box.
"""
logger.debug("Changing displayed dataset.")
if not self.module.model.displayed_measurement:
logger.debug("No measurement to display.")
return
index = self.module.view._ui_form.selectionBox.value()
self.module.model.dataset_index = index
self.module.view.update_displayed_measurement()
@pyqtSlot(Measurement) @pyqtSlot(Measurement)
def delete_measurement(self, measurement: Measurement) -> None: def delete_measurement(self, measurement: Measurement) -> None:
"""Delete a measurement. """Delete a measurement.

View file

@ -65,10 +65,13 @@ class MeasurementModel(ModuleModel):
self.measurement_frequency = 100.0 # MHz self.measurement_frequency = 100.0 # MHz
self.averages = 1 self.averages = 1
self.dataset_index = 0
self.frequency_valid = False self.frequency_valid = False
self.averages_valid = False self.averages_valid = False
self.dataset_index = 0
@property @property
def view_mode(self) -> str: def view_mode(self) -> str:
"""View mode of the measurement view. """View mode of the measurement view.
@ -97,9 +100,10 @@ class MeasurementModel(ModuleModel):
self.measurements.append(measurement) self.measurements.append(measurement)
# Change the maximum value of the selectionBox. # Change the maximum value of the selectionBox.
self.measurements_changed.emit(self.measurements) self.measurements_changed.emit(self.measurements)
self.displayed_measurement = measurement
self.displayed_measurement_changed.emit(measurement) self.displayed_measurement_changed.emit(measurement)
def remove_measurement(self, measurement : Measurement): def remove_measurement(self, measurement: Measurement):
"""Remove a measurement from the list of measurements.""" """Remove a measurement from the list of measurements."""
self.measurements.remove(measurement) self.measurements.remove(measurement)
# Change the maximum value of the selectionBox. # Change the maximum value of the selectionBox.
@ -117,12 +121,6 @@ class MeasurementModel(ModuleModel):
@displayed_measurement.setter @displayed_measurement.setter
def displayed_measurement(self, value: Measurement): def displayed_measurement(self, value: Measurement):
self._displayed_measurement = value self._displayed_measurement = value
if value is not None:
logger.debug("Displayed measurement: " + value.name)
self.displayed_measurement_changed.emit(value)
else:
self.module.view.update_displayed_measurement()
@property @property
def measurement_frequency(self): def measurement_frequency(self):
@ -164,3 +162,15 @@ class MeasurementModel(ModuleModel):
@averages_valid.setter @averages_valid.setter
def averages_valid(self, value: bool): def averages_valid(self, value: bool):
self._averages_valid = value self._averages_valid = value
@property
def dataset_index(self) -> int:
"""Index of the displayed dataset.
Every measurement has a number of different data sets associated with it. This index is used to select the data set that is displayed.
"""
return self._dataset_index
@dataset_index.setter
def dataset_index(self, value: int):
self._dataset_index = value

View file

@ -59,7 +59,7 @@ class MeasurementView(ModuleView):
# Connect signals # Connect signals
self.module.model.displayed_measurement_changed.connect( self.module.model.displayed_measurement_changed.connect(
self.update_displayed_measurement self.module.controller.change_displayed_measurement
) )
self.module.model.view_mode_changed.connect(self.update_displayed_measurement) self.module.model.view_mode_changed.connect(self.update_displayed_measurement)
@ -126,7 +126,7 @@ class MeasurementView(ModuleView):
# Connect selectionBox signal for switching the displayed measurement # Connect selectionBox signal for switching the displayed measurement
self._ui_form.selectionBox.valueChanged.connect( self._ui_form.selectionBox.valueChanged.connect(
self.module.controller.change_displayed_measurement self.module.controller.change_displayed_dataset
) )
def init_plotter(self) -> None: def init_plotter(self) -> None:
@ -165,7 +165,6 @@ class MeasurementView(ModuleView):
plotter.canvas.ax.set_title("Measurement data - Frequency domain") plotter.canvas.ax.set_title("Measurement data - Frequency domain")
plotter.canvas.ax.grid() plotter.canvas.ax.grid()
@pyqtSlot()
def update_displayed_measurement(self) -> None: def update_displayed_measurement(self) -> None:
"""Update displayed measurement data.""" """Update displayed measurement data."""
logger.debug("Updating displayed measurement view.") logger.debug("Updating displayed measurement view.")
@ -184,11 +183,13 @@ class MeasurementView(ModuleView):
return return
index = self.module.model.dataset_index
logger.debug(f"Displaying dataset index {index}.")
if self.module.model.view_mode == self.module.model.FFT_VIEW: if self.module.model.view_mode == self.module.model.FFT_VIEW:
self.change_to_fft_view() self.change_to_fft_view()
y = self.module.model.displayed_measurement.fdy[0] y = self.module.model.displayed_measurement.fdy[index]
x = ( x = (
self.module.model.displayed_measurement.fdx[0] self.module.model.displayed_measurement.fdx[index]
+ float( + float(
self.module.model.displayed_measurement.target_frequency self.module.model.displayed_measurement.target_frequency
- self.module.model.displayed_measurement.IF_frequency - self.module.model.displayed_measurement.IF_frequency
@ -197,8 +198,8 @@ class MeasurementView(ModuleView):
) )
else: else:
self.change_to_time_view() self.change_to_time_view()
x = self.module.model.displayed_measurement.tdx[0] x = self.module.model.displayed_measurement.tdx[index]
y = self.module.model.displayed_measurement.tdy[0] y = self.module.model.displayed_measurement.tdy[index]
self._ui_form.plotter.canvas.ax.plot( self._ui_form.plotter.canvas.ax.plot(
x, y.real, label="Real", linestyle="-", alpha=0.35, color="red" x, y.real, label="Real", linestyle="-", alpha=0.35, color="red"
@ -229,14 +230,6 @@ class MeasurementView(ModuleView):
else: else:
item.setSelected(False) item.setSelected(False)
# Update the number of the selectionBox
for measurement in self.module.model.measurements:
if measurement.name == self.module.model.displayed_measurement.name:
self._ui_form.selectionBox.setValue(
self.module.model.measurements.index(measurement)
)
break
except AttributeError as e: except AttributeError as e:
logger.debug(f"No measurement data to display: {e}") logger.debug(f"No measurement data to display: {e}")
@ -328,14 +321,6 @@ class MeasurementView(ModuleView):
"""Slot for when a measurement is added.""" """Slot for when a measurement is added."""
logger.debug("Measurement changed.") logger.debug("Measurement changed.")
if len(self.module.model.measurements) == 0:
self.module.view._ui_form.selectionBox.setMaximum(0)
self.module.view._ui_form.selectionBox.setValue(0)
else:
self.module.view._ui_form.selectionBox.setMaximum(
len(self.module.model.measurements) - 1
)
# Clear the measurements list # Clear the measurements list
self._ui_form.measurementsList.clear() self._ui_form.measurementsList.clear()