Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ numpy==1.15.4
matplotlib==3.3.0
pandas==1.0.0
pyflakes==2.1.1
pyongc[data]
python-dateutil>=2.5.0
pytz
sphinx==1.7.2
Expand Down
29 changes: 29 additions & 0 deletions skyfield/data/ongc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from math import pi

PANDAS_MESSAGE = """Skyfield needs Pandas to load the OpenNGC catalog

To load the OpenNGC star catalog, Skyfield needs the Pandas data
analysis toolkit. Try installing it using your usual Python package
installer, like "pip install pandas" or "conda install pandas".
"""

def load_dataframe(in_dataframe):
"""Convert a dataframe from pyongc.data for import in skyfield."""
try:
from pandas import read_csv
except ImportError:
raise ImportError(PANDAS_MESSAGE)

df = in_dataframe[['name', 'ra', 'dec', 'parallax', 'pmra', 'pmdec']].copy()

df = df.assign(
ra_hours = df['ra'] * 180 / pi / 15.0,
dec_degrees = df['dec'] * 180 / pi,
epoch_year = 2000,
)

df.rename(columns = {'parallax':'parallax_mas',
'pmra':'ra_mas_per_year',
'pmdec':'dec_mas_per_year'}, inplace = True)

return df.set_index('name')
14 changes: 12 additions & 2 deletions skyfield/tests/test_stars.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from pyongc import data
from skyfield import api
from skyfield.data.hipparcos import load_dataframe
from skyfield.data import hipparcos, ongc

def test_dataframe():
with api.load.open('hip_main.dat.gz') as f:
df = load_dataframe(f)
df = hipparcos.load_dataframe(f)
star = api.Star.from_dataframe(df)
assert repr(star) == 'Star(ra shape=9933, dec shape=9933, ra_mas_per_year shape=9933, dec_mas_per_year shape=9933, parallax_mas shape=9933, epoch shape=9933)'

def test_dataframe_from_ongc():
ongc_data = data.all()
df = ongc.load_dataframe(ongc_data)
hercules = api.Star.from_dataframe(df.loc['NGC6205'])
assert repr(hercules) == (
'Star(ra=250.42345833333337, dec=36.46130555555556, ra_mas_per_year=-3.18, '
'dec_mas_per_year=-2.56, parallax_mas=0.0813, epoch=2451545.0)'
)