|
1 | 1 | # 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 |
3 | 3 | import inspect
|
4 | 4 | from types import FunctionType
|
5 | 5 | from typing import Tuple, Union
|
@@ -77,23 +77,22 @@ def _fit_initialise(y_values: Quantity, y_errs: Quantity, x_values: Quantity, x_
|
77 | 77 | y_not_nans = np.where(~np.isnan(y_values))[0]
|
78 | 78 | all_not_nans = np.intersect1d(x_not_nans, y_not_nans)
|
79 | 79 |
|
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] |
84 | 84 |
|
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)) |
89 | 87 |
|
90 | 88 | # Intersect the two selection criteria
|
91 | 89 | all_acc = np.intersect1d(all_not_nans, all_err_not_neg)
|
92 | 90 |
|
93 | 91 | # 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) |
95 | 93 | 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) |
97 | 96 |
|
98 | 97 | # Only values that aren't NaN and don't have negative errors will be permitted
|
99 | 98 | x_values = x_values[all_acc]
|
|
0 commit comments