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_parabolic_elements_fail_early():
attractor = Earth
ecc = 1.0 * u.one
_d = 1.0 * u.AU # Unused distance
_a = 1.0 * u.deg # Unused angle
with pytest.raises(ValueError) as excinfo:
Orbit.from_classical(attractor, _d, ecc, _a, _a, _a, _a)
assert (
"ValueError: For parabolic orbits use Orbit.parabolic instead"
in excinfo.exconly()
)
def test_orbit_from_horizons_has_expected_elements():
epoch = Time("2018-07-23", scale="tdb")
# Orbit Parameters of Ceres
# Taken from https://ssd.jpl.nasa.gov/horizons.cgi
ss = Orbit.from_classical(
Sun,
2.76710759221651 * u.au,
0.07554803091400027 * u.one,
27.18502494739172 * u.deg,
23.36913218336299 * u.deg,
132.2919809219236 * u.deg,
21.28957916690369 * u.deg,
epoch,
)
ss1 = Orbit.from_horizons(name="Ceres", attractor=Sun, epoch=epoch)
assert ss.pqw()[0].value.all() == ss1.pqw()[0].value.all()
assert_quantity_allclose(ss.r_a, ss1.r_a, rtol=1.0e-4)
assert_quantity_allclose(ss.a, ss1.a, rtol=1.0e-4)
def test_convert_from_rv_to_coe():
# Data from Vallado, example 2.6
attractor = Earth
p = 11_067.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 = [6_525.344, 6_861.535, 6_449.125] * u.km
expected_v = [4.902276, 5.533124, -1.975709] * u.km / u.s
r, v = Orbit.from_classical(
attractor, p / (1 - ecc ** 2), ecc, inc, raan, argp, nu
).rv()
assert_quantity_allclose(r, expected_r, rtol=1e-5)
assert_quantity_allclose(v, expected_v, rtol=1e-5)
def test_expected_last_perifocal_passage():
# Example from Curtis
expected_t_p = 4077 * u.s
attractor = Earth
_a = 1.0 * u.deg # Unused angle
a = 15_300 * u.km
ecc = 0.37255 * u.one
nu = 120 * u.deg
orbit = Orbit.from_classical(attractor, a, ecc, _a, _a, _a, nu)
orbit_t_p = orbit.t_p
assert_quantity_allclose(orbit_t_p, expected_t_p, rtol=1e-2)
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 = J2000
ss = Orbit.from_classical(_body, _d, _, _a, _a, _a, _a)
assert ss.epoch == expected_epoch
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 = Orbit.from_classical(Sun, _d, _, _a, _a, _a, _a)
dt = 1 * u.h
dv = [0, 0, 0] * u.km / u.s
orbit_new = ss.apply_maneuver([(dt, dv)])
assert orbit_new.epoch == ss.epoch + dt