.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_mpc_state.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_mpc_state.py: Plot states from the MPC ======================== This will open an interactive 3d plot of the solar system. This plots all of the Hildas from the MPC, along with the last 90 days of their orbit. .. GENERATED FROM PYTHON SOURCE LINES 9-65 .. image-sg:: /auto_examples/images/sphx_glr_plot_mpc_state_001.png :alt: plot mpc state :srcset: /auto_examples/images/sphx_glr_plot_mpc_state_001.png :class: sphx-glr-single-img .. code-block:: Python import kete import matplotlib.pyplot as plt import numpy as np # Set the X/Y/Z scale zoom = 4.0 # Fetch all known asteroid orbits orb = kete.mpc.fetch_known_orbit_data() # Subset to the Hildas orb = orb[orb["group_name"] == "Hilda"] # convert the table of data to State objects states = kete.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 will propagate the states to the first state's epoch. states = kete.propagate_two_body(states, states[0].jd) # Grab the positions from this subset pos = np.array([p.pos for p in states]) plt.figure(dpi=250) ax = plt.gcf().add_subplot(projection="3d") # Plot the objects ax.scatter(pos[:, 0], pos[:, 1], pos[:, 2], s=0.1, alpha=0.5) # Plot the planets for 1 orbit each for i, planet in enumerate(["Mercury", "Venus", "Earth", "Mars", "Jupiter"]): jd = states[0].jd plan = kete.spice.get_state(planet, jd) ax.scatter(plan.pos.x, plan.pos.y, color=f"C{i}", s=10) jds = np.linspace(jd - plan.elements.orbital_period, jd, 100) pos = np.array([kete.spice.get_state(planet, jd).pos for jd in jds]).T ax.plot(pos[0], pos[1], pos[2], color="black", alpha=0.2) for state in states: jd = states[0].jd jds = np.linspace(jd - 90, jd, 100) pos = np.array([kete.propagate_two_body([state], jd)[0].pos for jd in jds]).T 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]) ax.set_yticks([-zoom, 0, zoom]) ax.set_zticks([-zoom, 0, zoom]) ax.set_xlim(-zoom, zoom) ax.set_ylim(-zoom, zoom) ax.set_zlim(-zoom, zoom) plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 9.927 seconds) .. _sphx_glr_download_auto_examples_plot_mpc_state.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mpc_state.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mpc_state.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_mpc_state.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_