|
7 | 7 | import quivr as qv |
8 | 8 | from astropy import units as u |
9 | 9 |
|
| 10 | +from ...coordinates.cartesian import CartesianCoordinates |
| 11 | +from ...coordinates.covariances import CoordinateCovariances |
| 12 | +from ...coordinates.origin import Origin |
10 | 13 | from ...observers import Observers |
| 14 | +from ...orbits import Orbits |
11 | 15 | from ...time import Timestamp |
12 | 16 | from ..ephemeris import generate_ephemeris_2body |
13 | 17 | from ..propagation import propagate_2body |
@@ -190,3 +194,53 @@ def to_profile(): |
190 | 194 | stats_file = tmp_path / "ephemeris_profile.prof" |
191 | 195 | profiler.dump_stats(stats_file) |
192 | 196 | 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