Clean-room DE binary reader (~400 lines C) with Chebyshev/Clenshaw evaluation — no GPL dependency on jpl_eph. Per-backend lazy initialization preserves PARALLEL SAFE. Existing VSOP87/ELP82B functions stay IMMUTABLE; new _de() variants are STABLE with automatic fallback to compiled-in ephemerides on any DE failure. Implementation: - de_reader.c: header parse, record seek, Clenshaw recurrence - eph_provider.c: GUC (pg_orbit.ephemeris_path), lazy init, ICRS-to-ecliptic frame rotation, on_proc_exit cleanup - de_funcs.c: 11 new SQL functions (_de variants + diagnostics) - Constant chain of custody rules 6-8 (frame rotation, same-provider, AU consistency) Extract observe_from_geocentric() to astro_math.h for shared use by planet_funcs.c, moon_funcs.c, and de_funcs.c. 57 → 68 functions, 11 → 12 regression test suites, all passing.
87 lines
4.3 KiB
SQL
87 lines
4.3 KiB
SQL
-- pg_orbit 0.2.0 -> 0.3.0 migration
|
|
--
|
|
-- Adds optional JPL DE440/441 ephemeris functions.
|
|
-- Existing VSOP87/ELP2000-82B functions are unchanged (still IMMUTABLE).
|
|
-- New _de() functions are STABLE (depend on external DE binary file).
|
|
-- When DE is unavailable, _de() functions fall back to VSOP87 silently.
|
|
|
|
-- ============================================================
|
|
-- Phase 5: DE ephemeris functions (optional high-precision)
|
|
-- ============================================================
|
|
|
|
-- Planet observation with DE ephemeris
|
|
|
|
CREATE FUNCTION planet_heliocentric_de(int4, timestamptz) RETURNS heliocentric
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION planet_heliocentric_de(int4, timestamptz) IS
|
|
'Heliocentric ecliptic J2000 position via JPL DE (sub-arcsecond). Falls back to VSOP87 if DE unavailable. Body IDs: 0=Sun, 1-8=Mercury-Neptune.';
|
|
|
|
CREATE FUNCTION planet_observe_de(int4, observer, timestamptz) RETURNS topocentric
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION planet_observe_de(int4, observer, timestamptz) IS
|
|
'Observe planet via JPL DE. Falls back to VSOP87. Body IDs: 1-8 (Mercury-Neptune).';
|
|
|
|
CREATE FUNCTION sun_observe_de(observer, timestamptz) RETURNS topocentric
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION sun_observe_de(observer, timestamptz) IS
|
|
'Observe Sun via JPL DE. Falls back to VSOP87.';
|
|
|
|
CREATE FUNCTION moon_observe_de(observer, timestamptz) RETURNS topocentric
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION moon_observe_de(observer, timestamptz) IS
|
|
'Observe Moon via JPL DE. Falls back to ELP2000-82B.';
|
|
|
|
|
|
-- Lambert transfer with DE positions
|
|
|
|
CREATE FUNCTION lambert_transfer_de(
|
|
dep_body_id int4, arr_body_id int4,
|
|
dep_time timestamptz, arr_time timestamptz,
|
|
OUT c3_departure float8, OUT c3_arrival float8,
|
|
OUT v_inf_departure float8, OUT v_inf_arrival float8,
|
|
OUT tof_days float8, OUT transfer_sma float8
|
|
) RETURNS RECORD
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION lambert_transfer_de(int4, int4, timestamptz, timestamptz) IS
|
|
'Lambert transfer via JPL DE positions. Falls back to VSOP87. Body IDs 1-8.';
|
|
|
|
CREATE FUNCTION lambert_c3_de(int4, int4, timestamptz, timestamptz) RETURNS float8
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION lambert_c3_de(int4, int4, timestamptz, timestamptz) IS
|
|
'Departure C3 via JPL DE. Falls back to VSOP87. For pork chop plots.';
|
|
|
|
|
|
-- Planetary moon observation with DE parent positions
|
|
|
|
CREATE FUNCTION galilean_observe_de(int4, observer, timestamptz) RETURNS topocentric
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION galilean_observe_de(int4, observer, timestamptz) IS
|
|
'Observe Galilean moon with JPL DE parent position. L1.2 moon offsets. Body IDs: 0-3 (Io-Callisto).';
|
|
|
|
CREATE FUNCTION saturn_moon_observe_de(int4, observer, timestamptz) RETURNS topocentric
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION saturn_moon_observe_de(int4, observer, timestamptz) IS
|
|
'Observe Saturn moon with JPL DE parent position. TASS 1.7 moon offsets. Body IDs: 0-7 (Mimas-Hyperion).';
|
|
|
|
CREATE FUNCTION uranus_moon_observe_de(int4, observer, timestamptz) RETURNS topocentric
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION uranus_moon_observe_de(int4, observer, timestamptz) IS
|
|
'Observe Uranus moon with JPL DE parent position. GUST86 moon offsets. Body IDs: 0-4 (Miranda-Oberon).';
|
|
|
|
CREATE FUNCTION mars_moon_observe_de(int4, observer, timestamptz) RETURNS topocentric
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
|
|
COMMENT ON FUNCTION mars_moon_observe_de(int4, observer, timestamptz) IS
|
|
'Observe Mars moon with JPL DE parent position. MarsSat moon offsets. Body IDs: 0-1 (Phobos-Deimos).';
|
|
|
|
|
|
-- Diagnostic function
|
|
|
|
CREATE FUNCTION pg_orbit_ephemeris_info(
|
|
OUT provider text, OUT file_path text,
|
|
OUT start_jd float8, OUT end_jd float8,
|
|
OUT version int4, OUT au_km float8
|
|
) RETURNS RECORD
|
|
AS 'MODULE_PATHNAME' LANGUAGE C STABLE PARALLEL SAFE;
|
|
COMMENT ON FUNCTION pg_orbit_ephemeris_info() IS
|
|
'Returns current ephemeris provider status: VSOP87 or JPL_DE with file path, JD range, version, and AU value.';
|