Skip to content

Commit

Permalink
Use the pixel_value_valid function in a few more places
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Mar 1, 2024
1 parent 7a1ae0b commit 3ec1179
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/kbmod/search/psi_phi_array_ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct PsiPhi {

// Helper utility functions.
inline float encode_uint_scalar(float value, float min_val, float max_val, float scale) {
return (value == NO_DATA) ? 0 : (std::max(std::min(value, max_val), min_val) - min_val) / scale + 1.0;
return !pixel_value_valid(value) ? 0 : (std::max(std::min(value, max_val), min_val) - min_val) / scale + 1.0;
}

inline float decode_uint_scalar(float value, float min_val, float scale) {
Expand Down
2 changes: 1 addition & 1 deletion src/kbmod/search/stack_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ std::vector<float> StackSearch::extract_psi_or_phi_curve(Trajectory& trj, bool e
PsiPhi psi_phi_val = psi_phi_array.read_psi_phi(i, pred_idx.i, pred_idx.j);

float value = (extract_psi) ? psi_phi_val.psi : psi_phi_val.phi;
if (value != NO_DATA) {
if (pixel_value_valid(value)) {
result[i] = value;
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/test_psi_phi_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def encode_uint_scalar(self):
# NO_DATA always encodes to 0.0.
self.assertAlmostEqual(encode_uint_scalar(KB_NO_DATA, 0.0, 10.0, 0.1), 0.0)

# NAN always encodes to 0.0.
self.assertAlmostEqual(encode_uint_scalar(math.nan, 0.0, 10.0, 0.1), 0.0)
self.assertAlmostEqual(encode_uint_scalar(np.nan, 0.0, 10.0, 0.1), 0.0)

# Test clipping.
self.assertAlmostEqual(encode_uint_scalar(11.0, 0.0, 10.0, 0.1), 100.0)
self.assertAlmostEqual(encode_uint_scalar(-100.0, 0.0, 10.0, 0.1), 1.0)
Expand Down

0 comments on commit 3ec1179

Please sign in to comment.