Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_redraw_keeps_trajectories():
# See https://github.com/poliastro/poliastro/issues/518
op = StaticOrbitPlotter()
trajectory = churi.sample()
op.plot_body_orbit(Mars, J2000, label="Mars")
op.plot_trajectory(trajectory, label="67P")
assert len(op.trajectories) == 2
op.set_body_frame(Mars)
assert len(op.trajectories) == 2
def test_plot_trajectory_sets_label():
expected_label = "67P"
op = StaticOrbitPlotter()
trajectory = churi.sample()
op.plot_body_orbit(Mars, J2000, label="Mars")
op.plot_trajectory(trajectory, label=expected_label)
legend = plt.gca().get_legend()
assert legend.get_texts()[1].get_text() == expected_label
def test_orbit_attractor():
r = [3_539.08827417, 5_310.19903462, 3_066.31301457] * u.km
v = [-6.49780849, 3.24910291, 1.87521413] * u.km / u.s
ss = Orbit.from_vectors(Mars, r, v)
C_D = 2.2 * u.one # dimentionless (any value would do)
A = ((np.pi / 4.0) * (u.m ** 2)).to(u.km ** 2)
m = 100 * u.kg
spacecraft = Spacecraft(A, C_D, m)
with pytest.raises(ValueError) as excinfo:
EarthSatellite(ss, spacecraft)
assert "The attractor must be Earth" in excinfo.exconly()
def test_set_different_attractor_raises_error(plotter_class):
body1 = Earth
body2 = Mars
frame = plotter_class()
frame.set_attractor(body1)
with pytest.raises(NotImplementedError) as excinfo:
frame.set_attractor(body2)
assert "Attractor has already been set to Earth" in excinfo.exconly()
def test_porkchop_plotting():
fig, ax = plt.subplots()
launch_span = time_range("2005-04-30", end="2005-10-07")
arrival_span = time_range("2005-11-16", end="2006-12-21")
dv_dpt, dv_arr, c3dpt, c3arr, tof = porkchop(
Earth, Mars, launch_span, arrival_span, ax=ax
)
return fig
(Mars, MarsICRS),
(Jupiter, JupiterICRS),
(Saturn, SaturnICRS),
(Uranus, UranusICRS),
(Neptune, NeptuneICRS),
],
)
def test_orbit_get_frame_returns_proper_frame(attractor, expected_frame_class):
# Dummy data
r = [1e09, -4e09, -1e09] * u.km
v = [5e00, -1e01, -4e00] * u.km / u.s
epoch = Time("2015-07-14 07:59", scale="tdb")
ss = Orbit.from_vectors(attractor, r, v, epoch)
frame = ss.get_frame()
assert frame.is_equivalent_frame(expected_frame_class(obstime=epoch))
(Mars, MarsICRS),
(Jupiter, JupiterICRS),
(Saturn, SaturnICRS),
(Uranus, UranusICRS),
(Neptune, NeptuneICRS),
],
)
def test_planetary_icrs_frame_is_just_translation(body, frame):
with solar_system_ephemeris.set("builtin"):
epoch = J2000
vector = CartesianRepresentation(x=100 * u.km, y=100 * u.km, z=100 * u.km)
vector_result = (
frame(vector, obstime=epoch)
.transform_to(ICRS)
.represent_as(CartesianRepresentation)
)
def _get_state(body, time):
""" Computes the position of a body for a given time. """
solar_system_bodies = [
Sun,
Mercury,
Venus,
Earth,
Moon,
Mars,
Jupiter,
Saturn,
Uranus,
Neptune,
Pluto,
]
# We check if body belongs to poliastro.bodies
if body in solar_system_bodies:
rr, vv = coord.get_body_barycentric_posvel(body.name, time)
else:
rr, vv = body.propagate(time).rv()
rr = coord.CartesianRepresentation(rr)
vv = coord.CartesianRepresentation(vv)
return rr.xyz, vv.xyz
def plot_solar_system(outer=True, epoch=None):
"""
Plots the whole solar system in one single call.
.. versionadded:: 0.9.0
Parameters
------------
outer : bool, optional
Whether to print the outer Solar System, default to True.
epoch: ~astropy.time.Time, optional
Epoch value of the plot, default to J2000.
"""
bodies = [Mercury, Venus, Earth, Mars]
if outer:
bodies.extend([Jupiter, Saturn, Uranus, Neptune])
op = OrbitPlotter()
for body in bodies:
orb = Orbit.from_body_ephem(body, epoch)
op.plot(orb, label=str(body))
# Sets frame to the orbit of the Earth by default
# TODO: Wait until https://github.com/poliastro/poliastro/issues/316
# op.set_frame(*Orbit.from_body_ephem(Earth, epoch).pqw())
return op
NeptuneFixed,
SaturnFixed,
UranusFixed,
VenusFixed,
)
_FRAME_MAPPING = {
Sun: {Planes.EARTH_EQUATOR: HCRS, Planes.EARTH_ECLIPTIC: HeliocentricEclipticJ2000},
Mercury: {Planes.EARTH_EQUATOR: MercuryICRS, Planes.BODY_FIXED: MercuryFixed},
Venus: {Planes.EARTH_EQUATOR: VenusICRS, Planes.BODY_FIXED: VenusFixed},
Earth: {
Planes.EARTH_EQUATOR: GCRS,
Planes.EARTH_ECLIPTIC: GeocentricMeanEcliptic,
Planes.BODY_FIXED: ITRS,
},
Mars: {Planes.EARTH_EQUATOR: MarsICRS, Planes.BODY_FIXED: MarsFixed},
Jupiter: {Planes.EARTH_EQUATOR: JupiterICRS, Planes.BODY_FIXED: JupiterFixed},
Saturn: {Planes.EARTH_EQUATOR: SaturnICRS, Planes.BODY_FIXED: SaturnFixed},
Uranus: {Planes.EARTH_EQUATOR: UranusICRS, Planes.BODY_FIXED: UranusFixed},
Neptune: {Planes.EARTH_EQUATOR: NeptuneICRS, Planes.BODY_FIXED: NeptuneFixed},
} # type: Dict[SolarSystemPlanet, Dict[Planes, FrameMeta]]
def get_frame(attractor, plane, obstime=J2000):
"""Returns an appropriate reference frame from an attractor and a plane.
Available planes are Earth equator (parallel to GCRS) and Earth ecliptic.
The fundamental direction of both is the equinox of epoch (J2000).
An obstime is needed to properly locate the attractor.
Parameters
----------