def test_orbits_are_same(): epoch = Time("2018-07-23") # Orbit Parameters of Ceres # Taken from https://ssd.jpl.nasa.gov/horizons.cgi ss = Orbit.from_classical( Sun, 2.767107584017257 * u.au, 0.07554802949294502 * u.one, 27.18502520750381 * u.deg, 23.36913256044832 * u.deg, 132.2919806192451 * u.deg, 21.28958091587153 * u.deg, epoch, ) ss1 = Orbit.from_horizons(name="Ceres", epoch=epoch) assert ss.pqw()[0].value.all() == ss1.pqw()[0].value.all() assert ss.r_a == ss1.r_a assert ss.a == ss1.a
def test_plane_is_set_in_horizons(): plane = Planes.EARTH_ECLIPTIC ss = Orbit.from_horizons(name="Ceres", plane=plane) assert ss.plane == plane
def test_from_horizons_raise_valueerror(): with pytest.raises(ValueError) as exep: Orbit.from_horizons(name="Dummy") assert ("ValueError: Unknown target (Dummy). Maybe try different id_type?" in exep.exconly())
def transfer_vel(body1, body2, attractor): """Returns transfer parameters for body1 (e.g. Earth) to body2 (e.g. Mars). Optionally, the main attractor can be specified. If omitted, Sun is assumed. Returns: helio1 - heliocentric velocity at departure (before Hohmann) (body1) helio2 - heliocentric velocity at arrival (body2) v1 - heliocentric velocity at departure (after Hohmann burn) v2 - heliocentric velocity at arrival (before Hohmann burn) tof - time of flight (in days) """ # How to obtain the orbit. The from_horisons method seems to be no longer supported # as of perylune 0.16.3. method = "ephem" # allowed values are ephem, horizons_orbit if attractor is None: attractor = Sun # Let's assume the calculations are done for 2020. date_start = time.Time("2020-01-01 00:00", scale="utc").tdb date_end = time.Time("2021-12-31 23:59", scale="utc").tdb name1, id_type1 = name_to_horizons_id(body1) name2, id_type2 = name_to_horizons_id(body2) if method == "ephem": # Get the ephemerides first and then contruct orbit based on them. This is the recommended # way. See warning in Orbit.from_horizons about deprecation. ephem1 = Ephem.from_horizons(name=name1, epochs=time_range(date_start, end=date_end), plane=Planes.EARTH_ECLIPTIC, id_type=id_type1) ephem2 = Ephem.from_horizons(name=name2, epochs=time_range(date_start, end=date_end), plane=Planes.EARTH_ECLIPTIC, id_type=id_type2) # Solve for departure and target orbits orb1 = Orbit.from_ephem(Sun, ephem1, date_start + 180 * u.day) orb2 = Orbit.from_ephem(Sun, ephem2, date_end) elif method == "horizons_orbit": # This is the old way. Sadly, it produces way better values. orb1 = Orbit.from_horizons(name=name1, attractor=attractor, plane=Planes.EARTH_ECLIPTIC, id_type=id_type1) orb2 = Orbit.from_horizons(name=name2, attractor=attractor, plane=Planes.EARTH_ECLIPTIC, id_type=id_type2) else: raise "Invalid method set." # The escape_delta_v returns a tuple of escape velocity at current, periapsis, apoapsis. helio1 = heliocentric_velocity(orb1) helio2 = heliocentric_velocity(orb2) #vesc1 = escape_vel(orb1, False)[1] #vesc2 = escape_vel(orb2, False)[1] hoh1, hoh2, tof = hohmann_velocity(orb1, orb2) return helio1, helio2, hoh1, hoh2, tof