Skip to content

Load deepsky objects from pyongc #824

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did a good job repeating the patterns in hipparcos.py!

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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for including tests! Many developers don't think to write them, and it's very helpful.

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, '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I would object to a repr() since even very small changes in how numbers are input and rounded will break the tests, but in this case it's a bit elegant—it lets us very quickly verify that all the essential properties of the star are correct. So let's keep it this way, and see if it ever breaks!

'dec_mas_per_year=-2.56, parallax_mas=0.0813, epoch=2451545.0)'
)