From ef7f4b85f102068b652872d7e79f0eaed6624c4a Mon Sep 17 00:00:00 2001 From: Paul Grogan Date: Wed, 25 Nov 2026 11:46:17 -0700 Subject: [PATCH 1/2] Do not require provenance of sourced values set to None A catalog model of sourced values dumped with its defaults (such as a spacecraft's resources with an unknown storage) gives values as None, which needed a provenance, so a system's record could not be written: its check parses the dumped system again. A value set to None is not given. --- src/tatc/catalog/schemas.py | 8 +++++++- tests/catalog/test_systems.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/tatc/catalog/schemas.py b/src/tatc/catalog/schemas.py index 23fa34f3..1b07ead2 100644 --- a/src/tatc/catalog/schemas.py +++ b/src/tatc/catalog/schemas.py @@ -139,8 +139,14 @@ def _check_sourced(model: Any, paired: Mapping[str, str] | None = None) -> None: Checks that a model of sourced values gives at least one value and a provenance for each value given (and only those), and that each value given of `paired` gives the value it is paired with (such as its exponent). + A value set to `None` (as a model dumped with its defaults gives it) is not + given. """ - given = set(model.model_fields_set) - {"provenance"} + given = { + name + for name in model.model_fields_set - {"provenance"} + if getattr(model, name) is not None + } if not given: raise ValueError("sourced values need at least one value") _check_provenance(given, model.provenance) diff --git a/tests/catalog/test_systems.py b/tests/catalog/test_systems.py index 9e465f42..3ef2f160 100644 --- a/tests/catalog/test_systems.py +++ b/tests/catalog/test_systems.py @@ -665,6 +665,16 @@ def test_loaded_copies_independent(self): system.spacecraft[0].__dict__["name"] = "changed" self.assertEqual(get_system("jpss").spacecraft[0].name, "NOAA-20") + def test_dumped_systems_parse(self): + """ + Test that every system, dumped with its defaults (as its record is checked + when written), parses again: values dumped as `None`, such as a + spacecraft's unknown storage, need no provenance. + """ + for system_id in get_system_ids(): + with self.subTest(system_id): + parse_system(get_system(system_id).model_dump(mode="json")) + def test_spacecraft_belong_to_one_system(self): """ Test that every spacecraft belongs to one system, and that every platform From 34e3f8a9d95a2c4beff1695e62fe138b8db4c639 Mon Sep 17 00:00:00 2001 From: Paul Grogan Date: Wed, 25 Nov 2026 11:46:17 -0700 Subject: [PATCH 2/2] Place GeosynchronousOrbit at its longitude at epoch The node used the apparent rather than the mean sidereal time of SGP4's TEME frame, and SGP4's deep-space lunar and solar terms displace the satellite at its epoch from its mean elements, by up to about 0.04 deg by the date. The node is now solved so that the sub-satellite point at epoch is at the longitude (rotated by the argument of latitude), within 1e-6 deg. GOES's slot record is rerun (its longitude error was 0.037 deg). --- CHANGELOG.md | 2 + .../resources/validation/systems/goes.json | 4 +- src/tatc/schemas/orbit/geosynchronous.py | 95 +++++++++++++++++-- tests/schemas/orbit/test_geosynchronous.py | 52 ++++++++-- 4 files changed, 132 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcc68643..bee821b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ Changed: - A function of a study's results (such as the `evaluate` of a `tradespace.Study`, or the metrics of an `ObservationStudy`) whose first parameter is named `design` is given what it is of (such as what a design builds) in it, rather than raising a `TypeError`; a later parameter named `design` is given the realized design, as before. Fixed: + - `GeosynchronousOrbit` placed its satellite off its `longitude` by up to about 0.04 deg, by the date: its node used the apparent rather than the mean sidereal time of SGP4's TEME frame, and SGP4's deep-space (lunar and solar) terms displace the satellite at its epoch from its mean elements. The node is now solved so that the sub-satellite point at epoch is at the longitude (rotated by the argument of latitude), within 1e-6 deg; within each day of the repeat cycle, the longitude still drifts by up to about 0.006 deg. GOES's slot record is updated (its longitude error had been 0.037 deg). + - Catalog values of sourced models (such as a spacecraft's resources) set to `None`, as a model dumped with its defaults gives them, needed a provenance, so a system's record could not be written. - `analysis.collect_footprint_observations` failed for the footprints of radar stations with pandas 3. - `analysis.compute_latencies` missed a contact in progress when another contact (with another ground station or a relay) that had not started ended first, downlinking the observation later. - `analysis.estimate_sampling_error` failed (with an `IndexError`) for observations without any rows, rather than giving every target no samples and no error. diff --git a/src/tatc/resources/validation/systems/goes.json b/src/tatc/resources/validation/systems/goes.json index 4d02e6ff..a480bd66 100644 --- a/src/tatc/resources/validation/systems/goes.json +++ b/src/tatc/resources/validation/systems/goes.json @@ -4,7 +4,7 @@ "slot": { "digest": "90f85842bc73fd97586561cb85cb84a098fcfc5dae95c665b0445ca2f2d66eb9", "standard_version": 3, - "tatc_version": "3.6.0", + "tatc_version": "3.7.0", "source": "validation/catalog/validate_system_orbits.py", "reference": "Element sets of the spacecraft (registered, from NOAA's archives of the JPSS satellites, or in files of element sets)", "period": "2026-11-21", @@ -17,7 +17,7 @@ "metrics": [ { "name": "slot_longitude_error_p95", - "value": 0.0371, + "value": 0.0, "scope": "goes-19" }, { diff --git a/src/tatc/schemas/orbit/geosynchronous.py b/src/tatc/schemas/orbit/geosynchronous.py index a22401e1..af5044a8 100644 --- a/src/tatc/schemas/orbit/geosynchronous.py +++ b/src/tatc/schemas/orbit/geosynchronous.py @@ -11,8 +11,10 @@ import numpy as np from pydantic import AliasChoices, Field +from skyfield.api import wgs84 from ... import constants, utils +from ...utils.cache import get_cached from .base_circular import CircularOrbitBase from .gp import GeneralPerturbationsOrbit @@ -22,6 +24,9 @@ utils.orbital.mean_motion_to_semimajor_axis(360 / constants.EARTH_SIDEREAL_DAY_S) - constants.EARTH_MEAN_RADIUS ) +# the corrections of the node that place the sub-satellite point at epoch, at most, +# and the error (degrees) at which they stop +_NODE_ITERATIONS, _NODE_TOLERANCE = 5, 1e-9 class GeosynchronousOrbit(CircularOrbitBase): @@ -69,20 +74,62 @@ def get_inclination(self) -> float: def get_right_ascension_ascending_node(self) -> float: """ - Gets the right ascension of ascending node, derived from this - orbit's fixed longitude and Earth's rotation angle (Greenwich - Apparent Sidereal Time) at epoch, since a geosynchronous satellite - remains above a fixed Earth-relative longitude rather than a - fixed inertial-frame RAAN. As with SunSynchronousOrbit's - equator-crossing-time convention, this is computed independently - of true_anomaly. + Gets the right ascension of ascending node, derived from this orbit's + fixed longitude, since a geosynchronous satellite remains above a fixed + Earth-relative longitude rather than a fixed inertial-frame RAAN: the node + (in the TEME frame of SGP4) that places the satellite's sub-satellite + point at epoch at the orbit's longitude, rotated by its argument of + latitude (its true anomaly and argument of perigee), as SGP4 propagates + it (see `to_gp_orbit`). + + The node starts from the Earth's rotation angle that orients TEME + (Greenwich Mean Sidereal Time) at epoch plus the longitude, and is + corrected for the periodic lunar and solar terms of SGP4's deep-space + propagation, which displace the satellite at its epoch from the position + of its mean elements (by up to about 0.04 degrees, by the date). As with + SunSynchronousOrbit's equator-crossing-time convention, the longitude is + that of the node, independent of the true anomaly. + + Returns: + float: the right ascension of ascending node (degrees) + """ + return get_cached( + self, + "right_ascension_ascending_node", + self.model_dump_json(), + self._compute_right_ascension_ascending_node, + ) + + def _compute_right_ascension_ascending_node(self) -> float: + """ + Computes the right ascension of ascending node (see + `get_right_ascension_ascending_node`), without caching. Returns: float: the right ascension of ascending node (degrees) """ epoch_time = constants.timescale.from_datetime(self.epoch) - earth_rotation_angle = epoch_time.gast * 15 # hours -> degrees - return (earth_rotation_angle + self.longitude) % 360 + # the longitude of the sub-satellite point, from the node's longitude and + # the argument of latitude + latitude_argument = np.radians( + self.get_perigee_argument() + self.get_true_anomaly() + ) + inclination = np.radians(self.inclination) + expected = self.longitude + np.degrees( + np.arctan2( + np.cos(inclination) * np.sin(latitude_argument), + np.cos(latitude_argument), + ) + ) + node = epoch_time.gmst * 15 + self.longitude # hours -> degrees + for _ in range(_NODE_ITERATIONS): + track = self._build_gp_orbit(node).get_orbit_track(self.epoch) + error = (expected - wgs84.subpoint_of(track).longitude.degrees + 180) % 360 + error -= 180 + node += error + if abs(error) < _NODE_TOLERANCE: + break + return float(node % 360) def get_derived_orbit( self, delta_mean_anomaly: float, delta_raan: float @@ -121,8 +168,36 @@ def _compute_gp_orbit(self) -> GeneralPerturbationsOrbit: Returns: GeneralPerturbationsOrbit: the general perturbations orbit """ + return self._build_gp_orbit(self.get_right_ascension_ascending_node()) + + def _build_gp_orbit(self, node: float) -> GeneralPerturbationsOrbit: + """ + Builds the general perturbations orbit of this orbit with a right + ascension of ascending node, maintained at its longitude on a repeat + ground track with a repeat cycle of one nodal day. + + Args: + node (float): The right ascension of ascending node (degrees). + + Returns: + GeneralPerturbationsOrbit: the general perturbations orbit + """ + # deferred import to avoid a circular import (keplerian.py imports the + # orbit base module) + # pylint: disable-next=import-outside-toplevel,cyclic-import + from .keplerian import KeplerianOrbit + + elements = KeplerianOrbit( + semimajor_axis=self.get_semimajor_axis(), + inclination=self.get_inclination(), + right_ascension_ascending_node=node % 360, + eccentricity=self.get_eccentricity(), + perigee_argument=self.get_perigee_argument(), + true_anomaly=self.get_true_anomaly(), + epoch=self.get_epoch(), + ).to_gp_orbit() return GeneralPerturbationsOrbit( - elements=super()._compute_gp_orbit().elements, + elements=elements.elements, remove_drag=True, repeat_cycle=timedelta(days=1), ) diff --git a/tests/schemas/orbit/test_geosynchronous.py b/tests/schemas/orbit/test_geosynchronous.py index 0d77d38f..48316071 100644 --- a/tests/schemas/orbit/test_geosynchronous.py +++ b/tests/schemas/orbit/test_geosynchronous.py @@ -7,6 +7,7 @@ import unittest from datetime import datetime, timedelta, timezone +import numpy as np from pydantic import ValidationError from tatc import constants @@ -118,20 +119,53 @@ def test_get_orbit_period_is_one_sidereal_day(self): delta=1.0, ) - def test_get_right_ascension_ascending_node_at_greenwich_matches_gast(self): + def test_get_right_ascension_ascending_node_near_gmst(self): """ - Test that a satellite at longitude 0 (the Greenwich meridian) has - a right ascension of ascending node exactly equal to Earth's - rotation angle (Greenwich Apparent Sidereal Time) at epoch -- the - defining relationship between Earth-fixed longitude and inertial - right ascension. + Test that a satellite at longitude 0 (the Greenwich meridian) has a right + ascension of ascending node near Earth's rotation angle that orients the + TEME frame of SGP4 (Greenwich Mean Sidereal Time) at epoch, within the + correction for SGP4's lunar and solar terms (up to about 0.04 deg). """ epoch = datetime(2022, 6, 15, 6, 0, 0, tzinfo=timezone.utc) o = GeosynchronousOrbit(longitude=0, epoch=epoch) - expected_raan = constants.timescale.from_datetime(epoch).gast * 15 % 360 - self.assertAlmostEqual( - o.get_right_ascension_ascending_node(), expected_raan, delta=1e-6 + gmst = constants.timescale.from_datetime(epoch).gmst * 15 % 360 + self.assertAlmostEqual(o.get_right_ascension_ascending_node(), gmst, delta=0.05) + + def test_longitude_at_epoch(self): + """ + Test that the sub-satellite point at epoch is at the orbit's longitude on + every month of a year, whose SGP4 lunar and solar terms differ (they + displaced it by up to about 0.04 deg before the node was corrected). + """ + for month in range(1, 13): + for longitude in (-75.2, 0.0, 140.7): + epoch = datetime(2026, month, 1, tzinfo=timezone.utc) + orbit = GeosynchronousOrbit(longitude=longitude, epoch=epoch) + position = orbit.to_gp_orbit().get_geographic_position(epoch) + self.assertAlmostEqual( + position.longitude.degrees, longitude, delta=1e-6, msg=epoch + ) + # the lunar and solar terms also move its latitude, by up to about + # 0.004 deg, which the node does not correct + self.assertAlmostEqual(position.latitude.degrees, 0, delta=0.01) + + def test_longitude_at_epoch_with_argument_of_latitude(self): + """ + Test that a satellite offset in true anomaly (as in a constellation) and + inclined lies at the longitude its argument of latitude gives, from the + orbit's longitude at its node. + """ + epoch = datetime(2026, 11, 8, 12, tzinfo=timezone.utc) + orbit = GeosynchronousOrbit( + longitude=10.0, inclination=5.0, true_anomaly=30.0, epoch=epoch + ) + expected = 10.0 + np.degrees( + np.arctan2( + np.cos(np.radians(5)) * np.sin(np.radians(30)), np.cos(np.radians(30)) + ) ) + position = orbit.to_gp_orbit().get_geographic_position(epoch) + self.assertAlmostEqual(position.longitude.degrees, expected, delta=1e-6) def test_get_right_ascension_ascending_node_wraps_to_0_360(self): """