From 1162458290f1ff34e9994e1c9ce2889d5af247aa Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 4 Apr 2024 17:26:52 +0000 Subject: [PATCH] catch empty sets before fit (#265); closes #261 Co-authored-by: Dominik Demuth Reviewed-on: https://gitea.pkm.physik.tu-darmstadt.de/IPKM/nmreval/pulls/265 --- src/gui_qt/main/management.py | 4 ++-- src/nmreval/fit/data.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index d334930..56c387a 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -543,7 +543,7 @@ class UpperManagement(QtCore.QObject): else: 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}') + raise Exception(f'Setting data failed for {data_i.name}') from e d.set_model(m) try: @@ -559,7 +559,7 @@ class UpperManagement(QtCore.QObject): return True 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(), 'Fit prep failed', f'Fit preparation failed:\n' diff --git a/src/nmreval/fit/data.py b/src/nmreval/fit/data.py index b6b94ff..7b39aa2 100644 --- a/src/nmreval/fit/data.py +++ b/src/nmreval/fit/data.py @@ -10,6 +10,9 @@ 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.x.size == 0 or self.y.size == 0: + raise ValueError("Data is empty") + 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]}')