From 4b6820af1891ebd1a8bb1c9dde890c85d68f9305 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 30 Jan 2024 17:45:05 +0100 Subject: [PATCH] add comments for my understanding --- src/gui_qt/main/management.py | 22 ++++++++++++++++++---- src/nmreval/fit/data.py | 5 +++-- src/nmreval/fit/result.py | 8 ++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 3185b30..c046b8e 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -503,11 +503,25 @@ class UpperManagement(QtCore.QObject): we = we_option if m_complex is None or m_complex == 1: + # model is not complex: m_complex = None + # model is complex, fit real part: m_complex = 1 _y = data_i.y.real - elif m_complex == 2 and np.iscomplexobj(data_i.y): - _y = data_i.y.imag + data_complex = 1 + elif m_complex == 2: + # model is complex, fit imag part: m_complex = 2 + if np.iscomplexobj(data_i.y): + # data is complex, use imag part + _y = data_i.y.imag + data_complex = 2 + else: + # data is real + _y = data_i.y + data_complex = 1 else: + # model is complex, fit complex: m_complex = 0 + # use data as given (complex or not) _y = data_i.y + data_complex = 0 _x = data_i.x @@ -521,9 +535,9 @@ class UpperManagement(QtCore.QObject): try: if isinstance(we, str): - d = fit_d.Data(_x[inside], _y[inside], we=we, idx=set_id) + d = fit_d.Data(_x[inside], _y[inside], we=we, idx=set_id, complex_type=data_complex) else: - d = fit_d.Data(_x[inside], _y[inside], we=we[inside], idx=set_id) + d = fit_d.Data(_x[inside], _y[inside], we=we[inside], idx=set_id, complex_type=data_complex) except Exception as e: raise Exception(f'Setting data failed for {set_id}') diff --git a/src/nmreval/fit/data.py b/src/nmreval/fit/data.py index f6f2cc5..b6b94ff 100644 --- a/src/nmreval/fit/data.py +++ b/src/nmreval/fit/data.py @@ -6,8 +6,8 @@ from .model import Model from .parameter import Parameters, Parameter -class Data(object): - def __init__(self, x, y, we=None, idx=None): +class Data: + def __init__(self, x, y, we=None, idx=None, complex_type: int = 0): self.x = np.asarray(x) self.y = np.asarray(y) if self.y.shape[0] != self.x.shape[0]: @@ -20,6 +20,7 @@ class Data(object): self.parameter = Parameters() self.para_keys: list = [] self.fun_kwargs = {} + self.complex_type = complex_type def __len__(self): return self.y.shape[0] diff --git a/src/nmreval/fit/result.py b/src/nmreval/fit/result.py index 87fa94f..463a8eb 100644 --- a/src/nmreval/fit/result.py +++ b/src/nmreval/fit/result.py @@ -54,6 +54,7 @@ class FitResultCreator: nvar: int, corr: np.ndarray, pcorr: np.ndarray, + data_mode: int = 1, ) -> FitResult: if np.all(x_orig > 0) and (np.max(x_orig) > 100 * np.min(x_orig)): islog = True @@ -87,9 +88,12 @@ class FitResultCreator: if not actual_mode < 0: if actual_mode == 1: - _y.imag = 0 + _Y = _y.real + # _y.imag = 0 elif actual_mode == 2: - _y.real = 0 + # if data_mode == + _y = _y.imag + # _y.real = 0 fun_kwargs['complex_mode'] = actual_mode