Skip to content

Commit

Permalink
Remove old NamedStar experiment (from version 0.5)
Browse files Browse the repository at this point in the history
This old experimental `NamedStar` API from 2015, which was never
documented, is now broken because the Hipparcos catalog is not (for the
moment) being downloaded in compressed form (see #454).  Rather than
delay today’s release to fix `NamedStar`, let’s remove it.

This is a dicey and uncharacteristic decision for me.  I usually pride
myself on not breaking anything that appears in a file like `api.py` and
that someone might have started using through their own research of the
code.  But in this case, with the function marked as deprecated for
several years, I am going to chance it.

Thanks to the original author, though, as the experiment led eventually
to the modern approach of loading stars using a Pandas Dataframe!

The actual dictionary of named stars is retained, per promises in #304.
  • Loading branch information
brandon-rhodes committed Sep 24, 2020
1 parent ad118f7 commit 1d76970
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 98 deletions.
9 changes: 4 additions & 5 deletions builders/build_novas_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
from skyfield.api import Topos, load
from skyfield.constants import AU_KM, AU_M
from skyfield.data import hipparcos
from skyfield.functions import length_of
from skyfield.functions import BytesIO, length_of
from .fixes import low_precision_ERA
OLD_AU_KM = 149597870.691 # TODO: load from de405
Expand Down Expand Up @@ -465,10 +465,9 @@ def output_catalog_tests(dates):
output(locals(), r"""
def test_hipparcos_conversion{i}(earth):
line = 'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
star = hipparcos.parse(line)
compare(star.ra.hours, {polaris.ra!r}, 0.001 * ra_arcsecond)
compare(star.dec.degrees, {polaris.dec!r}, 0.001 * arcsecond)
line = b'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
df = hipparcos.load_dataframe(BytesIO(line))
star = starlib.Star.from_dataframe(df.iloc[0])
ra, dec, distance = earth.at(load.timescale().tt_jd({jd})).observe(star).radec()
compare(ra.hours, {ra!r}, 0.00001 * ra_arcsecond)
compare(dec.degrees, {dec!r}, 0.00001 * arcsecond)
Expand Down
6 changes: 3 additions & 3 deletions skyfield/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
)
from .toposlib import Topos
from .units import Angle, Distance
from .named_stars import NamedStar

load = Loader('.')

__all__ = [
'Angle', 'B1950', 'Distance', 'EarthSatellite',
'GREGORIAN_START', 'GREGORIAN_START_ENGLAND',
'Loader', 'NamedStar', 'PlanetaryConstants', 'Star', 'T0', 'Time',
'Timescale', 'Topos', 'datetime', 'load', 'load_constellation_map',
'Loader', 'PlanetaryConstants', 'Star',
'T0', 'Time', 'Timescale', 'Topos',
'datetime', 'load', 'load_constellation_map',
'load_file', 'position_from_radec', 'position_of_radec',
'utc', 'pi', 'tau',
]
Expand Down
51 changes: 6 additions & 45 deletions skyfield/data/hipparcos.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import gzip
from skyfield.functions import to_spherical
from skyfield.starlib import Star
from skyfield.timelib import T0
from skyfield.units import Angle

days = T0 - 2448349.0625

# This URL worked until September 2020:

#URL = 'http://cdsarc.u-strasbg.fr/ftp/cats/I/239/hip_main.dat.gz'
Expand All @@ -24,32 +16,6 @@

url = URL # old name, in case anyone used it

def parse(line):
"DEPRECATED; see :func:`~skyfield.data.hipparcos.load_dataframe() instead."
# See ftp://cdsarc.u-strasbg.fr/cats/I/239/ReadMe
star = Star(
ra=Angle(degrees=float(line[51:63])),
dec=Angle(degrees=float(line[64:76])),
ra_mas_per_year=float(line[87:95]),
dec_mas_per_year=float(line[96:104]),
parallax_mas=float(line[79:86]),
names=[('HIP', int(line[8:14]))],
)
star._position_au += star._velocity_au_per_d * days
distance, dec, ra = to_spherical(star._position_au)
star.ra = Angle(radians=ra, preference='hours')
star.dec = Angle(radians=dec)
return star

def load(match_function):
"DEPRECATED; see :func:`~skyfield.data.hipparcos.load_dataframe() instead."
from skyfield import api

with api.load.open(url) as f:
for line in gzip.GzipFile(fileobj=f):
if match_function(line):
yield parse(line)

PANDAS_MESSAGE = """Skyfield needs Pandas to load the Hipparcos catalog
To load the Hipparcos star catalog, Skyfield needs the Pandas data
Expand Down Expand Up @@ -84,8 +50,13 @@ def load_dataframe(fobj):
except ImportError:
raise ImportError(PANDAS_MESSAGE)

fobj.seek(0)
magic = fobj.read(2)
compression = 'gzip' if (magic == b'\x1f\x8b') else None
fobj.seek(0)

df = read_csv(
fobj, sep='|', names=_COLUMN_NAMES,
fobj, sep='|', names=_COLUMN_NAMES, compression=compression,
usecols=['HIP', 'Vmag', 'RAdeg', 'DEdeg', 'Plx', 'pmRA', 'pmDE'],
na_values=[' ', ' ', ' ', ' '],
)
Expand All @@ -98,13 +69,3 @@ def load_dataframe(fobj):
epoch_year = 1991.25,
)
return df.set_index('hip')

def get(which):
"DEPRECATED; see :func:`~skyfield.data.hipparcos.load_dataframe() instead."
if isinstance(which, str):
pattern = ('H| %6s' % which).encode('ascii')
for star in load(lambda line: line.startswith(pattern)):
return star
else:
patterns = set(id.encode('ascii').rjust(6) for id in which)
return list(load(lambda line: line[8:14] in patterns))
21 changes: 5 additions & 16 deletions skyfield/named_stars.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# TODO: Deprecate; maybe even remove, since it's not documented?
"""
Convenience functions for users to get a Star instance using a small database
of named stars.
"""
from .data import hipparcos
# This list was seeded from:
# https://en.wikipedia.org/wiki/List_of_stars_in_the_Hipparcos_Catalogue

# Recent discussion:
# https://github.com/skyfielders/python-skyfield/issues/304

#This list was seeded from
#https://en.wikipedia.org/wiki/List_of_stars_in_the_Hipparcos_Catalogue
named_star_dict= {
'Achernar': 7588,
'Acrux': 60718,
Expand Down Expand Up @@ -128,11 +125,3 @@
'Wei': 82396,
'Wezen': 34444
}

def NamedStar(name):
"""DEPRECATED: See stars.rst for how to load a star catalog."""
try:
hid = named_star_dict[name]
return hipparcos.get(str(hid))
except KeyError:
raise ValueError("No star named {0} known to skyfield.".format(name))
37 changes: 16 additions & 21 deletions skyfield/tests/test_against_novas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from skyfield.api import Topos, load
from skyfield.constants import AU_KM, AU_M
from skyfield.data import hipparcos
from skyfield.functions import length_of
from skyfield.functions import BytesIO, length_of
from .fixes import low_precision_ERA

OLD_AU_KM = 149597870.691 # TODO: load from de405
Expand Down Expand Up @@ -3105,46 +3105,41 @@ def test_moon_topocentric_date4(de405):
compare(az.degrees, (151.19707488767745, 338.13295291812307, 156.2971102404744, 191.29497427201525), 0.0005 * arcsecond)

def test_hipparcos_conversion0(earth):
line = 'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
star = hipparcos.parse(line)
compare(star.ra.hours, 2.530301023497941, 0.001 * ra_arcsecond)
compare(star.dec.degrees, 89.26410950742938, 0.001 * arcsecond)
line = b'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
df = hipparcos.load_dataframe(BytesIO(line))
star = starlib.Star.from_dataframe(df.iloc[0])
ra, dec, distance = earth.at(load.timescale().tt_jd(2440423.345833333)).observe(star).radec()
compare(ra.hours, 2.5283697000528966, 0.00001 * ra_arcsecond)
compare(dec.degrees, 89.26420852419295, 0.00001 * arcsecond)

def test_hipparcos_conversion1(earth):
line = 'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
star = hipparcos.parse(line)
compare(star.ra.hours, 2.530301023497941, 0.001 * ra_arcsecond)
compare(star.dec.degrees, 89.26410950742938, 0.001 * arcsecond)
line = b'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
df = hipparcos.load_dataframe(BytesIO(line))
star = starlib.Star.from_dataframe(df.iloc[0])
ra, dec, distance = earth.at(load.timescale().tt_jd(2448031.5)).observe(star).radec()
compare(ra.hours, 2.529691010447949, 0.00001 * ra_arcsecond)
compare(dec.degrees, 89.26413900274704, 0.00001 * arcsecond)

def test_hipparcos_conversion2(earth):
line = 'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
star = hipparcos.parse(line)
compare(star.ra.hours, 2.530301023497941, 0.001 * ra_arcsecond)
compare(star.dec.degrees, 89.26410950742938, 0.001 * arcsecond)
line = b'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
df = hipparcos.load_dataframe(BytesIO(line))
star = starlib.Star.from_dataframe(df.iloc[0])
ra, dec, distance = earth.at(load.timescale().tt_jd(2451545.0)).observe(star).radec()
compare(ra.hours, 2.5302921836971946, 0.00001 * ra_arcsecond)
compare(dec.degrees, 89.26411033462212, 0.00001 * arcsecond)

def test_hipparcos_conversion3(earth):
line = 'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
star = hipparcos.parse(line)
compare(star.ra.hours, 2.530301023497941, 0.001 * ra_arcsecond)
compare(star.dec.degrees, 89.26410950742938, 0.001 * arcsecond)
line = b'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
df = hipparcos.load_dataframe(BytesIO(line))
star = starlib.Star.from_dataframe(df.iloc[0])
ra, dec, distance = earth.at(load.timescale().tt_jd(2456164.5)).observe(star).radec()
compare(ra.hours, 2.5311170753257395, 0.00001 * ra_arcsecond)
compare(dec.degrees, 89.26406913848278, 0.00001 * arcsecond)

def test_hipparcos_conversion4(earth):
line = 'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
star = hipparcos.parse(line)
compare(star.ra.hours, 2.530301023497941, 0.001 * ra_arcsecond)
compare(star.dec.degrees, 89.26410950742938, 0.001 * arcsecond)
line = b'H| 11767| |02 31 47.08|+89 15 50.9| 1.97|1|H|037.94614689|+89.26413805| | 7.56| 44.22| -11.74| 0.39| 0.45| 0.48| 0.47| 0.55|-0.16| 0.05| 0.27|-0.01| 0.08| 0.05| 0.04|-0.12|-0.09|-0.36| 1| 1.22| 11767| 2.756|0.003| 2.067|0.003| | 0.636|0.003|T|0.70|0.00|L| | 2.1077|0.0021|0.014|102| | 2.09| 2.13| 3.97|P|1|A|02319+8915|I| 1| 1| | | | | | | | | |S| |P| 8890|B+88 8 | | |0.68|F7:Ib-IIv SB|G\n'
df = hipparcos.load_dataframe(BytesIO(line))
star = starlib.Star.from_dataframe(df.iloc[0])
ra, dec, distance = earth.at(load.timescale().tt_jd([2440423.345833333, 2448031.5, 2451545.0, 2456164.5])).observe(star).radec()
compare(ra.hours, (2.5283697000528966, 2.529691010447949, 2.5302921836971946, 2.5311170753257395), 0.00001 * ra_arcsecond)
compare(dec.degrees, (89.26420852419295, 89.26413900274704, 89.26411033462212, 89.26406913848278), 0.00001 * arcsecond)
Expand Down
8 changes: 0 additions & 8 deletions skyfield/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,6 @@ def test_from_altaz_parameters(ts):
assert str(p.from_altaz(alt=a, az=a).distance()) == '0.1 au'
assert str(p.from_altaz(alt=a, az=a, distance=d).distance()) == '0.234 au'

def test_named_star_throws_valueerror():
with assert_raises(ValueError, 'No star named foo known to skyfield'):
api.NamedStar('foo')

def test_named_star_returns_star():
s = api.NamedStar('Polaris')
assert isinstance(s, api.Star)

def test_github_81(ts):
t = ts.utc(1980, 1, 1)
assert t == t
Expand Down

0 comments on commit 1d76970

Please sign in to comment.