Example #1
0
def orbit_plot():
    """This function plots the boundaries of Low Earth Orbit (LEO), Medium Earth
    Orbit (MEO), Geosyncronous Orbit (GEO) and High Earth Orbit.
    """
    # LEO boundary
    LEO_orb = Orbit.circular(Earth, alt=2000 * u.km)
    # MEO boundary
    MEO_orb = Orbit.circular(Earth, alt=35786 * u.km)
    fig, ax = plt.subplots(figsize=(17, 10))
    op = StaticOrbitPlotter(ax)
    op.plot(LEO_orb, label='LEO/MEO Boundary')
    op.plot(MEO_orb, label='GEO Orbit & MEO/HEO Boundary')
    ax.set_title('Geocentric Orbit Boundaries')
    plt.savefig('visualizations/orbit_fig.png')
Example #2
0
def maneuver_phasing_form_orbit(part_of_period,
                                orbit,
                                plot=False,
                                intermediate=True):
    period = (orbit.period).value
    time_maneuver = part_of_period * period
    semi_major_axis_maneuver = semi_major_axis_from_period(time_maneuver)
    delta_v = linear_velocity((orbit.a).value, (orbit.a).value) - \
              linear_velocity((orbit.a).value, semi_major_axis_maneuver)

    a_ph = semi_major_axis_maneuver
    ss_i = orbit
    hoh = Maneuver.hohmann(ss_i, a_ph * u.km)
    ss_a, ss_f = ss_i.apply_maneuver(hoh, intermediate=intermediate)
    if plot:
        fig, ax = plt.subplots()  # (figsize=(4, 4))
        plotter = StaticOrbitPlotter(ax)
        plotter.plot(ss_i, label="Initial orbit", color="red")
        plotter.plot(ss_a, label="Phasing orbit", color="blue")
        plt.savefig("figures/ManeuverPhasing, t_man=" + str(part_of_period) +
                    ".png")

    return 2 * delta_v, period * part_of_period, ss_a, ss_f
Example #3
0
date_arrival = time.Time((DATA_LAUNCH.unix + t_maneuver), format='unix')
r_arr = [r_x, 10, 0] * u.km
# orbit_arr = Orbit.from_vectors(Earth, r_2, v_2, epoch=date_arrival)

orbit_arr = Orbit.from_vectors(Earth, r_arr, v, epoch=date_arrival)

# orbit3 = orbit2.propagate_to_anomaly(2*30/180 * np.pi * u.rad)

man_lambert = Maneuver.lambert(orbit_dpt, orbit_arr, short=False, M=2)
orbit_trans, orbit_target = orbit_dpt.apply_maneuver(man_lambert,
                                                     intermediate=True)

# try to plot it
fig, ax = plt.subplots()  # (figsize=(4, 4))
plotter = StaticOrbitPlotter(ax)
plotter.plot(orbit_dpt, label="Initial orbit", color="red")
plotter.plot(orbit_trans, label="Trans orbit", color="blue")
plotter.plot(orbit_target, label="Final orbit", color="green")

print("Total cost")
print(man_lambert.get_total_cost())

print("Total time")
print(man_lambert.get_total_time())

# plt.savefig(
#     "figures_lamb/ManeuverLambert, t_man [month] = " + str(t_maneuver / (3600 * 24 * 30)) + "T, revol=" + str(
#         num_revol) + ".png")
# plt.savefig("figures_lamb/ManeuverLambert, t_man [month] = " + str(t_maneuver / (3600 * 24 * 30)) + "T.png")
plt.show()
ss_1_a.change_plane(Planes.EARTH_ECLIPTIC)

# In[44]:

ss_1_b.change_plane(Planes.EARTH_ECLIPTIC)

# Therefore, **the correct option is the first one**.

# In[45]:

ss_1_a.period.to(u.day)

# In[46]:

ss_1_a.a

# And, finally, we plot the solution:

# In[47]:

from poliastro.plotting import StaticOrbitPlotter

frame = StaticOrbitPlotter(plane=Planes.EARTH_ECLIPTIC)

frame.plot_body_orbit(Earth, d_launch)
frame.plot_body_orbit(Venus, flyby_1_time)
frame.plot(ss01, label="#0 to #1", color="C2")
frame.plot(ss_1_a, label="#1 to #2", color="C3")

plt.show()
florence_e = Ephem.from_horizons("Florence", epochs, attractor=Earth)
florence_e

# We now retrieve the ephemerides of the Moon, which are given directly in GCRS:

