Beispiel #1
0
def test_number_of_lines_for_osculating_orbit():
    op1 = StaticOrbitPlotter()
    ss = iss

    l1 = op1.plot(ss)

    assert len(l1) == 2
Beispiel #2
0
def test_axes_labels_and_title():
    ax = plt.gca()
    op = StaticOrbitPlotter(ax)
    ss = iss
    op.plot(ss)

    assert ax.get_xlabel() == "$x$ (km)"
    assert ax.get_ylabel() == "$y$ (km)"
Beispiel #3
0
def test_set_frame():
    op = StaticOrbitPlotter()
    p = [1, 0, 0] * u.one
    q = [0, 1, 0] * u.one
    w = [0, 0, 1] * u.one
    op.set_frame(p, q, w)

    assert op._frame == (p, q, w)
Beispiel #4
0
def test_legend():
    op = StaticOrbitPlotter()
    ss = iss
    op.plot(ss, label="ISS")
    legend = plt.gca().get_legend()

    ss.epoch.out_subfmt = "date_hm"
    label = f"{ss.epoch.iso} (ISS)"

    assert legend.get_texts()[0].get_text() == label
Beispiel #5
0
def test_color():
    op = StaticOrbitPlotter()
    ss = iss
    c = "#FF0000"
    op.plot(ss, label="ISS", color=c)
    ax = plt.gca()

    assert ax.get_legend().get_lines()[0].get_c() == c
    for element in ax.get_lines():
        assert element.get_c() == c
Beispiel #6
0
def _plot_solar_system_2d(epoch, outer=True, interactive=False):
    if interactive:
        orbit_plotter = OrbitPlotter2D(
            plane=Planes.EARTH_ECLIPTIC
        )  # type: Union[OrbitPlotter2D, StaticOrbitPlotter]
    else:
        orbit_plotter = StaticOrbitPlotter(plane=Planes.EARTH_ECLIPTIC)

    orbit_plotter.set_body_frame(Earth, epoch)

    _plot_bodies(orbit_plotter, outer, epoch)

    return orbit_plotter
Beispiel #7
0
def test_body_frame_raises_warning_if_time_is_not_tdb_with_proper_time(
        recwarn):
    from poliastro.warnings import TimeScaleWarning

    body = Jupiter
    epoch = Time("2017-09-29 07:31:26", scale="utc")
    expected_epoch_string = "2017-09-29 07:32:35.182"  # epoch.tdb.value

    op = StaticOrbitPlotter()
    op.set_body_frame(body, epoch)

    w = recwarn.pop(TimeScaleWarning)

    assert expected_epoch_string in str(w.message)
Beispiel #8
0
def test_basic_trajectory_plotting():
    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.set_attractor(Earth)
    plotter.set_orbit_frame(iss)
    plotter.plot_trajectory(iss.sample())

    return fig
Beispiel #9
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:
            from poliastro.plotting.static import StaticOrbitPlotter

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

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

            return OrbitPlotter2D().plot(self, label=label)
Beispiel #10
0
def test_redraw_keeps_trajectories():
    # See https://github.com/poliastro/poliastro/issues/518
    op = StaticOrbitPlotter()
    trajectory = churi.sample()
    op.plot_body_orbit(Mars, J2000_TDB, label="Mars")
    op.plot_trajectory(trajectory, label="67P")

    assert len(op.trajectories) == 2

    op.set_body_frame(Mars)

    assert len(op.trajectories) == 2
Beispiel #11
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
Beispiel #12
0
def test_redraw_keeps_trajectories():
    # See https://github.com/poliastro/poliastro/issues/518
    op = StaticOrbitPlotter()
    earth = Orbit.from_body_ephem(Earth)
    mars = Orbit.from_body_ephem(Mars)
    trajectory = earth.sample()
    op.plot(mars, label="Mars")
    op.plot_trajectory(trajectory, label="Earth")

    assert len(op.trajectories) == 2

    op.set_frame(*mars.pqw())

    assert len(op.trajectories) == 2
