Skip to content

Commit

Permalink
Fix badly rounded constellation boundaries (#548)
Browse files Browse the repository at this point in the history
Fixes #547.
  • Loading branch information
mgarraha committed Feb 6, 2021
1 parent dd4ec5b commit 6e79462
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 3 additions & 6 deletions builders/build_constellations.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,11 @@ def compute_constellation(ra, dec, sorted_ra, sorted_dec, sorted_consts, grid):
def extend(s):
"""Return a float for `s` extended to machine precision.
Takes a string like '13.6667', extends it to >30 digits by
duplicating the second-to-last character ('6' and not '7' because
the '7' in many cases will have been rounded), and passes it to
`float()`.
Takes a string like '13.6667', passes it to `float()`,
and snaps it to the nearest whole second.
"""
s = s[:-2] + 30 * s[-2:-1] + s[-1:]
return float(s)
return round(3600 * float(s)) / 3600.

# Some discarded code that I might want to revive someday: how to grow
# and shrink a list of segments as new ones supersede old ones on the
Expand Down
Binary file modified skyfield/data/constellations.npz
Binary file not shown.
6 changes: 6 additions & 0 deletions skyfield/tests/test_constellations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from skyfield.api import load_constellation_map, position_of_radec
from skyfield.timelib import Time, julian_date_of_besselian_epoch

def test_constellations():
lookup = load_constellation_map()
Expand All @@ -10,6 +11,11 @@ def test_constellations():
assert lookup(position_of_radec(4.65, 0)) == 'Eri'
assert lookup(position_of_radec(4.75, 0.3)) == 'Ori'

# exploit extend() bug, issue 547
B1875 = Time(None, julian_date_of_besselian_epoch(1875))
assert lookup(position_of_radec(18.1747, 39., epoch=B1875)) == 'Her'
assert lookup(position_of_radec(18.1753, 39., epoch=B1875)) == 'Lyr'

# Test vectorization.
assert list(
lookup(position_of_radec([4.65, 4.75], [0, 0.3]))
Expand Down

0 comments on commit 6e79462

Please sign in to comment.