catch empty sets before fit

This commit is contained in:
Dominik Demuth 2024-04-04 19:25:43 +02:00
parent c8aad904a8
commit 7127cb4e94
2 changed files with 5 additions and 2 deletions

View File

@ -543,7 +543,7 @@ class UpperManagement(QtCore.QObject):
else: else:
d = fit_d.Data(_x[inside], _y[inside], we=we[inside], idx=set_id, complex_type=data_complex) d = fit_d.Data(_x[inside], _y[inside], we=we[inside], idx=set_id, complex_type=data_complex)
except Exception as e: except Exception as e:
raise Exception(f'Setting data failed for {set_id}') raise Exception(f'Setting data failed for {data_i.name}') from e
d.set_model(m) d.set_model(m)
try: try:
@ -559,7 +559,7 @@ class UpperManagement(QtCore.QObject):
return True return True
except Exception as e: except Exception as e:
logger.error('Fit preparation failed', *e.args) logger.error(f'Fit preparation failed with error: {e.args}')
QtWidgets.QMessageBox.warning(QtWidgets.QWidget(), QtWidgets.QMessageBox.warning(QtWidgets.QWidget(),
'Fit prep failed', 'Fit prep failed',
f'Fit preparation failed:\n' f'Fit preparation failed:\n'

View File

@ -10,6 +10,9 @@ class Data:
def __init__(self, x, y, we=None, idx=None, complex_type: int = 0): def __init__(self, x, y, we=None, idx=None, complex_type: int = 0):
self.x = np.asarray(x) self.x = np.asarray(x)
self.y = np.asarray(y) self.y = np.asarray(y)
if self.x.size == 0 or self.y.size == 0:
raise ValueError("Data is empty")
if self.y.shape[0] != self.x.shape[0]: if self.y.shape[0] != self.x.shape[0]:
raise ValueError(f'x and y have different lengths {self.x.shape[0]} and {self.y.shape[0]}') raise ValueError(f'x and y have different lengths {self.x.shape[0]} and {self.y.shape[0]}')