fix point selection for values with all the same x (#190)
All checks were successful
Build AppImage / Explore-Gitea-Actions (push) Successful in 1m59s

bugfix for issue #189; closes #189

Co-authored-by: Dominik Demuth <dominik.demuth@physik.tu-darmstadt.de>
Reviewed-on: #190
This commit is contained in:
Dominik Demuth 2023-12-28 10:24:34 +00:00
parent 92a3933ed4
commit 2cf94af2c4
2 changed files with 24 additions and 15 deletions

View File

@ -742,8 +742,10 @@ class UpperManagement(QtCore.QObject):
new_datasets[data_i.group] = [], [] new_datasets[data_i.group] = [], []
new_x_axis, _temp = new_datasets[data_i.group] new_x_axis, _temp = new_datasets[data_i.group]
pts = data_i.points(params)
if pts:
new_x_axis.append(data_i.value) new_x_axis.append(data_i.value)
_temp.append(data_i.points(params)) _temp.append(pts)
key_list = [] key_list = []
for label, (new_x_axis, _temp) in new_datasets.items(): for label, (new_x_axis, _temp) in new_datasets.items():

View File

@ -319,39 +319,46 @@ class Points:
if pts is None: if pts is None:
pts = [] pts = []
_tmp_x = self._x[self.mask]
_tmp_y = self._y[self.mask]
if idx is not None: if idx is not None:
for x in idx: for idx_i in idx:
if isinstance(x, tuple): if isinstance(idx_i, tuple):
x_idx = np.argmin(np.abs(self._x[self.mask] - (x[0]+x[1])/2)) in_region = np.where((_tmp_x - idx_i[0] > 0) & (idx_i[1] - _tmp_x > 0))[0]
left_b = np.argmin(np.abs(self._x[self.mask] - x[0])) if len(in_region) > 0:
right_b = np.argmin(np.abs(self._x[self.mask] - x[1])) x_idx = in_region[in_region.size//2]
left_b = in_region[0]
right_b = in_region[-1] + 1
else: else:
x_idx = np.argmin(np.abs(self._x[self.mask]-x)) continue
else:
x_idx = np.argmin(np.abs(_tmp_x-idx_i))
left_b = int(max(0, x_idx - avg_range[0])) left_b = int(max(0, x_idx - avg_range[0]))
right_b = int(min(len(self), x_idx + avg_range[1] + 1)) right_b = int(min(len(self), x_idx + avg_range[1] + 1))
if left_b < right_b: if left_b < right_b:
pts.append([self._x[x_idx], *self._average(avg_mode, x_idx, left_b, right_b)]) pts.append([_tmp_x[x_idx], *self._average(avg_mode, x_idx, left_b, right_b)])
else: else:
pts.append([self._x[x_idx], self._y[x_idx], self._y_err[x_idx]]) pts.append([_tmp_x[x_idx], _tmp_y[x_idx], self._y_err[x_idx]])
if special is not None: if special is not None:
if special not in ['max', 'min', 'absmax', 'absmin']: if special not in ['max', 'min', 'absmax', 'absmin']:
raise ValueError('Parameter "special" must be "max", "min", "absmax", "absmin".') raise ValueError('Parameter "special" must be "max", "min", "absmax", "absmin".')
if special == 'max': if special == 'max':
x_idx = np.argmax(self._y.real[self.mask]) x_idx = np.argmax(_tmp_y.real)
elif special == 'min': elif special == 'min':
x_idx = np.argmax(self._y.real[self.mask]) x_idx = np.argmax(_tmp_y.real)
elif special == 'absmax': elif special == 'absmax':
x_idx = np.argmax(np.abs(self._y[self.mask])) x_idx = np.argmax(np.abs(_tmp_y))
else: else:
x_idx = np.argmin(np.abs(self._y[self.mask])) x_idx = np.argmin(np.abs(_tmp_y))
left_b = int(max(0, x_idx - avg_range[0])) left_b = int(max(0, x_idx - avg_range[0]))
right_b = int(min(len(self), x_idx + avg_range[1] + 1)) right_b = int(min(len(self), x_idx + avg_range[1] + 1))
pts.append([self._x[self.mask][x_idx], *self._average(avg_mode, x_idx, left_b, right_b)]) pts.append([_tmp_x[x_idx], *self._average(avg_mode, x_idx, left_b, right_b)])
return pts return pts