From 1703b8d514d69b900bebab8028dfd92120f28337 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 15 Jun 2023 19:57:13 +0200 Subject: [PATCH] add binning --- src/gui_qt/data/container.py | 7 +++++++ src/gui_qt/main/mainwindow.py | 9 +++++++++ src/gui_qt/main/management.py | 9 +++++++++ src/gui_qt/math/binning.py | 21 +++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 src/gui_qt/math/binning.py diff --git a/src/gui_qt/data/container.py b/src/gui_qt/data/container.py index b4c2d69..667f577 100644 --- a/src/gui_qt/data/container.py +++ b/src/gui_qt/data/container.py @@ -480,6 +480,13 @@ class ExperimentContainer(QtCore.QObject): return new_data + def binning(self, digits: int): + new_data = self.copy(full=True) + new_data.data = self._data.binning(decimals=digits) + print(new_data.x) + + return new_data + class PointContainer(ExperimentContainer): symbols = symbolcycle() diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index 3e0a406..7409c8a 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -25,6 +25,7 @@ from ..io.filedialog import * from ..lib import get_icon, make_action_icons from ..lib.pg_objects import RegionItem from ..lib.starter import make_starter +from ..math.binning import BinningWindow from ..math.evaluation import QEvalDialog from ..math.interpol import InterpolDialog from ..math.mean_dialog import QMeanTimes @@ -696,6 +697,14 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.eval.exec() + @QtCore.pyqtSlot(name='on_actionBinning_triggered') + def open_binning(self): + dialog = BinningWindow(self) + res = dialog.exec() + if res: + digits = dialog.spinbox.value() + self.management.binning(digits) + @QtCore.pyqtSlot(name='on_actionDerivation_triggered') # @QtCore.pyqtSlot(name='on_actionIntegration_triggered') @QtCore.pyqtSlot(name='on_actionFilon_triggered') diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 0a817c1..f4b13c6 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -766,6 +766,15 @@ class UpperManagement(QtCore.QObject): self.newData.emit(new_key, dest_graph) + def binning(self, digits: int): + _active = self.graphs[self.current_graph].active + new_data = [] + for sid in _active: + key = self.add(self.data[sid].binning(digits=digits)) + new_data.append(key) + + self.newData.emit(new_data, '') + @QtCore.pyqtSlot(int, dict) def smooth_data(self, npoints, param_kwargs): _active = self.graphs[self.current_graph].active diff --git a/src/gui_qt/math/binning.py b/src/gui_qt/math/binning.py new file mode 100644 index 0000000..5bafd16 --- /dev/null +++ b/src/gui_qt/math/binning.py @@ -0,0 +1,21 @@ +from ..Qt import QtWidgets + + +class BinningWindow(QtWidgets.QDialog): + def __init__(self, parent=None): + super().__init__(parent=parent) + + layout = QtWidgets.QFormLayout() + + self.label = QtWidgets.QLabel('Digits (negative values position left of decimal point)') + self.spinbox = QtWidgets.QSpinBox() + self.spinbox.setMinimum(-10) + self.spinbox.setMaximum(10) + layout.addRow(self.label, self.spinbox) + + self.dialogbox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel) + self.dialogbox.accepted.connect(self.accept) + self.dialogbox.rejected.connect(self.reject) + layout.addWidget(self.dialogbox) + + self.setLayout(layout)