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_cowell_propagation_with_zero_acceleration_equals_kepler():
# Data from Vallado, example 2.4
r0 = np.array([1131.340, -2282.343, 6672.423]) * u.km
v0 = np.array([-5.64305, 4.30333, 2.42879]) * u.km / u.s
tofs = [40 * 60.0] * u.s
orbit = Orbit.from_vectors(Earth, r0, v0)
expected_r = np.array([-4219.7527, 4363.0292, -3958.7666]) * u.km
expected_v = np.array([3.689866, -1.916735, -6.112511]) * u.km / u.s
r, v = cowell(Earth.k, orbit.r, orbit.v, tofs, ad=None)
assert_quantity_allclose(r[0], expected_r, rtol=1e-5)
assert_quantity_allclose(v[0], expected_v, rtol=1e-4)
def halley():
return Orbit.from_vectors(
Sun,
[-9018878.63569932, -94116054.79839276, 22619058.69943215] * u.km,
[-49.95092305, -12.94843055, -4.29251577] * u.km / u.s,
)
def test_propagation_hyperbolic():
# Data from Curtis, example 3.5
r0 = [Earth.R.to(u.km).value + 300, 0, 0] * u.km
v0 = [0, 15, 0] * u.km / u.s
expected_r_norm = 163180 * u.km
expected_v_norm = 10.51 * u.km / u.s
ss0 = Orbit.from_vectors(Earth, r0, v0)
tof = 14941 * u.s
ss1 = ss0.propagate(tof)
r, v = ss1.rv()
assert_quantity_allclose(norm(r), expected_r_norm, rtol=1e-4)
assert_quantity_allclose(norm(v), expected_v_norm, rtol=1e-3)
def test_cowell_works_with_small_perturbations():
r0 = [-2384.46, 5729.01, 3050.46] * u.km
v0 = [-7.36138, -2.98997, 1.64354] * u.km / u.s
r_expected = [
13179.39566663877121754922,
-13026.25123408228319021873,
-9852.66213692844394245185,
] * u.km
v_expected = (
[2.78170542314378943516, 3.21596786944631274352, 0.16327165546278937791]
* u.km
/ u.s
)
initial = Orbit.from_vectors(Earth, r0, v0)
def accel(t0, state, k):
v_vec = state[3:]
norm_v = (v_vec * v_vec).sum() ** 0.5
return 1e-5 * v_vec / norm_v
final = initial.propagate(3 * u.day, method=cowell, ad=accel)
assert_quantity_allclose(final.r, r_expected)
assert_quantity_allclose(final.v, v_expected)
def test_repr_maneuver():
alt_f = 35781.34857 * u.km
r = [-6045, -3490, 2500] * u.km
v = [-3.457, 6.618, 2.533] * u.km / u.s
alt_b = 503873.0 * u.km
alt_fi = 376310.0 * u.km
ss_i = Orbit.from_vectors(Earth, r, v)
expected_hohmann_manuever = "Number of impulses: 2, Total cost: 3.060548 km / s"
expected_bielliptic_maneuver = "Number of impulses: 3, Total cost: 3.122556 km / s"
assert repr(Maneuver.hohmann(ss_i, Earth.R + alt_f)) == expected_hohmann_manuever
assert (
repr(Maneuver.bielliptic(ss_i, Earth.R + alt_b, Earth.R + alt_fi))
== expected_bielliptic_maneuver
)
def test_propagation_sets_proper_epoch():
expected_epoch = time.Time("2017-09-01 12:05:50", scale="tdb")
r = [-2.76132873e08, -1.71570015e08, -1.09377634e08] * u.km
v = [13.17478674, -9.82584125, -1.48126639] * u.km / u.s
florence = Orbit.from_vectors(Sun, r, v, plane=Planes.EARTH_ECLIPTIC)
propagated = florence.propagate(expected_epoch)
assert propagated.epoch == expected_epoch
initial,
tofs,
method=cowell,
ad=J2_perturbation,
J2=J2,
R=R
)
print("")
print("Positions and velocity vectors are:")
#print(str(rr.x))
#print([float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.x))])
r=[[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.x))][0],[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.y))][0],[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.z))][0]]* u.km
v=[[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.v_x))][0],[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.v_y))][0],[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.v_z))][0]]* u.km / u.s
f_orbit= Orbit.from_vectors(Earth, r, v)
print(r)
print(v)
#f_orbit.plot()
print("")
print("Orbital elements:")
print(f_orbit.classical())
print("")
#print("")
#print(f_orbit.ecc)
plotOrbit((f_orbit.a.value),(f_orbit.ecc.value),(f_orbit.inc.value),(f_orbit.raan.value),(f_orbit.argp.value),(f_orbit.nu.value))
initial,
tofs,
method=cowell,
ad=J3_perturbation,
J3=J3,
R=R
)
print("")
print("Positions and velocity vectors are:")
#print(str(rr.x))
#print([float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.x))])
r=[[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.x))][0],[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.y))][0],[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.z))][0]]* u.km
v=[[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.v_x))][0],[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.v_y))][0],[float(s) for s in re.findall(r'-?\d+\.?\d*',str(rr.v_z))][0]]* u.km / u.s
f_orbit= Orbit.from_vectors(Earth, r, v)
print(r)
print(v)
#f_orbit.plot()
print("")
print("Orbital elements:")
print(f_orbit.classical())
print("")
#print("")
#print(f_orbit.ecc)
plotOrbit((f_orbit.a.value),(f_orbit.ecc.value),(f_orbit.inc.value),(f_orbit.raan.value),(f_orbit.argp.value),(f_orbit.nu.value))
"""Example data.
"""
from astropy import time, units as u
from poliastro.bodies import Earth, Sun
from poliastro.twobody import Orbit
iss = Orbit.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"),
)
"""ISS orbit example
Taken from Plyades (c) 2012 Helge Eichhorn (MIT License)
"""
molniya = Orbit.from_classical(
Earth, 26600 * u.km, 0.75 * u.one, 63.4 * u.deg, 0 * u.deg, 270 * u.deg, 80 * u.deg
)
"""Molniya orbit example"""