Skip to content

Expose lunar eclipse geometry - #300

Merged
rhannequin merged 11 commits into
mainfrom
expose-lunar-eclipse-geometry
Aug 26, 2026
Merged

rhannequin merged 11 commits into
mainfrom
expose-lunar-eclipse-geometry

Conversation

@rhannequin

@rhannequin rhannequin commented Aug 25, 2026 •

Copy link
Copy Markdown
Owner

Astronoby::LunarEclipse describes 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 inside LunarEclipseCalculator and 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 #gamma and #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.

ephem = Astronoby::Ephem.load("inpop19a.bsp")

eclipse = Astronoby::Moon.eclipse_events(
  ephem: ephem,
  start_time: Time.utc(2025, 1, 1),
  end_time: Time.utc(2026, 1, 1)
).first

geometry = eclipse.geometry

geometry.umbra_angular_radius.degrees * 60     # => 39.23 (arcminutes)
geometry.penumbra_angular_radius.degrees * 60  # => 71.39
geometry.angular_axis_distance.degrees * 60    # => 19.03
geometry.position_angle.degrees                # => 29.07

eclipse.penumbral.starting_geometry.position_angle.degrees # => 131.8 (P1)
eclipse.total.starting_geometry.position_angle.degrees     # => 350.46 (U2)

Each Astronoby::LunarEclipseGeometry exposes:

  • #umbra_radius and #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 as Astronoby::Angle through #umbra_angular_radius and #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_magnitude and #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_angle is 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 uses P4.

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:

                    before     after
2020-2030           2184 ms    1908 ms
2000-2050          10813 ms    9423 ms

(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:

                              before      after
contacts within 1s           171/204     197/204
worst contact                  8.93s       2.18s
greatest magnitude error      5.3e-4      1.4e-4
umbra / penumbra radius     0.36"        0.21"
axis distance at contacts     0.44"       0.25"
position angle at contacts    0.045 deg   0.020 deg

Greatest eclipse, #gamma and #shadow_axis_distance are 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.new now requires starting_geometry: and ending_geometry:, and Astronoby::LunarEclipse.new now requires geometry:. Both objects are built by Astronoby::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.

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.
@rhannequin rhannequin self-assigned this Aug 25, 2026
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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::LunarEclipseGeometry and exposes it on LunarEclipse (greatest eclipse) and EclipsePhase (start/end contacts).
  • Updates LunarEclipseCalculator to 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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_magnitude does; penumbral_magnitude is 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The geometry implementation is coherent, documented, and covered by focused numerical and integration tests.

Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation, public API wiring, documentation, and regression coverage are consistent with the stated behavior.

Review details
  • Files reviewed: 13/13 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@rhannequin
rhannequin merged commit 4ed9ec6 into main Aug 26, 2026
45 checks passed
@rhannequin
rhannequin deleted the expose-lunar-eclipse-geometry branch August 26, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants