From f05d28f6e64120b87255bdbd698dc420d1e9d8da Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sat, 7 Jan 2023 19:13:13 +0100 Subject: [PATCH] added autophase; fixes T217 --- src/gui_qt/_py/editsignalwidget.py | 213 ++++++++++-------- src/gui_qt/data/container.py | 3 +- src/gui_qt/data/datawidget/datawidget.py | 4 +- .../data/signaledit/editsignalwidget.py | 41 ++-- src/gui_qt/data/signaledit/phase_dialog.py | 2 +- src/gui_qt/lib/undos.py | 15 ++ src/gui_qt/main/management.py | 5 +- src/nmreval/data/signals.py | 5 +- src/resources/_ui/editsignalwidget.ui | 121 ++++++---- 9 files changed, 237 insertions(+), 172 deletions(-) diff --git a/src/gui_qt/_py/editsignalwidget.py b/src/gui_qt/_py/editsignalwidget.py index 1dacbd5..227e705 100644 --- a/src/gui_qt/_py/editsignalwidget.py +++ b/src/gui_qt/_py/editsignalwidget.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'resources/_ui/editsignalwidget.ui' +# Form implementation generated from reading ui file 'src/resources/_ui/editsignalwidget.ui' # -# Created by: PyQt5 UI code generator 5.15.4 +# Created by: PyQt5 UI code generator 5.15.2 # # 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. @@ -19,74 +19,91 @@ class Ui_Form(object): self.verticalLayout.setContentsMargins(3, 3, 3, 3) self.verticalLayout.setSpacing(3) self.verticalLayout.setObjectName("verticalLayout") - self.groupBox_4 = QtWidgets.QGroupBox(Form) - self.groupBox_4.setObjectName("groupBox_4") - self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.groupBox_4) + self.baseline_box = QtWidgets.QGroupBox(Form) + self.baseline_box.setObjectName("baseline_box") + self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.baseline_box) self.horizontalLayout_3.setContentsMargins(3, 3, 3, 3) self.horizontalLayout_3.setObjectName("horizontalLayout_3") - self.baselinebutton = QtWidgets.QPushButton(self.groupBox_4) + self.baselinebutton = QtWidgets.QPushButton(self.baseline_box) self.baselinebutton.setObjectName("baselinebutton") self.horizontalLayout_3.addWidget(self.baselinebutton) - self.verticalLayout.addWidget(self.groupBox_4) - self.groupBox = QtWidgets.QGroupBox(Form) - self.groupBox.setObjectName("groupBox") - self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBox) + self.verticalLayout.addWidget(self.baseline_box) + self.leftshift_box = QtWidgets.QGroupBox(Form) + self.leftshift_box.setObjectName("leftshift_box") + self.gridLayout_3 = QtWidgets.QGridLayout(self.leftshift_box) self.gridLayout_3.setContentsMargins(3, 3, 3, 3) self.gridLayout_3.setObjectName("gridLayout_3") - self.leftshiftbutton = QtWidgets.QPushButton(self.groupBox) + self.leftshiftbutton = QtWidgets.QPushButton(self.leftshift_box) self.leftshiftbutton.setObjectName("leftshiftbutton") self.gridLayout_3.addWidget(self.leftshiftbutton, 1, 0, 1, 2) - self.comboBox = QtWidgets.QComboBox(self.groupBox) - self.comboBox.setObjectName("comboBox") - self.comboBox.addItem("") - self.comboBox.addItem("") - self.gridLayout_3.addWidget(self.comboBox, 0, 0, 1, 1) + self.leftshift_comboBox = QtWidgets.QComboBox(self.leftshift_box) + self.leftshift_comboBox.setObjectName("leftshift_comboBox") + self.leftshift_comboBox.addItem("") + self.leftshift_comboBox.addItem("") + self.gridLayout_3.addWidget(self.leftshift_comboBox, 0, 0, 1, 1) self.verticalLayout_2 = QtWidgets.QVBoxLayout() self.verticalLayout_2.setContentsMargins(-1, 0, -1, -1) self.verticalLayout_2.setSpacing(0) self.verticalLayout_2.setObjectName("verticalLayout_2") - self.lsspinBox = QtWidgets.QSpinBox(self.groupBox) - self.lsspinBox.setMaximum(9999) - self.lsspinBox.setObjectName("lsspinBox") - self.verticalLayout_2.addWidget(self.lsspinBox) - self.lineEdit = QtWidgets.QLineEdit(self.groupBox) - self.lineEdit.setObjectName("lineEdit") - self.verticalLayout_2.addWidget(self.lineEdit) + self.ls_spinBox = QtWidgets.QSpinBox(self.leftshift_box) + self.ls_spinBox.setMaximum(9999) + self.ls_spinBox.setObjectName("ls_spinBox") + self.verticalLayout_2.addWidget(self.ls_spinBox) + self.ls_lineEdit = QtWidgets.QLineEdit(self.leftshift_box) + self.ls_lineEdit.setObjectName("ls_lineEdit") + self.verticalLayout_2.addWidget(self.ls_lineEdit) self.gridLayout_3.addLayout(self.verticalLayout_2, 0, 1, 1, 1) - self.verticalLayout.addWidget(self.groupBox) - self.groupBox_6 = QtWidgets.QGroupBox(Form) - self.groupBox_6.setFlat(False) - self.groupBox_6.setObjectName("groupBox_6") - self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.groupBox_6) + self.verticalLayout.addWidget(self.leftshift_box) + self.zerofill_box = QtWidgets.QGroupBox(Form) + self.zerofill_box.setFlat(False) + self.zerofill_box.setObjectName("zerofill_box") + self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.zerofill_box) self.horizontalLayout_4.setContentsMargins(3, 3, 3, 3) self.horizontalLayout_4.setObjectName("horizontalLayout_4") - self.zfbutton = QtWidgets.QPushButton(self.groupBox_6) + self.zfbutton = QtWidgets.QPushButton(self.zerofill_box) self.zfbutton.setObjectName("zfbutton") self.horizontalLayout_4.addWidget(self.zfbutton) - self.verticalLayout.addWidget(self.groupBox_6) - self.groupBox_2 = QtWidgets.QGroupBox(Form) - self.groupBox_2.setFlat(False) - self.groupBox_2.setObjectName("groupBox_2") - self.gridLayout_4 = QtWidgets.QGridLayout(self.groupBox_2) + self.verticalLayout.addWidget(self.zerofill_box) + self.phase_box = QtWidgets.QGroupBox(Form) + self.phase_box.setFlat(False) + self.phase_box.setObjectName("phase_box") + self.gridLayout_4 = QtWidgets.QGridLayout(self.phase_box) self.gridLayout_4.setContentsMargins(3, 3, 3, 3) self.gridLayout_4.setVerticalSpacing(0) self.gridLayout_4.setObjectName("gridLayout_4") - self.ph1slider = QtWidgets.QDoubleSpinBox(self.groupBox_2) + self.label_8 = QtWidgets.QLabel(self.phase_box) + self.label_8.setObjectName("label_8") + self.gridLayout_4.addWidget(self.label_8, 7, 0, 1, 1) + self.phase_prev_button = QtWidgets.QPushButton(self.phase_box) + self.phase_prev_button.setObjectName("phase_prev_button") + self.gridLayout_4.addWidget(self.phase_prev_button, 9, 0, 1, 1) + self.ph0slider = QtWidgets.QDoubleSpinBox(self.phase_box) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.ph0slider.sizePolicy().hasHeightForWidth()) + self.ph0slider.setSizePolicy(sizePolicy) + self.ph0slider.setWrapping(True) + self.ph0slider.setMinimum(-180.0) + self.ph0slider.setMaximum(180.0) + self.ph0slider.setObjectName("ph0slider") + self.gridLayout_4.addWidget(self.ph0slider, 2, 1, 1, 1) + self.ph1slider = QtWidgets.QDoubleSpinBox(self.phase_box) + self.ph1slider.setWrapping(True) self.ph1slider.setMinimum(-360.0) self.ph1slider.setMaximum(360.0) - self.ph1slider.setWrapping(True) self.ph1slider.setObjectName("ph1slider") self.gridLayout_4.addWidget(self.ph1slider, 5, 1, 1, 1) - self.label_6 = QtWidgets.QLabel(self.groupBox_2) + self.phasebutton = QtWidgets.QPushButton(self.phase_box) + self.phasebutton.setObjectName("phasebutton") + self.gridLayout_4.addWidget(self.phasebutton, 9, 1, 1, 1) + self.label_6 = QtWidgets.QLabel(self.phase_box) self.label_6.setObjectName("label_6") self.gridLayout_4.addWidget(self.label_6, 4, 0, 3, 1) - self.pushButton_2 = QtWidgets.QPushButton(self.groupBox_2) - self.pushButton_2.setObjectName("pushButton_2") - self.gridLayout_4.addWidget(self.pushButton_2, 8, 0, 1, 1) - self.label = QtWidgets.QLabel(self.groupBox_2) + self.label = QtWidgets.QLabel(self.phase_box) self.label.setObjectName("label") self.gridLayout_4.addWidget(self.label, 1, 0, 3, 1) - self.pivot_lineedit = QtWidgets.QLineEdit(self.groupBox_2) + self.pivot_lineedit = QtWidgets.QLineEdit(self.phase_box) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -95,91 +112,93 @@ class Ui_Form(object): self.pivot_lineedit.setInputMethodHints(QtCore.Qt.ImhDigitsOnly) self.pivot_lineedit.setObjectName("pivot_lineedit") self.gridLayout_4.addWidget(self.pivot_lineedit, 7, 1, 1, 1) - self.ph0slider = QtWidgets.QDoubleSpinBox(self.groupBox_2) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.ph0slider.sizePolicy().hasHeightForWidth()) - self.ph0slider.setSizePolicy(sizePolicy) - self.ph0slider.setMinimum(-180.0) - self.ph0slider.setMaximum(180.0) - self.ph0slider.setWrapping(True) - self.ph0slider.setObjectName("ph0slider") - self.gridLayout_4.addWidget(self.ph0slider, 2, 1, 1, 1) - self.label_8 = QtWidgets.QLabel(self.groupBox_2) - self.label_8.setObjectName("label_8") - self.gridLayout_4.addWidget(self.label_8, 7, 0, 1, 1) - self.phasebutton = QtWidgets.QPushButton(self.groupBox_2) - self.phasebutton.setObjectName("phasebutton") - self.gridLayout_4.addWidget(self.phasebutton, 8, 1, 1, 1) - self.verticalLayout.addWidget(self.groupBox_2) - self.groupBox_3 = QtWidgets.QGroupBox(Form) + self.autophase_check = QtWidgets.QCheckBox(self.phase_box) + self.autophase_check.setObjectName("autophase_check") + self.gridLayout_4.addWidget(self.autophase_check, 8, 0, 1, 2) + self.verticalLayout.addWidget(self.phase_box) + self.apod_box = QtWidgets.QGroupBox(Form) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.groupBox_3.sizePolicy().hasHeightForWidth()) - self.groupBox_3.setSizePolicy(sizePolicy) - self.groupBox_3.setObjectName("groupBox_3") - self.verticalLayout_7 = QtWidgets.QVBoxLayout(self.groupBox_3) + sizePolicy.setHeightForWidth(self.apod_box.sizePolicy().hasHeightForWidth()) + self.apod_box.setSizePolicy(sizePolicy) + self.apod_box.setObjectName("apod_box") + self.verticalLayout_7 = QtWidgets.QVBoxLayout(self.apod_box) self.verticalLayout_7.setContentsMargins(3, 3, 3, 3) self.verticalLayout_7.setObjectName("verticalLayout_7") - self.apodcombobox = QtWidgets.QComboBox(self.groupBox_3) + self.apodcombobox = QtWidgets.QComboBox(self.apod_box) self.apodcombobox.setObjectName("apodcombobox") self.verticalLayout_7.addWidget(self.apodcombobox) - self.label_2 = QtWidgets.QLabel(self.groupBox_3) - self.label_2.setIndent(3) - self.label_2.setObjectName("label_2") - self.verticalLayout_7.addWidget(self.label_2) - self.verticalLayout_8 = QtWidgets.QVBoxLayout() - self.verticalLayout_8.setSpacing(0) - self.verticalLayout_8.setObjectName("verticalLayout_8") - self.verticalLayout_7.addLayout(self.verticalLayout_8) + self.apod_name_label = QtWidgets.QLabel(self.apod_box) + self.apod_name_label.setIndent(3) + self.apod_name_label.setObjectName("apod_name_label") + self.verticalLayout_7.addWidget(self.apod_name_label) + self.apod_layout = QtWidgets.QVBoxLayout() + self.apod_layout.setSpacing(0) + self.apod_layout.setObjectName("apod_layout") + self.verticalLayout_7.addLayout(self.apod_layout) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") - self.pushButton = QtWidgets.QPushButton(self.groupBox_3) - self.pushButton.setObjectName("pushButton") - self.horizontalLayout.addWidget(self.pushButton) - self.apodbutton = QtWidgets.QPushButton(self.groupBox_3) + self.apod_prev_button = QtWidgets.QPushButton(self.apod_box) + self.apod_prev_button.setObjectName("apod_prev_button") + self.horizontalLayout.addWidget(self.apod_prev_button) + self.apodbutton = QtWidgets.QPushButton(self.apod_box) self.apodbutton.setObjectName("apodbutton") self.horizontalLayout.addWidget(self.apodbutton) self.verticalLayout_7.addLayout(self.horizontalLayout) - self.verticalLayout.addWidget(self.groupBox_3) - self.groupBox_5 = QtWidgets.QGroupBox(Form) - self.groupBox_5.setObjectName("groupBox_5") - self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.groupBox_5) + self.verticalLayout.addWidget(self.apod_box) + self.fft_box = QtWidgets.QGroupBox(Form) + self.fft_box.setObjectName("fft_box") + self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.fft_box) self.horizontalLayout_5.setContentsMargins(3, 3, 3, 3) self.horizontalLayout_5.setObjectName("horizontalLayout_5") - self.fourierutton = QtWidgets.QPushButton(self.groupBox_5) + self.fourierutton = QtWidgets.QPushButton(self.fft_box) self.fourierutton.setObjectName("fourierutton") self.horizontalLayout_5.addWidget(self.fourierutton) - self.verticalLayout.addWidget(self.groupBox_5) + self.verticalLayout.addWidget(self.fft_box) spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.verticalLayout.addItem(spacerItem) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) + Form.setTabOrder(self.baselinebutton, self.leftshift_comboBox) + Form.setTabOrder(self.leftshift_comboBox, self.ls_spinBox) + Form.setTabOrder(self.ls_spinBox, self.ls_lineEdit) + Form.setTabOrder(self.ls_lineEdit, self.leftshiftbutton) + Form.setTabOrder(self.leftshiftbutton, self.zfbutton) + Form.setTabOrder(self.zfbutton, self.ph0slider) + Form.setTabOrder(self.ph0slider, self.ph1slider) + Form.setTabOrder(self.ph1slider, self.pivot_lineedit) + Form.setTabOrder(self.pivot_lineedit, self.autophase_check) + Form.setTabOrder(self.autophase_check, self.phase_prev_button) + Form.setTabOrder(self.phase_prev_button, self.phasebutton) + Form.setTabOrder(self.phasebutton, self.apodcombobox) + Form.setTabOrder(self.apodcombobox, self.apod_prev_button) + Form.setTabOrder(self.apod_prev_button, self.apodbutton) + Form.setTabOrder(self.apodbutton, self.fourierutton) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) - self.groupBox_4.setTitle(_translate("Form", "Baseline correction")) + self.baseline_box.setTitle(_translate("Form", "Baseline correction")) self.baselinebutton.setText(_translate("Form", "Apply")) - self.groupBox.setTitle(_translate("Form", "Left shift")) + self.leftshift_box.setTitle(_translate("Form", "Left shift")) self.leftshiftbutton.setText(_translate("Form", "Apply")) - self.comboBox.setItemText(0, _translate("Form", "Points")) - self.comboBox.setItemText(1, _translate("Form", "Seconds")) - self.groupBox_6.setTitle(_translate("Form", "Zerofilling")) + self.leftshift_comboBox.setItemText(0, _translate("Form", "Points")) + self.leftshift_comboBox.setItemText(1, _translate("Form", "Seconds")) + self.zerofill_box.setTitle(_translate("Form", "Zerofilling")) self.zfbutton.setText(_translate("Form", "Apply")) - self.groupBox_2.setTitle(_translate("Form", "Phase correction")) + self.phase_box.setTitle(_translate("Form", "Phase correction")) + self.label_8.setText(_translate("Form", "Pivot")) + self.phase_prev_button.setText(_translate("Form", "Preview")) + self.phasebutton.setText(_translate("Form", "Apply")) self.label_6.setText(_translate("Form", "Phase 1")) - self.pushButton_2.setText(_translate("Form", "Preview")) self.label.setText(_translate("Form", "Phase 0")) self.pivot_lineedit.setText(_translate("Form", "0")) - self.label_8.setText(_translate("Form", "Pivot")) - self.phasebutton.setText(_translate("Form", "Apply")) - self.groupBox_3.setTitle(_translate("Form", "Apodization")) - self.label_2.setText(_translate("Form", "TextLabel")) - self.pushButton.setText(_translate("Form", "Preview")) + self.autophase_check.setText(_translate("Form", "Autophase at pivot point")) + self.apod_box.setTitle(_translate("Form", "Apodization")) + self.apod_name_label.setText(_translate("Form", "TextLabel")) + self.apod_prev_button.setText(_translate("Form", "Preview")) self.apodbutton.setText(_translate("Form", "Apply")) - self.groupBox_5.setTitle(_translate("Form", "FFT")) + self.fft_box.setTitle(_translate("Form", "FFT")) self.fourierutton.setText(_translate("Form", "Apply")) diff --git a/src/gui_qt/data/container.py b/src/gui_qt/data/container.py index b1b5b51..c9acdce 100644 --- a/src/gui_qt/data/container.py +++ b/src/gui_qt/data/container.py @@ -656,7 +656,8 @@ class SignalContainer(ExperimentContainer): def _update_actions(self): super()._update_actions() - self.actions.update({'ph': self._data.manual_phase, 'bls': self._data.baseline_spline}) + self.actions.update({'ph': self._data.manual_phase, 'bls': self._data.baseline_spline, + 'autoph': self._data.autophase}) if isinstance(self._data, Spectrum): self.actions.update({'bl': self._data.baseline, 'ls': self._data.shift, 'divide': self._data.divide, 'ft': self.fourier}) diff --git a/src/gui_qt/data/datawidget/datawidget.py b/src/gui_qt/data/datawidget/datawidget.py index 8823c7f..4cbe668 100644 --- a/src/gui_qt/data/datawidget/datawidget.py +++ b/src/gui_qt/data/datawidget/datawidget.py @@ -81,7 +81,7 @@ class DataTree(QtWidgets.QTreeWidget): self.update_indexes() @QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem) - def data_change(self, item: QtWidgets.QTreeWidgetItem) -> Tuple[set, set]: + def data_change(self, item: QtWidgets.QTreeWidgetItem) -> tuple[set, set]: idd = item.data(0, QtCore.Qt.UserRole) is_selected = item.checkState(0) == QtCore.Qt.Checked to_be_hidden = set() @@ -259,7 +259,7 @@ class DataTree(QtWidgets.QTreeWidget): set_cnt = 0 item.setText(1, f'G[{graph_cnt}]') else: - item.setText(1, f'G[{graph_cnt}].S[{set_cnt}]') + item.setText(1, f'.S[{set_cnt}]') set_cnt += 1 iterator += 1 diff --git a/src/gui_qt/data/signaledit/editsignalwidget.py b/src/gui_qt/data/signaledit/editsignalwidget.py index 3232f9f..73571ea 100644 --- a/src/gui_qt/data/signaledit/editsignalwidget.py +++ b/src/gui_qt/data/signaledit/editsignalwidget.py @@ -18,8 +18,8 @@ class EditSignalWidget(QtWidgets.QWidget, Ui_Form): self.apodlist = find_models(apodization) - self.lineEdit.hide() - self.lineEdit.setValidator(QtGui.QDoubleValidator()) + self.ls_lineEdit.hide() + self.ls_lineEdit.setValidator(QtGui.QDoubleValidator()) for ap in self.apodlist: self.apodcombobox.addItem(str(ap().name)) @@ -32,8 +32,8 @@ class EditSignalWidget(QtWidgets.QWidget, Ui_Form): self.leftshiftbutton.clicked.connect(lambda: self.apply_changes('ls')) self.fourierutton.clicked.connect(lambda: self.apply_changes('ft')) - self.pushButton.clicked.connect(lambda: self.preview_triggered.emit('ap')) - self.pushButton_2.clicked.connect(lambda: self.preview_triggered.emit('ph')) + self.apod_prev_button.clicked.connect(lambda: self.preview_triggered.emit('ap')) + self.phase_prev_button.clicked.connect(lambda: self.preview_triggered.emit('ph')) @QtCore.pyqtSlot(str) def apply_changes(self, sender): @@ -41,8 +41,8 @@ class EditSignalWidget(QtWidgets.QWidget, Ui_Form): self.do_something.emit(sender, tuple()) elif sender == 'ls': - if self.comboBox.currentIndex() == 0: - _nop = int(self.lsspinBox.text()) + if self.leftshift_comboBox.currentIndex() == 0: + _nop = int(self.ls_spinBox.text()) stype = 'pts' else: try: @@ -54,14 +54,17 @@ class EditSignalWidget(QtWidgets.QWidget, Ui_Form): elif sender == 'ap': apodmodel = self.apodlist[self.apodcombobox.currentIndex()] - p = [float(x.text()) for x in self.groupBox_3.findChildren(QtWidgets.QLineEdit)] + p = [float(x.text()) for x in self.apod_box.findChildren(QtWidgets.QLineEdit)] self.do_something.emit(sender, (p, apodmodel)) elif sender == 'ph': - ph0 = float(self.ph0slider.value()) - ph1 = float(self.ph1slider.value()) pvt = float(self.pivot_lineedit.text()) - self.do_something.emit(sender, (ph0, ph1, pvt)) + if self.autophase_check.isChecked(): + self.do_something.emit('autoph', (pvt,)) + else: + ph0 = float(self.ph0slider.value()) + ph1 = float(self.ph1slider.value()) + self.do_something.emit(sender, (ph0, ph1, pvt)) else: print('You should never reach this by accident.') @@ -69,10 +72,10 @@ class EditSignalWidget(QtWidgets.QWidget, Ui_Form): @QtCore.pyqtSlot(int, name='on_apodcombobox_currentIndexChanged') def change_apodization(self, index): apod_func = self.apodlist[index] - self.label_2.setText(convert(apod_func.equation)) + self.apod_name_label.setText(convert(apod_func.equation)) - while self.verticalLayout_8.count(): - item = self.verticalLayout_8.takeAt(0) + while self.apod_layout.count(): + item = self.apod_layout.takeAt(0) try: item.widget().deleteLater() except AttributeError: @@ -80,13 +83,13 @@ class EditSignalWidget(QtWidgets.QWidget, Ui_Form): for k, v in enumerate(apod_func.params): widgt = FormWidget(name=v) - self.verticalLayout_8.addWidget(widgt) + self.apod_layout.addWidget(widgt) - @QtCore.pyqtSlot(int, name='on_comboBox_currentIndexChanged') + @QtCore.pyqtSlot(int, name='on_leftshift_comboBox_currentIndexChanged') def change_ls(self, idx): if idx: - self.lineEdit.show() - self.lsspinBox.hide() + self.ls_lineEdit.show() + self.ls_spinBox.hide() else: - self.lineEdit.hide() - self.lsspinBox.show() + self.ls_lineEdit.hide() + self.ls_spinBox.show() diff --git a/src/gui_qt/data/signaledit/phase_dialog.py b/src/gui_qt/data/signaledit/phase_dialog.py index ceeb3a7..5962ed0 100644 --- a/src/gui_qt/data/signaledit/phase_dialog.py +++ b/src/gui_qt/data/signaledit/phase_dialog.py @@ -103,7 +103,7 @@ class QPhasedialog(QPreviewDialogs, Ui_SignalEdit): return float(self.ph0slider.text()), float(self.ph1slider.text()), float(self.pivot_lineedit.text()) def move_line(self, evt): - self.pivot_lineedit.setText(str(int(evt.value()))) + self.pivot_lineedit.setText(f'{evt.value():.5g}') class QApodDialog(QPreviewDialogs, Ui_ApodEdit): diff --git a/src/gui_qt/lib/undos.py b/src/gui_qt/lib/undos.py index d2231af..9ee255c 100644 --- a/src/gui_qt/lib/undos.py +++ b/src/gui_qt/lib/undos.py @@ -54,6 +54,21 @@ class PhaseCommand(QtWidgets.QUndoCommand): self.__data.apply('ph', self.__phase) +class AutophaseCommand(QtWidgets.QUndoCommand): + def __init__(self, data, pvt: float): + super().__init__('Autophase') + + self.__data = data + self.__data_data = copy.deepcopy(data.data) + self.__pvt = pvt + + def undo(self): + self.__data.data = copy.deepcopy(self.__data_data) + + def redo(self): + self.__data.apply('autoph', (self.__pvt,)) + + class ShiftCommand(QtWidgets.QUndoCommand): def __init__(self, data, value, mode): super().__init__('Fourier') diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 018ff84..8c4c8b5 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -87,14 +87,15 @@ class UpperManagement(QtCore.QObject): 'cut': (CutCommand, 'Cut'), 'ap': (ApodizationCommand, 'Apodization'), 'zf': (ZerofillCommand, 'Zerofill'), - 'ph': (PhaseCommand, 'Phase'), + 'ph': (PhaseCommand, 'Phase correction'), + 'autoph': (AutophaseCommand, 'Autophase'), 'bl': (BaselineCommand, 'Baseline'), 'bls': (BaselineSplineCommand, 'Baseline'), 'ft': (FourierCommand, 'Fourier'), 'ft_pake': 'FT (de-paked)', 'sort': (SortCommand, 'Sort'), 'norm': (NormCommand, 'Normalize'), - 'center': (CenterCommand, 'Center on max') + 'center': (CenterCommand, 'Center on max'), } def __init__(self, window): diff --git a/src/nmreval/data/signals.py b/src/nmreval/data/signals.py index 5a408cb..1df749d 100644 --- a/src/nmreval/data/signals.py +++ b/src/nmreval/data/signals.py @@ -55,8 +55,9 @@ class Signal(Points): return self - def simple_phase(self, pos: int = 0, avg: int = 0): - ph = np.mean(np.angle(self._y)[pos-avg:pos+avg+1]) + def autophase(self, pos: float = 0, avg: int = 0): + pos = np.argmin(np.abs(pos-self.x)) + ph = np.mean(np.angle(self.y)[pos-avg:pos+avg+1]) self._y *= np.exp(-1j*ph) self.meta['phase'].append((ph, 0, 0)) diff --git a/src/resources/_ui/editsignalwidget.ui b/src/resources/_ui/editsignalwidget.ui index e9a6e63..b2d0443 100644 --- a/src/resources/_ui/editsignalwidget.ui +++ b/src/resources/_ui/editsignalwidget.ui @@ -30,7 +30,7 @@ 3 - + Baseline correction @@ -58,7 +58,7 @@ - + Left shift @@ -83,7 +83,7 @@ - + Points @@ -105,14 +105,14 @@ 0 - + 9999 - + @@ -120,7 +120,7 @@ - + Zerofilling @@ -151,7 +151,7 @@ - + Phase correction @@ -174,6 +174,39 @@ 0 + + + + Pivot + + + + + + + Preview + + + + + + + + 0 + 0 + + + + true + + + -180.000000000000000 + + + 180.000000000000000 + + + @@ -187,6 +220,13 @@ + + + + Apply + + + @@ -194,13 +234,6 @@ - - - - Preview - - - @@ -224,36 +257,10 @@ - - - - - 0 - 0 - - - - true - - - -180.000000000000000 - - - 180.000000000000000 - - - - - + + - Pivot - - - - - - - Apply + Autophase at pivot point @@ -261,7 +268,7 @@ - + 0 @@ -288,7 +295,7 @@ - + TextLabel @@ -298,7 +305,7 @@ - + 0 @@ -307,7 +314,7 @@ - + Preview @@ -326,7 +333,7 @@ - + FFT @@ -368,6 +375,24 @@ + + baselinebutton + leftshift_comboBox + ls_spinBox + ls_lineEdit + leftshiftbutton + zfbutton + ph0slider + ph1slider + pivot_lineedit + autophase_check + phase_prev_button + phasebutton + apodcombobox + apod_prev_button + apodbutton + fourierutton +