From 8d994bb9b478a606c70d71fb4ecdd10e4bad5d91 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 18 Sep 2023 17:39:31 +0200 Subject: [PATCH] fixed preview --- src/gui_qt/fit/fitwindow.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/gui_qt/fit/fitwindow.py b/src/gui_qt/fit/fitwindow.py index b93ebec..9888685 100644 --- a/src/gui_qt/fit/fitwindow.py +++ b/src/gui_qt/fit/fitwindow.py @@ -11,6 +11,7 @@ from pyqtgraph import mkPen from nmreval.fit._meta import MultiModel, ModelFactory from nmreval.fit.data import Data from nmreval.fit.model import Model +from nmreval.fit.parameter import Parameters from nmreval.fit.result import FitResult from .fit_forms import FitTableWidget @@ -419,25 +420,37 @@ class QFitDialog(QtWidgets.QWidget, Ui_FitDialog): def make_previews(self, x, models_parameters: dict): self.preview_lines = [] + # needed to create namespace + param_dict = Parameters() + + cnt = 0 + for model in models_parameters.values(): + f = model['func'] + for parameter_list in model['data_parameter'].values(): + for i, p_value in enumerate(parameter_list[0]): + p_value.name = f.params[i] + param_dict.add_parameter(f'a{cnt}', p_value) + cnt += 1 + for k, model in models_parameters.items(): - f = Model(model['func']) + f = model['func'] is_complex = self._complex[k] parameters = model['data_parameter'] color = model['color'] for p, kwargs in parameters.values(): - print(pp.value for pp in p) + p_value = [pp.value for pp in p] if is_complex is not None: - y = f.func(x, *p, complex_mode=is_complex, **kwargs) + y = f.func(x, *p_value, complex_mode=is_complex, **kwargs) if np.iscomplexobj(y): self.preview_lines.append(PlotItem(x=x, y=y.real, pen=mkPen(width=3))) self.preview_lines.append(PlotItem(x=x, y=y.imag, pen=mkPen(width=3))) else: self.preview_lines.append(PlotItem(x=x, y=y, pen=mkPen(width=3))) else: - y = f.func(x, *p, **kwargs) + y = f.func(x, *p_value, **kwargs) self.preview_lines.append(PlotItem(x=x, y=y, pen=mkPen(width=3))) if isinstance(f, MultiModel): @@ -445,7 +458,7 @@ class QFitDialog(QtWidgets.QWidget, Ui_FitDialog): if is_complex is not None: sub_kwargs.update({'complex_mode': is_complex}) - for i, s in enumerate(f.subs(x, *p, **sub_kwargs)): + for i, s in enumerate(f.subs(x, *p_value, **sub_kwargs)): pen_i = mkPen(QtGui.QColor.fromRgbF(*color[i])) if np.iscomplexobj(s): self.preview_lines.append(PlotItem(x=x, y=s.real, pen=pen_i)) @@ -453,6 +466,8 @@ class QFitDialog(QtWidgets.QWidget, Ui_FitDialog): else: self.preview_lines.append(PlotItem(x=x, y=s, pen=pen_i)) + param_dict.clear() + return self.preview_lines def set_parameter(self, parameter: dict[str, FitResult]):