pg_orrery/sql/pg_orrery--0.9.0--0.10.0.sql
Ryan Malloy b0741c553b Add v0.10.0: aberration, DE apparent, angular separation, stellar parallax
Annual stellar aberration (~20 arcsec) added to all 6 existing _apparent()
functions via classical first-order v/c projection (Ron & Vondrak). Earth
velocity sourced from VSOP87 xyz[3..5] (analytic) or DE numerical
differentiation.

New functions (106 -> 114):
- eq_angular_distance(): Vincenty formula, stable at 0 and 180 deg
- eq_within_cone(): cosine shortcut for fast cone-search predicate
- <-> operator on equatorial type
- 6 DE apparent variants with VSOP87 fallback:
  planet/sun/moon_observe_apparent_de(),
  planet/moon_equatorial_apparent_de(),
  small_body_observe_apparent_de()

Stellar parallax now functional in star_observe_pm() and
star_equatorial_pm() — Green (1985) Eq. 11.3 displacement using
Earth heliocentric position from VSOP87.

All 19 regression suites pass (18 existing + new aberration suite).
2026-02-21 21:47:42 -07:00

64 lines
3.5 KiB
SQL

-- pg_orrery 0.9.0 -> 0.10.0 migration
--
-- Adds annual aberration to existing _apparent() functions,
-- 6 new _apparent_de() variants, equatorial angular separation
-- operator and cone predicate, and stellar annual parallax.
-- ============================================================
-- Equatorial angular distance and cone search
-- ============================================================
CREATE FUNCTION eq_angular_distance(equatorial, equatorial) RETURNS float8
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION eq_angular_distance(equatorial, equatorial) IS
'Angular separation in degrees between two equatorial positions. Vincenty formula (stable at 0 and 180 degrees).';
CREATE FUNCTION eq_within_cone(equatorial, equatorial, float8) RETURNS bool
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION eq_within_cone(equatorial, equatorial, float8) IS
'True if first position is within radius_deg of second position. Cosine shortcut for fast rejection.';
CREATE OPERATOR <-> (
LEFTARG = equatorial,
RIGHTARG = equatorial,
FUNCTION = eq_angular_distance,
COMMUTATOR = <->
);
COMMENT ON OPERATOR <-> (equatorial, equatorial) IS
'Angular separation in degrees between two equatorial positions.';
-- ============================================================
-- DE apparent observation functions (STABLE, light-time + aberration)
-- ============================================================
CREATE FUNCTION planet_observe_apparent_de(int4, observer, timestamptz) RETURNS topocentric
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION planet_observe_apparent_de(int4, observer, timestamptz) IS
'Observe a planet with light-time correction and annual aberration via JPL DE (falls back to VSOP87).';
CREATE FUNCTION sun_observe_apparent_de(observer, timestamptz) RETURNS topocentric
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION sun_observe_apparent_de(observer, timestamptz) IS
'Observe the Sun with aberration via JPL DE (falls back to VSOP87).';
CREATE FUNCTION moon_observe_apparent_de(observer, timestamptz) RETURNS topocentric
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION moon_observe_apparent_de(observer, timestamptz) IS
'Observe the Moon with light-time correction and annual aberration via JPL DE (falls back to ELP2000-82B).';
CREATE FUNCTION planet_equatorial_apparent_de(int4, timestamptz) RETURNS equatorial
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION planet_equatorial_apparent_de(int4, timestamptz) IS
'Geocentric apparent RA/Dec of a planet with light-time correction and annual aberration via JPL DE (falls back to VSOP87).';
CREATE FUNCTION moon_equatorial_apparent_de(timestamptz) RETURNS equatorial
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION moon_equatorial_apparent_de(timestamptz) IS
'Geocentric apparent RA/Dec of the Moon with light-time correction and annual aberration via JPL DE (falls back to ELP2000-82B).';
CREATE FUNCTION small_body_observe_apparent_de(orbital_elements, observer, timestamptz) RETURNS topocentric
AS 'MODULE_PATHNAME' LANGUAGE C STABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION small_body_observe_apparent_de(orbital_elements, observer, timestamptz) IS
'Observe a comet/asteroid with light-time correction and annual aberration. Earth position via JPL DE (falls back to VSOP87).';