Repository Public
1<!--2ORIX Cosmos3File: Documentation/modules/CosmosCoordinates.md4Description: What CosmosCoordinates implements (constant frames, Earth orientation, geodesy, horizon coordinates, sexagesimal text, proper motion), models and references, accuracy measured in the tests, and known limits.5Author: Simon-Pierre Boucher6Contact: contact@spboucher.ai7-->8# CosmosCoordinates910Frame rotations and spherical astronomy. Depends on `CosmosCore`, `CosmosMath`, `CosmosTime`.11All angles are radians, lengths metres; matrices follow the frame-rotation convention of `CosmosMath.Rotation`.1213## What is implemented1415| File | Main API |16|---|---|17| `Frames.swift` | `Frames.icrfToEclipticJ2000`, `icrfToGalactic`, `obliquityJ2000`, `constantRotation(from:to:)`, `rotation(from:to:at:bodyFixed:)`, `transform(_:from:to:)`, `sphericalCoordinates(rightAscension:declination:in:)`, `equatorialCoordinates(longitude:latitude:in:)`; `FrameRotation` (matrix + derivative); protocol `BodyFixedRotationProvider`; `StateVector.expressed(in:bodyFixed:)` |18| `EarthOrientation.swift` | `EarthModels` (pure IAU models of explicit TT/UT1 arguments) and `EarthOrientation` (same at an `Instant`; implements `BodyFixedRotationProvider` for `naif:399`) |19| `Geodesy.swift` | `Ellipsoid` (`.wgs84`, `.grs80`), `GeodeticPosition`, `Geodesy.earthFixed`, `geodetic(earthFixed:)`, `eastNorthUpMatrix`; `HorizontalCoordinates`; `Topocentric.horizontal`, `hourAngleDeclination`, `parallacticAngle`, `hourAngle`, `equatorial`; `EarthOrientation.horizontal(ofICRFDirection:site:at:)`, `icrfDirection(of:site:at:)`, `icrfToEastNorthUp`, `observerState(site:at:)` |20| `Sexagesimal.swift` | `Sexagesimal.parseRightAscension`, `parseDeclination`, `parseCoordinates`, `formatRightAscension`, `formatDeclination`, `formatDegrees` |21| `ProperMotion.swift` | `StarAstrometry`, `ProperMotion.propagate(_:toEpoch:)` → `PropagatedStar` (with `ProperMotionMethod`), `ProperMotion.direction(of:atEpoch:)` |2223## Models and references2425### Constant frames26- **Ecliptic J2000**: rotation of 84381.448″ about x — SPICE `ECLIPJ2000` (IAU 1976 obliquity).27- **Galactic (IAU 1958)**: built as SPICE builds `GALACTIC`: J2000 → B1950 `[1152.84248596724″]₃[−1002.26108439117″]₂[1153.04066200330″]₃`,28 B1950 → FK4 `[0.525″]₃`, FK4 → galactic `[327°]₃[62.6°]₁[282.25°]₃`. The angles were read back from CSPICE N006729 (`pxform` + `m2eul`) and the resulting matrix is compared with CSPICE in the tests.30 It differs by 3.3 mas (measured at the ERFA test direction) from the Hipparcos-based matrix of ERFA `eraIcrs2g`.31- `ReferenceFrame.icrf` is treated as J2000 for these constant frames (no frame bias), as stated in `CosmosCore`.3233### Earth orientation34| Quantity | Model | Reference implementation followed |35|---|---|---|36| Mean obliquity | IAU 2006 | ERFA `eraObl06` |37| Precession (with ICRS frame bias) | IAU 2006, Fukushima–Williams angles | `eraPfw06`, `eraFw2m`, `eraPmat06`, `eraBp06` |38| Nutation | **IAU 2000B** (77 luni-solar terms + fixed planetary offset), not 2000A | `eraNut00b` |39| Earth rotation angle | IAU 2000 | `eraEra00` |40| GMST | IAU 2006 | `eraGmst06` |41| Equation of the equinoxes | Δψ·cos ε_A + complementary terms (IERS 2003) | `eraEect00`, fundamental arguments `eraFal03` … `eraFapa03` |42| GAST | GMST + equation of the equinoxes (equinox-based) | — |4344Rotations: `icrfToMeanOfDate` (bias + precession), `precessionMatrix` (J2000 mean → mean of date, no bias),45`icrfToTrueOfDate` (bias, precession, nutation), `trueOfDateToEarthFixed` = R₃(GAST), `icrfToEarthFixed`46(`FrameRotation`, derivative = Earth spin 7.292115e-5 rad/s from the ERA rate). Unlike the constant frames, the47Earth-orientation chain **does** include the ≈23 mas ICRS frame bias, as the IAU models require.48Time arguments: TT from `TimeSystem.julianCenturiesTT`, UT1 from `TimeSystem.ut1` (whose source/status is exposed by49`EarthOrientation.rotationStatus`).5051**Ignored, by design:** polar motion (≈0.3″, ≈10 m on the ground), celestial pole offsets dX/dY (< 1 mas),52sub-daily UT1 tides, the s′ locator, the deflection of the vertical, and the geoid (heights are ellipsoidal).53"Earth-fixed" is therefore the terrestrial intermediate frame, within 0.3″ of ITRF.5455### Geodesy and horizon56WGS 84 (a = 6378137 m, 1/f = 298.257223563). Geodetic → Cartesian closed form (`eraGd2gce`); Cartesian → geodetic57by Fukushima (2006) (`eraGc2gde`). East-north-up matrix from geodetic longitude/latitude. Azimuth is measured from58north through east; altitude is geometric (**no atmospheric refraction** — that belongs to CosmosObservation).59`eraHd2ae`, `eraAe2hd`, `eraHd2pa` are followed for hour angle/declination ↔ azimuth/altitude and the parallactic angle.6061### Sexagesimal text62Rules are stated in the `Sexagesimal` doc comment. In short: RA with `h`, colons or several fields is in hours;63RA as one plain decimal number or with `°`/`d` is in degrees; Dec is always degrees; in a pair the declination64starts at its sign, otherwise 2/4/6 numeric fields are split evenly. Out-of-range or ambiguous input throws65`CosmosError.invalidInput` (never a guess). Formatting rounds with full carry and never prints "−0".6667### Proper motion68`StarAstrometry` stores α, δ, μα* (**with** cos δ), μδ, optional parallax and radial velocity, and the Julian epoch.69- Parallax > 0 **and** radial velocity present → `rigorousSpaceMotion`: port of ERFA `eraStarpv`/`eraPvstar`/`eraStarpm`70 (space motion, perspective acceleration, light-time change, relativistic Doppler terms).71- Otherwise → `linearTangential`: great-circle motion at constant |μ|; parallax and radial velocity are passed72 through unchanged (nil stays nil). Non-positive parallaxes (they exist in Gaia) are treated as unknown distance.73The method used is always returned. No aberration, parallax shift or light deflection is applied here.7475### Body-fixed frames76`ReferenceFrame.bodyFixed` is resolved through `BodyFixedRotationProvider.rotationFromICRF(toBodyFixed:at:)`77(matrix and time derivative). This module provides it for the Earth only (`EarthOrientation`); planetary rotation78models belong to CosmosEphemeris, which should conform a type to the protocol. Without a provider,79`Frames.rotation` / `StateVector.expressed` throw `CosmosError.unsupported`.8081## Validation and tolerances (tests: `Packages/CosmosCoordinates/Tests`, 25 tests)8283| Check | Reference | Tolerance | Measured / why |84|---|---|---|---|85| J2000→ECLIPJ2000, J2000→GALACTIC, ECLIPJ2000→GALACTIC matrices | CSPICE N0067 `pxform` (`spice_frames_reference.json`) | 1e-15 | 0, 1.1e-16, 1.1e-16 (1 ulp) |86| galactic coordinates | ERFA `t_icrs2g` (Hipparcos matrix) | 20 mas | 3.3 mas: two different definitions |87| obliquity, F-W angles, F-W matrix | ERFA `t_obl06`, `t_pfw06`, `t_fw2m` | 1e-14 / 1e-12…1e-16 / 1e-12 | ERFA's own tolerances |88| bias, precession, bias-precession matrices | ERFA `t_bp06`, `t_pmat06` | 1e-14 | ERFA's own tolerance on off-diagonal terms |89| nutation 2000B | ERFA `t_nut00b` | 1e-13 rad | ERFA's own tolerance |90| complementary terms, ERA, GMST, fundamental argument | ERFA `t_eect00`, `t_era00`, `t_gmst06`, `t_fal03` | 1e-20, 1e-12, 1e-12, 1e-12 | ERFA's own tolerances |91| NPB matrix (2006 + 2000B) vs IAU 2006/2000A | ERFA `t_pnm06a` | 1 mas | **0.35 mas** — the stated 2000B − 2000A accuracy is 1 mas for 1995–2050 |92| GAST, equation of the equinoxes vs 2006/2000A | ERFA `t_gst06a`, `t_ee06a` | 1 mas | **−0.31 mas** (= 21 µs of time) |93| geodetic ↔ Cartesian | ERFA `t_gd2gc`, `t_gc2gd` (WGS84, GRS80) | 1e-7 m / 1e-14 rad, 1e-8 m | ERFA's own tolerances |94| geodetic round trip (2000 points, −11 km … 40 000 km) | property | 1e-10 rad, 1e-6 m | 2.6e-11 rad, 1.5e-8 m |95| site Cartesian coordinates | JPL Horizons header (cylindrical, km, 5 decimals) | 1 cm | 0.08 cm, 0.34 cm |96| (h, δ) ↔ (az, alt), parallactic angle | ERFA `t_hd2ae`, `t_ae2hd`, `t_hd2pa` | 1e-13 / 1e-14 | ERFA's own tolerances |97| **Local apparent sidereal time** (5 epochs 2024, Cerro Pachón) | JPL Horizons quantity 7, with IERS UT1 − UTC | 0.05 s of time | **7.7 ms** (0.12″): polar motion ignored (≈0.3″) + Horizons' IAU 76/80 equinox offset (53 mas) |98| az/el from Horizons apparent RA/Dec + Horizons LAST | JPL Horizons quantity 4 | 1″ | 2.5e-6″ (pure geometry) |99| az/el end to end (UTC → UT1 → GAST → LAST → az/el) | JPL Horizons quantity 4 | 1″ | **0.11″** |100| same, without Earth-orientation table (ΔT model) | JPL Horizons | 10 s (sanity bound) | LAST off by **5.3 s** — see CosmosTime |101| rigorous proper motion | ERFA `t_starpm` | 1e-13 rad, 1e-17 rad/yr, 1e-13″, 1e-11 km/s | ERFA's own tolerances |102| linear proper motion: arc = |μ|Δt, reversibility | property | 1e-13 rad | |103| rigorous vs linear, 10.4″/yr star at 1.83 pc, −110.5 km/s, 50 yr | — | 0.01″ … 5″ | 1.6″: size of the perspective acceleration that the linear method omits |104| sexagesimal text round trip (1000 random, two styles) | property | half a unit of the last digit | |105| Earth-fixed state of a ground site: zero velocity, ω·ρ inertial speed, Ṁ vs finite difference | property | 1e-9 m/s, 1e-10 s⁻¹ | |106107Fixtures and their URLs/dates: `Packages/CosmosCoordinates/Tests/Fixtures/README.txt`.108109## Known limits110111- Nutation is IAU 2000B: ≈1 mas-class up to 2050, degrading slowly outside; precession polynomials are intended112 for a few centuries around J2000 (IAU 2006 is not a long-term model; millennia away the error grows to113 arcminutes and more). No validity gate is enforced on the date: callers showing Earth orientation far from the114 present should say so (the dominant error there is ΔT, flagged by `TimeSystem.validity`).115- Earth rotation accuracy is set by UT1: milliseconds with an IERS table, seconds (tens of arcseconds) with the116 ΔT model, far more in the distant past/future.117- No polar motion, no refraction, no aberration/light-time/deflection (those are applied by the ephemeris and118 observation modules before calling the geometric functions here).119- `FrameRotation.derivative` for the Earth neglects precession/nutation rates (1e-7 of the spin: < 0.05 mm/s at the surface).120- Proper-motion `rigorousSpaceMotion` refuses data implying speeds above 0.5 c and stars exactly at a pole121 (falls back to linear); the linear method ignores perspective acceleration.122- The galactic frame is SPICE's (IAU 1958 via FK4), not the Hipparcos/ICRS-defined matrix; the difference is a few mas.123- Ecliptic-of-date, supergalactic and FK4/B1950 frames are not provided.124