Skip to content

Commit 56660b4

Browse files
committed
Ensure we send in times correctly to jacobian calc
1 parent df0f32d commit 56660b4

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/adam_core/dynamics/ephemeris.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def generate_ephemeris_2body(
278278
_generate_ephemeris_2body,
279279
in_axes=(0, 0, 0, 0, None, None, None, None),
280280
out_axes=(0, 0, 0),
281-
observation_times=times.utc.mjd,
281+
observation_times=times,
282282
observer_coordinates=observer_coordinates,
283283
mu=mu,
284284
lt_tol=lt_tol,

src/adam_core/dynamics/tests/test_ephemeris.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import quivr as qv
88
from astropy import units as u
99

10+
from ...coordinates.cartesian import CartesianCoordinates
11+
from ...coordinates.covariances import CoordinateCovariances
12+
from ...coordinates.origin import Origin
1013
from ...observers import Observers
14+
from ...orbits import Orbits
1115
from ...time import Timestamp
1216
from ..ephemeris import generate_ephemeris_2body
1317
from ..propagation import propagate_2body
@@ -190,3 +194,53 @@ def to_profile():
190194
stats_file = tmp_path / "ephemeris_profile.prof"
191195
profiler.dump_stats(stats_file)
192196
print(f"Run 'snakeviz {stats_file}' to view the profile results.")
197+
198+
199+
def test_generate_ephemeris_2body_covariance_branch_uses_input_times() -> None:
200+
"""
201+
Regression test for a bug where the covariance branch treated `times` (already a numpy
202+
array of MJD floats) as a Time object and tried to access `times.utc.mjd`.
203+
"""
204+
time = Timestamp.from_mjd([60000.0], scale="tdb")
205+
206+
cartesian_cov = CoordinateCovariances.from_matrix(
207+
np.eye(6, dtype=np.float64).reshape(1, 6, 6) * 1e-12
208+
)
209+
210+
# Use SSB origin/frame so `generate_ephemeris_2body`'s internal transforms are no-ops.
211+
origin_ssb = Origin.from_kwargs(code=["SOLAR_SYSTEM_BARYCENTER"])
212+
213+
orbits = Orbits.from_kwargs(
214+
orbit_id=["o1"],
215+
object_id=["o1"],
216+
coordinates=CartesianCoordinates.from_kwargs(
217+
x=[2.0],
218+
y=[0.0],
219+
z=[0.0],
220+
vx=[0.0],
221+
vy=[0.0],
222+
vz=[0.0],
223+
time=time,
224+
covariance=cartesian_cov,
225+
origin=origin_ssb,
226+
frame="ecliptic",
227+
),
228+
)
229+
observers = Observers.from_kwargs(
230+
code=["500"],
231+
coordinates=CartesianCoordinates.from_kwargs(
232+
x=[1.0],
233+
y=[0.0],
234+
z=[0.0],
235+
vx=[0.0],
236+
vy=[0.0],
237+
vz=[0.0],
238+
time=time,
239+
origin=origin_ssb,
240+
frame="ecliptic",
241+
),
242+
)
243+
244+
eph = generate_ephemeris_2body(orbits, observers, predict_magnitudes=False)
245+
assert eph.coordinates.covariance is not None
246+
assert eph.coordinates.covariance.to_matrix().shape == (1, 6, 6)

0 commit comments

Comments
 (0)