Skip to content

Commit

Permalink
Merge pull request #421 from linien-org/feature/fix-psd-algorithm-sel…
Browse files Browse the repository at this point in the history
…ection

Fix PSD algorithm selection
  • Loading branch information
bleykauf authored Aug 14, 2024
2 parents a12e620 + bed8fdb commit 08ffe3e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

* Fixed example code in the readme by @bleykauf in https://github.com/linien-org/linien/pull/420, thanks to @Andrew-wi for reporting this issue
* Fixed a bug preventing the selection of a PSD algorithm via the GUI by @bleykauf in https://github.com/linien-org/linien/pull/421, thanks to @martinssonh for reporting this issue

## [2.0.4] - 2024-05-30

Expand Down
8 changes: 5 additions & 3 deletions linien-gui/linien_gui/ui/psd_plot_widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2018-2022 Benjamin Wiegand <[email protected]>
# Copyright 2021-2022 Bastian Leykauf <[email protected]>
# Copyright 2021-2024 Bastian Leykauf <[email protected]>
#
# This file is part of Linien and based on redpid.
#
Expand Down Expand Up @@ -212,7 +212,9 @@ def show_cursor_position(self, show):
self.cursor_label.setVisible(show)

def leaveEvent(self, QEvent):
"""This method is called when the mouse used to hover the plot and
not left. In this case, we hide crosshair and cursor label."""
"""
This method is called when the mouse used to hover the plot and not left. In
this case, we hide crosshair and cursor label.
"""
super().leaveEvent(QEvent)
self.show_cursor_position(False)
64 changes: 37 additions & 27 deletions linien-gui/linien_gui/ui/psd_window.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2018-2022 Benjamin Wiegand <[email protected]>
# Copyright 2021-2022 Bastian Leykauf <[email protected]>
# Copyright 2021-2024 Bastian Leykauf <[email protected]>
#
# This file is part of Linien and based on redpid.
#
Expand All @@ -23,6 +23,8 @@
from linien_common.common import PSDAlgorithm
from linien_gui.config import UI_PATH
from linien_gui.dialogs import error_dialog
from linien_gui.ui.psd_plot_widget import PSDPlotWidget
from linien_gui.ui.psd_table_widget import PSDTableWidget
from linien_gui.utils import (
RandomColorChoser,
get_linien_app_instance,
Expand All @@ -33,6 +35,18 @@


class PSDWindow(QtWidgets.QMainWindow):
PSDPlot: PSDPlotWidget
curveTable: PSDTableWidget
maxMeasurementTimeComboBox: QtWidgets.QComboBox
PSDAlgorithmComboBox: QtWidgets.QComboBox
startPSDPushButton: QtWidgets.QPushButton
stopPSDPushButton: QtWidgets.QPushButton
exportPSDPushButton: QtWidgets.QPushButton
importPSDPushButton: QtWidgets.QPushButton
deleteCurveButton: QtWidgets.QPushButton
PSDRunningContainer: QtWidgets.QWidget
PSDNotRunningContainer: QtWidgets.QGroupBox

def __init__(self, *args, **kwargs):
super(PSDWindow, self).__init__(*args, **kwargs)
uic.loadUi(UI_PATH / "psd_window.ui", self)
Expand All @@ -46,21 +60,19 @@ def __init__(self, *args, **kwargs):
self.data = {}
self.complete_uids = []

self.start_psd_button.clicked.connect(self.start_psd)
self.stop_psd_button.clicked.connect(self.stop_psd)
self.startPSDPushButton.clicked.connect(self.start_psd)
self.stopPSDPushButton.clicked.connect(self.stop_psd)

self.curve_table.show_or_hide_curve.connect(
self.psd_plot_widget.show_or_hide_curve
)
self.delete_curve_button.clicked.connect(self.delete_curve)
self.export_psd_button.clicked.connect(self.export_psd)
self.import_psd_button.clicked.connect(self.import_psd)
self.curveTable.show_or_hide_curve.connect(self.PSDPlot.show_or_hide_curve)
self.deleteCurveButton.clicked.connect(self.delete_curve)
self.exportPSDPushButton.clicked.connect(self.export_psd)
self.importPSDPushButton.clicked.connect(self.import_psd)

self.maximum_measurement_time.currentIndexChanged.connect(
self.change_maximum_measurement_time
self.maxMeasurementTimeComboBox.currentIndexChanged.connect(
self.on_maximum_measurement_time_changed
)

self.psd_algorithm.currentIndexChanged.connect(self.change_psd_algorithm)
self.PSDAlgorithmComboBox.currentIndexChanged.connect(self.change_psd_algorithm)

def on_connection_established(self):
self.parameters = self.app.parameters
Expand All @@ -75,19 +87,19 @@ def on_connection_established(self):

param2ui(
self.parameters.psd_acquisition_max_decimation,
self.maximum_measurement_time,
self.maxMeasurementTimeComboBox,
lambda max_decimation: max_decimation - 12,
)
param2ui(self.parameters.psd_algorithm, self.psd_algorithm)
param2ui(self.parameters.psd_algorithm, self.PSDAlgorithmComboBox)

def update_status(_):
psd_running = self.parameters.psd_acquisition_running.value
if psd_running:
self.container_psd_running.show()
self.container_psd_not_running.hide()
self.PSDRunningContainer.show()
self.PSDNotRunningContainer.hide()
else:
self.container_psd_running.hide()
self.container_psd_not_running.show()
self.PSDRunningContainer.hide()
self.PSDNotRunningContainer.show()

self.parameters.psd_acquisition_running.add_callback(update_status)

Expand All @@ -97,13 +109,11 @@ def closeEvent(self, event, *args, **kwargs):
event.ignore()
self.hide()

def change_maximum_measurement_time(self, index):
def on_maximum_measurement_time_changed(self, index):
self.parameters.psd_acquisition_max_decimation.value = 12 + index

def change_psd_algorithm(self, index):
self.parameters.psd_algorithm.value = [PSDAlgorithm.LPSD, PSDAlgorithm.WELCH][
index
]
def change_psd_algorithm(self, index: int) -> None:
self.parameters.psd_algorithm.value = list(PSDAlgorithm)[index]

def psd_data_received(self, data_pickled):
if data_pickled is None:
Expand All @@ -130,8 +140,8 @@ def psd_data_received(self, data_pickled):
else:
color = self.colors[curve_uuid]

self.psd_plot_widget.plot_curve(curve_uuid, data["psds"], color)
self.curve_table.add_curve(curve_uuid, data, color)
self.PSDPlot.plot_curve(curve_uuid, data["psds"], color)
self.curveTable.add_curve(curve_uuid, data, color)

self.data[curve_uuid] = data

Expand All @@ -150,9 +160,9 @@ def start_pid_optimization(self):
self.control.start_pid_optimization()

def delete_curve(self):
uuid = self.curve_table.delete_selected_curve()
uuid = self.curveTable.delete_selected_curve()
if uuid is not None:
self.psd_plot_widget.delete_curve(uuid)
self.PSDPlot.delete_curve(uuid)
del self.data[uuid]

def export_psd(self):
Expand Down
24 changes: 12 additions & 12 deletions linien-gui/linien_gui/ui/psd_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="PSDPlotWidget" name="psd_plot_widget">
<widget class="PSDPlotWidget" name="PSDPlot">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
Expand Down Expand Up @@ -46,7 +46,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QComboBox" name="maximum_measurement_time">
<widget class="QComboBox" name="maxMeasurementTimeComboBox">
<property name="currentIndex">
<number>5</number>
</property>
Expand Down Expand Up @@ -161,13 +161,13 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<widget class="QGroupBox" name="algorithmGroupBox">
<property name="title">
<string>Algorithm</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QComboBox" name="psd_algorithm">
<widget class="QComboBox" name="PSDAlgorithmComboBox">
<item>
<property name="text">
<string>LPSD</string>
Expand All @@ -184,13 +184,13 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="container_psd_not_running">
<widget class="QGroupBox" name="PSDNotRunningContainer">
<property name="title">
<string>Single PSD measurement</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="start_psd_button">
<widget class="QPushButton" name="startPSDPushButton">
<property name="font">
<font>
<weight>75</weight>
Expand All @@ -209,7 +209,7 @@
</widget>
</item>
<item>
<widget class="QWidget" name="container_psd_running" native="true">
<widget class="QWidget" name="PSDRunningContainer" native="true">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_2">
Expand All @@ -232,7 +232,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="stop_psd_button">
<widget class="QPushButton" name="stopPSDPushButton">
<property name="styleSheet">
<string notr="true">background-color: #d40000;</string>
</property>
Expand All @@ -245,7 +245,7 @@
</widget>
</item>
<item>
<widget class="PSDTableWidget" name="curve_table">
<widget class="PSDTableWidget" name="curveTable">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
Expand Down Expand Up @@ -290,7 +290,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="delete_curve_button">
<widget class="QPushButton" name="deleteCurveButton">
<property name="text">
<string>Delete selected</string>
</property>
Expand All @@ -302,14 +302,14 @@
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="import_psd_button">
<widget class="QPushButton" name="importPSDPushButton">
<property name="text">
<string>Import traces</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="export_psd_button">
<widget class="QPushButton" name="exportPSDPushButton">
<property name="text">
<string>Export traces</string>
</property>
Expand Down
2 changes: 1 addition & 1 deletion linien-server/linien_server/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def __init__(self):

self.psd_data_partial = Parameter(start=None)
self.psd_data_complete = Parameter(start=None)
self.psd_algorithm = Parameter(start=PSDAlgorithm.LPSD)
self.psd_algorithm = Parameter(start=PSDAlgorithm.LPSD, restorable=True)
self.psd_acquisition_running = Parameter(start=False)
self.psd_optimization_running = Parameter(start=False)
self.psd_acquisition_max_decimation = Parameter(
Expand Down

0 comments on commit 08ffe3e

Please sign in to comment.