mirror of
https://github.com/nqrduck/nqrduck-measurement.git
synced 2024-12-22 07:40:29 +00:00
Added multidimensional dataset display.
This commit is contained in:
parent
1b4160afda
commit
a4885926b5
3 changed files with 57 additions and 46 deletions
|
@ -133,7 +133,6 @@ class MeasurementController(ModuleController):
|
|||
and self.module.view.measurement_dialog.isVisible()
|
||||
):
|
||||
logger.debug("Received single measurement.")
|
||||
self.module.model.displayed_measurement = value
|
||||
self.module.model.add_measurement(value)
|
||||
self.module.view.measurement_dialog.hide()
|
||||
|
||||
|
@ -264,30 +263,47 @@ class MeasurementController(ModuleController):
|
|||
|
||||
dialog.deleteLater()
|
||||
|
||||
@pyqtSlot()
|
||||
def change_displayed_measurement(self, measurement=None) -> None:
|
||||
@pyqtSlot(Measurement)
|
||||
def change_displayed_measurement(self, measurement) -> None:
|
||||
"""Change the displayed measurement.
|
||||
|
||||
If no measurement is provided, the displayed measurement is changed to the selected measurement in the selection box.
|
||||
|
||||
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:
|
||||
logger.debug("No measurements to display.")
|
||||
return
|
||||
|
||||
self.module.model.displayed_measurement = measurement
|
||||
|
||||
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
|
||||
# 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)
|
||||
def delete_measurement(self, measurement: Measurement) -> None:
|
||||
|
|
|
@ -50,7 +50,7 @@ class MeasurementModel(ModuleModel):
|
|||
|
||||
displayed_measurement_changed = pyqtSignal(Measurement)
|
||||
measurements_changed = pyqtSignal(list)
|
||||
|
||||
|
||||
view_mode_changed = pyqtSignal(str)
|
||||
|
||||
measurement_frequency_changed = pyqtSignal(float)
|
||||
|
@ -65,10 +65,13 @@ class MeasurementModel(ModuleModel):
|
|||
|
||||
self.measurement_frequency = 100.0 # MHz
|
||||
self.averages = 1
|
||||
self.dataset_index = 0
|
||||
|
||||
self.frequency_valid = False
|
||||
self.averages_valid = False
|
||||
|
||||
self.dataset_index = 0
|
||||
|
||||
@property
|
||||
def view_mode(self) -> str:
|
||||
"""View mode of the measurement view.
|
||||
|
@ -97,9 +100,10 @@ class MeasurementModel(ModuleModel):
|
|||
self.measurements.append(measurement)
|
||||
# Change the maximum value of the selectionBox.
|
||||
self.measurements_changed.emit(self.measurements)
|
||||
self.displayed_measurement = 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."""
|
||||
self.measurements.remove(measurement)
|
||||
# Change the maximum value of the selectionBox.
|
||||
|
@ -117,12 +121,6 @@ class MeasurementModel(ModuleModel):
|
|||
@displayed_measurement.setter
|
||||
def displayed_measurement(self, value: Measurement):
|
||||
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
|
||||
def measurement_frequency(self):
|
||||
|
@ -164,3 +162,15 @@ class MeasurementModel(ModuleModel):
|
|||
@averages_valid.setter
|
||||
def averages_valid(self, value: bool):
|
||||
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
|
||||
|
|
|
@ -59,7 +59,7 @@ class MeasurementView(ModuleView):
|
|||
|
||||
# Connect signals
|
||||
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)
|
||||
|
||||
|
@ -126,7 +126,7 @@ class MeasurementView(ModuleView):
|
|||
|
||||
# Connect selectionBox signal for switching the displayed measurement
|
||||
self._ui_form.selectionBox.valueChanged.connect(
|
||||
self.module.controller.change_displayed_measurement
|
||||
self.module.controller.change_displayed_dataset
|
||||
)
|
||||
|
||||
def init_plotter(self) -> None:
|
||||
|
@ -165,7 +165,6 @@ class MeasurementView(ModuleView):
|
|||
plotter.canvas.ax.set_title("Measurement data - Frequency domain")
|
||||
plotter.canvas.ax.grid()
|
||||
|
||||
@pyqtSlot()
|
||||
def update_displayed_measurement(self) -> None:
|
||||
"""Update displayed measurement data."""
|
||||
logger.debug("Updating displayed measurement view.")
|
||||
|
@ -184,11 +183,13 @@ class MeasurementView(ModuleView):
|
|||
|
||||
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:
|
||||
self.change_to_fft_view()
|
||||
y = self.module.model.displayed_measurement.fdy[0]
|
||||
y = self.module.model.displayed_measurement.fdy[index]
|
||||
x = (
|
||||
self.module.model.displayed_measurement.fdx[0]
|
||||
self.module.model.displayed_measurement.fdx[index]
|
||||
+ float(
|
||||
self.module.model.displayed_measurement.target_frequency
|
||||
- self.module.model.displayed_measurement.IF_frequency
|
||||
|
@ -197,8 +198,8 @@ class MeasurementView(ModuleView):
|
|||
)
|
||||
else:
|
||||
self.change_to_time_view()
|
||||
x = self.module.model.displayed_measurement.tdx[0]
|
||||
y = self.module.model.displayed_measurement.tdy[0]
|
||||
x = self.module.model.displayed_measurement.tdx[index]
|
||||
y = self.module.model.displayed_measurement.tdy[index]
|
||||
|
||||
self._ui_form.plotter.canvas.ax.plot(
|
||||
x, y.real, label="Real", linestyle="-", alpha=0.35, color="red"
|
||||
|
@ -229,14 +230,6 @@ class MeasurementView(ModuleView):
|
|||
else:
|
||||
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:
|
||||
logger.debug(f"No measurement data to display: {e}")
|
||||
|
||||
|
@ -328,14 +321,6 @@ class MeasurementView(ModuleView):
|
|||
"""Slot for when a measurement is added."""
|
||||
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
|
||||
self._ui_form.measurementsList.clear()
|
||||
|
||||
|
|
Loading…
Reference in a new issue