Exemple #1
0
def test_from_horizons_scalar_epoch_uses_reshaped_epochs(horizons_mock):
    unused_name = "Strange Object"
    unused_id_type = "id_type"
    unused_plane = Planes.EARTH_EQUATOR
    unused_location_str = "500@399"
    unused_attractor = Earth

    expected_epochs = Time(["2020-03-01 12:00:00"], scale="tdb")
    epochs = expected_epochs[0]

    horizons_mock().vectors.return_value = {
        "x": [1] * u.au,
        "y": [0] * u.au,
        "z": [0] * u.au,
        "vx": [0] * (u.au / u.day),
        "vy": [1] * (u.au / u.day),
        "vz": [0] * (u.au / u.day),
    }

    Ephem.from_horizons(
        unused_name,
        epochs,
        attractor=unused_attractor,
        plane=unused_plane,
        id_type=unused_id_type,
    )

    horizons_mock.assert_called_with(
        id=unused_name,
        location=unused_location_str,
        epochs=expected_epochs.jd,
        id_type=unused_id_type,
    )
def test_ephem_from_horizons_calls_horizons_with_correct_parameters(
    horizons_mock, attractor, location_str, plane, refplane_str
):
    unused_name = "Strange Object"
    unused_id_type = "id_type"
    epochs = Time(["2020-03-01 12:00:00"], scale="tdb")

    horizons_mock().vectors.return_value = {
        "x": [1] * u.au,
        "y": [0] * u.au,
        "z": [0] * u.au,
        "vx": [0] * (u.au / u.day),
        "vy": [1] * (u.au / u.day),
        "vz": [0] * (u.au / u.day),
    }
    expected_coordinates = CartesianRepresentation(
        [(1, 0, 0)] * u.au,
        xyz_axis=1,
        differentials=CartesianDifferential([(0, 1, 0)] * (u.au / u.day), xyz_axis=1),
    )

    ephem = Ephem.from_horizons(
        unused_name, epochs, attractor=attractor, plane=plane, id_type=unused_id_type
    )

    horizons_mock.assert_called_with(
        id=unused_name, location=location_str, epochs=epochs.jd, id_type=unused_id_type
    )
    horizons_mock().vectors.assert_called_once_with(refplane=refplane_str)

    coordinates = ephem.sample()

    assert_coordinates_allclose(coordinates, expected_coordinates)
Exemple #3
0
def test_can_set_iss_attractor_to_earth():
    # See https://github.com/poliastro/poliastro/issues/798
    epoch = Time("2019-11-10 12:00:00")
    ephem = Ephem.from_horizons(
        "International Space Station", epochs=epoch, attractor=Sun, id_type="majorbody"
    )
    iss = Orbit.from_ephem(Sun, ephem, epoch)
    iss = iss.change_attractor(Earth)
    assert iss.attractor == Earth
Exemple #4
0
def test_plot_ephem_no_epoch():
    epoch = Time("2020-02-14 00:00:00")
    ephem = Ephem.from_horizons(
        "2020 CD3",
        time_range(Time("2020-02-13 12:00:00"), end=Time("2020-02-14 12:00:00")),
        attractor=Earth,
    )

    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.set_attractor(Earth)
    plotter.set_orbit_frame(Orbit.from_ephem(Earth, ephem, epoch))

    plotter.plot_ephem(ephem, label="2020 CD3 Minimoon", color="k")

    return fig
Exemple #5
0
def dist_chart(asteroid, date, timespan):
    solar_system_ephemeris.set('jpl')

    EPOCH = Time(date, scale="tdb")

    epochs = time_range(EPOCH - TimeDelta(timespan),
                        end=EPOCH + TimeDelta(timespan))

    epochs_moon = time_range(EPOCH - TimeDelta(15 * u.day),
                             end=EPOCH + TimeDelta(15 * u.day))

    moon = Ephem.from_body(Moon, epochs_moon, attractor=Earth)
    aster = Ephem.from_horizons(asteroid, epochs, attractor=Earth)

    plotter = StaticOrbitPlotter()
    plotter.set_attractor(Earth)
    plotter.set_body_frame(Moon)
    plotter.plot_ephem(moon, EPOCH, label=Moon)
    plotter.plot_ephem(aster, EPOCH, label=asteroid)

    return plotter
