more detailed error message in fit preparation

This commit is contained in:
Dominik Demuth 2023-09-18 16:08:42 +02:00
parent e51a02d277
commit 2cbc7e8d75

View File

@ -449,13 +449,23 @@ class UpperManagement(QtCore.QObject):
# sets are not in active order but in order they first appeared in fit dialog
# iterate over order of set id in active order and access parameter inside loop
# instead of directly looping
list_ids = list(model_p['parameter'].keys())
set_order = [self.active_id.index(i) for i in list_ids]
try:
list_ids = list(model_p['parameter'].keys())
set_order = [self.active_id.index(i) for i in list_ids]
except ValueError as e:
raise Exception('Getting order failed') from e
for pos in set_order:
set_id = list_ids[pos]
try:
data_i = self.data[set_id]
except KeyError as e:
raise KeyError(f'{set_id} not found') from e
data_i = self.data[set_id]
set_params = model_p['parameter'][set_id]
try:
set_params = model_p['parameter'][set_id]
except KeyError as e:
raise KeyError(f'No parameter found for {set_id}') from e
if we_option.lower() == 'deltay':
we = data_i.y_err**2
@ -474,20 +484,26 @@ class UpperManagement(QtCore.QObject):
if fit_limits == 'none':
inside = slice(None)
elif fit_limits == 'x':
x_lim, _ = self.graphs[self.current_graph].ranges
x_lim, _ = self.graphs[self.current_graph].range
inside = np.where((_x >= x_lim[0]) & (_x <= x_lim[1]))
else:
inside = np.where((_x >= fit_limits[0]) & (_x <= fit_limits[1]))
if isinstance(we, str):
d = fit_d.Data(_x[inside], _y[inside], we=we, idx=set_id)
else:
d = fit_d.Data(_x[inside], _y[inside], we=we[inside], idx=set_id)
try:
if isinstance(we, str):
d = fit_d.Data(_x[inside], _y[inside], we=we, idx=set_id)
else:
d = fit_d.Data(_x[inside], _y[inside], we=we[inside], idx=set_id)
except Exception as e:
raise Exception(f'Setting data failed for {set_id}')
d.set_model(m)
d.set_parameter(set_params[0], var=model_p['var'],
lb=model_p['lb'], ub=model_p['ub'],
fun_kwargs=set_params[1])
try:
d.set_parameter(set_params[0], var=model_p['var'],
lb=model_p['lb'], ub=model_p['ub'],
fun_kwargs=set_params[1])
except Exception as e:
raise Exception('Setting parameter failed') from e
self.fitter.add_data(d)
@ -504,7 +520,9 @@ class UpperManagement(QtCore.QObject):
logger.error('Fit preparation failed', *e.args)
QtWidgets.QMessageBox.warning(QtWidgets.QWidget(),
'Fit prep failed',
f'Fit preparation failed with message\n{e.args}')
f'Fit preparation failed:\n'
'Message:\n'
f'{e.args}:\n')
return False
def start_fit(self):