Skip to content

Commit 13a2d40

Browse files
committed
ACtually figured out the logic to use for the negative error removal, took me long enough.
1 parent 5b7d748 commit 13a2d40

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

xga/relations/fit.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 25/07/2024, 13:50. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 25/07/2024, 14:27. Copyright (c) The Contributors
33
import inspect
44
from types import FunctionType
55
from typing import Tuple, Union
@@ -77,23 +77,22 @@ def _fit_initialise(y_values: Quantity, y_errs: Quantity, x_values: Quantity, x_
7777
y_not_nans = np.where(~np.isnan(y_values))[0]
7878
all_not_nans = np.intersect1d(x_not_nans, y_not_nans)
7979

80-
# We'll warn the user if some entries are being excluded because they're NaNs
81-
thrown_away = len(x_values) - len(all_not_nans)
82-
if thrown_away != 0:
83-
warn("{} sources have NaN values and have been excluded".format(thrown_away), stacklevel=2)
80+
# We also check for negative uncertainties, which are obviously bogus and cause plotting/fit issues later on - we
81+
# take the opposite approach (in terms of boolean logic) to identifying the bad entries, because its easier
82+
x_err_are_neg = np.where(x_errs < 0)[0]
83+
y_err_are_neg = np.where(y_errs < 0)[0]
8484

85-
# We also check for negative uncertainties, which are obviously bogus and cause plotting/fit issues later on
86-
x_err_not_neg = np.where(x_errs >= 0)[0]
87-
y_err_not_neg = np.where(y_errs >= 0)[0]
88-
all_err_not_neg = np.intersect1d(x_err_not_neg, y_err_not_neg)
85+
all_err_not_neg = np.intersect1d(np.setdiff1d(np.arange(0, len(x_errs)), x_err_are_neg),
86+
np.setdiff1d(np.arange(0, len(y_errs)), y_err_are_neg))
8987

9088
# Intersect the two selection criteria
9189
all_acc = np.intersect1d(all_not_nans, all_err_not_neg)
9290

9391
# And we'll repeat the warning exercise if any were excluded because they have negative uncertainties
94-
thrown_away = len(x_values) - len(all_err_not_neg)
92+
thrown_away = len(x_values) - len(all_acc)
9593
if thrown_away != 0:
96-
warn("{} sources have negative uncertainties and have been excluded".format(thrown_away), stacklevel=2)
94+
warn("{} sources have NaN values or negative uncertainties and have been excluded".format(thrown_away),
95+
stacklevel=2)
9796

9897
# Only values that aren't NaN and don't have negative errors will be permitted
9998
x_values = x_values[all_acc]

0 commit comments

Comments
 (0)