from poliastro.util import time_range

EPOCH = Time("2018-02-18 12:00:00", scale="tdb")

# In[2]:

import plotly.io as pio

pio.renderers.default = "notebook_connected"

# In[3]:

roadster = Ephem.from_horizons(
    "SpaceX Roadster",
    epochs=time_range(EPOCH, end=EPOCH + 360 * u.day),
    attractor=Sun,
    plane=Planes.EARTH_ECLIPTIC,
    id_type="majorbody",
)
roadster

# In[4]:

from poliastro.plotting.misc import plot_solar_system

# In[5]:

frame = plot_solar_system(outer=False, epoch=EPOCH)
frame.plot_ephem(roadster, EPOCH, label="SpaceX Roadster", color="black")

# In[6]:
# 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:

# In[8]:

from poliastro.ephem import Ephem

# In[9]:

epochs = time_range(EPOCH - TimeDelta(3 * 30 * u.day),
                    end=EPOCH + TimeDelta(3 * 30 * u.day))

# In[10]:

florence = Ephem.from_horizons("Florence", epochs, plane=Planes.EARTH_ECLIPTIC)
florence

# In[11]:

florence.plane

# And now, let's compute the distance between Florence and the Earth at that epoch:

# In[12]:

earth = Ephem.from_body(Earth, epochs, plane=Planes.EARTH_ECLIPTIC)
earth

# In[13]:
def transfer_vel(body1, body2, attractor):
    """Returns transfer parameters for body1 (e.g. Earth) to body2 (e.g. Mars).
       Optionally, the main attractor can be specified. If omitted, Sun is assumed.

       Returns:
       helio1 - heliocentric velocity at departure (before Hohmann) (body1)
       helio2 - heliocentric velocity at arrival (body2)
       v1 - heliocentric velocity at departure (after Hohmann burn)
       v2 - heliocentric velocity at arrival (before Hohmann burn)
       tof - time of flight (in days) """

    # How to obtain the orbit. The from_horisons method seems to be no longer supported
    # as of perylune 0.16.3.
    method = "ephem"  # allowed values are ephem, horizons_orbit

    if attractor is None:
        attractor = Sun

    # Let's assume the calculations are done for 2020.
    date_start = time.Time("2020-01-01 00:00", scale="utc").tdb
    date_end = time.Time("2021-12-31 23:59", scale="utc").tdb

    name1, id_type1 = name_to_horizons_id(body1)
    name2, id_type2 = name_to_horizons_id(body2)

    if method == "ephem":
        # Get the ephemerides first and then contruct orbit based on them. This is the recommended
        # way. See warning in Orbit.from_horizons about deprecation.
        ephem1 = Ephem.from_horizons(name=name1,
                                     epochs=time_range(date_start,
                                                       end=date_end),
                                     plane=Planes.EARTH_ECLIPTIC,
                                     id_type=id_type1)
        ephem2 = Ephem.from_horizons(name=name2,
                                     epochs=time_range(date_start,
                                                       end=date_end),
                                     plane=Planes.EARTH_ECLIPTIC,
                                     id_type=id_type2)

        # Solve for departure and target orbits
        orb1 = Orbit.from_ephem(Sun, ephem1, date_start + 180 * u.day)
        orb2 = Orbit.from_ephem(Sun, ephem2, date_end)
    elif method == "horizons_orbit":
        # This is the old way. Sadly, it produces way better values.
        orb1 = Orbit.from_horizons(name=name1,
                                   attractor=attractor,
                                   plane=Planes.EARTH_ECLIPTIC,
                                   id_type=id_type1)
        orb2 = Orbit.from_horizons(name=name2,
                                   attractor=attractor,
                                   plane=Planes.EARTH_ECLIPTIC,
                                   id_type=id_type2)
    else:
        raise "Invalid method set."

    # The escape_delta_v returns a tuple of escape velocity at current, periapsis, apoapsis.
    helio1 = heliocentric_velocity(orb1)
    helio2 = heliocentric_velocity(orb2)

    #vesc1 = escape_vel(orb1, False)[1]
    #vesc2 = escape_vel(orb2, False)[1]

    hoh1, hoh2, tof = hohmann_velocity(orb1, orb2)

    return helio1, helio2, hoh1, hoh2, tof