From e1b76e837dad46757e2ca622c3f4123f52210210 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 16 Jul 2024 17:01:20 +0000 Subject: [PATCH] dev (#283) Co-authored-by: Dominik Demuth Reviewed-on: https://gitea.pkm.physik.tu-darmstadt.de/IPKM/nmreval/pulls/283 --- src/gui_qt/data/datawidget/datawidget.py | 13 ++++++++++--- src/gui_qt/fit/fit_toolbar.py | 2 +- src/gui_qt/main/mainwindow.py | 10 +++++++--- src/gui_qt/main/management.py | 14 +++++++++----- src/nmreval/distributions/energy.py | 7 ++++++- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/gui_qt/data/datawidget/datawidget.py b/src/gui_qt/data/datawidget/datawidget.py index e24c10d..23c1451 100644 --- a/src/gui_qt/data/datawidget/datawidget.py +++ b/src/gui_qt/data/datawidget/datawidget.py @@ -17,7 +17,7 @@ class DataTree(QtWidgets.QTreeWidget): moveItem = QtCore.pyqtSignal(list, str, str, int) # items, from, to, new row copyItem = QtCore.pyqtSignal(list, str) saveFits = QtCore.pyqtSignal(list) - extendFits = QtCore.pyqtSignal(list) + extendFits = QtCore.pyqtSignal(list, bool) # noinspection PyUnresolvedReferences def __init__(self, parent=None): @@ -465,7 +465,7 @@ class DataTree(QtWidgets.QTreeWidget): del_action = menu.addAction('Exterminate sets') cp_action = menu.addAction('Replicate sets') cat_action = menu.addAction('Join us!') - plt_action = save_action = extend_action = None + plt_action = save_action = extend_action = subfit_action = None menu.addSeparator() col_menu = menu.addMenu('Color cycle') for c in available_cycles.keys(): @@ -497,6 +497,7 @@ class DataTree(QtWidgets.QTreeWidget): plt_action = menu.addAction('Plot fit parameter') save_action = menu.addAction('Save fit parameter') extend_action = menu.addAction('Extrapolate fit') + subfit_action = menu.addAction('Plot partial functions') action = menu.exec(evt.globalPos()) @@ -504,6 +505,9 @@ class DataTree(QtWidgets.QTreeWidget): for gid, sets in idx.items(): s.extend(sets) + if action is None: + return + if action == del_action: self.management.delete_sets(s) @@ -521,7 +525,10 @@ class DataTree(QtWidgets.QTreeWidget): self.saveFits.emit(s) elif action == extend_action: - self.extendFits.emit(s) + self.extendFits.emit(s, False) + + elif action == subfit_action: + self.extendFits.emit(s, True) elif action.parent() == col_menu: self.management.set_cycle(s, action.text()) diff --git a/src/gui_qt/fit/fit_toolbar.py b/src/gui_qt/fit/fit_toolbar.py index 283c335..74ed526 100644 --- a/src/gui_qt/fit/fit_toolbar.py +++ b/src/gui_qt/fit/fit_toolbar.py @@ -10,7 +10,7 @@ class FitToolbar(QtWidgets.QToolBar): limit_menu: QtWidgets.QMenu, parent=None, ): - super().__init__(parent=parent) + super().__init__('Fit', parent=parent) self.fit_action = fitaction self.region = RegionItem() diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index 4851d40..713eb75 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -991,15 +991,19 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.editor.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal) self.editor.show() - @QtCore.pyqtSlot(list) - def extend_fit(self, sets: list): + @QtCore.pyqtSlot(list, bool) + def extend_fit(self, sets: list, only_subplots: bool): + if only_subplots: + self.management.extend_fits(sets, None, True) + return + w = FitExtension(self) res = w.exec() if res: p = w.values spacefunc = geomspace if p[3] else linspace x = spacefunc(p[0], p[1], num=p[2]) - self.management.extend_fits(sets, x) + self.management.extend_fits(sets, x, False) @QtCore.pyqtSlot(name='on_action_create_fit_function_triggered') def open_fitmodel_wizard(self): diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index f47362b..21715fa 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -711,17 +711,21 @@ class UpperManagement(QtCore.QObject): self.newData.emit(f_id_list, gid) - def extend_fits(self, set_id: list, x_range: np.ndarray): + def extend_fits(self, set_id: list, x_range: np.ndarray | None, only_subplots: bool): graphs = {} for sid in set_id: - data = self[sid] - fit = data.copy(full=True, keep_color=True) - fit.data = fit.data.with_new_x(x_range) + data = fit = self[sid] graph_id = data.graph if graph_id not in graphs: graphs[graph_id] = [] - graphs[graph_id].append(self.add(fit)) + + if not only_subplots: + fit = data.copy(full=True, keep_color=True) + if x_range is not None: + fit.data = fit.data.with_new_x(x_range) + + graphs[graph_id].append(self.add(fit)) color_scheme = available_cycles['colorblind'] for subfunc, col in zip(fit.data.sub(fit.x), cycle(color_scheme)): diff --git a/src/nmreval/distributions/energy.py b/src/nmreval/distributions/energy.py index 40f4c7f..059b2a5 100644 --- a/src/nmreval/distributions/energy.py +++ b/src/nmreval/distributions/energy.py @@ -3,7 +3,12 @@ from ctypes import c_double, cast, pointer, c_void_p import numpy as np from scipy import LowLevelCallable -from scipy.integrate import quad, simps as simpson + +from scipy.integrate import quad +try: + from scipy.integrate import simps as simpson +except ImportError: + from scipy.integrate import simpson from .base import Distribution from ..lib.utils import ArrayLike