def test_perifocal_points_to_perigee(): _d = 1.0 * u.AU # Unused distance _ = 0.5 * u.one # Unused dimensionless value _a = 1.0 * u.deg # Unused angle ss = State.from_classical(Sun, _d, _, _a, _a, _a, _a) p, _, _ = ss.pqw() assert_almost_equal(p, ss.e_vec / ss.ecc)
def test_default_time_for_new_state(): _d = 1.0 * u.AU # Unused distance _ = 0.5 * u.one # Unused dimensionless value _a = 1.0 * u.deg # Unused angle _body = Sun # Unused body expected_epoch = time.Time("J2000", scale='utc') ss = State.from_classical(_body, _d, _, _a, _a, _a, _a) assert ss.epoch == expected_epoch
def test_state_raises_unitserror_if_elements_units_are_wrong(): _d = 1.0 * u.AU # Unused distance _ = 0.5 * u.one # Unused dimensionless value _a = 1.0 * u.deg # Unused angle wrong_angle = 1.0 * u.AU with pytest.raises(u.UnitsError) as excinfo: ss = State.from_classical(Sun, _d, _, _a, _a, _a, wrong_angle) assert ("UnitsError: Units must be consistent" in excinfo.exconly())
def test_apply_maneuver_changes_epoch(): _d = 1.0 * u.AU # Unused distance _ = 0.5 * u.one # Unused dimensionless value _a = 1.0 * u.deg # Unused angle ss = State.from_classical(Sun, _d, _, _a, _a, _a, _a) dt = 1 * u.h dv = [0, 0, 0] * u.km / u.s ss_new = ss.apply_maneuver([(dt, dv)]) assert ss_new.epoch == ss.epoch + dt
def test_state_has_elements_given_in_constructor(): # Mars data from HORIZONS at J2000 a = 1.523679 * u.AU ecc = 0.093315 * u.one p = a * (1 - ecc**2) inc = 1.85 * u.deg raan = 49.562 * u.deg argp = 286.537 * u.deg nu = 23.33 * u.deg ss = State.from_classical(Sun, p, ecc, inc, raan, argp, nu) assert ss.coe() == (p, ecc, inc, raan, argp, nu)
def test_apply_zero_maneuver_returns_equal_state(): _d = 1.0 * u.AU # Unused distance _ = 0.5 * u.one # Unused dimensionless value _a = 1.0 * u.deg # Unused angle ss = State.from_classical(Sun, _d, _, _a, _a, _a, _a) dt = 0 * u.s dv = [0, 0, 0] * u.km / u.s ss_new = ss.apply_maneuver([(dt, dv)]) assert_almost_equal(ss_new.r.to(u.km).value, ss.r.to(u.km).value) assert_almost_equal(ss_new.v.to(u.km / u.s).value, ss.v.to(u.km / u.s).value)
def test_perigee_and_apogee(): expected_r_a = 500 * u.km expected_r_p = 300 * u.km a = (expected_r_a + expected_r_p) / 2 ecc = expected_r_a / a - 1 p = a * (1 - ecc**2) _a = 1.0 * u.deg # Unused angle ss = State.from_classical(Earth, p, ecc, _a, _a, _a, _a) assert_almost_equal(ss.r_a.to(u.km).value, expected_r_a.to(u.km).value) assert_almost_equal(ss.r_p.to(u.km).value, expected_r_p.to(u.km).value)
def test_convert_from_rv_to_coe(): # Data from Vallado, example 2.6 attractor = Earth p = 11067.790 * u.km ecc = 0.83285 * u.one inc = 87.87 * u.deg raan = 227.89 * u.deg argp = 53.38 * u.deg nu = 92.335 * u.deg expected_r = [6525.344, 6861.535, 6449.125] # km expected_v = [4.902276, 5.533124, -1.975709] # km / s r, v = State.from_classical(Earth, p, ecc, inc, raan, argp, nu).rv() assert_array_almost_equal(r.value, expected_r, decimal=1) assert_array_almost_equal(v.value, expected_v, decimal=5)
def test_state_has_individual_elements(): a = 1.523679 * u.AU ecc = 0.093315 * u.one p = a * (1 - ecc**2) inc = 1.85 * u.deg raan = 49.562 * u.deg argp = 286.537 * u.deg nu = 23.33 * u.deg ss = State.from_classical(Sun, p, ecc, inc, raan, argp, nu) assert ss.a == a assert ss.ecc == ecc assert ss.inc == inc assert ss.raan == raan assert ss.argp == argp assert ss.nu == nu
# coding: utf-8 """Example data. """ from astropy import time from astropy import units as u from poliastro.bodies import Earth from poliastro.twobody import State # Taken from Plyades (c) 2012 Helge Eichhorn (MIT License) iss = State.from_vectors(Earth, [8.59072560e2, -4.13720368e3, 5.29556871e3] * u.km, [7.37289205, 2.08223573, 4.39999794e-1] * u.km / u.s, time.Time("2013-03-18 12:00", scale='utc')) molniya = State.from_classical(Earth, 26600 * u.km, 0.75 * u.one, 63.4 * u.deg, 0 * u.deg, 270 * u.deg, 80 * u.deg)
def test_state_has_attractor_given_in_constructor(): _d = 1.0 * u.AU # Unused distance _ = 0.5 * u.one # Unused dimensionless value _a = 1.0 * u.deg # Unused angle ss = State.from_classical(Sun, _d, _, _a, _a, _a, _a) assert ss.attractor == Sun