From 141bb59e22e9de8a2b3e565cfcd9c17c7c525070 Mon Sep 17 00:00:00 2001 From: Travis Yeager Date: Tue, 27 Oct 2026 11:12:45 -0700 Subject: [PATCH] Use the shared Earth-rotation rate for surface-site velocity Delegate the surface helper to llh_to_gcrf so a fixed WGS84 site uses the same IAU 2006/2000A position and rotation derivative. Replace the physically incorrect fixed-GCRF-Z cross-product assertion with scoped independent Astropy EOP validation using the core route accuracy budget. Verified the corrected reference test (1 passed), unchanged positions and matching geodetic states across 12 site/epoch combinations including extrapolation. Independent Astropy velocity residual at the test epoch is 1.86e-5 m/s; the old formula is wrong by 1.11 m/s. Repository policy, Ruff syntax and whitespace checks pass. Full suites and CI remain merge gates. --- ssatk/coordinates/geodetic.py | 2 +- ssatk/yastropy/astropy_surface_rv.py | 20 ++++++++------------ tests/test_time_and_yastropy_helpers.py | 17 ++++++++++++++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/ssatk/coordinates/geodetic.py b/ssatk/coordinates/geodetic.py index a922deb1..05d8ce4a 100644 --- a/ssatk/coordinates/geodetic.py +++ b/ssatk/coordinates/geodetic.py @@ -77,7 +77,7 @@ def llh_to_gcrf(lon: float, lat: float, t: Time, height: float = 0.0, *, allow_p def surface_rv(lon, lat, elevation=0.0, t=Time(0, format="gps", scale="utc")): - """Return GCRF position and velocity of a surface point from Astropy.""" + """Return a WGS84 site's GCRF state using the shared Earth-rotation route.""" return astropy_surface_rv(lon=lon, lat=lat, elevation=elevation, t=t) diff --git a/ssatk/yastropy/astropy_surface_rv.py b/ssatk/yastropy/astropy_surface_rv.py index 9abc38d3..07fea136 100644 --- a/ssatk/yastropy/astropy_surface_rv.py +++ b/ssatk/yastropy/astropy_surface_rv.py @@ -1,7 +1,4 @@ from astropy.time import Time -import numpy as np - -from .astropy_llh_to_gcrf import astropy_llh_to_gcrf def astropy_surface_rv(lon, lat, elevation=0.0, t=Time(0, format="gps", scale="utc")): @@ -25,14 +22,13 @@ def astropy_surface_rv(lon, lat, elevation=0.0, t=Time(0, format="gps", scale="u Position vector in GCRF coordinates (m). v : ndarray, shape (3,) Velocity vector in GCRF coordinates (m/s). - """ - # Position in GCRF (meters) - r_gcrf = astropy_llh_to_gcrf(lon, lat, t, alt=elevation).reshape(3) - # Earth's angular velocity vector (rad/s) - omega_earth = np.array([0.0, 0.0, 7.2921150e-5]) # rotation about Z-axis - - # Velocity in GCRF: v = omega × r - v_gcrf = np.cross(omega_earth, r_gcrf) + Uses :func:`ssatk.coordinates.geodetic.llh_to_gcrf`: a WGS84 site fixed + in ITRF, transformed with the shared IAU 2006/2000A rotation and its + time derivative. Epochs outside the packaged EOP table use the nearest + record and emit an EarthOrientationExtrapolationWarning. + """ + # Geodetic imports this module, so resolve the shared route at call time. + from ..coordinates.geodetic import llh_to_gcrf - return r_gcrf, v_gcrf + return llh_to_gcrf(lon, lat, t, height=elevation) diff --git a/tests/test_time_and_yastropy_helpers.py b/tests/test_time_and_yastropy_helpers.py index 068e2811..584e6d08 100644 --- a/tests/test_time_and_yastropy_helpers.py +++ b/tests/test_time_and_yastropy_helpers.py @@ -1,7 +1,9 @@ -# Specified rigid-Earth cross product: 1e-10 m/s absolute arithmetic budget; not measured velocity. import numpy as np +import astropy.units as u +from astropy.coordinates import EarthLocation from astropy.time import Time - +from astropy.utils import iers +from ssatk.data import data_path from ssatk.yastropy.astropy_gcrf_to_llh import astropy_gcrf_to_llh from ssatk.yastropy.astropy_llh_to_gcrf import astropy_llh_to_gcrf from ssatk.yastropy.astropy_surface_rv import astropy_surface_rv @@ -21,4 +23,13 @@ def test_astropy_llh_gcrf_roundtrip_and_surface_velocity(): assert r_surface.shape == (3,) assert v_surface.shape == (3,) assert np.isclose(np.linalg.norm(r_surface), 6_378_137.0, rtol=0, atol=1e-6) - np.testing.assert_allclose(v_surface, np.cross([0.0, 0.0, 7.2921150e-5], r_surface), rtol=0, atol=1e-10) + + # R2: Astropy's independent transform, scoped to the packaged EOP. + # Use the core route's 2e-4 m/s budget for finite-difference roundoff + # and Astropy's omission of the celestial-pole offsets. + with data_path("environment/eop/finals2000A.all") as path: + table = iers.IERS_A.open(str(path)) + with iers.conf.set_temp("auto_download", False), iers.earth_orientation_table.set(table): + reference = EarthLocation.from_geodetic(0 * u.deg, 0 * u.deg).get_gcrs(time) + v_ref = reference.cartesian.differentials["s"].d_xyz.to_value(u.m / u.s) + np.testing.assert_allclose(v_surface, v_ref, rtol=0, atol=2e-4)