ensure sorted sets before averaging in pick points #226
@ -17,7 +17,7 @@ body:
|
|||||||
description: For which version have you observed this behavior?
|
description: For which version have you observed this behavior?
|
||||||
placeholder: You find the program version in "Help/About"
|
placeholder: You find the program version in "Help/About"
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: false
|
||||||
- type: textarea
|
- type: textarea
|
||||||
attributes:
|
attributes:
|
||||||
label: Expected behavior
|
label: Expected behavior
|
||||||
|
@ -320,7 +320,11 @@ class Points:
|
|||||||
pts = []
|
pts = []
|
||||||
|
|
||||||
_tmp_x = self._x[self.mask]
|
_tmp_x = self._x[self.mask]
|
||||||
_tmp_y = self._y[self.mask]
|
x_order = np.argsort(_tmp_x)
|
||||||
|
_tmp_x = _tmp_x[x_order]
|
||||||
|
_tmp_y = self._y[self.mask][x_order]
|
||||||
|
_tmp_yerr = self._y_err[self.mask][x_order]
|
||||||
|
|
||||||
if idx is not None:
|
if idx is not None:
|
||||||
for idx_i in idx:
|
for idx_i in idx:
|
||||||
if isinstance(idx_i, tuple):
|
if isinstance(idx_i, tuple):
|
||||||
@ -338,7 +342,7 @@ class Points:
|
|||||||
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([_tmp_x[x_idx], *self._average(avg_mode, x_idx, left_b, right_b)])
|
pts.append([_tmp_x[x_idx], *self._average(_tmp_x, _tmp_y, _tmp_yerr, avg_mode, x_idx, left_b, right_b)])
|
||||||
else:
|
else:
|
||||||
pts.append([_tmp_x[x_idx], _tmp_y[x_idx], self._y_err[x_idx]])
|
pts.append([_tmp_x[x_idx], _tmp_y[x_idx], self._y_err[x_idx]])
|
||||||
|
|
||||||
@ -358,28 +362,37 @@ class Points:
|
|||||||
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([_tmp_x[x_idx], *self._average(avg_mode, x_idx, left_b, right_b)])
|
pts.append([_tmp_x[x_idx], *self._average(_tmp_x, _tmp_y, _tmp_yerr, avg_mode, x_idx, left_b, right_b)])
|
||||||
|
|
||||||
return pts
|
return pts
|
||||||
|
|
||||||
def _average(self, mode: str, idx, left: int, right: int) -> tuple[float, float]:
|
@staticmethod
|
||||||
|
def _average(
|
||||||
|
x: np.ndarray,
|
||||||
|
y: np.ndarray,
|
||||||
|
y_err: np.ndarray,
|
||||||
|
mode: str,
|
||||||
|
idx: int,
|
||||||
|
left: int,
|
||||||
|
right: int,
|
||||||
|
) -> tuple[float, float]:
|
||||||
if mode == 'mean':
|
if mode == 'mean':
|
||||||
y_mean = np.mean(self._y[self.mask][left:right].real)
|
y_mean = np.mean(y[left:right].real)
|
||||||
y_err = np.linalg.norm(self._y_err[self.mask][left:right]) / (right - left)
|
y_err_mean = np.linalg.norm(y_err[left:right]) / (right - left)
|
||||||
|
|
||||||
elif mode == 'sum':
|
elif mode == 'sum':
|
||||||
y_mean = np.sum(self._y[self.mask][left:right].real)
|
y_mean = np.sum(y[left:right].real)
|
||||||
y_err = np.linalg.norm(self._y_err[self.mask][left:right])
|
y_err_mean = np.linalg.norm(y_err[left:right])
|
||||||
|
|
||||||
elif mode == 'integral':
|
elif mode == 'integral':
|
||||||
y_mean = simpson(self._y[self.mask][left:right].real, x=self._x[left:right])
|
y_mean = simpson(y[left:right].real, x=x[left:right])
|
||||||
y_err = np.linalg.norm(cumulative_trapezoid(self._y_err[self.mask][left:right].real, x=self._x[left:right]))
|
y_err_mean = np.linalg.norm(cumulative_trapezoid(y_err[left:right].real, x=x[left:right]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
y_mean = self._y[self.mask][idx].real
|
y_mean = y[idx].real
|
||||||
y_err = self._y_err[self.mask][idx]
|
y_err_mean = y_err[idx]
|
||||||
|
|
||||||
return y_mean, y_err
|
return y_mean, y_err_mean
|
||||||
|
|
||||||
def concatenate(self, other):
|
def concatenate(self, other):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user