From a310a78fb975c3cfd03279a1b64e9e60a92753f0 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Wed, 5 Jul 2023 19:51:06 +0200 Subject: [PATCH] added tnmh; some bugfixes --- src/gui_qt/_py/basewindow.py | 3 +- src/gui_qt/_py/tnmh_dialog.py | 53 ++++++------------ src/gui_qt/dsc/glass_dialog.py | 93 ++++++++++++++++++++----------- src/gui_qt/main/management.py | 19 +++++++ src/nmreval/fit/result.py | 4 +- src/resources/_ui/basewindow.ui | 3 +- src/resources/_ui/tnmh_dialog.ui | 96 ++++++++++---------------------- 7 files changed, 131 insertions(+), 140 deletions(-) diff --git a/src/gui_qt/_py/basewindow.py b/src/gui_qt/_py/basewindow.py index 3653193..e1534f4 100644 --- a/src/gui_qt/_py/basewindow.py +++ b/src/gui_qt/_py/basewindow.py @@ -472,7 +472,6 @@ class Ui_BaseWindow(object): self.menuStuff.addAction(self.actionTetris) self.menuStuff.addAction(self.actionMine) self.menuDSC.addAction(self.actionTNMH_model) - self.menuDSC.addAction(self.actionTNMH) self.menubar.addAction(self.menuFile.menuAction()) self.menubar.addAction(self.menuWindow.menuAction()) self.menubar.addAction(self.menuData.menuAction()) @@ -640,7 +639,7 @@ class Ui_BaseWindow(object): self.actionShow_error_log.setText(_translate("BaseWindow", "Show error log")) self.actionCreate_starter.setText(_translate("BaseWindow", "Create starter..")) self.actionAbout.setText(_translate("BaseWindow", "About...")) - self.actionTNMH_model.setText(_translate("BaseWindow", "Tg determination,,,")) + self.actionTNMH_model.setText(_translate("BaseWindow", "Tg , Hodge, TNMH,,,")) self.actionBinning.setText(_translate("BaseWindow", "Binning...")) self.actionTNMH.setText(_translate("BaseWindow", "TNMH...")) from ..data.datawidget.datawidget import DataWidget diff --git a/src/gui_qt/_py/tnmh_dialog.py b/src/gui_qt/_py/tnmh_dialog.py index 6037040..f521032 100644 --- a/src/gui_qt/_py/tnmh_dialog.py +++ b/src/gui_qt/_py/tnmh_dialog.py @@ -90,9 +90,6 @@ class Ui_Wizard(object): self.checkBox_6.setChecked(True) self.checkBox_6.setObjectName("checkBox_6") self.gridLayout_4.addWidget(self.checkBox_6, 2, 0, 1, 1) - self.pushButton_4 = QtWidgets.QPushButton(self.wizardPage2) - self.pushButton_4.setObjectName("pushButton_4") - self.gridLayout_4.addWidget(self.pushButton_4, 2, 2, 1, 1) self.new_graph_tau_check = QtWidgets.QCheckBox(self.wizardPage2) self.new_graph_tau_check.setChecked(True) self.new_graph_tau_check.setObjectName("new_graph_tau_check") @@ -106,6 +103,7 @@ class Ui_Wizard(object): self.checkBox_5.setObjectName("checkBox_5") self.gridLayout_4.addWidget(self.checkBox_5, 3, 0, 1, 1) self.new_graph_tau_combo = QtWidgets.QComboBox(self.wizardPage2) + self.new_graph_tau_combo.setEnabled(False) self.new_graph_tau_combo.setObjectName("new_graph_tau_combo") self.gridLayout_4.addWidget(self.new_graph_tau_combo, 0, 2, 1, 1) self.checkBox_4 = QtWidgets.QCheckBox(self.wizardPage2) @@ -116,6 +114,9 @@ class Ui_Wizard(object): self.checkBox.setChecked(True) self.checkBox.setObjectName("checkBox") self.gridLayout_4.addWidget(self.checkBox, 0, 0, 1, 1) + self.pushButton_4 = QtWidgets.QPushButton(self.wizardPage2) + self.pushButton_4.setObjectName("pushButton_4") + self.gridLayout_4.addWidget(self.pushButton_4, 4, 1, 1, 2) self.gridLayout_2.addLayout(self.gridLayout_4, 3, 0, 1, 2) Wizard.addPage(self.wizardPage2) self.wizardPage = QtWidgets.QWizardPage() @@ -128,31 +129,13 @@ class Ui_Wizard(object): self.wizardPage.setObjectName("wizardPage") self.gridLayout_6 = QtWidgets.QGridLayout(self.wizardPage) self.gridLayout_6.setObjectName("gridLayout_6") - self.fit_tnhm_fitbutton_2 = QtWidgets.QPushButton(self.wizardPage) - self.fit_tnhm_fitbutton_2.setObjectName("fit_tnhm_fitbutton_2") - self.gridLayout_6.addWidget(self.fit_tnhm_fitbutton_2, 0, 0, 1, 2) - self.graphicsView_3 = PlotWidget(self.wizardPage) - self.graphicsView_3.setObjectName("graphicsView_3") - self.gridLayout_6.addWidget(self.graphicsView_3, 1, 0, 1, 1) - self.gridLayout_3 = QtWidgets.QGridLayout() - self.gridLayout_3.setObjectName("gridLayout_3") - self.tnmh_tg_combo_2 = QtWidgets.QComboBox(self.wizardPage) - self.tnmh_tg_combo_2.setObjectName("tnmh_tg_combo_2") - self.tnmh_tg_combo_2.addItem("") - self.tnmh_tg_combo_2.addItem("") - self.tnmh_tg_combo_2.addItem("") - self.tnmh_tg_combo_2.addItem("") - self.tnmh_tg_combo_2.addItem("") - self.gridLayout_3.addWidget(self.tnmh_tg_combo_2, 0, 1, 1, 1) - self.label_3 = QtWidgets.QLabel(self.wizardPage) - self.label_3.setObjectName("label_3") - self.gridLayout_3.addWidget(self.label_3, 0, 0, 1, 1) - spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) - self.gridLayout_3.addItem(spacerItem1, 1, 0, 1, 1) - self.gridLayout_6.addLayout(self.gridLayout_3, 1, 1, 1, 1) + self.fit_tnhm_fitbutton = QtWidgets.QPushButton(self.wizardPage) + self.fit_tnhm_fitbutton.setObjectName("fit_tnhm_fitbutton") + self.gridLayout_6.addWidget(self.fit_tnhm_fitbutton, 0, 0, 1, 2) self.treeWidget_2 = QtWidgets.QTreeWidget(self.wizardPage) self.treeWidget_2.setObjectName("treeWidget_2") self.treeWidget_2.headerItem().setText(0, "1") + self.treeWidget_2.header().setVisible(False) self.gridLayout_6.addWidget(self.treeWidget_2, 2, 0, 1, 1) self.gridLayout_5 = QtWidgets.QGridLayout() self.gridLayout_5.setObjectName("gridLayout_5") @@ -161,20 +144,26 @@ class Ui_Wizard(object): self.new_graph_tnmh_check_2.setObjectName("new_graph_tnmh_check_2") self.gridLayout_5.addWidget(self.new_graph_tnmh_check_2, 1, 0, 1, 1) self.checkBox_14 = QtWidgets.QCheckBox(self.wizardPage) + self.checkBox_14.setChecked(True) self.checkBox_14.setObjectName("checkBox_14") self.gridLayout_5.addWidget(self.checkBox_14, 0, 0, 1, 1) self.pushButton_2 = QtWidgets.QPushButton(self.wizardPage) self.pushButton_2.setObjectName("pushButton_2") self.gridLayout_5.addWidget(self.pushButton_2, 2, 0, 1, 2) self.checkBox_13 = QtWidgets.QCheckBox(self.wizardPage) + self.checkBox_13.setChecked(True) self.checkBox_13.setObjectName("checkBox_13") self.gridLayout_5.addWidget(self.checkBox_13, 0, 1, 1, 1) self.new_graph_tnmh_combo_2 = QtWidgets.QComboBox(self.wizardPage) + self.new_graph_tnmh_combo_2.setEnabled(False) self.new_graph_tnmh_combo_2.setObjectName("new_graph_tnmh_combo_2") self.gridLayout_5.addWidget(self.new_graph_tnmh_combo_2, 1, 1, 1, 1) - spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) - self.gridLayout_5.addItem(spacerItem2, 3, 0, 1, 1) + spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) + self.gridLayout_5.addItem(spacerItem1, 3, 0, 1, 1) self.gridLayout_6.addLayout(self.gridLayout_5, 2, 1, 1, 1) + self.graphicsView_3 = PlotWidget(self.wizardPage) + self.graphicsView_3.setObjectName("graphicsView_3") + self.gridLayout_6.addWidget(self.graphicsView_3, 1, 0, 1, 2) Wizard.addPage(self.wizardPage) self.retranslateUi(Wizard) @@ -191,20 +180,14 @@ class Ui_Wizard(object): self.wizardPage2.setTitle(_translate("Wizard", "Hodge")) self.toolButton.setText(_translate("Wizard", "Calculate Hodge")) self.checkBox_6.setText(_translate("Wizard", "End")) - self.pushButton_4.setText(_translate("Wizard", "Export")) self.new_graph_tau_check.setText(_translate("Wizard", "New graph")) self.checkBox_7.setText(_translate("Wizard", "Fictive")) self.checkBox_5.setText(_translate("Wizard", "Inflection")) self.checkBox_4.setText(_translate("Wizard", "Midpoint")) self.checkBox.setText(_translate("Wizard", "Onset")) + self.pushButton_4.setText(_translate("Wizard", "Export")) self.wizardPage.setTitle(_translate("Wizard", "TNMH")) - self.fit_tnhm_fitbutton_2.setText(_translate("Wizard", "Fit TNMH model")) - self.tnmh_tg_combo_2.setItemText(0, _translate("Wizard", "Fictive")) - self.tnmh_tg_combo_2.setItemText(1, _translate("Wizard", "Onset")) - self.tnmh_tg_combo_2.setItemText(2, _translate("Wizard", "Midpoint")) - self.tnmh_tg_combo_2.setItemText(3, _translate("Wizard", "End")) - self.tnmh_tg_combo_2.setItemText(4, _translate("Wizard", "Inflection")) - self.label_3.setText(_translate("Wizard", "Tg for TNMH")) + self.fit_tnhm_fitbutton.setText(_translate("Wizard", "Fit TNMH model")) self.new_graph_tnmh_check_2.setText(_translate("Wizard", "New graph")) self.checkBox_14.setText(_translate("Wizard", "Export fit")) self.pushButton_2.setText(_translate("Wizard", "Export")) diff --git a/src/gui_qt/dsc/glass_dialog.py b/src/gui_qt/dsc/glass_dialog.py index f1c542f..b1cb9ff 100644 --- a/src/gui_qt/dsc/glass_dialog.py +++ b/src/gui_qt/dsc/glass_dialog.py @@ -87,8 +87,8 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard): self.add_sets() - self.new_graph_tau_combo.setEnabled(False) self.new_graph_tau_check.stateChanged.connect(lambda state: self.new_graph_tau_combo.setEnabled(not bool(state))) + self.new_graph_tau_check.stateChanged.connect(lambda state: self.new_graph_tnmh_combo_2.setEnabled(not bool(state))) def __call__(self): self.clear() @@ -119,6 +119,7 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard): self.new_graph_tau_combo.clear() for graphs in self._management.graphs.list(): self.new_graph_tau_combo.addItem(graphs[1], userData=graphs[0]) + self.new_graph_tnmh_combo_2.addItem(graphs[1], userData=graphs[0]) min_x = 10_000_000 max_x = -10_000_000 @@ -157,11 +158,11 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard): self.dsc_plot.addItem(tg_plot) fictive_cp = PlotItem(pen=mkPen(c.rgb())) -# self.graphicsView_2.addItem(fictive_cp) + self.graphicsView_3.addItem(fictive_cp) tnmh_fit = PlotItem() tnmh_fit.set_line(style=2, color=c) - # self.graphicsView_2.addItem(tnmh_fit) + self.graphicsView_3.addItem(tnmh_fit) self._plots[key] = (data_plot, tg_plot, glass, liquid, tangent, fictive_cp, tnmh_fit) self._tg_value[key] = { @@ -251,29 +252,16 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard): for val in plot: val.setVisible(is_checked) - @QtCore.pyqtSlot(name='on_pushButton_2_clicked') - def get_fictive(self): - baselines = tuple(lim.getRegion() for lim in self.limits) - if baselines[0][0] > baselines[1][0]: - baselines = baselines[1], baselines[0] + def get_fictive(self, key, baselines): + plot = self._plots[key] + data, _ = self._dsc[key] - for idx in range(self.listWidget.count()): - item = self.listWidget.item(idx) - if item.checkState() == QtCore.Qt.Unchecked: - continue + cp, tg = data.get_fictive_cp(*baselines) - key = item.data(QtCore.Qt.UserRole) - plot = self._plots[key] - data, _ = self._dsc[key] + plot[5].setData(cp.x, cp.y) + self._dsc[key] = (data, cp) - cp, tg = data.get_fictive_cp(*baselines) - - plot[5].setData(cp.x, cp.y) - self._dsc[key] = (data, cp) - - self._tg_value[key]['fictive'] = (tg, 0) - - self._update_tg_plots() + return cp @QtCore.pyqtSlot(name='on_fit_tnhm_fitbutton_clicked') def make_tnmh(self): @@ -281,22 +269,62 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard): if baselines[0][0] > baselines[1][0]: baselines = baselines[1], baselines[0] + self.treeWidget_2.clear() for idx in range(self.listWidget.count()): item = self.listWidget.item(idx) if item.checkState() == QtCore.Qt.Unchecked: continue key = item.data(QtCore.Qt.UserRole) - plot = self._plots[key] - _, data = self._dsc[key] - if data is None: - continue + data = self.get_fictive(key, baselines) res = data.calculate_tnmh([60, 0.5, 1, 2e5], *baselines, return_fictive=False) self._fit[key] = res + + plot = self._plots[key] plot[-1].setData(res.x, res.y) + for idx in range(self.listWidget.count()): + item = self.listWidget.item(idx) + + tree_item = QtWidgets.QTreeWidgetItem([item.text()]) + values = self._fit.get(item.data(QtCore.Qt.UserRole)) + + if values is not None: + child_item = QtWidgets.QTreeWidgetItem([values.parameter_string()]) + tree_item.addChild(child_item) + + self.treeWidget_2.addTopLevelItem(tree_item) + + @QtCore.pyqtSlot(name='on_pushButton_2_clicked') + def export_tnmh(self): + ret_dic = {} + for idx in range(self.listWidget.count()): + item = self.listWidget.item(idx) + if item.checkState() == QtCore.Qt.Unchecked: + continue + + key = item.data(QtCore.Qt.UserRole) + if self.checkBox_13.isChecked(): + _, cp = self._dsc[key] + else: + cp = None + + if self.checkBox_14.isChecked(): + line = self._fit[key] + else: + line = None + + ret_dic[key] = (cp, line) + + if self.new_graph_tnmh_check_2.isChecked(): + ret_dic['graph'] = '' + else: + ret_dic['graph'] = self.new_graph_tnmh_combo_2.currentData() + + self.newData.emit(ret_dic, 'tnmh') + @QtCore.pyqtSlot(name='on_toolButton_clicked') def hodge(self): for tg_type, (plot, data, fitplots, fit) in self._hodge.items(): @@ -334,15 +362,14 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard): for cb in (self.checkBox, self.checkBox_4, self.checkBox_6, self.checkBox_5, self.checkBox_7): if cb.isChecked(): item = cb.text().lower() - v = self._hodge.get(item) - ret_dic2[item] = v[1] + data = self._hodge.get(item) + if data[1] is not None: + ret_dic2[item] = data[1] if self.new_graph_tau_check.isChecked(): - ret_dic2['graph'] = self.new_graph_tau_combo.currentData() - else: ret_dic2['graph'] = '' - - print(ret_dic2) + else: + ret_dic2['graph'] = self.new_graph_tau_combo.currentData() self.newData.emit(ret_dic2, 'hodge') diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 9fde3a5..45b8339 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -800,6 +800,25 @@ class UpperManagement(QtCore.QObject): set_id_list.append(self.add(v)) self.newData.emit(set_id_list, graph_id) + elif dtype == 'tnmh': + set_id_list = [] + graph_id = dic1.pop('graph') + for k, (tg, fit) in dic1.items(): + p: ExperimentContainer = self[k] + col = p.plot_real.linecolor + + tg_data_id = [] + + if tg is not None: + set_id_list.append(self.add(tg, color=col)) + + set_id = self.add(fit, color=col) + self[set_id].setLine(style=LineStyle.Dashed) + self[set_id].setSymbol(symbol=SymbolStyle.No) + set_id_list.append(set_id) + + self.newData.emit(set_id_list, graph_id) + @QtCore.pyqtSlot(int, dict) def smooth_data(self, npoints, param_kwargs): _active = self.graphs[self.current_graph].active diff --git a/src/nmreval/fit/result.py b/src/nmreval/fit/result.py index 65d340d..27c047c 100644 --- a/src/nmreval/fit/result.py +++ b/src/nmreval/fit/result.py @@ -228,7 +228,7 @@ class FitResult(Points): print(' #data :', self.nobs) print(' #var :', self.nvar) print('\nParameter') - print(self._parameter_string()) + print(self.parameter_string()) if statistics: print('Statistics') @@ -240,7 +240,7 @@ class FitResult(Points): print(self._correlation_string()) print() - def _parameter_string(self): + def parameter_string(self): ret_val = '' for pval in self.parameter.values(): diff --git a/src/resources/_ui/basewindow.ui b/src/resources/_ui/basewindow.ui index 293724a..8a5efaf 100644 --- a/src/resources/_ui/basewindow.ui +++ b/src/resources/_ui/basewindow.ui @@ -332,7 +332,6 @@ DSC - @@ -1033,7 +1032,7 @@ - Tg determination,,, + Tg , Hodge, TNMH,,, diff --git a/src/resources/_ui/tnmh_dialog.ui b/src/resources/_ui/tnmh_dialog.ui index 03e8830..d9201d6 100644 --- a/src/resources/_ui/tnmh_dialog.ui +++ b/src/resources/_ui/tnmh_dialog.ui @@ -154,13 +154,6 @@ - - - - Export - - - @@ -192,7 +185,11 @@ - + + + false + + @@ -214,6 +211,13 @@ + + + + Export + + + @@ -233,70 +237,17 @@ - + Fit TNMH model - - - - - - - - - - Fictive - - - - - Onset - - - - - Midpoint - - - - - End - - - - - Inflection - - - - - - - - Tg for TNMH - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + false + 1 @@ -321,6 +272,9 @@ Export fit + + true + @@ -335,10 +289,17 @@ Export dTf / dT + + true + - + + + false + + @@ -355,6 +316,9 @@ + + +