Skip to content

Commit e5050ba

Browse files
committed
Use pyongc dataframes with starlib from_dataframe()
Signed-off-by: Mattia Verga <[email protected]>
1 parent 33aec1a commit e5050ba

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ numpy==1.15.4
77
matplotlib==3.3.0
88
pandas==1.0.0
99
pyflakes==2.1.1
10+
pyongc[data]
1011
python-dateutil>=2.5.0
1112
pytz
1213
sphinx==1.7.2

skyfield/data/ongc.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from math import pi
2+
3+
PANDAS_MESSAGE = """Skyfield needs Pandas to load the OpenNGC catalog
4+
5+
To load the OpenNGC star catalog, Skyfield needs the Pandas data
6+
analysis toolkit. Try installing it using your usual Python package
7+
installer, like "pip install pandas" or "conda install pandas".
8+
"""
9+
10+
def load_dataframe(in_dataframe):
11+
"""Convert a dataframe from pyongc.data for import in skyfield."""
12+
try:
13+
from pandas import read_csv
14+
except ImportError:
15+
raise ImportError(PANDAS_MESSAGE)
16+
17+
df = in_dataframe[['name', 'ra', 'dec', 'parallax', 'pmra', 'pmdec']].copy()
18+
19+
df = df.assign(
20+
ra_hours = df['ra'] * 180 / pi / 15.0,
21+
dec_degrees = df['dec'] * 180 / pi,
22+
epoch_year = 2000,
23+
)
24+
25+
df.rename(columns = {'parallax':'parallax_mas',
26+
'pmra':'ra_mas_per_year',
27+
'pmdec':'dec_mas_per_year'}, inplace = True)
28+
29+
return df.set_index('name')

skyfield/tests/test_stars.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
from pyongc import data
12
from skyfield import api
2-
from skyfield.data.hipparcos import load_dataframe
3+
from skyfield.data import hipparcos, ongc
34

45
def test_dataframe():
56
with api.load.open('hip_main.dat.gz') as f:
6-
df = load_dataframe(f)
7+
df = hipparcos.load_dataframe(f)
78
star = api.Star.from_dataframe(df)
89
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)'
10+
11+
def test_dataframe_from_ongc():
12+
ongc_data = data.all()
13+
df = ongc.load_dataframe(ongc_data)
14+
hercules = api.Star.from_dataframe(df.loc['NGC6205'])
15+
assert repr(hercules) == (
16+
'Star(ra=250.42345833333337, dec=36.46130555555556, ra_mas_per_year=-3.18, '
17+
'dec_mas_per_year=-2.56, parallax_mas=0.0813, epoch=2451545.0)'
18+
)

0 commit comments

Comments
 (0)