Skip to content

Commit

Permalink
Merge pull request #428 from dirac-institute/error_checking
Browse files Browse the repository at this point in the history
Check against case where all likelihoods < 0
  • Loading branch information
jeremykubica authored Jan 11, 2024
2 parents 08317b7 + 177459f commit b965404
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/kbmod/filters/sigma_g_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def compute_clipped_sigma_g(self, lh):
The indices that pass the filtering for a given set of curves.
"""
if self.clip_negative:
# Skip entries where we will clip everything (all lh < 0).
if np.count_nonzero(lh > 0) == 0:
return np.array([])
lower_per, median, upper_per = np.percentile(lh[lh > 0], [self.low_bnd, 50, self.high_bnd])
else:
lower_per, median, upper_per = np.percentile(lh, [self.low_bnd, 50, self.high_bnd])
Expand Down
7 changes: 7 additions & 0 deletions tests/test_sigma_g_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def test_sigma_g_negative_clipping(self):
for i in range(num_points):
self.assertEqual(i in result, i > 2 and i != 5 and i != 14)

def test_sigma_g_all_negative_clipping(self):
num_points = 10
lh = np.array([(-100.0 + i * 0.2) for i in range(num_points)])
params = SigmaGClipping(clip_negative=True)
result = params.compute_clipped_sigma_g(lh)
self.assertEqual(len(result), 0)

def test_apply_clipped_sigma_g(self):
"""Confirm the clipped sigmaG filter works when used in the bulk filter mode."""
num_times = 20
Expand Down

0 comments on commit b965404

Please sign in to comment.