Skip to content

Commit

Permalink
add fix and tests for values very close to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jan 10, 2025
1 parent f47a9ac commit ce36070
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions py/desiutil/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def radec_to_desiname(target_ra, target_dec):
# zfill works properly with '-' but counts it in number of characters
# so need one more
if dec.startswith('-'):
desiname += dec[:-precision].zfill(3) + '.' + dec[-precision:]
zdec = dec.zfill(7)
desiname += zdec[:-precision] + '.' + zdec[-precision:]
else:
desiname += '+' + dec[:-precision].zfill(2) + '.' + dec[-precision:]
zdec = dec.zfill(6)
desiname += '+' + dec[:-precision] + '.' + dec[-precision:]
desinames.append(desiname)

return np.array(desinames)
9 changes: 6 additions & 3 deletions py/desiutil/test/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ def tearDownClass(cls):
def test_radec_to_desiname(self):
"""Test computation of desiname.
"""
ras = [6.2457354547234, 23.914121939862518, 36.23454570972834,
ras = [0.003456789, 6.2457354547234, 23.914121939862518, 36.23454570972834, 40.669625, 40.669625,
235.25235223446, 99.9999999999999]
decs = [29.974787585945496, -42.945872347904356, -0.9968423456,
decs = [7.434432123, 29.974787585945496, -42.945872347904356, -0.9968423456, -0.013277777, 0.013277777,
8.45677345352345, 89.234958294953]
correct_names = np.array(['DESI J006.2457+29.9747',
correct_names = np.array(['DESI J000.0034+07.4344',
'DESI J006.2457+29.9747',
'DESI J023.9141-42.9458',
'DESI J036.2345-00.9968',
'DESI J040.6696-00.0132',
'DESI J040.6696+00.0132',
'DESI J235.2523+08.4567',
'DESI J099.9999+89.2349'])
# Test scalar conversion
Expand Down

0 comments on commit ce36070

Please sign in to comment.