207-noncomplex-fits #244

Merged
dominik merged 4 commits from 207-noncomplex-fits into master 2024-02-11 17:40:51 +00:00
3 changed files with 27 additions and 8 deletions
Showing only changes of commit 4b6820af18 - Show all commits

View File

@ -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}')

View File

@ -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]

View File

@ -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