Skip to content

Commit

Permalink
update mpc state example
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlend committed Jul 18, 2024
1 parent f0ab1b5 commit 396c2f9
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/examples/plot_mpc_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
This will open an interactive 3d plot of the solar system.
This plots all comets from the MPC, along with the last 365 days of their orbit.
This plots all of the Hildas from the MPC, along with the last 90 days of their orbit.
"""

import neospy
import matplotlib.pyplot as plt
import numpy as np

# Set the X/Y/Z scale
zoom = 4
zoom = 4.0

# Fetch all known comet orbits
orb = neospy.mpc.fetch_known_comet_orbit_data()
# Fetch all known asteroid orbits
orb = neospy.mpc.fetch_known_orbit_data()

# Subset to the Hildas
orb = orb[orb["group_name"] == "Hilda"]

# convert the table of data to State objects
states = neospy.mpc.table_to_states(orb)

# Every object in the MPC orbit file has its own epoch of fit.
# This means that some objects epochs may be months or years away from
# others. In order to bring all of these objects to the same epoch, the
# function below finds the most common epoch in the data, and uses n-body
# integration to calculate the position of all objects that the median
# epoch. If all known objects are included, then this may take a little
# while to compute.
states = neospy.mpc.table_to_states(orb)

# function below will propagate the states to the first state's epoch.
states = neospy.propagate_two_body(states, states[0].jd)

# Grab the positions from this subset
pos = np.array([p.pos for p in states])
Expand All @@ -46,13 +48,10 @@
ax.plot(pos[0], pos[1], pos[2], color="black", alpha=0.2)

for state in states:
# Skip fragments
if " " in state.desig:
continue
jd = states[0].jd
jds = np.linspace(jd - 365, jd, 100)
jds = np.linspace(jd - 90, jd, 100)
pos = np.array([neospy.propagate_two_body([state], jd)[0].pos for jd in jds]).T
ax.plot(pos[0], pos[1], pos[2], color="black", alpha=0.2, lw=0.2)
ax.plot(pos[0], pos[1], pos[2], color="black", alpha=0.1, lw=0.2)

ax.scatter(0, 0, 0, color="red")
ax.set_xticks([-zoom, 0, zoom])
Expand Down

0 comments on commit 396c2f9

Please sign in to comment.