示例#1
0
def test_plot_ephem_different_plane_raises_error():
    unused_epochs = Time.now().reshape(-1)
    unused_coordinates = CartesianRepresentation(
        [(1, 0, 0)] * u.au,
        xyz_axis=1,
        differentials=CartesianDifferential([(0, 1, 0)] * (u.au / u.day),
                                            xyz_axis=1),
    )

    op = StaticOrbitPlotter(plane=Planes.EARTH_ECLIPTIC)
    op.set_attractor(Sun)
    op.set_body_frame(Earth)
    with pytest.raises(ValueError) as excinfo:
        op.plot_ephem(
            Ephem(unused_epochs, unused_coordinates, Planes.EARTH_EQUATOR))

    assert (
        "sample the ephemerides using a different plane or create a new plotter"
        in excinfo.exconly())
示例#2
0
    def plot(
        self,
        epoch=None,
        label=None,
        use_3d=False,
        interactive=False,
        plane=Planes.EARTH_ECLIPTIC,
    ):
        """Plots the body orbit.

        Parameters
        ----------
        epoch : astropy.time.Time, optional
            Epoch of current position.
        label : str, optional
            Label for the orbit, defaults to empty.
        use_3d : bool, optional
            Produce a 3D plot, default to False.
        interactive : bool, optional
            Produce an interactive (rather than static) image of the orbit, default to False.
            This option requires Plotly properly installed and configured for your environment.

        """
        if not interactive and use_3d:
            raise ValueError(
                "The static plotter does not support 3D, use `interactive=True`"
            )
        elif not interactive:
            from poliastro.plotting.static import StaticOrbitPlotter

            return StaticOrbitPlotter(plane=plane).plot_body_orbit(
                self, epoch, label=label
            )
        elif use_3d:
            from poliastro.plotting.core import OrbitPlotter3D

            return OrbitPlotter3D(plane=plane).plot_body_orbit(self, epoch, label=label)
        else:
            from poliastro.plotting.core import OrbitPlotter2D

            return OrbitPlotter2D(plane=plane).plot_body_orbit(self, epoch, label=label)
示例#3
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
示例#4
0
    def plot(self, label=None, use_3d=False, static=False):
        """Plots the orbit as an interactive widget.

        Parameters
        ----------
        label : str, optional
            Label for the orbit, defaults to empty.
        use_3d : bool, optional
            Produce a 3D plot, default to False.
        static : bool, optional
            Produce a static image of the figure, default to false
        """
        from poliastro.plotting.static import StaticOrbitPlotter

        if static and use_3d:
            raise ValueError("static and use_3d cannot be true at the same time")
        elif static:
            return StaticOrbitPlotter().plot(self, label=label)
        elif use_3d:
            return OrbitPlotter3D().plot(self, label=label)
        else:
            return OrbitPlotter2D().plot(self, label=label)
示例#5
0
    def plot(self, label=None, use_3d=False, interactive=False):
        """Plots the orbit as an interactive widget.

        Parameters
        ----------
        label : str, optional
            Label for the orbit, defaults to empty.
        use_3d : bool, optional
            Produce a 3D plot, default to False.
        interactive : bool, optional
            Produce an interactive (rather than static) image of the orbit, default to False.
            This option requires Plotly properly installed and configured for your environment.
        """
        if not interactive and use_3d:
            raise ValueError(
                "The static plotter does not support 3D, use `interactive=True`"
            )
        elif not interactive:
            return StaticOrbitPlotter().plot(self, label=label)
        elif use_3d:
            return OrbitPlotter3D().plot(self, label=label)
        else:
            return OrbitPlotter2D().plot(self, label=label)
示例#6
0
    def render(self, mode='live'):
        # Render the environment to the screen
        #plt.clf()
        if mode == 'live':

            if self.i <= self.n:
                plt.figure()

                op = StaticOrbitPlotter()


                orb = [Orbit.from_vectors(Earth, r=(x[:3] / 1000) * u.km, v=(x[3:] / 1000) * u.km / u.s) for x in
                       self.x_true[self.i]]
                orb1 = [Orbit.from_vectors(Earth, r=(x[:3] / 1000) * u.km, v=(x[3:] / 1000) * u.km / u.s) for x in
                        self.x_filter[self.i]]
                palette = sns.color_palette("hls", len(orb))

                for i, c in enumerate(orb):
                    new = op.plot(c, label="true", color=palette[i])
                    new[0].set_linestyle("-")
                for j, d in enumerate(orb1):
                    op.plot(d, label="filtered", color=palette[j])
                plt.pause(0.001)
                plt.savefig('fig'+str(self.i)+'.png')
