Skip to content

Commit

Permalink
explicitly add precision to zero-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jan 10, 2025
1 parent 7f7b770 commit ff61ead
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions py/desiutil/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def radec_to_desiname(target_ra, target_dec):
# IAU compliant term
desinames = []
for ra, dec in zip(ratrunc, dectrunc):
zra = ra.zfill(7)
zra = ra.zfill(3 + precision) # RA always has 3 leading digits.
desiname = 'DESI J' + zra[:-precision] + '.' + zra[-precision:]
# Positive numbers need an explicit "+" while negative numbers
# already have a "-".
# zfill works properly with '-' but counts it in number of characters
# so need one more
# zfill works properly with '-' but counts it in the number of characters
# so need one extra character is needed.
if dec.startswith('-'):
zdec = dec.zfill(7)
zdec = dec.zfill(3 + precision) # 2 leading digits plus space for '-'.
desiname += zdec[:-precision] + '.' + zdec[-precision:]
else:
zdec = dec.zfill(6)
zdec = dec.zfill(2 + precision) # 2 leading digits and the '+' is added explicitly.
desiname += '+' + zdec[:-precision] + '.' + zdec[-precision:]
desinames.append(desiname)

Expand Down

0 comments on commit ff61ead

Please sign in to comment.