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

Add bounds checks to radec_to_desiname #207

Merged
merged 11 commits into from
May 14, 2024
14 changes: 7 additions & 7 deletions py/desiutil/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def radec_to_desiname(target_ra, target_dec):
target_ra, target_dec = np.atleast_1d(target_ra), np.atleast_1d(target_dec)

inputs = {'target_ra': target_ra, 'target_dec': target_dec}
tests = {'NaN values': np.isnan,
'Infinite values': np.isinf,
'RA not in range [0, 360)': lambda x: (x < 0) | (x >= 360),
'Dec not in range [-90, 90]': lambda x: (x < -90) | (x > 90)}
tests = (('NaN values', np.isnan),
('Infinite values', np.isinf),
('RA not in range [0, 360)', lambda x: (x < 0) | (x >= 360)),
('Dec not in range [-90, 90]', lambda x: (x < -90) | (x > 90)))
for i in inputs:
weaverba137 marked this conversation as resolved.
Show resolved Hide resolved
for t in tests:
if (tests[t](inputs[i])).any():
raise ValueError(f"{t} detected in {i}!")
for key, check in tests:
if (check(inputs[i])).any():
raise ValueError(f"{key} detected in {i}!")
weaverba137 marked this conversation as resolved.
Show resolved Hide resolved

# Number of decimal places in final naming convention
precision = 4
Expand Down
5 changes: 5 additions & 0 deletions py/desiutil/test/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ def test_radec_to_desiname_bad_values(self):
with self.assertRaises(ValueError) as e:
outnames = radec_to_desiname(ras, decs)
self.assertEqual(str(e.exception), "NaN values detected in target_ra!")
weaverba137 marked this conversation as resolved.
Show resolved Hide resolved

ras[2] = np.inf
with self.assertRaises(ValueError) as e:
outnames = radec_to_desiname(ras, decs)
self.assertEqual(str(e.exception), "Infinite values detected in target_ra!")
Loading