# In[20]:

moon = Ephem.from_body(Moon, epochs, attractor=Earth)
moon

# In[21]:

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)

# And now, the glorious final plot:

# In[22]:

import matplotlib.pyplot as plt

frame = StaticOrbitPlotter()

frame.set_attractor(Earth)
frame.set_orbit_frame(Orbit.from_ephem(Earth, florence_e, EPOCH))
# If we now apply previous maneuver to the Junos's initial orbit (assume it is the Earth's one for simplicity), we will obtain the orbit around the Sun for Juno. The first inner cruise maneuver is defined just till the ahelion orbit. While Juno is traveling around its new orbit, Earth is also moving. After Juno reaches the aphelion it will be necessary to apply a second maneuver so the flyby is performed around Earth. Once that is achieved a final maneuver will be made in order to benefit from the gravity assist. Let us first propagate Juno's orbit till the aphelion.

# In[6]:

ss_e0 = Orbit.from_ephem(Sun, earth, date_launch)
ss_efly = Orbit.from_ephem(Sun, earth, date_flyby)

# Inner Cruise 1
ic1 = ss_e0.apply_maneuver(man)
ic1_end = ic1.propagate_to_anomaly(180.0 * u.deg)

# We solve for Earth's position when Juno is at aphelion
ss_e_ic1 = Orbit.from_ephem(Sun, earth, epoch=ic1_end.epoch)

# We can check new bodies positions
plotter = StaticOrbitPlotter()
plotter.plot_body_orbit(Earth, ic1_end.epoch, label="Earth at end of flyby")
plotter.plot_trajectory(
    ic1_end.sample(min_anomaly=0 * u.deg, max_anomaly=180 * u.deg),
    label="Inner cruise 1 full orbit",
    color="C1",
)

# We can check that the period of the orbit is similar to the one stated in the mission's documentation. Remember that in previous plot we only plotter half of the orbit for Juno first maneuver and the period is the time that would take Juno to complete one full revolution around this new orbit.

# In[7]:

ic1.period.to(u.day)

# Notice in previous plot that Earth's position is not the initial one since while Juno is moving Earth also does. We now solve for the Lambert maneuver in order to perform a flyby around the earth when it is at flyby date.
Example #7
0
# coding: utf-8

# # Customising static orbit plots

# The default styling for plots works pretty well however sometimes you may need to change things. The following will show you how to change the style of your plots and have different types of lines and dots
#
# This is the default plot we will start with:

from astropy.time import Time
import matplotlib.pyplot as plt

from poliastro.plotting import StaticOrbitPlotter
from poliastro.frames import Planes
from poliastro.bodies import Earth, Mars, Jupiter, Sun
from poliastro.twobody import Orbit

dat = "2020-06-15 11:00:00"
epoch = Time(dat, scale="tdb")

fig, ax = plt.subplots()
ax.grid(True)
ax.set_title("Earth, Mars, and Jupiter")
ax.set_facecolor("None")

plotter = StaticOrbitPlotter(ax)
plotter.plot_body_orbit(Earth, epoch, label=Earth)
plotter.plot_body_orbit(Mars, epoch, label=Mars)
plotter.plot_body_orbit(Jupiter, epoch, label=Jupiter)
plt.savefig("./orbit.png")
plt.show()
Example #8
0
print(
    "Relative error of {:.2f} %".format(
        (norm(exit.v) - v_estimated) / v_estimated * 100
    )
)


# So it stays within the same order of magnitude. Which is reasonable, because real life burns are not instantaneous.

# In[5]:


import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(8, 8))
op = StaticOrbitPlotter(ax=ax)

op.plot(parking)
op.plot(exit)

ax.set_xlim(-8000, 8000)
ax.set_ylim(-20000, 20000);


# ### Option b): Compute $v_{\infty}$ using the Jupyter flyby
# 
# According to Wikipedia, the closest approach occurred at 05:43:40 UTC. We can use this data to compute the solution of the Lambert problem between the Earth and Jupiter.

# In[6]:

# In[1]:

from astropy.time import Time
import matplotlib.pyplot as plt

from poliastro.plotting import StaticOrbitPlotter
from poliastro.frames import Planes
from poliastro.bodies import Earth, Mars, Jupiter, Sun
from poliastro.twobody import Orbit

# In[2]:

epoch = Time("2018-08-17 12:05:50", scale="tdb")

plotter = StaticOrbitPlotter(plane=Planes.EARTH_ECLIPTIC)
plotter.plot_body_orbit(Earth, epoch, label="Earth")
plotter.plot_body_orbit(Mars, epoch, label="Mars")
plotter.plot_body_orbit(Jupiter, epoch, label="Jupiter")

# In[3]:

epoch = Time("2018-08-17 12:05:50", scale="tdb")

plotter = StaticOrbitPlotter(plane=Planes.EARTH_ECLIPTIC)
earth_plots_traj, earth_plots_pos = plotter.plot_body_orbit(Earth,
                                                            epoch,
                                                            label=Earth)

earth_plots_traj[0].set_linestyle("-")  # solid line
earth_plots_traj[0].set_linewidth(0.5)
Example #10
0
def phasing_man(t_maneuvers,
                distance_sc_dergee,
                orbit_ssc_first,
                file_maneuvers,
                num_dfi_in_fi=1,
                plot=False):
    file_maneuvers.write("-- -- -- -- -- --" + '\n')
    file_maneuvers.write("Where is SSC: SSC is the first one or last one" +
                         '\n')
    file_maneuvers.write(
        "Number of dfi (one revolution) in  fi (maneuver to one SC): " +
        str(num_dfi_in_fi) + '\n')

    for t_man in t_maneuvers:
        file_maneuvers.write("Limit time of maneuver [sec]: " + str(t_man) +
                             '\n')
        file_maneuvers.write("[month]: " + str(t_man / (3600 * 24 * 30)) +
                             '\n\n')
        t_man = t_man / num_dfi_in_fi
        dv_back, T_man_back, ss_a, ss_f = maneuver_phasing_form_orbit(
            part_of_period=1 + (360 - 5 * distance_sc_dergee) / 360,
            orbit=orbit_ssc_first,
            plot=False)
        file_maneuvers.write(
            "Last maneuver to return at init point (similar for all), it is a part of maneuvers, "
            "which is added automatic to final answers " + '\n')
        file_maneuvers.write("dv back: " + str(dv_back) + '\n')
        file_maneuvers.write("T maneuver back: " + str(T_man_back) + '\n\n')

        for num_revol_on_circ_orbit in range(1, MAX_REVOL_ON_CIRC_ORBIT):
            file_maneuvers.write(
                "Time of one revolution in maneuver (for one dfi) in periods of circ orbit: "
                + str(num_revol_on_circ_orbit +
                      distance_sc_dergee / num_dfi_in_fi / 360) + '\n')

            dv, T_man, ss_a, ss_f = maneuver_phasing_form_orbit(
                part_of_period=num_revol_on_circ_orbit +
                distance_sc_dergee / num_dfi_in_fi / 360,
                orbit=orbit_ssc_first,
                plot=False)

            check_alt(ss_f, file_maneuvers)

            print("dv for one man = " + str(dv) + '\n')
            print("T_man for one man = " + str(T_man) + '\n')

            dv_tot = dv * 5 + dv_back
            T_man_tot = T_man * 5 + T_man_back

            if t_man * num_dfi_in_fi < T_man_tot:
                file_maneuvers.write("OVER TIME" + '\n\n')

            file_maneuvers.write("dv: " + str(dv_tot) + '\n')
            file_maneuvers.write("T maneuver: " + str(T_man_tot) + '\n\n')
            file_maneuvers.write("- - - - - - - - - - " + '\n')

            if plot:
                fig, ax = plt.subplots()
                plotter = StaticOrbitPlotter(ax)
                plotter.plot(ss_a, label="Initial orbit", color="red")
                plotter.plot(ss_f, label="Phasing orbit", color="blue")
                plt.savefig("figures/ManeuverPhasing, t_man=" +
                            str(T_man_tot) + ".png")
                plt.show()
Example #11
0

eros = Orbit.from_sbdb("Eros")
eros.plot(label="Eros");


# You can also search by IAU number or SPK-ID (there is a faster `neows.orbit_from_spk_id()` function in that case, although):

# In[3]:


ganymed = Orbit.from_sbdb("1036")  # Ganymed IAU number
amor = Orbit.from_sbdb("2001221")  # Amor SPK-ID
eros = Orbit.from_sbdb("2000433")  # Eros SPK-ID

frame = StaticOrbitPlotter(plane=Planes.EARTH_ECLIPTIC)
frame.plot(ganymed, label="Ganymed")
frame.plot(amor, label="Amor")
frame.plot(eros, label="Eros");


# You can use the wildcards from that browser: `*` and `?`.

