Fix #143: routine to read Stellarium star names
This commit is contained in:
parent
bce98b8fd6
commit
614fa8b5f5
|
@ -1,5 +1,9 @@
|
|||
"""Parse Stellarium data files."""
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
StarName = namedtuple('StarName', 'hip name')
|
||||
|
||||
def parse_constellations(lines):
|
||||
"""Return a list of constellation outlines.
|
||||
|
||||
|
@ -29,3 +33,25 @@ def parse_constellations(lines):
|
|||
for i in range(2, len(fields), 2)]
|
||||
constellations.append((name.decode('utf-8'), edges))
|
||||
return constellations
|
||||
|
||||
def parse_star_names(lines):
|
||||
"""Return the names in a Stellarium ``star_names.fab`` file.
|
||||
|
||||
Returns a list of named tuples, each of which offers a ``.hip``
|
||||
attribute with a Hipparcos catalog number and a ``.name`` attribute
|
||||
with the star name. Do not depend on the tuple having only length
|
||||
two; additional fields may be added in the future.
|
||||
|
||||
"""
|
||||
names = []
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line == b'' or line.startswith(b'#'):
|
||||
continue
|
||||
fields = line.split()
|
||||
hip, name = fields[0].split(b'|')
|
||||
names.append(StarName(
|
||||
int(hip),
|
||||
name.strip(b'_(")').decode('utf-8'),
|
||||
))
|
||||
return names
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# 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.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import gzip
|
||||
from skyfield import iokit
|
||||
from skyfield.data.hipparcos import load_dataframe
|
||||
from skyfield.data import hipparcos, stellarium
|
||||
from skyfield.functions import BytesIO
|
||||
from skyfield.iokit import parse_tle
|
||||
|
||||
|
@ -125,7 +125,7 @@ def test_hipparcos():
|
|||
g.close()
|
||||
b.seek(0)
|
||||
try:
|
||||
df = load_dataframe(b)
|
||||
df = hipparcos.load_dataframe(b)
|
||||
except ImportError:
|
||||
# raise SkipTest('pandas not available')
|
||||
# Assay doesn't understand skipping tests yet; just pass
|
||||
|
@ -135,3 +135,21 @@ def test_hipparcos():
|
|||
row = df.iloc[0]
|
||||
assert abs(row.ra_degrees - 000.00091185) < 1e-30
|
||||
assert abs(row.dec_degrees - +01.08901332) < 1e-30
|
||||
|
||||
star_text = b"""\
|
||||
# star names by constellation
|
||||
# Andromeda (And)
|
||||
677|_("Alpheratz") 1,2,5,6,11,12
|
||||
677|_("Sirrah")
|
||||
5447|_("Mirach") 1,2,5,6,11,12,23
|
||||
9640|_("Almach") 1,2,5,6,11,12
|
||||
9640|_("Almaak")
|
||||
"""
|
||||
|
||||
def test_stellarium_star_names():
|
||||
f = BytesIO(star_text)
|
||||
star_names = stellarium.parse_star_names(f)
|
||||
assert star_names[0].hip == 677
|
||||
assert star_names[0].name == 'Alpheratz'
|
||||
assert star_names[4].hip == 9640
|
||||
assert star_names[4].name == 'Almaak'
|
||||
|
|
Loading…
Reference in New Issue