Catch that asteroid!¶
In [1]:
import matplotlib.pyplot as plt
plt.ion()
from astropy import units as u
from astropy.time import Time
In [2]:
from astropy.utils.data import conf
conf.dataurl
Out[2]:
'http://data.astropy.org/'
In [3]:
conf.remote_timeout
Out[3]:
10.0
First, we need to increase the timeout time to allow the download of data occur properly
In [4]:
conf.remote_timeout = 10000
Then, we do the rest of the imports and create our initial orbits.
In [5]:
from astropy.coordinates import solar_system_ephemeris
solar_system_ephemeris.set("jpl")
from poliastro.bodies import *
from poliastro.twobody import Orbit
from poliastro.plotting import OrbitPlotter, plot
EPOCH = Time("2017-09-01 12:05:50", scale="tdb")
In [6]:
earth = Orbit.from_body_ephem(Earth, EPOCH)
earth
Out[6]:
1 x 1 AU x 23.4 deg orbit around Sun (☉)
In [7]:
plot(earth, label=Earth);

In [8]:
from poliastro.neos import neows
In [9]:
florence = neows.orbit_from_name("Florence")
florence
Out[9]:
1 x 3 AU x 22.1 deg orbit around Sun (☉)
Two problems: the epoch is not the one we desire, and the inclination is with respect to the ecliptic!
In [10]:
florence.epoch
Out[10]:
<Time object: scale='tdb' format='jd' value=2458200.5>
In [11]:
florence.epoch.iso
Out[11]:
'2018-03-23 00:00:00.000'
In [12]:
florence.inc
Out[12]:
We first propagate:
In [13]:
florence = florence.propagate(EPOCH)
florence.epoch.tdb.iso
Out[13]:
'2017-09-01 12:05:50.000'
And now we have to convert to another reference frame, using http://docs.astropy.org/en/stable/coordinates/.
In [14]:
from astropy.coordinates import (
ICRS, GCRS,
CartesianRepresentation, CartesianDifferential
)
from poliastro.frames import HeliocentricEclipticJ2000
The NASA servers give the orbital elements of the asteroids in an Heliocentric Ecliptic frame. Fortunately, it is already defined in Astropy:
In [15]:
florence_heclip = HeliocentricEclipticJ2000(
x=florence.r[0], y=florence.r[1], z=florence.r[2],
v_x=florence.v[0], v_y=florence.v[1], v_z=florence.v[2],
representation=CartesianRepresentation,
differential_type=CartesianDifferential,
obstime=EPOCH
)
florence_heclip
Out[15]:
<HeliocentricEclipticJ2000 Coordinate (obstime=2017-09-01 12:05): (x, y, z) in km
(1.45898575e+08, -58567565.51292471, 2279107.77284053)
(v_x, v_y, v_z) in km / s
(7.40829055, 31.11151455, 12.79669447)>
Now we just have to convert to ICRS, which is the “standard” reference in which poliastro works:
In [16]:
florence_icrs_trans = florence_heclip.transform_to(ICRS)
florence_icrs_trans.representation = CartesianRepresentation
florence_icrs_trans
Out[16]:
<ICRS Coordinate: (x, y, z) in km
(1.46265478e+08, -53881737.42618975, -20898600.42756944)
(v_x, v_y, v_z) in km / s
(7.39988214, 23.46299465, 24.12028277)>
In [17]:
florence_icrs = Orbit.from_vectors(
Sun,
r=[florence_icrs_trans.x, florence_icrs_trans.y, florence_icrs_trans.z] * u.km,
v=[florence_icrs_trans.v_x, florence_icrs_trans.v_y, florence_icrs_trans.v_z] * (u.km / u.s),
epoch=florence.epoch
)
florence_icrs
Out[17]:
1 x 3 AU x 44.5 deg orbit around Sun (☉)
In [18]:
florence_icrs.rv()
Out[18]:
(<Quantity [ 1.46265478e+08, -5.38817374e+07, -2.08986004e+07] km>,
<Quantity [ 7.39988214, 23.46299465, 24.12028277] km / s>)
Let us compute the distance between Florence and the Earth:
In [19]:
from poliastro.util import norm
In [20]:
norm(florence_icrs.r - earth.r) - Earth.R
Out[20]:
This value is consistent with what ESA says! \(7\,060\,160\) km
In [21]:
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>— AeroPython (@AeroPython) <a href="https://twitter.com/AeroPython/status/903197147914543105">August 31, 2017</a></blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>"""
)
Out[21]:
La @esa_es ha preparado un resumen del asteroide #Florence 😍 pic.twitter.com/Sk1lb7Kz0j
— AeroPython (@AeroPython) August 31, 2017
And now we can plot!
In [22]:
frame = OrbitPlotter()
frame.plot(earth, label="Earth")
frame.plot(Orbit.from_body_ephem(Mars, EPOCH))
frame.plot(Orbit.from_body_ephem(Venus, EPOCH))
frame.plot(Orbit.from_body_ephem(Mercury, EPOCH))
frame.plot(florence_icrs, label="Florence");

The difference between doing it well and doing it wrong is clearly visible:
In [23]:
frame = OrbitPlotter()
frame.plot(earth, label="Earth")
frame.plot(florence, label="Florence (Ecliptic)")
frame.plot(florence_icrs, label="Florence (ICRS)");

And now let’s do something more complicated: express our orbit with respect to the Earth! For that, we will use GCRS, with care of setting the correct observation time:
In [24]:
florence_gcrs_trans = florence_heclip.transform_to(GCRS(obstime=EPOCH))
florence_gcrs_trans.representation = CartesianRepresentation
florence_gcrs_trans
Out[24]:
<GCRS Coordinate (obstime=2017-09-01 12:05, obsgeoloc=(0., 0., 0.) m, obsgeovel=(0., 0., 0.) m / s): (x, y, z) in km
(4960528.39215574, -5020204.25120256, 306195.44251179)
(v_x, v_y, v_z) in km / s
(-2.76863626, -1.95773245, 13.09966915)>
In [25]:
florence_hyper = Orbit.from_vectors(
Earth,
r=[florence_gcrs_trans.x, florence_gcrs_trans.y, florence_gcrs_trans.z] * u.km,
v=[florence_gcrs_trans.v_x, florence_gcrs_trans.v_y, florence_gcrs_trans.v_z] * (u.km / u.s),
epoch=EPOCH
)
florence_hyper
Out[25]:
7064205 x -7068561 km x 104.3 deg orbit around Earth (♁)
Notice that the ephemerides of the Moon is also given in ICRS, and therefore yields a weird hyperbolic orbit!
In [26]:
moon = Orbit.from_body_ephem(Moon, EPOCH)
moon
Out[26]:
151218466 x -151219347 km x 23.3 deg orbit around Earth (♁)
In [27]:
moon.a
Out[27]:
In [28]:
moon.ecc
Out[28]:
So we have to convert again.
In [29]:
moon_icrs = ICRS(
x=moon.r[0], y=moon.r[1], z=moon.r[2],
v_x=moon.v[0], v_y=moon.v[1], v_z=moon.v[2],
representation=CartesianRepresentation,
differential_type=CartesianDifferential
)
moon_icrs
Out[29]:
<ICRS Coordinate: (x, y, z) in km
(1.41399531e+08, -49228391.42507221, -21337616.62766309)
(v_x, v_y, v_z) in km / s
(11.10890252, 25.6785744, 11.0567569)>
In [30]:
moon_gcrs = moon_icrs.transform_to(GCRS(obstime=EPOCH))
moon_gcrs.representation = CartesianRepresentation
moon_gcrs
Out[30]:
<GCRS Coordinate (obstime=2017-09-01 12:05, obsgeoloc=(0., 0., 0.) m, obsgeovel=(0., 0., 0.) m / s): (x, y, z) in km
(94189.90120828, -367278.24304992, -133087.21297573)
(v_x, v_y, v_z) in km / s
(0.94073662, 0.25786326, 0.03569047)>
In [31]:
moon = Orbit.from_vectors(
Earth,
[moon_gcrs.x, moon_gcrs.y, moon_gcrs.z] * u.km,
[moon_gcrs.v_x, moon_gcrs.v_y, moon_gcrs.v_z] * (u.km / u.s),
epoch=EPOCH
)
moon
Out[31]:
367937 x 405209 km x 19.4 deg orbit around Earth (♁)
And finally, we plot the Moon:
In [32]:
plot(moon, label=Moon)
plt.gcf().autofmt_xdate()

And now for the final plot:
In [44]:
from poliastro.twobody.propagation import kepler
In [46]:
florence_hyper.sample(150, method=kepler)
Out[46]:
(<Time object: scale='tdb' format='iso' value=['1856-07-27 09:14' '2016-11-20 05:18' '2017-04-11 13:53'
'2017-05-29 05:07' '2017-06-22 01:56' '2017-07-06 10:15'
'2017-07-16 00:13' '2017-07-22 20:50' '2017-07-28 00:34'
'2017-08-01 01:03' '2017-08-04 06:27' '2017-08-06 21:59'
'2017-08-09 03:06' '2017-08-11 00:12' '2017-08-12 15:01'
'2017-08-14 00:48' '2017-08-15 06:29' '2017-08-16 08:49'
'2017-08-17 08:20' '2017-08-18 05:30' '2017-08-19 00:39'
'2017-08-19 18:05' '2017-08-20 10:02' '2017-08-21 00:41'
'2017-08-21 14:13' '2017-08-22 02:46' '2017-08-22 14:25'
'2017-08-23 01:18' '2017-08-23 11:30' '2017-08-23 21:04'
'2017-08-24 06:04' '2017-08-24 14:35' '2017-08-24 22:38'
'2017-08-25 06:16' '2017-08-25 13:31' '2017-08-25 20:26'
'2017-08-26 03:03' '2017-08-26 09:22' '2017-08-26 15:25'
'2017-08-26 21:13' '2017-08-27 02:49' '2017-08-27 08:11'
'2017-08-27 13:23' '2017-08-27 18:24' '2017-08-27 23:15'
'2017-08-28 03:57' '2017-08-28 08:31' '2017-08-28 12:57'
'2017-08-28 17:15' '2017-08-28 21:27' '2017-08-29 01:33'
'2017-08-29 05:33' '2017-08-29 09:27' '2017-08-29 13:16'
'2017-08-29 17:01' '2017-08-29 20:42' '2017-08-30 00:18'
'2017-08-30 03:51' '2017-08-30 07:20' '2017-08-30 10:46'
'2017-08-30 14:09' '2017-08-30 17:30' '2017-08-30 20:48'
'2017-08-31 00:03' '2017-08-31 03:17' '2017-08-31 06:29'
'2017-08-31 09:39' '2017-08-31 12:48' '2017-08-31 15:56'
'2017-08-31 19:02' '2017-08-31 22:08' '2017-09-01 01:12'
'2017-09-01 04:17' '2017-09-01 07:20' '2017-09-01 10:24'
'2017-09-01 13:27' '2017-09-01 16:31' '2017-09-01 19:35'
'2017-09-01 22:39' '2017-09-02 01:44' '2017-09-02 04:49'
'2017-09-02 07:56' '2017-09-02 11:03' '2017-09-02 14:12'
'2017-09-02 17:22' '2017-09-02 20:34' '2017-09-02 23:48'
'2017-09-03 03:04' '2017-09-03 06:22' '2017-09-03 09:42'
'2017-09-03 13:05' '2017-09-03 16:32' '2017-09-03 20:01'
'2017-09-03 23:33' '2017-09-04 03:10' '2017-09-04 06:50'
'2017-09-04 10:35' '2017-09-04 14:24' '2017-09-04 18:19'
'2017-09-04 22:19' '2017-09-05 02:24' '2017-09-05 06:36'
'2017-09-05 10:55' '2017-09-05 15:21' '2017-09-05 19:54'
'2017-09-06 00:37' '2017-09-06 05:28' '2017-09-06 10:29'
'2017-09-06 15:40' '2017-09-06 21:03' '2017-09-07 02:38'
'2017-09-07 08:27' '2017-09-07 14:30' '2017-09-07 20:49'
'2017-09-08 03:25' '2017-09-08 10:20' '2017-09-08 17:36'
'2017-09-09 01:14' '2017-09-09 09:17' '2017-09-09 17:47'
'2017-09-10 02:48' '2017-09-10 12:22' '2017-09-10 22:33'
'2017-09-11 09:26' '2017-09-11 21:06' '2017-09-12 09:38'
'2017-09-12 23:10' '2017-09-13 13:50' '2017-09-14 05:47'
'2017-09-14 23:13' '2017-09-15 18:22' '2017-09-16 15:31'
'2017-09-17 15:03' '2017-09-18 17:22' '2017-09-19 23:04'
'2017-09-21 08:51' '2017-09-22 23:39' '2017-09-24 20:46'
'2017-09-27 01:53' '2017-09-29 17:24' '2017-10-02 22:48'
'2017-10-06 23:17' '2017-10-12 03:02' '2017-10-18 23:38'
'2017-10-28 13:37' '2017-11-11 21:56' '2017-12-05 18:45'
'2018-01-22 09:59' '2018-06-13 18:34' '2178-10-07 14:37']>,
<CartesianRepresentation (x, y, z) in km
[( 1.40608752e+10, 9.95968511e+09, -6.65760007e+10),
( 7.31133620e+07, 4.32930111e+07, -3.22494731e+08),
( 3.91061697e+07, 1.91842030e+07, -1.61418594e+08),
( 2.77269012e+07, 1.11170869e+07, -1.07520383e+08),
( 2.20252581e+07, 7.07502919e+06, -8.05144352e+07),
( 1.85979768e+07, 4.64534267e+06, -6.42810792e+07),
( 1.63087937e+07, 3.02249210e+06, -5.34383640e+07),
( 1.46702861e+07, 1.86092716e+06, -4.56775952e+07),
( 1.34385933e+07, 9.87766859e+05, -3.98437185e+07),
( 1.24781776e+07, 3.06924048e+05, -3.52947552e+07),
( 1.17076894e+07, -2.39272819e+05, -3.16453897e+07),
( 1.10753467e+07, -6.87533588e+05, -2.86503556e+07),
( 1.05466208e+07, -1.06233691e+06, -2.61461060e+07),
( 1.00976024e+07, -1.38063279e+06, -2.40193941e+07),
( 9.71121073e+06, -1.65453046e+06, -2.21893158e+07),
( 9.37491766e+06, -1.89291145e+06, -2.05965316e+07),
( 9.07932575e+06, -2.10243794e+06, -1.91965300e+07),
( 8.81724754e+06, -2.28820533e+06, -1.79552675e+07),
( 8.58309193e+06, -2.45417736e+06, -1.68462616e+07),
( 8.37244409e+06, -2.60348382e+06, -1.58486014e+07),
( 8.18177153e+06, -2.73862901e+06, -1.49455551e+07),
( 8.00821401e+06, -2.86164064e+06, -1.41235752e+07),
( 7.84943083e+06, -2.97417813e+06, -1.33715748e+07),
( 7.70348783e+06, -3.07761263e+06, -1.26803927e+07),
( 7.56877276e+06, -3.17308711e+06, -1.20423926e+07),
( 7.44393089e+06, -3.26156200e+06, -1.14511577e+07),
( 7.32781547e+06, -3.34385024e+06, -1.09012563e+07),
( 7.21944922e+06, -3.42064467e+06, -1.03880596e+07),
( 7.11799405e+06, -3.49253941e+06, -9.90759803e+06),
( 7.02272707e+06, -3.56004694e+06, -9.45644760e+06),
( 6.93302140e+06, -3.62361167e+06, -9.03163901e+06),
( 6.84833061e+06, -3.68362097e+06, -8.63058421e+06),
( 6.76817622e+06, -3.74041405e+06, -8.25101681e+06),
( 6.69213733e+06, -3.79428928e+06, -7.89094327e+06),
( 6.61984218e+06, -3.84551020e+06, -7.54860274e+06),
( 6.55096110e+06, -3.89431054e+06, -7.22243375e+06),
( 6.48520065e+06, -3.94089829e+06, -6.91104645e+06),
( 6.42229871e+06, -3.98545927e+06, -6.61319937e+06),
( 6.36202037e+06, -4.02816002e+06, -6.32777982e+06),
( 6.30415439e+06, -4.06915027e+06, -6.05378733e+06),
( 6.24851025e+06, -4.10856508e+06, -5.79031951e+06),
( 6.19491561e+06, -4.14652662e+06, -5.53656006e+06),
( 6.14321411e+06, -4.18314573e+06, -5.29176843e+06),
( 6.09326350e+06, -4.21852322e+06, -5.05527093e+06),
( 6.04493403e+06, -4.25275108e+06, -4.82645302e+06),
( 5.99810706e+06, -4.28591341e+06, -4.60475271e+06),
( 5.95267377e+06, -4.31808733e+06, -4.38965473e+06),
( 5.90853417e+06, -4.34934371e+06, -4.18068544e+06),
( 5.86559612e+06, -4.37974787e+06, -3.97740845e+06),
( 5.82377450e+06, -4.40936013e+06, -3.77942068e+06),
( 5.78299052e+06, -4.43823633e+06, -3.58634893e+06),
( 5.74317105e+06, -4.46642831e+06, -3.39784686e+06),
( 5.70424804e+06, -4.49398428e+06, -3.21359226e+06),
( 5.66615806e+06, -4.52094919e+06, -3.03328471e+06),
( 5.62884181e+06, -4.54736507e+06, -2.85664337e+06),
( 5.59224373e+06, -4.57327130e+06, -2.68340512e+06),
( 5.55631163e+06, -4.59870484e+06, -2.51332281e+06),
( 5.52099636e+06, -4.62370052e+06, -2.34616377e+06),
( 5.48625155e+06, -4.64829119e+06, -2.18170833e+06),
( 5.45203329e+06, -4.67250797e+06, -2.01974864e+06),
( 5.41829992e+06, -4.69638034e+06, -1.86008746e+06),
( 5.38501184e+06, -4.71993639e+06, -1.70253717e+06),
( 5.35213121e+06, -4.74320289e+06, -1.54691876e+06),
( 5.31962189e+06, -4.76620545e+06, -1.39306101e+06),
( 5.28744917e+06, -4.78896864e+06, -1.24079963e+06),
( 5.25557965e+06, -4.81151612e+06, -1.08997655e+06),
( 5.22398111e+06, -4.83387069e+06, -9.40439190e+05),
( 5.19262235e+06, -4.85605444e+06, -7.92039847e+05),
( 5.16147306e+06, -4.87808884e+06, -6.44635060e+05),
( 5.13050370e+06, -4.89999477e+06, -4.98085046e+05),
( 5.09968540e+06, -4.92179268e+06, -3.52253150e+05),
( 5.06898985e+06, -4.94350260e+06, -2.07005323e+05),
( 5.03838915e+06, -4.96514426e+06, -6.22096286e+04),
( 5.00785578e+06, -4.98673714e+06, 8.22642523e+04),
( 4.97736243e+06, -5.00830054e+06, 2.26545486e+05),
( 4.94688196e+06, -5.02985367e+06, 3.70762553e+05),
( 4.91638725e+06, -5.05141570e+06, 5.15043705e+05),
( 4.88585116e+06, -5.07300582e+06, 6.59517422e+05),
( 4.85524637e+06, -5.09464334e+06, 8.04312870e+05),
( 4.82454534e+06, -5.11634773e+06, 9.49560367e+05),
( 4.79372018e+06, -5.13813869e+06, 1.09539185e+06),
( 4.76274255e+06, -5.16003626e+06, 1.24194137e+06),
( 4.73158356e+06, -5.18206085e+06, 1.38934557e+06),
( 4.70021366e+06, -5.20423333e+06, 1.53774424e+06),
( 4.66860250e+06, -5.22657514e+06, 1.68728084e+06),
( 4.63671887e+06, -5.24910833e+06, 1.83810307e+06),
( 4.60453049e+06, -5.27185569e+06, 1.99036351e+06),
( 4.57200394e+06, -5.29484083e+06, 2.14422022e+06),
( 4.53910448e+06, -5.31808827e+06, 2.29983750e+06),
( 4.50579589e+06, -5.34162358e+06, 2.45738656e+06),
( 4.47204031e+06, -5.36547349e+06, 2.61704640e+06),
( 4.43779807e+06, -5.38966601e+06, 2.77900465e+06),
( 4.40302745e+06, -5.41423059e+06, 2.94345853e+06),
( 4.36768449e+06, -5.43919825e+06, 3.11061591e+06),
( 4.33172272e+06, -5.46460178e+06, 3.28069643e+06),
( 4.29509292e+06, -5.49047592e+06, 3.45393277e+06),
( 4.25774282e+06, -5.51685757e+06, 3.63057207e+06),
( 4.21961676e+06, -5.54378598e+06, 3.81087746e+06),
( 4.18065533e+06, -5.57130309e+06, 3.99512974e+06),
( 4.14079499e+06, -5.59945373e+06, 4.18362935e+06),
( 4.09996756e+06, -5.62828599e+06, 4.37669849e+06),
( 4.05809979e+06, -5.65785157e+06, 4.57468348e+06),
( 4.01511273e+06, -5.68820615e+06, 4.77795752e+06),
( 3.97092110e+06, -5.71940991e+06, 4.98692368e+06),
( 3.92543258e+06, -5.75152796e+06, 5.20201834e+06),
( 3.87854698e+06, -5.78463099e+06, 5.42371511e+06),
( 3.83015528e+06, -5.81879590e+06, 5.65252927e+06),
( 3.78013859e+06, -5.85410655e+06, 5.88902280e+06),
( 3.72836690e+06, -5.89065467e+06, 6.13381021e+06),
( 3.67469767e+06, -5.92854077e+06, 6.38756516e+06),
( 3.61897425e+06, -5.96787538e+06, 6.65102821e+06),
( 3.56102392e+06, -6.00878032e+06, 6.92501563e+06),
( 3.50065578e+06, -6.05139024e+06, 7.21042977e+06),
( 3.43765816e+06, -6.09585444e+06, 7.50827109e+06),
( 3.37179565e+06, -6.14233896e+06, 7.81965225e+06),
( 3.30280560e+06, -6.19102907e+06, 8.14581469e+06),
( 3.23039395e+06, -6.24213216e+06, 8.48814820e+06),
( 3.15423035e+06, -6.29588125e+06, 8.84821423e+06),
( 3.07394227e+06, -6.35253910e+06, 9.22777359e+06),
( 2.98910792e+06, -6.41240318e+06, 9.62881975e+06),
( 2.89924780e+06, -6.47581171e+06, 1.00536190e+07),
( 2.80381437e+06, -6.54315087e+06, 1.05047595e+07),
( 2.70217941e+06, -6.61486375e+06, 1.09852102e+07),
( 2.59361850e+06, -6.69146129e+06, 1.14983952e+07),
( 2.47729180e+06, -6.77353583e+06, 1.20482838e+07),
( 2.35221996e+06, -6.86177811e+06, 1.26395049e+07),
( 2.21725382e+06, -6.95699864e+06, 1.32774899e+07),
( 2.07103578e+06, -7.06015494e+06, 1.39686554e+07),
( 1.91195018e+06, -7.17238653e+06, 1.47206377e+07),
( 1.73805878e+06, -7.29506045e+06, 1.55425975e+07),
( 1.54701592e+06, -7.42983110e+06, 1.64456215e+07),
( 1.33595532e+06, -7.57872005e+06, 1.74432568e+07),
( 1.10133699e+06, -7.74422406e+06, 1.85522349e+07),
( 8.38736783e+05, -7.92946346e+06, 1.97934659e+07),
( 5.42551737e+05, -8.13839001e+06, 2.11934319e+07),
( 2.05579193e+05, -8.37608372e+06, 2.27861752e+07),
(-1.81598233e+05, -8.64918664e+06, 2.46162062e+07),
(-6.31535104e+05, -8.96655345e+06, 2.67428628e+07),
(-1.16134853e+06, -9.34025680e+06, 2.92470470e+07),
(-1.79499832e+06, -9.78719544e+06, 3.22420024e+07),
(-2.56708649e+06, -1.03317740e+07, 3.58912716e+07),
(-3.52950455e+06, -1.10105915e+07, 4.04401143e+07),
(-4.76377460e+06, -1.18811450e+07, 4.62738360e+07),
(-6.40572145e+06, -1.30392312e+07, 5.40343978e+07),
(-8.69972246e+06, -1.46572085e+07, 6.48768229e+07),
(-1.21342332e+07, -1.70795826e+07, 8.11097439e+07),
(-1.78479247e+07, -2.11094536e+07, 1.08114966e+08),
(-2.92512714e+07, -2.91522152e+07, 1.62011729e+08),
(-6.33304865e+07, -5.31881739e+07, 3.23083531e+08),
(-1.40807298e+10, -9.93960262e+09, 6.65748057e+10)]>)
In [43]:
%debug
> /home/juanlu/.miniconda36/envs/poliastro36/lib/python3.6/site-packages/scipy/optimize/zeros.py(215)newton()
213 q1 = func(*((p1,) + args))
214 msg = "Failed to converge after %d iterations, value is %s" % (maxiter, p)
--> 215 raise RuntimeError(msg)
216
217
ipdb> u
> /home/juanlu/Development/poliastro/poliastro-library/src/poliastro/twobody/angles.py(160)M_to_F()
158 with u.set_enabled_equivalencies(u.dimensionless_angles()):
159 F = optimize.newton(_kepler_equation_hyper, M, _kepler_equation_prime_hyper,
--> 160 args=(M, ecc))
161 return F
162
ipdb> u
> /home/juanlu/Development/poliastro/poliastro-library/src/poliastro/twobody/angles.py(233)M_to_nu()
231 """
232 if ecc > 1:
--> 233 F = M_to_F(M, ecc)
234 nu = F_to_nu(F, ecc)
235 else:
ipdb> u
> /home/juanlu/Development/poliastro/poliastro-library/src/poliastro/twobody/propagation.py(142)mean_motion()
140 with u.set_enabled_equivalencies(u.dimensionless_angles()):
141 M = M0 + tof * np.sqrt(k / np.abs(a ** 3)) * u.rad
--> 142 nu = M_to_nu(M, ecc)
143
144 # parabolic orbit
ipdb> u
> /home/juanlu/Development/poliastro/poliastro-library/src/poliastro/twobody/propagation.py(209)propagate()
207
208 """
--> 209 r, v = method(orbit, time_of_flight.to(u.s).value, rtol=rtol, **kwargs)
210 return orbit.from_vectors(orbit.attractor, r * u.km, v * u.km / u.s, orbit.epoch + time_of_flight)
211
ipdb> u
> /home/juanlu/Development/poliastro/poliastro-library/src/poliastro/twobody/orbit.py(275)propagate()
273 time_of_flight = time.TimeDelta(value)
274
--> 275 return propagate(self, time_of_flight, method=method, rtol=rtol, **kwargs)
276
277 def sample(self, values=None, method=mean_motion):
ipdb> u
> /home/juanlu/Development/poliastro/poliastro-library/src/poliastro/twobody/orbit.py(343)_sample()
341 values = np.zeros((len(time_values), 3)) * self.r.unit
342 for ii, epoch in enumerate(time_values):
--> 343 rr = self.propagate(epoch, method).r
344 values[ii] = rr
345
ipdb> p time_values
<Time object: scale='tdb' format='iso' value=['1856-07-27 09:14']>
ipdb> q
In [33]:
frame = OrbitPlotter()
# This first plot sets the frame
frame.plot(florence_hyper, label="Florence")
# And then we add the Moon
frame.plot(moon, label=Moon)
plt.xlim(-1000000, 8000000)
plt.ylim(-5000000, 5000000)
plt.gcf().autofmt_xdate()
/home/juanlu/.miniconda36/envs/poliastro36/lib/python3.6/site-packages/astropy/units/quantity.py:639: RuntimeWarning:
overflow encountered in cosh
/home/juanlu/.miniconda36/envs/poliastro36/lib/python3.6/site-packages/astropy/units/quantity.py:639: RuntimeWarning:
overflow encountered in sinh
/home/juanlu/.miniconda36/envs/poliastro36/lib/python3.6/site-packages/astropy/units/quantity.py:639: RuntimeWarning:
invalid value encountered in true_divide
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-33-ccd86024eefa> in <module>()
2
3 # This first plot sets the frame
----> 4 frame.plot(florence_hyper, label="Florence")
5
6 # And then we add the Moon
~/Development/poliastro/poliastro-library/src/poliastro/plotting.py in plot(self, orbit, label, color)
169 self.set_attractor(orbit.attractor)
170 self._redraw_attractor(orbit.r_p * 0.15) # Arbitrary Threshhold
--> 171 _, positions = orbit.sample(self.num_points)
172
173 x0, y0 = self._project(orbit.r[None])
~/Development/poliastro/poliastro-library/src/poliastro/twobody/orbit.py in sample(self, values, method)
331 nu_values = np.linspace(-nu_limit, nu_limit, values)
332
--> 333 return self.sample(nu_values, method)
334
335 elif hasattr(values, "unit") and values.unit in ('rad', 'deg'):
~/Development/poliastro/poliastro-library/src/poliastro/twobody/orbit.py in sample(self, values, method)
336 values = self._generate_time_values(values)
337
--> 338 return values, self._sample(values, method)
339
340 def _sample(self, time_values, method=mean_motion):
~/Development/poliastro/poliastro-library/src/poliastro/twobody/orbit.py in _sample(self, time_values, method)
341 values = np.zeros((len(time_values), 3)) * self.r.unit
342 for ii, epoch in enumerate(time_values):
--> 343 rr = self.propagate(epoch, method).r
344 values[ii] = rr
345
~/Development/poliastro/poliastro-library/src/poliastro/twobody/orbit.py in propagate(self, value, method, rtol, **kwargs)
273 time_of_flight = time.TimeDelta(value)
274
--> 275 return propagate(self, time_of_flight, method=method, rtol=rtol, **kwargs)
276
277 def sample(self, values=None, method=mean_motion):
~/Development/poliastro/poliastro-library/src/poliastro/twobody/propagation.py in propagate(orbit, time_of_flight, method, rtol, **kwargs)
207
208 """
--> 209 r, v = method(orbit, time_of_flight.to(u.s).value, rtol=rtol, **kwargs)
210 return orbit.from_vectors(orbit.attractor, r * u.km, v * u.km / u.s, orbit.epoch + time_of_flight)
211
~/Development/poliastro/poliastro-library/src/poliastro/twobody/propagation.py in mean_motion(orbit, tof, **kwargs)
140 with u.set_enabled_equivalencies(u.dimensionless_angles()):
141 M = M0 + tof * np.sqrt(k / np.abs(a ** 3)) * u.rad
--> 142 nu = M_to_nu(M, ecc)
143
144 # parabolic orbit
~/Development/poliastro/poliastro-library/src/poliastro/twobody/angles.py in M_to_nu(M, ecc)
231 """
232 if ecc > 1:
--> 233 F = M_to_F(M, ecc)
234 nu = F_to_nu(F, ecc)
235 else:
~/Development/poliastro/poliastro-library/src/poliastro/twobody/angles.py in M_to_F(M, ecc)
158 with u.set_enabled_equivalencies(u.dimensionless_angles()):
159 F = optimize.newton(_kepler_equation_hyper, M, _kepler_equation_prime_hyper,
--> 160 args=(M, ecc))
161 return F
162
~/.miniconda36/envs/poliastro36/lib/python3.6/site-packages/scipy/optimize/zeros.py in newton(func, x0, fprime, args, tol, maxiter, fprime2)
213 q1 = func(*((p1,) + args))
214 msg = "Failed to converge after %d iterations, value is %s" % (maxiter, p)
--> 215 raise RuntimeError(msg)
216
217
RuntimeError: Failed to converge after 50 iterations, value is nan rad

Per Python ad astra!