From 2adf15104f052ad5e47e6d623ecd62015cf2a7dc Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Fri, 19 May 2023 17:35:32 +0200 Subject: [PATCH] attempt to only show real/imag part of complex fit functions; closes #72 --- src/nmreval/fit/result.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/nmreval/fit/result.py b/src/nmreval/fit/result.py index c888b32..c7bd517 100644 --- a/src/nmreval/fit/result.py +++ b/src/nmreval/fit/result.py @@ -63,9 +63,19 @@ class FitResultCreator: parameters = OrderedDict([(k, v) for k, v in zip(pnames, p)]) p_final = [p.value for p in parameters.values()] - _y = model.func(p_final, _x, **fun_kwargs) resid = model.func(p_final, x_orig, **fun_kwargs) - y_orig + actual_complex_mode = 0 + if 'complex_mode' in fun_kwargs: + actual_complex_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 + stats = FitResultCreator.calc_statistics(_y, resid, nobs, nvar) varied = [p.var for p in parameters.values()] @@ -356,7 +366,7 @@ class FitResult(Points): def with_new_x(self, x_values): if self.func is None: - raise ValueError('no fit function available to calcualate new y values') + raise ValueError('no fit function available to calculate new y values') new_fit = self.copy() y_values = self.func.func(self.p_final, x_values, **self.fun_kwargs) @@ -372,4 +382,4 @@ class FitResult(Points): else: part_functions.append(Points(x_values, sub_y, name=sub_name)) - return part_functions \ No newline at end of file + return part_functions