Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check against case where all likelihoods < 0 #428

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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