-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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') |
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(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally I would object to a |
||
'dec_mas_per_year=-2.56, parallax_mas=0.0813, epoch=2451545.0)' | ||
) |
There was a problem hiding this comment.
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
!