示例#7
0
def test_redraw_makes_attractor_none():
    # TODO: Review
    op = StaticOrbitPlotter()
    op._redraw()
    assert op._attractor_radius is not None
示例#8
0
def test_dark_mode_plots_dark_plot(dark, expected_color):
    op = StaticOrbitPlotter(dark=dark)
    assert op._ax.get_facecolor() == expected_color
示例#9
0
def test_trail_plotting():
    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.plot(iss, trail=True)

    return fig
示例#10
0
def test_basic_plotting():
    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.plot(iss)

    return fig
示例#11
0
def test_dark_mode_plots_dark_plot():
    op = StaticOrbitPlotter(dark=True)
    assert op.ax.get_facecolor() == (0.0, 0.0, 0.0, 1.0)
    op = StaticOrbitPlotter()
    assert op.ax.get_facecolor() == (1.0, 1.0, 1.0, 1)
示例#12
0
def test_orbitplotter_has_axes():
    ax = "Unused axes"
    op = StaticOrbitPlotter(ax)
    assert op.ax is ax
    ss_long, _ = ss_dpt.apply_maneuver(lambert_long, intermediate=True)

    return ss_short, ss_long


# ### Solutions for M=0
#
# By making use of the previous defined function, we can easily get the different transfer orbit regarding the number of required revolutions, in this case 0.

# In[4]:

# Solving for direct (M=0) transfer long and short arcs
ss_short0, ss_long0 = lambert_transfer(earth_departure, mars_arrival, revs=0)

fig, ax = plt.subplots(figsize=(5, 10))
op = StaticOrbitPlotter(ax=ax)
ax.set_title("Direct arc transfer ($M=0$)")

orbit_set = {ss_short0: ["Short0", "black"], ss_long0: ["Long0", "grey"]}

op.plot_body_orbit(Earth, EPOCH_DPT)
op.plot_body_orbit(Mars, EPOCH_ARR)

for ss in orbit_set:
    op.plot(ss, label=orbit_set[ss][0], color=orbit_set[ss][-1], trail=True)

# ### Solutions for M=1

# In[5]:

# Solving for M=1 long and short arc transfers
示例#14
0
    """
    tru_anom = mean_anomaly + (2*eccentricity - (1/4)*eccentricity**3)*np.sin(mean_anomaly) +  (5/4)*np.sin(2*mean_anomaly)*eccentricity**(2) + (13/12)*np.sin(3*mean_anomaly)*eccentricity**3 *3
    return tru_anom


def dateUnpack(self, packed):
        """A package from mpcorgbet"""
        yearcode = {"I":"18","J":"19","K":"20"}
        daycode = "123456789ABCDEFGHIJKLMNOPQRSTUV"
        year = yearcode[packed[0]]+packed[1:3]
        month = daycode.index(packed[3])+1
        day = daycode.index(packed[4])+1
        return "%s/%s/%s" % (month, day, year)
###############################
#Main Execution

#Commands for getting mpcorgbet data
#first = mpcorbget.MPCORB("162269")
#epoch, mean_anomaly, argument_of_perihelion, longitude_of_ascendingnode, inclination, eccentricity, semimajor_axis,mean_daily_motion = returnOrbitalElements(first)

#Commands for getting eros data from txt file
i, e, a, ME, long, peri = ImportFromTxt('/home/alli/NugentResearch/eros.txt')
tru_anom = calculateTrueAnomaly(ME, e)
print(i, e, a, ME, long, peri)
#Creating poliastro orbit object
ss = Orbit.from_classical(Earth, a* u.AU, e* u.one, i* u.deg, long * u.deg, peri * u.deg, tru_anom * u.deg)
#Plotting Eros
plotter = StaticOrbitPlotter() #creating plotter class
plotter.plot(ss, label="Eros") #plotting Eros
plt.show()