# <div class="alert alert-info">Keep it in mind that `from_sbdb()` can only return one Orbit, so if several objects are found with that name, it will raise an error with the different bodies.</div>

# In[4]:


try:
    Orbit.from_sbdb("*alley")
except ValueError as err:
Example #12
0
def maneuver_lambert(orbit_dpt,
                     orbit_arr_sc,
                     orbit_last,
                     t_maneuver,
                     file_maneuvers,
                     distance_sc_dergee,
                     flag,
                     plot=False,
                     num_revol=None,
                     is_short=False,
                     intermediate=True):

    # calculate time to return back
    alfa_back = (360 - distance_sc_dergee * 5) / 180 * np.pi * u.rad
    orbit_back = orbit_last.propagate_to_anomaly(alfa_back)
    r2_back = orbit_back.r
    v2_back = orbit_back.v
    date_arrival_back = time.Time(
        (DATA_LAUNCH.unix + 2.5 * orbit_dpt.period.value *
         ((360 - distance_sc_dergee * 5) / 360)),
        format='unix')
    orbit_arr_back = Orbit.from_vectors(Earth,
                                        r2_back,
                                        v2_back,
                                        epoch=date_arrival_back)

    man_lambert_back = Maneuver.lambert(orbit_last,
                                        orbit_arr_back,
                                        short=is_short,
                                        M=1)

    cost_maneuver_back = man_lambert_back.get_total_cost()
    time_maneuver_back = man_lambert_back.get_total_time()

    dv_tot = cost_maneuver_back
    T_man_tot = time_maneuver_back

    if flag:
        file_maneuvers.write(
            "Last maneuver to return at init point (similar for all), it is a part of maneuvers, "
            "which is added automatic to final answers " + '\n')
        file_maneuvers.write("dv back: " + str(cost_maneuver_back) + '\n')
        file_maneuvers.write("T maneuver back: " + str(time_maneuver_back) +
                             '\n\n')

    t_maneuver = (t_maneuver - time_maneuver_back.value) / 5

    file_maneuvers.write("Number of revolution to go to one sc: " +
                         str(num_revol) + '\n')
    file_maneuvers.write("Time of maneuver to go to one sc [sec]: " +
                         str(t_maneuver) + '\n')

    alfa = orbit_dpt.n.value * t_maneuver * u.rad
    orbit = orbit_arr_sc.propagate_to_anomaly(alfa)

    r2 = orbit.r
    v2 = orbit.v
    date_arrival = time.Time((DATA_LAUNCH.unix + t_maneuver), format='unix')
    orbit_arr = Orbit.from_vectors(Earth, r2, v2, epoch=date_arrival)

    if num_revol:
        man_lambert = Maneuver.lambert(orbit_dpt,
                                       orbit_arr,
                                       short=is_short,
                                       M=num_revol)
    else:
        man_lambert = Maneuver.lambert(orbit_dpt, orbit_arr, short=is_short)

    orbit_trans, orbit_target = orbit_dpt.apply_maneuver(
        man_lambert, intermediate=intermediate)

    if plot:
        # try to plot it
        fig, ax = plt.subplots()  # (figsize=(4, 4))
        plotter = StaticOrbitPlotter(ax)
        plotter.plot(orbit_dpt, label="Initial orbit", color="red")
        plotter.plot(orbit_trans, label="Trans orbit", color="blue")
        plotter.plot(orbit_target, label="Final orbit", color="green")
        if num_revol:
            plt.savefig("figures_lamb/ManeuverLambert, t_man [month] = " +
                        str(t_maneuver / (3600 * 24 * 30)) + "T, revol=" +
                        str(num_revol) + ".png")
        else:
            plt.savefig("figures_lamb/ManeuverLambert, t_man [month] = " +
                        str(t_maneuver / (3600 * 24 * 30)) + "T.png")
        plt.show()

    check_alt(orbit_trans, file_maneuvers)

    cost_maneuver = man_lambert.get_total_cost()
    time_maneuver = man_lambert.get_total_time()

    dv_tot = dv_tot + cost_maneuver * 5
    T_man_tot = T_man_tot + time_maneuver * 5

    file_maneuvers.write("dv: " + str(dv_tot) + '\n')
    file_maneuvers.write("T maneuver: " + str(T_man_tot) + '\n\n')
    file_maneuvers.write("- - - - - - - - - - " + '\n')

    print("dv: " + str(dv_tot) + '\n')
    print("T maneuver: " + str(T_man_tot) + '\n\n')
    return False