Visualizing the SpaceX Tesla Roadster trip to Mars

In [1]:
# Temporary hack, see
from IPython.display import HTML
HTML('<script type="text/javascript" src=""></script>')
In [2]:
from astropy.time import Time

from astropy.coordinates import solar_system_ephemeris

from poliastro.bodies import *
from poliastro.twobody import Orbit
from poliastro.plotting import OrbitPlotter, plot

EPOCH = Time("2018-02-18 12:00:00", scale="tdb")
In [3]:
from astroquery.jplhorizons import conf
conf.horizons_server = ''

from astroquery.jplhorizons import Horizons

from astropy.coordinates import ICRS, CartesianRepresentation, CartesianDifferential
from poliastro.frames import Planes

def get_roadster_orbit(epoch):
    roadster = Horizons(
        id="SpaceX Roadster", location="[email protected]", epochs=[epoch.jd], id_type="majorbody"

    # Create Orbit object to do conversions
    roadster_eclip = Orbit.from_classical(
        roadster['a'][0] *,
        roadster['e'][0] *,
        roadster['incl'][0] * u.deg,
        roadster['Omega'][0] * u.deg,
        roadster['w'][0] * u.deg,
        roadster['nu'][0] * u.deg,

    # Create final orbit
    roadster_icrs = roadster_eclip.to_icrs()

    return roadster_icrs
In [4]:
roadster = get_roadster_orbit(EPOCH)
1 x 2 AU x 24.2 deg (ICRS) orbit around Sun (☉) at epoch 2018-02-18 12:00:00.000 (TDB)
In [5]:
from poliastro.plotting import plot_solar_system
In [6]:
frame = plot_solar_system(outer=False, epoch=EPOCH)
frame.plot(roadster, label="SpaceX Roadster", color='k');
/home/juanlu/Development/poliastro/poliastro-library/src/poliastro/twobody/ UserWarning:

Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

In [7]:
from poliastro.plotting import OrbitPlotter3D

from plotly.offline import init_notebook_mode

In [8]:
frame = OrbitPlotter3D()

frame.plot(Orbit.from_body_ephem(Earth, EPOCH), label=Earth)
frame.plot(Orbit.from_body_ephem(Mars, EPOCH), label=Mars)
frame.plot(roadster, label="SpaceX Roadster", color='black')

frame.set_view(30 * u.deg, -100 * u.deg, 2 *
/home/juanlu/Development/poliastro/poliastro-library/src/poliastro/twobody/ UserWarning:

Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned