Skip to content

Commit

Permalink
Add a check the num_obs is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Jan 17, 2025
1 parent e02df26 commit 6194af1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/kbmod/search/stack_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ StackSearch::StackSearch(ImageStack& imstack) : stack(imstack), results(0), gpu_
// Configuration functions
// --------------------------------------------

void StackSearch::set_min_obs(int new_value) { params.min_observations = new_value; }
void StackSearch::set_min_obs(int new_value) {
if (new_value < 0)
throw std::runtime_error("min_obs must be >= 0.");
if (new_value > stack.img_count())
throw std::runtime_error("min_obs cannot be greater than the number of images.");

params.min_observations = new_value;
}

void StackSearch::set_min_lh(float new_value) { params.min_lh = new_value; }

Expand Down
8 changes: 8 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ def test_results_off_chip(self):
self.assertAlmostEqual(best.vx / trj.vx, 1, delta=self.velocity_error)
self.assertAlmostEqual(best.vy / trj.vy, 1, delta=self.velocity_error)

def test_stack_search_set_min_obs(self):
self.search.set_min_obs(1) # Okay
self.search.set_min_obs(self.img_count) # Okay
with self.assertRaises(RuntimeError):
self.search.set_min_obs(-1)
with self.assertRaises(RuntimeError):
self.search.set_min_obs(self.img_count + 1)

@staticmethod
def result_hash(res):
return hash((res.x, res.y, res.vx, res.vy, res.lh, res.obs_count))
Expand Down

0 comments on commit 6194af1

Please sign in to comment.