Repository navigation
Add Lunar eclipses - #280
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds first-class lunar eclipse support to Astronoby by introducing data models for lunar eclipses/phases, an ephemeris-backed calculator to find eclipses within a time range (seeded from full moons), and a public API entry point on Astronoby::Moon, along with documentation and specs.
Changes:
- Add
Astronoby::LunarEclipse/Astronoby::EclipsePhasedomain objects and aAstronoby::LunarEclipseCalculatorto compute eclipse events and contacts. - Expose
Astronoby::Moon.eclipse_events(ephem:, start_time:, end_time:)as the public API. - Add comprehensive specs and new documentation page, plus navigation links from existing docs.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/astronoby/events/lunar_eclipse_spec.rb | Unit specs for Astronoby::LunarEclipse attributes, aliases, predicates, and immutability. |
| spec/astronoby/events/lunar_eclipse_calculator_spec.rb | Integration-style specs validating computed eclipses (kind, greatest eclipse, magnitudes, contacts) against reference timings. |
| spec/astronoby/events/eclipse_phase_spec.rb | Specs for Astronoby::EclipsePhase duration/boundaries and immutability. |
| spec/astronoby/bodies/moon_spec.rb | Specs for Moon.eclipse_events delegating to the calculator and returning eclipse objects. |
| lib/astronoby/events/lunar_eclipse.rb | Adds immutable LunarEclipse model with API described in the PR. |
| lib/astronoby/events/lunar_eclipse_calculator.rb | Implements the lunar eclipse search/geometry, including seeded search, minimization, and contact bisection. |
| lib/astronoby/events/eclipse_phase.rb | Adds immutable EclipsePhase model with a #duration helper. |
| lib/astronoby/bodies/moon.rb | Adds Moon.eclipse_events public API method. |
| lib/astronoby.rb | Wires new event classes into the library requires. |
| docs/moon_phases.md | Adds navigation link to the lunar eclipse documentation. |
| docs/lunar_observation.md | Adds navigation link to the lunar eclipse documentation. |
| docs/lunar_eclipses.md | New documentation page describing API usage, returned objects, and precision notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rhannequin
force-pushed
the
add-lunar-eclipses
branch
from
June 24, 2026 14:15
78cfcf9 to
b264d73
Compare
Merged
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
rhannequin
added a commit
that referenced
this pull request
Jun 26, 2026
## 0.10.0 - 2026-06-26 _If you are upgrading: please see [UPGRADING.md]._ ### Bug fixes * Fix constant name typo ([#245]) * Fix matrix multiplication order in Apparent frame ([#250]) * Remove spurious N·P from observer ECEF-to-TOD transformation ([#251]) * Apply aberration in GCRS before precession/nutation rotation ([#253]) * Fix Moon magnitude ([#254]) * Fix astrometric position for Deep Sky Objects ([#272]) ### Features * Defer Solar System body computations lazily ([#244]) * Integrate `iers` gem for Delta T and GMST ([#249]) * Add IERS polar motion correction to observer ECEF-to-TOD transformation ([#252]) * Fall back to polynomial GMST for dates outside IERS EOP range ([#255]) * Add ICRS frame bias to precession matrix ([#257]) * Extract `EarthRotation` class from `Observer` ([#260]) * Add TEME reference frame for satellite tracking ([#261]) * Add ECEF to geodetic conversion (WGS-84) ([#262]) * Memoize per-instant conversions on `Instant` ([#268]) * Add `ReferenceFrame#separation_from` for angular separation ([#269]) * Introduce `Center`, `Body` and `Position` domain objects ([#270]) * Add planetary phenomena ([#271]) * Add lunar libration, position angle of axis and bright limb ([#273]) * Add `Astronoby::Orientation` for arcsecond lunar libration ([#279]) * Add Lunar eclipses ([#280]) * Add `Astronoby::Duration` ([#281]) ### Improvements * Optimize nutation loop by eliminating array allocations ([#246]) * Reuse single Nutation instance in observer matrix computation ([#247]) * Memoize Observer geodetic computation methods ([#248]) * Update documentation with recent values ([#256]) * Update referential frames documentation ([#258]) * YARD documentation update ([#259]) * Update zlib, JSON and ERB for security reasons * Add references to README * Bump actions/checkout from 5 to 7 by @dependabot ([#239], [#276]) * Bump rubyzip from 3.2.1 to 3.4.0 by @dependabot ([#237], [#267], [#275]) * Bump irb from 1.15.2 to 1.17.0 by @dependabot ([#242]) * Bump standard from 1.51.1 to 1.55.0 by @dependabot ([#243], [#274]) * Bump rake from 13.3.1 to 13.4.2 by @dependabot ([#264]) * Bump ephem from 0.4.1 to 0.5.0 by @dependabot ([#278]) * Upgrade default Ruby to 4.0.5 ([#277]) ### Backward-incompatible changes * Minimum Ruby version bumped to 3.2.0 ([#249]) * Delta T and GMST now use IERS data ([#249]) * Defer Solar System body computations lazily ([#244]) * `SolarSystemBody#ephem` is now publicly accessible ([#244]) * `ReferenceFrame#center_identifier` replaced by `#center` ([#270]) * `Sun#equation_of_time` now returns a `Duration` ([#281]) **Full Changelog**: v0.9.0...v0.10.0 [#237]: #237 [#239]: #239 [#242]: #242 [#243]: #243 [#244]: #244 [#245]: #245 [#246]: #246 [#247]: #247 [#248]: #248 [#249]: #249 [#250]: #250 [#251]: #251 [#252]: #252 [#253]: #253 [#254]: #254 [#255]: #255 [#256]: #256 [#257]: #257 [#258]: #258 [#259]: #259 [#260]: #260 [#261]: #261 [#262]: #262 [#264]: #264 [#267]: #267 [#268]: #268 [#269]: #269 [#270]: #270 [#271]: #271 [#272]: #272 [#273]: #273 [#274]: #274 [#275]: #275 [#276]: #276 [#277]: #277 [#278]: #278 [#279]: #279 [#280]: #280 [#281]: #281 [UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A lunar eclipse happens when the Moon passes through the shadow Earth casts behind it. Earth's shadow has two parts: the penumbra, the outer region where the Sun is only partially hidden, and the umbra, the inner region where the Sun is completely hidden. This gives three kinds of eclipse. A penumbral eclipse is when the Moon only grazes the penumbra, which is subtle and easy to miss. A partial eclipse is when part of the Moon enters the umbra. A total eclipse is when the whole Moon is inside the umbra, the famous "blood Moon".
Unlike a solar eclipse, a lunar eclipse looks the same for everyone who can see the Moon, so there is no observer involved here. It is a geocentric event.
This change introduces the ability to find lunar eclipses between two times. It searches around each full moon in the range, because a lunar eclipse can only happen at full moon, and returns the ones that actually occur.
The result is an array of
Astronoby::LunarEclipse, sorted by time. Note that it is possible for no eclipse to happen in the provided range, in which case the array is empty. Most months have a full moon but no eclipse, because the Moon usually passes above or below the shadow.Each
Astronoby::LunarEclipseexposes:#instant(Astronoby::Instant), the moment of greatest eclipse, when the Moon's centre is least distant from the axis of Earth's shadow. It is also available as#greatest_eclipse, which reads better in some contexts.#kind(Symbol), one of:penumbral,:partialor:total, with the matching#penumbral?,#partial?and#total?predicates.#umbral_magnitudeand#penumbral_magnitude(Float), the fraction of the Moon's diameter inside the umbra and the penumbra at greatest eclipse. The umbral magnitude is negative for a penumbral eclipse (the Moon misses the umbra), between 0 and 1 for a partial one, and 1 or more for a total one.#gamma(Float), the least distance of the Moon's centre from the shadow axis in Earth radii, positive when the Moon passes north of the axis and negative when it passes south. This is the standard dimensionless parameter used by IMCCE and NASA to describe an eclipse.#shadow_axis_distance(Astronoby::Distance), the same quantity as gamma but as a proper distance, for consistency with the rest of the library.The phases are exposed as
Astronoby::EclipsePhaseobjects, each with a#starting_instant, an#ending_instant(bothAstronoby::Instant) and a#durationin seconds (Integer). The penumbral phase is always present. The partial phase is present for partial and total eclipses, and the total phase (totality) only for total eclipses. A phase that does not happen isnil, so for a penumbral eclipse both#partialand#totalarenil, and for a partial eclipse#totalisnil.How it works
The geometry is built from the apparent geocentric positions of the Sun and Moon, which Astronoby already knows how to compute. At a given instant it builds Earth's umbra and penumbra as cones pointing away from the Sun, works out their radii at the Moon's distance, and compares them with the distance of the Moon's centre from the shadow axis. From there it gets the magnitudes, and the contacts are the instants when the Moon's limb crosses each boundary.
Searching every instant in a range would be wasteful, so the search is seeded. A lunar eclipse only happens at full moon, and Astronoby can already compute the full moons of a month analytically (the same Meeus method used by
Astronoby::Events::MoonPhases), at no ephemeris cost. Each full moon in the range becomes a candidate. Full moons where the Moon is clearly too far from a node are skipped straight away with a cheap check, which is most of them. For the remaining ones, greatest eclipse is found by minimising the distance from the shadow axis, and each contact is found by bisecting between greatest eclipse (the Moon inside the shadow) and the edge of the search window (the Moon outside it). Bisecting from a known bracket like this keeps it reliable even for a very short totality or a grazing penumbral eclipse, where sampling a fixed grid could step right over the event.One detail worth mentioning is the shadow itself. Earth's atmosphere makes the shadow slightly larger than pure geometry predicts. The usual way to account for this is to enlarge Earth's radius a little before building the cones (Danjon's approach). The exact factor is a convention, and different sources disagree by a fraction of a percent, which is enough to move the contact times by tens of seconds. I calibrated the factor against IMCCE so the results line up with their data.
Accuracy
Values have been compared with the IMCCE, through their Opale web service, which uses the same INPOP19A ephemeris Astronoby can load. The eclipse kind, the greatest eclipse instant, the magnitudes and the contact times all match to within a second or two over the 2023 to 2025 eclipses. Greatest eclipse and gamma do not depend on the shadow enlargement and match exactly. The contact times depend on it, so a second or two of difference there is expected and is also the level at which published sources differ from each other.