Skip to content

Commit 03679bf

Browse files
committed
WIP: Add propagate to date, test failing
Waiting for official response for an Astropy issue astropy/astropy#6638
1 parent b166e99 commit 03679bf

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎src/poliastro/tests/tests_twobody/test_propagation.py‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# coding: utf-8
2-
from numpy.testing import assert_allclose
1+
from pytest import approx
2+
33
import numpy as np
4+
from numpy.testing import assert_allclose
45

56
from astropy import units as u
7+
from astropy import time
68
from astropy.tests.helper import assert_quantity_allclose
79

10+
from poliastro.constants import J2000
811
from poliastro.bodies import Sun, Earth
912
from poliastro.twobody import Orbit
1013
from poliastro.twobody.propagation import cowell
@@ -144,3 +147,23 @@ def constant_accel(t0, u, k):
144147
dv = abs(norm(ss_final.v) - norm(ss.v))
145148
accel_dt = accel * u.km / u.s**2 * tof
146149
assert_quantity_allclose(dv, accel_dt, rtol=1e-2)
150+
151+
152+
def test_propagate_to_date_has_proper_epoch():
153+
# Data from Vallado, example 2.4
154+
r0 = [1131.340, -2282.343, 6672.423] * u.km
155+
v0 = [-5.64305, 4.30333, 2.42879] * u.km / u.s
156+
init_epoch = J2000
157+
final_epoch = time.Time("2000-01-01 12:40:00", scale="tdb")
158+
159+
expected_r = [-4219.7527, 4363.0292, -3958.7666] * u.km
160+
expected_v = [3.689866, -1.916735, -6.112511] * u.km / u.s
161+
162+
ss0 = Orbit.from_vectors(Earth, r0, v0, epoch=init_epoch)
163+
ss1 = ss0.propagate(final_epoch)
164+
165+
r, v = ss1.rv()
166+
167+
assert_quantity_allclose(r, expected_r, rtol=1e-5)
168+
assert_quantity_allclose(v, expected_v, rtol=1e-4)
169+
assert (ss1.epoch - final_epoch).sec == approx(0.0)

‎src/poliastro/twobody/orbit.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,22 @@ def __str__(self):
210210
def __repr__(self):
211211
return self.__str__()
212212

213-
def propagate(self, time_of_flight, rtol=1e-10):
213+
def propagate(self, epoch_or_duration, rtol=1e-10):
214214
"""Propagate this `Orbit` some `time` and return the result.
215215
216+
Parameters
217+
----------
218+
epoch_or_duration : Time, TimeDelta or equivalent
219+
Final epoch or time of flight.
220+
rtol : float, optional
221+
Relative tolerance for the propagation algorithm, default to 1e-10.
222+
216223
"""
224+
if isinstance(epoch_or_duration, time.Time):
225+
time_of_flight = epoch_or_duration - self.epoch
226+
else:
227+
time_of_flight = time.TimeDelta(epoch_or_duration)
228+
217229
return propagate(self, time_of_flight, rtol=rtol)
218230

219231
def apply_maneuver(self, maneuver, intermediate=False):

0 commit comments

Comments
 (0)