From b2a3881fa8dc52553f73b2d740ea4a8f92bc2481 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Wed, 11 Sep 2024 15:33:00 +0000 Subject: [PATCH] dev (#285) Co-authored-by: Dominik Demuth Reviewed-on: https://gitea.pkm.physik.tu-darmstadt.de/IPKM/nmreval/pulls/285 --- src/gui_qt/_py/ptstab.py | 11 +++++++---- src/gui_qt/data/point_select.py | 6 +++--- src/nmreval/data/points.py | 12 +++++++++--- src/resources/_ui/ptstab.ui | 7 ++++++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/gui_qt/_py/ptstab.py b/src/gui_qt/_py/ptstab.py index 677b38b..211722f 100644 --- a/src/gui_qt/_py/ptstab.py +++ b/src/gui_qt/_py/ptstab.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'resources/_ui/ptstab.ui' +# Form implementation generated from reading ui file './nmreval/src/resources/_ui/ptstab.ui' # -# Created by: PyQt5 UI code generator 5.12.3 +# Created by: PyQt5 UI code generator 5.15.10 # -# WARNING! All changes made in this file will be lost! +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. from PyQt5 import QtCore, QtGui, QtWidgets @@ -45,6 +46,7 @@ class Ui_Form(object): self.average_combobox.addItem("") self.average_combobox.addItem("") self.average_combobox.addItem("") + self.average_combobox.addItem("") self.horizontalLayout.addWidget(self.average_combobox) self.verticalLayout.addWidget(self.groupBox) self.groupBox_2 = QtWidgets.QGroupBox(Form) @@ -111,7 +113,7 @@ class Ui_Form(object): "Single number for points (e.g. 1e-6); \n" "two numbers separated by space for regions (e.g. 1e-6 5e-6). \n" "Changing between regions and points is NOT possible")) - self.groupBox.setTitle(_translate("Form", "Average")) + self.groupBox.setTitle(_translate("Form", "Average (drop-down used for pts and regions)")) self.left_pt.setSuffix(_translate("Form", " pts")) self.left_pt.setPrefix(_translate("Form", "- ")) self.right_pt.setSuffix(_translate("Form", " pts")) @@ -119,6 +121,7 @@ class Ui_Form(object): self.average_combobox.setItemText(0, _translate("Form", "Mean")) self.average_combobox.setItemText(1, _translate("Form", "Sum")) self.average_combobox.setItemText(2, _translate("Form", "Integral")) + self.average_combobox.setItemText(3, _translate("Form", "Std. deviation")) self.groupBox_2.setTitle(_translate("Form", "Special value")) self.special_comboBox.setToolTip(_translate("Form", "Automatic selection of respective points")) self.special_comboBox.setItemText(0, _translate("Form", "max(y)")) diff --git a/src/gui_qt/data/point_select.py b/src/gui_qt/data/point_select.py index 512e5e8..377ee38 100644 --- a/src/gui_qt/data/point_select.py +++ b/src/gui_qt/data/point_select.py @@ -91,7 +91,7 @@ class PointSelectWidget(QtWidgets.QWidget, Ui_Form): item = QtWidgets.QListWidgetItem(f'{self.pts[-1][0]:.5g} - {self.pts[-1][1]:.5g}') else: item = QtWidgets.QListWidgetItem(f'{self.pts[-1]:.5g}') - item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable) + item.setFlags(item.flags() ^ QtCore.Qt.ItemFlag.ItemIsEditable) self.peaktable.blockSignals(True) self.peaktable.addItem(item) self.peaktable.blockSignals(False) @@ -103,7 +103,7 @@ class PointSelectWidget(QtWidgets.QWidget, Ui_Form): @QtCore.pyqtSlot() def apply(self) -> dict: ret_dic = {'avg_range': [self.left_pt.value(), self.right_pt.value()], - 'avg_mode': {0: 'mean', 1: 'sum', 2: 'integral'}[self.average_combobox.currentIndex()], + 'avg_mode': {0: 'mean', 1: 'sum', 2: 'integral', 3: 'std'}[self.average_combobox.currentIndex()], 'special': None, 'idx': None, 'xy': (self.xbutton.isChecked(), self.ybutton.isChecked())} @@ -199,4 +199,4 @@ class PointSelectWidget(QtWidgets.QWidget, Ui_Form): @QtCore.pyqtSlot(int, name='on_graph_checkbox_stateChanged') def changed_state(self, checked): - self.graph_combobox.setEnabled(checked != QtCore.Qt.Checked) + self.graph_combobox.setEnabled(checked != QtCore.Qt.CheckState.Checked) diff --git a/src/nmreval/data/points.py b/src/nmreval/data/points.py index 1f891ae..656c685 100644 --- a/src/nmreval/data/points.py +++ b/src/nmreval/data/points.py @@ -294,7 +294,7 @@ class Points: avg_range (tuple of int) : Region for average of y values. Tuple (a, b) uses ``y[i-a:i+b+1]`` around index `i`. Default is (0, 0). - avg_mode (str {'mean', 'sum', 'integral'} , optional) : + avg_mode (str {'mean', 'sum', 'integral', 'std'} , optional) : Averaging type `mean` : Arithmetic average @@ -303,6 +303,8 @@ class Points: 'integral`: Integration over range using Simpson's rule + 'std': Standard deviation + pts (list, optional) : If given, points will be appended. @@ -313,8 +315,8 @@ class Points: if (idx is None) and (special is None): raise ValueError('Either `idx` or `special` must be given') - if avg_mode not in ['mean', 'sum', 'integral']: - raise ValueError(f'Parameter `avg_mode` is `mean`, `sum`, `integral`, not `{avg_mode}`' ) + if avg_mode not in ['mean', 'sum', 'integral', 'std']: + raise ValueError(f'Parameter `avg_mode` is `mean`, `sum`, `integral`, `std`, not `{avg_mode}`' ) if pts is None: pts = [] @@ -388,6 +390,10 @@ class Points: y_mean = simpson(y[left:right].real, x=x[left:right]) y_err_mean = np.linalg.norm(cumulative_trapezoid(y_err[left:right].real, x=x[left:right])) + elif mode == 'std': + y_mean = np.std(y[left:right]) + y_err_mean = 0. + else: y_mean = y[idx].real y_err_mean = y_err[idx] diff --git a/src/resources/_ui/ptstab.ui b/src/resources/_ui/ptstab.ui index 7ae4e05..d7c31ef 100644 --- a/src/resources/_ui/ptstab.ui +++ b/src/resources/_ui/ptstab.ui @@ -42,7 +42,7 @@ Changing between regions and points is NOT possible - Average + Average (drop-down used for pts and regions) @@ -109,6 +109,11 @@ Changing between regions and points is NOT possible Integral + + + Std. deviation + +