From 65034d45189630e8531b5844edba3c145710aa29 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Fri, 19 May 2023 18:13:57 +0200 Subject: [PATCH] sub function show numbering; closes #70 --- src/gui_qt/main/management.py | 6 ++--- src/nmreval/fit/_meta.py | 5 ++-- src/nmreval/fit/result.py | 45 +++++++++++++++++++++++++++++------ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 0a817c1..a85e4d1 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -653,12 +653,10 @@ class UpperManagement(QtCore.QObject): else: continue - for key, pvalue in data.parameter.items(): - name = pvalue.full_name - fit_key = key + data.model_name + for fit_key, pvalue in data.parameter.items(): if fit_key not in fit_dict: - fit_dict[fit_key] = [[], name] + fit_dict[fit_key] = [[], fit_key] err = 0 if pvalue.error is None else pvalue.error diff --git a/src/nmreval/fit/_meta.py b/src/nmreval/fit/_meta.py index 230cb68..9fe9c34 100644 --- a/src/nmreval/fit/_meta.py +++ b/src/nmreval/fit/_meta.py @@ -68,6 +68,7 @@ class MultiModel: self._kwargs_right = {} self._kwargs_left = {} self.fun_kwargs = {} + self.idx = (left_idx, right_idx) # mapping kwargs to kwargs of underlying functions self._ext_int_kw = {} @@ -178,13 +179,13 @@ class MultiModel: if isinstance(self._left, MultiModel): yield from self._left.sub_name() elif hasattr(self._left, 'name'): - yield self._left.name + yield f'{self._left.name}({self.idx[0]})' else: yield self.name + '(lhs)' if isinstance(self._right, MultiModel): yield from self._right.sub_name() elif hasattr(self._right, 'name'): - yield self._right.name + yield f'{self._right.name}({self.idx[1]})' else: yield self.name + '(rhs)' diff --git a/src/nmreval/fit/result.py b/src/nmreval/fit/result.py index c7bd517..65d340d 100644 --- a/src/nmreval/fit/result.py +++ b/src/nmreval/fit/result.py @@ -65,16 +65,20 @@ class FitResultCreator: resid = model.func(p_final, x_orig, **fun_kwargs) - y_orig - actual_complex_mode = 0 + actual_mode = -1 if 'complex_mode' in fun_kwargs: - actual_complex_mode = fun_kwargs['complex_mode'] + actual_mode = fun_kwargs['complex_mode'] fun_kwargs['complex_mode'] = 0 _y = model.func(p_final, _x, **fun_kwargs) - if actual_complex_mode == 1: - _y.imag = 0 - elif actual_complex_mode == 2: - _y.real = 0 + + if not actual_mode < 0: + if actual_mode == 1: + _y.imag = 0 + elif actual_mode == 2: + _y.real = 0 + + fun_kwargs['complex_mode'] = actual_mode stats = FitResultCreator.calc_statistics(_y, resid, nobs, nvar) varied = [p.var for p in parameters.values()] @@ -368,18 +372,45 @@ class FitResult(Points): if self.func is None: raise ValueError('no fit function available to calculate new y values') + actual_mode = -1 + if 'complex_mode' in self.fun_kwargs: + actual_mode = self.fun_kwargs['complex_mode'] + self.fun_kwargs['complex_mode'] = 0 + new_fit = self.copy() y_values = self.func.func(self.p_final, x_values, **self.fun_kwargs) + if not actual_mode < 0: + if actual_mode == 1: + y_values.imag = 0 + elif actual_mode == 2: + y_values.real = 0 + + self.fun_kwargs['complex_mode'] = actual_mode + new_fit.set_data(x_values, y_values) return new_fit def sub(self, x_values): part_functions = [] + actual_mode = -1 + if 'complex_mode' in self.fun_kwargs: + actual_mode = self.fun_kwargs['complex_mode'] + self.fun_kwargs['complex_mode'] = 0 + for sub_name, sub_y in zip(self.func.sub_name(), self.func.sub(self.p_final, x_values, **self.fun_kwargs)): - if np.iscomplexobj(sub_y): + if not actual_mode < 0: + if actual_mode == 1: + sub_y.imag = 0 + elif actual_mode == 2: + sub_y.real = 0 + part_functions.append(Signal(x_values, sub_y, name=sub_name)) + else: part_functions.append(Points(x_values, sub_y, name=sub_name)) + if actual_mode < 0: + self.fun_kwargs['complex_mode'] = actual_mode + return part_functions