Skip to content

Commit

Permalink
For #463, properly handle duplicate comets in file
Browse files Browse the repository at this point in the history
Turns out?  A given comet like `C/2020 F3 (NEOWISE)` can appear twice in
the Minor Planet Center’s `CometEls.txt`.  So let’s show users how to
select the most recent of several possible orbits.
  • Loading branch information
brandon-rhodes committed Oct 23, 2020
1 parent d43b64d commit 6b5728c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
9 changes: 5 additions & 4 deletions examples/comet_neowise_chart.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection

from skyfield import api
from skyfield.api import Star, load, tau
from skyfield.api import Star, load
from skyfield.constants import GM_SUN_Pitjeva_2005_km3_s2 as GM_SUN
from skyfield.data import hipparcos, mpc, stellarium
from skyfield.projections import build_stereographic_projection
Expand All @@ -28,7 +26,10 @@
with load.open(mpc.COMET_URL) as f:
comets = mpc.load_comets_dataframe(f)

comets = comets.set_index('designation', drop=False)
comets = (comets.sort_values('reference')
.groupby('designation', as_index=False).last()
.set_index('designation', drop=False))

row = comets.loc['C/2020 F3 (NEOWISE)']
comet = sun + mpc.comet_orbit(row, ts, GM_SUN)

Expand Down
4 changes: 2 additions & 2 deletions skyfield/data/mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def d(s):
'perihelion_distance_au', 'eccentricity', 'argument_of_perihelion_degrees',
'longitude_of_ascending_node_degrees', 'inclination_degrees',
'magnitude_H', 'magnitude_G',
'designation',
'designation', 'reference',
)

_fast_comet_re = None
Expand Down Expand Up @@ -166,7 +166,7 @@ def load_comets_dataframe(fobj):
pat.append(' ' * (start - previous_end))
keep = name in keepers
if name == 'designation':
pat.append('(.*?) .*')
pat.append('(.*?) +(.*)')
break
else:
if keep:
Expand Down
7 changes: 5 additions & 2 deletions skyfield/documentation/kepler-orbits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ but most Skyfield users will simply index their dataframe by comet designation.

.. testcode::

# Index by designation for fast lookup.
comets = comets.set_index('designation', drop=False)
# Keep only the most recent orbit for each comet,
# and index by designation for fast lookup.
comets = (comets.sort_values('reference')
.groupby('designation', as_index=False).last()
.set_index('designation', drop=False))

# Sample lookups.
row = comets.loc['1P/Halley']
Expand Down

0 comments on commit 6b5728c

Please sign in to comment.