Integrate IAU 2000B nutation (~9 arcsec) into the solar system observation pipeline via precess_and_nutate_j2000_to_date(). Affects all planet, star, moon, and small body RA/Dec and az/el values. Satellite SGP4/TEME pipeline unchanged. Add make_equatorial(ra_hours, dec_deg, distance_km) constructor to replace error-prone text literal casts. Add 8 rise/set prediction functions (planet_next_rise/set, sun_next_rise/set, moon_next_rise/set, sun_next_rise/set_refracted) using bisection algorithm adapted from satellite pass prediction. Returns NULL for circumpolar and polar night edge cases. Fix DE fallback test fragility: replace exact float equality with tolerance comparisons to handle GCC LTO inlining divergence across translation units. 132 -> 141 SQL objects. 22 -> 24 regression suites. All 24 passing.
109 lines
5.1 KiB
SQL
109 lines
5.1 KiB
SQL
-- rise_set.sql -- Tests for v0.13.0: rise/set prediction functions
|
|
--
|
|
-- Verifies solar system body rise/set predictions using the bisection
|
|
-- algorithm adapted from satellite pass prediction.
|
|
|
|
CREATE EXTENSION IF NOT EXISTS pg_orrery;
|
|
|
|
-- ============================================================
|
|
-- Test observer: Eagle, Idaho (~43.7N, ~116.4W, 800m)
|
|
-- Mid-latitude location with normal rise/set behavior.
|
|
-- ============================================================
|
|
|
|
-- Use a fixed epoch in northern hemisphere winter (Jan 15, 2024 midnight UTC)
|
|
-- Sun should rise around ~15:30 UTC (8:30 AM MST) and set around ~00:30 UTC next day
|
|
|
|
-- Sun rise/set (geometric)
|
|
SELECT sun_next_rise('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
IS NOT NULL AS sun_rises;
|
|
|
|
SELECT sun_next_set('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
IS NOT NULL AS sun_sets;
|
|
|
|
-- Sunrise should be within 24h of the epoch
|
|
SELECT extract(epoch FROM
|
|
sun_next_rise('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
- '2024-01-15 00:00:00+00'::timestamptz) / 3600.0
|
|
BETWEEN 0 AND 24.0 AS sunrise_within_24h;
|
|
|
|
-- Sunset should be within 24h of the epoch
|
|
SELECT extract(epoch FROM
|
|
sun_next_set('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
- '2024-01-15 00:00:00+00'::timestamptz) / 3600.0
|
|
BETWEEN 0 AND 24.0 AS sunset_within_24h;
|
|
|
|
-- ============================================================
|
|
-- Moon rise/set
|
|
-- ============================================================
|
|
|
|
SELECT moon_next_rise('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
IS NOT NULL AS moon_rises;
|
|
|
|
SELECT moon_next_set('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
IS NOT NULL AS moon_sets;
|
|
|
|
-- ============================================================
|
|
-- Planet rise/set (Jupiter -- typically visible in winter evening)
|
|
-- ============================================================
|
|
|
|
SELECT planet_next_rise(5, '(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
IS NOT NULL AS jupiter_rises;
|
|
|
|
SELECT planet_next_set(5, '(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
IS NOT NULL AS jupiter_sets;
|
|
|
|
-- ============================================================
|
|
-- Refracted vs geometric: refracted sunrise earlier than geometric
|
|
-- ============================================================
|
|
|
|
SELECT sun_next_rise_refracted('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
< sun_next_rise('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
AS refracted_sunrise_earlier;
|
|
|
|
SELECT sun_next_set_refracted('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
> sun_next_set('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
AS refracted_sunset_later;
|
|
|
|
-- Refracted-geometric difference should be ~2-5 minutes (120-300 seconds)
|
|
SELECT abs(extract(epoch FROM
|
|
sun_next_rise('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
- sun_next_rise_refracted('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)))
|
|
BETWEEN 60 AND 600 AS refraction_offset_reasonable;
|
|
|
|
-- ============================================================
|
|
-- Consistency: rise_time of the NEXT rise should be ~24h later
|
|
-- ============================================================
|
|
|
|
SELECT extract(epoch FROM
|
|
sun_next_rise('(43.7,-116.4,800)'::observer,
|
|
sun_next_rise('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz)
|
|
+ interval '1 minute')
|
|
- sun_next_rise('(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz))
|
|
/ 3600.0
|
|
BETWEEN 23.0 AND 25.0 AS next_rise_about_24h_later;
|
|
|
|
-- ============================================================
|
|
-- Circumpolar check: Sun from 70N in June (midnight sun)
|
|
-- Sun should NOT set within 7 days
|
|
-- ============================================================
|
|
|
|
SELECT sun_next_set('(70.0,25.0,0)'::observer, '2024-06-21 00:00:00+00'::timestamptz)
|
|
IS NULL AS midnight_sun_no_set;
|
|
|
|
-- ============================================================
|
|
-- Never-rises check: Sun from 70N in December (polar night)
|
|
-- Sun should NOT rise within 7 days
|
|
-- ============================================================
|
|
|
|
SELECT sun_next_rise('(70.0,25.0,0)'::observer, '2024-12-21 00:00:00+00'::timestamptz)
|
|
IS NULL AS polar_night_no_rise;
|
|
|
|
-- ============================================================
|
|
-- Error cases
|
|
-- ============================================================
|
|
|
|
-- Invalid body_id
|
|
DO $$ BEGIN PERFORM planet_next_rise(0, '(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'body_id=0: %', SQLERRM; END $$;
|
|
DO $$ BEGIN PERFORM planet_next_rise(3, '(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'body_id=3(Earth): %', SQLERRM; END $$;
|
|
DO $$ BEGIN PERFORM planet_next_rise(9, '(43.7,-116.4,800)'::observer, '2024-01-15 00:00:00+00'::timestamptz); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'body_id=9: %', SQLERRM; END $$;
|