<jupyter_start><jupyter_text>Catch that asteroid! First, we need to increase the timeout time to allow the download of data occur properly<jupyter_code>from astropy.utils.data import conf
conf.dataurl
conf.remote_timeout 
conf.remote_timeout = 10000<jupyter_output><empty_output><jupyter_text>Then, we do the rest of the imports.<jupyter_code>from astropy import units as u
from astropy.time import Time, TimeDelta
from astropy.coordinates import solar_system_ephemeris
solar_system_ephemeris.set("jpl")

from poliastro.bodies import Sun, Earth, Moon
from poliastro.ephem import Ephem
from poliastro.frames import Planes
from poliastro.twobody import Orbit
from poliastro.plotting import StaticOrbitPlotter
from poliastro.plotting.misc import plot_solar_system
from poliastro.util import time_range

EPOCH = Time("2017-09-01 12:05:50", scale="tdb")
C_FLORENCE = "#000"
C_MOON = "#999"
Earth.plot(EPOCH);<jupyter_output><empty_output><jupyter_text>Our first option to retrieve the orbit of the Florence asteroid is to use `Orbit.from_sbdb`, which gives us the osculating elements at a certain epoch:<jupyter_code>florence_osc = Orbit.from_sbdb("Florence")
florence_osc<jupyter_output><empty_output><jupyter_text>However, the epoch of the result is not close to the time of the close approach we are studying:<jupyter_code>florence_osc.epoch.iso<jupyter_output><empty_output><jupyter_text>Therefore, if we `propagate` this orbit to `EPOCH`, the results will be a bit different from the reality. Therefore, we need to find some other means.Let's use the `Ephem.from_horizons` method as an alternative, sampling over a period of 6 months:<jupyter_code>from poliastro.ephem import Ephem
epochs = time_range(
    EPOCH - TimeDelta(3 * 30 * u.day), end=EPOCH + TimeDelta(3 * 30 * u.day)
)
florence = Ephem.from_horizons("Florence", epochs, plane=Planes.EARTH_ECLIPTIC)
florence
florence.plane<jupyter_output><empty_output><jupyter_text>And now, let's compute the distance between Florence and the Earth at that epoch:<jupyter_code>earth = Ephem.from_body(Earth, epochs, plane=Planes.EARTH_ECLIPTIC)
earth
from poliastro.util import norm
min_distance = norm(florence.rv(EPOCH)[0] - earth.rv(EPOCH)[0]) - Earth.R
min_distance.to(u.km)<jupyter_output><empty_output><jupyter_text>This value is consistent with what ESA says! $7\,060\,160$ km<jupyter_code>abs((min_distance - 7060160 * u.km) / (7060160 * u.km)).decompose()
from IPython.display import HTML

HTML(
"""<blockquote class="twitter-tweet" data-lang="en"><p lang="es" dir="ltr">La <a href="https://twitter.com/esa_es">@esa_es</a> ha preparado un resumen del asteroide <a href="https://twitter.com/hashtag/Florence?src=hash">#Florence</a> 😍 <a href="https://t.co/Sk1lb7Kz0j">pic.twitter.com/Sk1lb7Kz0j</a></p>&mdash; AeroPython (@AeroPython) <a href="https://twitter.com/AeroPython/status/903197147914543105">August 31, 2017</a></blockquote>
<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script>"""
)<jupyter_output><empty_output><jupyter_text>And now we can plot!<jupyter_code>frame = plot_solar_system(outer=False, epoch=EPOCH)
frame.plot_ephem(florence, EPOCH, label="Florence", color=C_FLORENCE);<jupyter_output><empty_output><jupyter_text>Finally, we are going to visualize the orbit of Florence with respect to the Earth. For that, we set a narrower time range, and specify that we want to retrieve the ephemerides with respect to our planet:<jupyter_code>epochs = time_range(EPOCH - TimeDelta(5 * u.day), end=EPOCH + TimeDelta(5 * u.day))
florence_e = Ephem.from_horizons("Florence", epochs, attractor=Earth)
florence_e<jupyter_output><empty_output><jupyter_text>We now retrieve the ephemerides of the Moon, which are given directly in GCRS:<jupyter_code>moon = Ephem.from_body(Moon, epochs, attractor=Earth)
moon
from poliastro.plotting.static import StaticOrbitPlotter

plotter = StaticOrbitPlotter()
plotter.set_attractor(Earth)
plotter.set_body_frame(Moon)
plotter.plot_ephem(moon, EPOCH, label=Moon, color=C_MOON);<jupyter_output><empty_output><jupyter_text>And now, the glorious final plot:<jupyter_code>import matplotlib.pyplot as plt

frame = StaticOrbitPlotter()

frame.set_attractor(Earth)
frame.set_orbit_frame(Orbit.from_ephem(Earth, florence_e, EPOCH))

frame.plot_ephem(florence_e, EPOCH, label="Florence", color=C_FLORENCE)
frame.plot_ephem(moon, EPOCH, label=Moon, color=C_MOON);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11090909090909092, 'fraction_numerical': 0.02, 'mean_word_length': 7.447216890595009, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '106225', 'license': 'MIT', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1565, 'n_words': 369, 'path': 'docs/source/examples/Catch that asteroid!.ipynb', 'repo_name': 'NanuSai/poliastro', 'size': '4400'}