Repository navigation
Expose lunar eclipse geometry - #300
Conversation
Replaces separation_from plus the rotation to ecliptic coordinates with a single orthonormal basis at the antisolar point. Same results to 1e-13, about 10% faster over the 2020-2030 eclipse search.
Adds LunarEclipseGeometry, carrying the cone radii, the Moon's distance from the shadow axis and its position angle, plus the magnitudes derived from them. It hangs off the eclipse at greatest eclipse and off each phase at its two contacts. The contact geometry reuses what the bisection already computed within CONTACT_TOLERANCE of the contact, so it costs no ephemeris call. Validated against IMCCE (Opale, INPOP19A) across 2024-2026: umbra radius to 0.2", penumbra radius to 0.4", angular distance from the axis to 0.1", position angle to 0.03 degrees.
position_angle is now the position angle of the contact point on the Moon's limb, which is what IMCCE and NASA publish, rather than the axis-to-Moon direction it is derived from. Consumers no longer have to know that the two differ by 180 degrees at an external tangency. Agrees with IMCCE to 0.004 degrees at every contact across the 2023-2026 eclipses.
The class docstring and the docs page still described position_angle as the axis-to-Moon direction, contradicting the reader doc and pointing consumers 180 degrees the wrong way at every external contact. The docs page also carried the 2026-03-03 values under a snippet bound to the 2025-03-14 eclipse. Substitutes the right ones, corrects the contact count, seals Geometry as a private constant, and pins gamma's sign, whose derivation changed with the vector rewrite and was unasserted.
The 0.004 degree figure was the outer contacts only. The total contacts sit at 0.02 degrees, where the contact instants differ from IMCCE by about two seconds.
There was a problem hiding this comment.
🟡 Changes recommended
Contact instants and returned contact geometries can be inconsistent because bisect_contact returns a midpoint JD but geometry evaluated at inside_jd.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds a first-class value object for lunar eclipse shadow geometry and wires it through LunarEclipse and EclipsePhase so consumers can access umbra/penumbra radii, axis distance, and published position angles at greatest eclipse and at every contact.
Changes:
- Introduces
Astronoby::LunarEclipseGeometryand exposes it onLunarEclipse(greatest eclipse) andEclipsePhase(start/end contacts). - Updates
LunarEclipseCalculatorto compute/store position angle + Moon distance and to attach geometry without recomputation at contacts. - Adds/updates specs and documentation (UPGRADING/CHANGELOG/docs) for the new API and breaking initializer requirements.
File summaries
| File | Description |
|---|---|
| UPGRADING.md | Documents breaking initializer changes requiring geometry. |
| CHANGELOG.md | Notes the new geometry feature and vector-based axis offset computation. |
| docs/lunar_eclipses.md | Adds user-facing documentation and examples for the new geometry API and accuracy notes. |
| lib/astronoby.rb | Requires the new lunar_eclipse_geometry file. |
| lib/astronoby/events/eclipse_phase.rb | Adds starting_geometry / ending_geometry to EclipsePhase API. |
| lib/astronoby/events/lunar_eclipse.rb | Adds geometry at greatest eclipse to LunarEclipse. |
| lib/astronoby/events/lunar_eclipse_geometry.rb | New immutable value object exposing shadow geometry + derived angular/magnitude helpers. |
| lib/astronoby/events/lunar_eclipse_calculator.rb | Computes position angle via an orthonormal basis; plumbs geometry through phases and greatest eclipse. |
| spec/astronoby/events/eclipse_phase_spec.rb | Updates construction expectations for new required geometry params. |
| spec/astronoby/events/lunar_eclipse_spec.rb | Updates eclipse construction expectations to include geometry. |
| spec/astronoby/events/lunar_eclipse_calculator_spec.rb | Adds assertions for gamma sign, geometry exposure, position angles, and contact closure. |
| spec/astronoby/events/lunar_eclipse_geometry_spec.rb | New unit tests for magnitudes, angular forms, and immutability. |
Review details
- Files reviewed: 12/12 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The date is the bracket midpoint and the geometry is from its inner end, at most 2 ms apart. Pairing them exactly by returning the inner end as the date is the worse estimate of the crossing and shifts one contact of 462 across a rounded second over 2000-2050.
There was a problem hiding this comment.
🔵 Needs a closer look
The new public geometry API contains inaccurate magnitude and position-angle documentation.
Review details
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
docs/lunar_eclipses.md:85
- This sentence implies both magnitude accessors equal 1 at total contacts, but only
umbral_magnitudedoes;penumbral_magnitudeis already greater than 1 there because the Moon is much farther inside the penumbra. Please distinguish the contact conditions so the new public API is documented accurately.
`#umbral_magnitude` and `#penumbral_magnitude` are available at any of these instants, not only at greatest eclipse. They are 0 at the contacts that define them and 1 at the total contacts.
lib/astronoby/events/lunar_eclipse_geometry.rb:36
- This parameter description conflicts with the accessor contract: the angle is measured from celestial north, and at external contacts it describes the contact point rather than the axis-to-Moon direction. Document the value actually accepted by this public constructor.
# @param position_angle [Astronoby::Angle] position angle from the axis
- Files reviewed: 12/12 changed files
- Comments generated: 0 new
- Review effort level: Balanced
The magnitudes sentence read as though both were 1 at the total contacts. Only the umbral magnitude is; the penumbral magnitude is 2.081 there. The constructor's position_angle param still described the axis-to-Moon direction, contradicting the reader doc two lines up.
The published bounds came from one eclipse (2026-03-03) for the per-contact residuals and from eight for greatest eclipse, then got merged into a single sentence. Measured properly over all eight: umbra 0.211", penumbra 0.332", axis distance 0.018" at greatest, 0.231" at the outer contacts and 0.448" at the total contacts, position angles 0.0112 / 0.0225 / 0.0457 degrees.
Extends the comparison from 8 eclipses to the 50 between 2026 and 2048. All classified identically; 171 of 204 contacts within a second, 199 within two. Records the three ill-conditioned cases that dominate the tail, and the systematic 0.42 arcsecond at the umbral contacts, which traces to Astronoby using the Moon's physical radius of 1737.4 km where IMCCE uses the IAU eclipse constant k, 1738.09 km.
One paragraph stating the precision, matching the existing register.
IMCCE and NASA reduce lunar eclipses with k = 0.2725076 Earth radii, putting the Moon's radius at 1738.09 km rather than its physical 1737.4 km. The atmospheric enlargement is recalibrated with it, from 1/99 of Earth's radius to a 64 km shell. The two must move together: 1/99 was partly compensating for the smaller lunar radius, so either alone makes agreement worse. Over the 50 eclipses from 2026 to 2048, contacts within a second go from 171/204 to 197/204 and the worst contact from 8.93s to 2.18s; magnitude error drops from 5.3e-4 to 1.4e-4 and the shadow radii from 0.36" to 0.21". Greatest eclipse, gamma and the axis distance are untouched, depending on neither constant.
Astronoby::LunarEclipsedescribes an eclipse well enough to talk about it, but not enough to draw it or to check it against a published table. The umbra and penumbra radii were already computed insideLunarEclipseCalculatorand then thrown away. The only geometric quantity that survived was the distance of the Moon's centre from the shadow axis at greatest eclipse, through#gammaand#shadow_axis_distance, without its direction, and nothing at all was available at any other instant.This exposes that geometry as a value object,
Astronoby::LunarEclipseGeometry. The eclipse carries the geometry at greatest eclipse, and each phase carries the geometry at its two boundaries, so all six contacts of a total eclipse are reachable as well as greatest eclipse.Each
Astronoby::LunarEclipseGeometryexposes:#umbra_radiusand#penumbra_radius(Astronoby::Distance), the radii of the two shadow cones, cut by the plane perpendicular to the shadow axis at the Moon's distance, which is where they are published. Earth's radius is enlarged by its atmosphere before the cones are built, so these are the enlarged, observable radii. Also available asAstronoby::Anglethrough#umbra_angular_radiusand#penumbra_angular_radius.#axis_distance(Astronoby::Distance) and#angular_axis_distance(Astronoby::Angle), the distance of the Moon's centre from the axis of Earth's shadow.#position_angle(Astronoby::Angle), the position angle of the contact point on the Moon's limb, from celestial north through east.#umbral_magnitudeand#penumbral_magnitude(Float), which are now available at every contact and not only at greatest eclipse. They land on 0 at the contacts that define them and on 1 at the total contacts.#moon_distance(Astronoby::Distance), the geocentric distance of the Moon, which is the distance of the plane the radii are measured in.Position angle
IMCCE and NASA publish, for each contact, the position angle of the contact point on the Moon's limb, seen from the Moon's centre. That is not the same thing as the direction from the shadow axis to the Moon, which is what the geometry naturally produces. The two differ by 180 degrees at an external tangency (P1, U1, U4 and P4), where the contact point is on the limb facing the axis, and they agree at an internal one (U2 and U3), where it is on the far limb. At greatest eclipse there is no contact point at all, and both sources report the axis to Moon direction there.
#position_angleis the published quantity, so a value can be compared with IMCCE or NASA with no conversion. The 180 degree bookkeeping stays inside the calculator, where the tangency of each phase boundary is already known.Note that IMCCE labels the end of the penumbral phase
P2, where Astronoby's documentation usesP4.How it works
The geometry at each contact is not recomputed. Each contact is already found by bisecting down to
CONTACT_TOLERANCE, a ten-millionth of a day, so the geometry at the inner end of the final bracket is the geometry at the contact to within a few milliseconds of the Moon's motion, about a thousandth of an arcsecond. That is more than two orders of magnitude inside the second the contact times themselves are reported to, and it costs no ephemeris call.The distance from the shadow axis used to come from
ReferenceFrame#separation_from, and the sign of gamma from a rotation of the Moon's position into ecliptic coordinates. Both are now replaced by a single orthonormal basis at the antisolar point, which gives the axial distance, the perpendicular distance, the side of the axis the Moon passes and the position angle at once. The results are unchanged to 1e-13, and it removes enough work from the inner loop that the whole eclipse search is about 13% faster than before despite the extra data:(fastest of six runs each, same machine and session)
The cone radii and the axis distance are lengths perpendicular to the shadow axis, so the angles they subtend follow from their sine and not from their tangent. Getting that wrong is worth up to 2 arcseconds at the outer contacts, which is more than the whole error budget of the rest of the computation.
Accuracy
Values have been compared with IMCCE, through their Opale web service, which uses the same INPOP19A ephemeris Astronoby can load, across the eclipses from 2026 to 2048. Every one is classified identically. Contacts agree to within a couple of seconds, the umbra and penumbra radii to 0.25", the angular distance from the shadow axis to 0.02" at greatest eclipse and 0.45" at the contacts, position angles to 0.03 degrees, and the greatest magnitude to 0.0002.
Exposing the axis distance at each contact made a pre-existing systematic difference measurable for the first time, and it turned out to be worth fixing here. IMCCE's published angular radii imply a lunar radius of 1738.09 km, which is the IAU eclipse constant k = 0.2725076 Earth radii, while Astronoby was using the Moon's physical equatorial radius of 1737.4 km. Adopting k is not enough on its own: the 1/99 atmospheric enlargement had been calibrated with the smaller radius in place and was partly compensating for it, so changing either constant alone makes agreement with IMCCE worse. Retuning both together, to k and a 64 km atmospheric shell, improves every measure at once:
Greatest eclipse,
#gammaand#shadow_axis_distanceare untouched: they depend on neither constant, which is also the control that confirms the two knobs were the cause. The enlargement is now expressed as a 64 km shell rather than a 1/99 ratio, since a shell is what it physically is, and 64 km is within 0.03 km of the optimum rather than a fitted denominator.Breaking changes
Astronoby::EclipsePhase.newnow requiresstarting_geometry:andending_geometry:, andAstronoby::LunarEclipse.newnow requiresgeometry:. Both objects are built byAstronoby::LunarEclipseCalculator, so this only affects code constructing them directly.Contact times may also shift by a second or two, and the magnitudes in the fifth decimal, from the constants above.