Beispiel #13
0
def test_basic_orbit_and_trajectory_plotting():
    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.plot(iss)
    plotter.plot_trajectory(molniya.sample(), label="Molniya")

    return fig
Beispiel #14
0
def test_plot_different_planes():
    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.plot(iss)
    plotter.plot(molniya.change_plane(Planes.EARTH_ECLIPTIC))

    return fig
Beispiel #15
0
def test_plot_maneuver():
    # Data from Vallado, example 6.1
    alt_i = 191.34411 * u.km
    alt_f = 35781.34857 * u.km
    _a = 0 * u.deg
    ss_i = Orbit.from_classical(
        attractor=Earth,
        a=Earth.R + alt_i,
        ecc=0 * u.one,
        inc=_a,
        raan=_a,
        argp=_a,
        nu=_a,
    )

    # Create the maneuver
    man = Maneuver.hohmann(ss_i, Earth.R + alt_f)

    # Plot the maneuver
    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.plot(ss_i, label="Initial orbit", color="blue")
    plotter.plot_maneuver(ss_i, man, label="Hohmann maneuver", color="red")

    return fig
Beispiel #16
0
def test_set_frame_plots_same_colors():
    # TODO: Review
    op = StaticOrbitPlotter()
    op.plot_body_orbit(Jupiter, J2000_TDB)
    colors1 = [orb[2] for orb in op.trajectories]
    op.set_body_frame(Jupiter)
    colors2 = [orb[2] for orb in op.trajectories]
    assert colors1 == colors2
Beispiel #17
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
Beispiel #18
0
def test_set_frame_plots_same_colors():
    # TODO: Review
    op = StaticOrbitPlotter()
    jupiter = Orbit.from_body_ephem(Jupiter)
    op.plot(jupiter)
    colors1 = [orb[2] for orb in op.trajectories]
    op.set_frame(*jupiter.pqw())
    colors2 = [orb[2] for orb in op.trajectories]
    assert colors1 == colors2
Beispiel #19
0
def test_plot_trajectory_sets_label():
    op = StaticOrbitPlotter()
    earth = Orbit.from_body_ephem(Earth)
    mars = Orbit.from_body_ephem(Mars)
    trajectory = earth.sample()
    op.plot(mars, label="Mars")
    op.plot_trajectory(trajectory, label="Earth")
    legend = plt.gca().get_legend()
    assert legend.get_texts()[1].get_text() == "Earth"
Beispiel #20
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')
Beispiel #21
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()
    )
Beispiel #22
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.
        plane : ~poliastro.frames.Planes
            Reference plane of the coordinates.

        """
        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.interactive import OrbitPlotter3D

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

            return OrbitPlotter2D(plane=plane).plot_body_orbit(self,
                                                               epoch,
                                                               label=label)
Beispiel #23
0
def test_plot_trajectory_sets_label():
    expected_label = "67P"

    op = StaticOrbitPlotter()
    trajectory = churi.sample()
    op.plot_body_orbit(Mars, J2000_TDB, label="Mars")

    op.plot_trajectory(trajectory, label=expected_label)

    legend = plt.gca().get_legend()
    assert legend.get_texts()[1].get_text() == expected_label
Beispiel #24
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)
Beispiel #25
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)
Beispiel #26
0
def test_basic_plotting():
    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.plot(iss)

    return fig
Beispiel #27
0
def test_redraw_makes_attractor_none():
    # TODO: Review
    op = StaticOrbitPlotter()
    op._redraw()
    assert op._attractor_radius is not None
Beispiel #28
0
def test_dark_mode_plots_dark_plot(dark, expected_color):
    op = StaticOrbitPlotter(dark=dark)
    assert op._ax.get_facecolor() == expected_color
Beispiel #29
0
def test_trail_plotting():
    fig, ax = plt.subplots()
    plotter = StaticOrbitPlotter(ax=ax)
    plotter.plot(iss, trail=True)

    return fig
Beispiel #30
0
def test_orbitplotter_has_axes():
    ax = "Unused axes"
    op = StaticOrbitPlotter(ax)
    assert op.ax is ax