def test_body_from_parameters_raises_valueerror_if_k_units_not_correct(): wrong_k = 4902.8 * u.kg _name = _symbol = "" _R = 0 with pytest.raises(u.UnitsError) as excinfo: Body.from_parameters(None, wrong_k, _name, _symbol, _R) assert ( "UnitsError: Argument 'k' to function 'from_parameters' must be in units convertible to 'km3 / s2'." in excinfo.exconly())
def test_body_printing_has_name_and_symbol(): name = "2 Pallas" symbol = u"\u26b4" k = 1.41e10 * u.m**3 / u.s**2 pallas2 = Body(None, k, name, symbol) assert name in str(pallas2) assert symbol in str(pallas2)
def test_body_from_parameters_returns_body_object(): k = 1.26712763e17 * u.m**3 / u.s**2 R = 71492000 * u.m _name = _symbol = "jupiter" jupiter = Body.from_parameters(Sun, k, _name, _symbol, Jupiter.R) assert jupiter.k == k assert jupiter.R == R
def test_orbit_from_custom_body_raises_error_when_asked_frame(): attractor = Body(Sun, 1 * u.km**3 / u.s**2, "_DummyPlanet") r = [1e09, -4e09, -1e09] * u.km v = [5e00, -1e01, -4e00] * u.km / u.s ss = Orbit.from_vectors(attractor, r, v) with pytest.raises(NotImplementedError) as excinfo: ss.frame assert ("Frames for orbits around custom bodies are not yet supported" in excinfo.exconly())
def test_from_relative(): TRAPPIST1 = Body.from_relative( reference=Sun, parent=None, k=0.08, # Relative to the Sun name="TRAPPIST", symbol=None, R=0.114, ) # Relative to the Sun # Check values properly calculated VALUECHECK = Body.from_relative( reference=Earth, parent=TRAPPIST1, k=1, name="VALUECHECK", symbol=None, R=1, ) assert Earth.k == VALUECHECK.k assert Earth.R == VALUECHECK.R
def test_body_has_k_given_in_constructor(): k = 3.98e5 * u.km**3 / u.s**2 earth = Body(None, k, "") assert earth.k == k
def test_hill_radius_given_a(): parent = Body(None, 1 * u.km**3 / u.s**2, "Parent") body = Body(parent, 1 * u.km**3 / u.s**2, "Body") r_SOI = hill_radius(body, 1 * u.km, 0.25 * u.one) expected_r_SOI = 520.02096 * u.m assert_quantity_allclose(r_SOI, expected_r_SOI, rtol=1e-8)
def test_laplace_radius_given_a(): parent = Body(None, 1 * u.km**3 / u.s**2, "Parent") body = Body(parent, 1 * u.km**3 / u.s**2, "Body") r_SOI = laplace_radius(body, 1 * u.km) assert r_SOI == 1 * u.km
import gym from astropy.time import Time from gym import spaces from astropy.coordinates import solar_system_ephemeris from astropy import units as u from astropy.constants import g0, G from poliastro.bodies import Saturn, Body from poliastro.ephem import Ephem from poliastro.maneuver import Maneuver import numpy as np from poliastro.twobody.orbit import Orbit from poliastro.util import norm moon_dict = { 601: { "body": Body(Saturn, (G * 4e19 * u.kg), "Mimas", R=396 * u.km), "orbital_radius": 185_537 * u.km, "soi": None, "index": [(0, 6), (6, 601)] }, 602: { "body": Body(Saturn, (G * 1.1e20 * u.kg), "Enceladus", R=504 * u.km), "orbital_radius": 237_948 * u.km, "soi": None, "index": [(0, 6), (6, 602)] }, 603: { "body": Body(Saturn, (G * 6.2e20 * u.kg), "Tethys", R=1_062 * u.km), "orbital_radius": 294_619 * u.km, "soi": None, "index": [(0, 6), (6, 603)]
def wrapper(t, u_, k, *args, **kwargs): r, v = u_[:3], u_[3:] ss = RVState(Body(None, k * u.km3s2, "_Dummy"), r * u.km, v * u.kms) return func(t, ss, *args, **kwargs)
def wrapper(t, u_, k, *args, **kwargs): r, v = u_[:3], u_[3:] ss = RVState(Body(None, k * u.au3s2, "_Dummy"), r * u.au, v * u.aus, Planes.EARTH_EQUATOR) return func(t, ss, *args, **kwargs)
def test_compute_soi_given_a(): parent = Body(None, 1 * u.km ** 3 / u.s ** 2, "Parent") body = Body(parent, 1 * u.km ** 3 / u.s ** 2, "Body") r_SOI = compute_soi(body, 1 * u.km) assert r_SOI == 1 * u.km