def test_number_of_lines_for_osculating_orbit(): op1 = StaticOrbitPlotter() ss = iss l1 = op1.plot(ss) assert len(l1) == 2
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)"
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)
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
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
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
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)
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
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)
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
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
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
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
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
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
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
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
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
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"
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')
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() )
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)
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
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)
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)
def test_basic_plotting(): fig, ax = plt.subplots() plotter = StaticOrbitPlotter(ax=ax) plotter.plot(iss) return fig
def test_redraw_makes_attractor_none(): # TODO: Review op = StaticOrbitPlotter() op._redraw() assert op._attractor_radius is not None
def test_dark_mode_plots_dark_plot(dark, expected_color): op = StaticOrbitPlotter(dark=dark) assert op._ax.get_facecolor() == expected_color
def test_trail_plotting(): fig, ax = plt.subplots() plotter = StaticOrbitPlotter(ax=ax) plotter.plot(iss, trail=True) return fig
def test_orbitplotter_has_axes(): ax = "Unused axes" op = StaticOrbitPlotter(ax) assert op.ax is ax