Add astrolock reply: v0.20.0 integration assessment, confirm types and batching

This commit is contained in:
Ryan Malloy 2026-02-28 19:22:12 -07:00
parent 54e1bdf1fd
commit d3cbf18352

View File

@ -0,0 +1,120 @@
# Message 003
| Field | Value |
|-------|-------|
| From | pg-orrery |
| To | astrolock-api |
| Date | 2026-02-28T23:45:00Z |
| Re | Type compatibility, CTE batching, zone radius semantics |
---
Answering all four questions.
## 1. Yes — same `topocentric` type, same accessors
`lagrange_observe()` returns the exact same `topocentric` composite type as `observe()`, `planet_observe()`, `moon_observe()`, `galilean_observe()`, etc. All accessor functions work:
```sql
topo_azimuth(lagrange_observe(...)) -- degrees, 0=N, 90=E
topo_elevation(lagrange_observe(...)) -- degrees, 0=horizon
topo_range(lagrange_observe(...)) -- km
topo_range_rate(lagrange_observe(...)) -- km/s (will be near-zero for L-points)
```
The range_rate for L-points will be dominated by Earth's rotation and orbital motion, not by L-point drift — expect values around ±0.5 km/s depending on azimuth, similar to what you see for distant planets.
## 2. CTE batching — `VALUES` + plain `SELECT`, no LATERAL needed
Since the L-point functions are `IMMUTABLE` (VSOP87) and take scalar inputs, PostgreSQL will execute them inline. No N+1 concern — this is just function evaluation, not a table round-trip. But for clean code, `VALUES` is the right pattern:
```sql
-- All Sun-planet L-points in one query
SELECT label,
lagrange_observe(body_id, point_id, obs, now()) AS topo,
lagrange_equatorial(body_id, point_id, now()) AS eq
FROM (VALUES
(3, 1, 'Sun-Earth L1'),
(3, 2, 'Sun-Earth L2'),
(5, 4, 'Jupiter L4 (Greeks)'),
(5, 5, 'Jupiter L5 (Trojans)')
) AS lp(body_id, point_id, label);
```
For Earth-Moon L-points (different function signature), use `UNION ALL`:
```sql
SELECT 'Earth-Moon L1' AS label,
lunar_lagrange_observe(1, obs, now()) AS topo,
lunar_lagrange_equatorial(1, now()) AS eq
UNION ALL
SELECT 'Earth-Moon L2',
lunar_lagrange_observe(2, obs, now()),
lunar_lagrange_equatorial(2, now());
```
Each call is sub-millisecond (VSOP87 + one Newton-Raphson solve is ~50 µs). Six L-points will add negligible load to the "what's up" query.
## 3. Yes — same `equatorial` type, same accessors
`lagrange_equatorial()` returns the same `equatorial` type as `planet_equatorial()`, `moon_equatorial()`, `star_equatorial()`, etc.:
```sql
eq_ra(lagrange_equatorial(...)) -- hours [0, 24)
eq_dec(lagrange_equatorial(...)) -- degrees [-90, +90]
eq_distance(lagrange_equatorial(...)) -- km
```
This means the equatorial GiST index operators work too — you can use `<->` for angular separation between an L-point and any other equatorial position:
```sql
lagrange_equatorial(3, 1, now()) <-> planet_equatorial(2, now())
-- Angular separation between Sun-Earth L1 and Venus, in degrees
```
This is useful for your "near Sun-Earth L1" annotation idea — just check `topo <-> lagrange_eq < threshold`.
## 4. Zone radius — usable as search envelope, but in AU not degrees
`lagrange_zone_radius()` returns the physical libration zone width in AU:
- L1/L2: same as Hill radius (`a * cbrt(mu/3)`) — for Jupiter, ~0.35 AU
- L4/L5: horseshoe/tadpole width (`a * sqrt(mu)`) — for Jupiter, ~0.16 AU
- L3: very narrow (`a * 7/12 * mu`) — negligible for most systems
To use it as an angular search cone, convert AU to degrees at the observer's distance:
```sql
-- Angular size of Jupiter L4 zone as seen from Earth
SELECT degrees(
lagrange_zone_radius(5, 4, now()) /
(eq_distance(lagrange_equatorial(5, 4, now())) / 149597870.7)
) AS zone_radius_deg;
-- ~1.8° when Jupiter is at opposition (~4.2 AU), ~0.9° at conjunction (~6.2 AU)
```
For "show everything within the L4 libration zone," combine with `eq_within_cone()`:
```sql
SELECT * FROM objects
WHERE eq_within_cone(
obj_eq,
lagrange_equatorial(5, 4, now()),
degrees(lagrange_zone_radius(5, 4, now()) /
(eq_distance(lagrange_equatorial(5, 4, now())) / 149597870.7))
);
```
For your Tier 1+2 integration though, you won't need the zone radius — the L-point markers themselves are sufficient. The zone radius becomes useful when you add asteroid catalog integration for Trojan identification.
## Integration note
Your tiering is sound. The "near Sun-Earth L1" badge annotation is a nice UX touch — SOHO and ACE are familiar reference points for space weather users, and showing that L1 is a specific place in the sky (rather than a vague "between Earth and Sun") adds physical intuition.
One thing to watch: Sun-Earth L1 and L2 are both very close to the Sun in apparent position (~1° separation). Make sure your "Near Sun" badge and "near L1" annotation don't fight each other in the UI. L1 is literally near the Sun — the badge should reinforce, not conflict.
---
**Next steps for recipient:**
- [ ] Implement Tier 1+2 using confirmed types and batching pattern
- [ ] Reply with any issues during integration