Skip to content

Add #events_between to TwilightCalculator with better accuracy#204

Merged
rhannequin merged 7 commits intomainfrom
improved-twilight
Aug 21, 2025
Merged

Add #events_between to TwilightCalculator with better accuracy#204
rhannequin merged 7 commits intomainfrom
improved-twilight

Conversation

@rhannequin
Copy link
Owner

To mimic RiseTransitSetCalculator, this adds #events_between to TwilightCalculator, allowing to compute twilight times for a date range instead of having to loop over each date. This drastically improves the performance over long date ranges.

This was also the opportunity to tune the algorithm in order to get closer to the source of truth for this feature: IMCCE. This change made the difference with IMCCE data for test scenarios to e few seconds instead of between one and two minutes previously.

Finally, utc_offset optional parameter was added to #event_on to ensure the times are properly calculated for a date of local time. Without this parameter, the times are calculated for happening between midinight and midnight UTC (00:00+00:00), which is for example not the definition of a civil day in Singapore, where a civil day is between midnight and midnight GMT+8 (00:00+08:00). The more far from the Greenwich meridian, the more likely the algorithm was to compute morning or evening twilight times for the wrong date.

@rhannequin rhannequin self-assigned this Aug 18, 2025
@rhannequin rhannequin requested a review from Copilot August 19, 2025 20:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the TwilightCalculator class to improve performance and accuracy for twilight time calculations. The primary purpose is to add a new #events_between method that can calculate twilight times for a date range, similar to the existing RiseTransitSetCalculator, while also improving algorithmic accuracy.

  • Adds #events_between method for calculating twilight times across date ranges
  • Improves accuracy by tuning the algorithm to match IMCCE reference data
  • Adds utc_offset parameter support for proper local time calculations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
lib/astronoby/events/twilight_calculator.rb Major refactoring to add events_between method and utc_offset support, improving accuracy
lib/astronoby/events/twilight_events.rb New class to hold collections of twilight times for the events_between method
lib/astronoby.rb Adds require statement for the new TwilightEvents class
spec/astronoby/events/twilight_calculator_spec.rb Updates test data and adds new tests for utc_offset functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

rhannequin and others added 4 commits August 19, 2025 22:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rhannequin rhannequin merged commit 885f64e into main Aug 21, 2025
43 checks passed
@rhannequin rhannequin deleted the improved-twilight branch August 21, 2025 14:50
@rhannequin rhannequin mentioned this pull request Aug 21, 2025
rhannequin added a commit that referenced this pull request Sep 1, 2025
## 0.8.0 - 2025-09-01

_If you are upgrading: please see [UPGRADING.md]._

### Bug fixes

* Fix UPGRADING documentation ([#178])
* Fix possible division by zero in RTS ([#185])

### Features

* Introduce performance benchmark ([#183])
* Cache positions in RTS calculator ([#182])
* Internal global LRU cache ([#186])
* Global configuration ([#187])
* Compute the constellation a body is in ([#199])
* Add `#phase_angle` and `#illuminated_fraction` to planets ([#200])
* Apparent magnitude ([#201])
* Add #events_between to TwilightCalculator with better accuracy ([#204])
* `#angular_diameter` on Solar System bodies ([#207])
* Fix constellation boundaries near 24h right ascension ([#209])

### Improvements

* Bump standard from 1.49.0 to 1.50.0 by @dependabot ([#177])
* Bump ephem from 0.3.0 to 0.4.1 by @dependabot ([#181], [#191])
* Bump irb from 1.14.3 to 1.15.2 by @dependabot ([#184])
* Bump rspec from 3.13.0 to 3.13.1 by @dependabot ([#188])
* Bump benchmark from 0.4.0 to 0.4.1 by @dependabot ([#189])
* Bump rake from 13.2.1 to 13.3.0 by @dependabot ([#190])
* Bump matrix from 0.4.2 to 0.4.3 by @dependabot ([#193])
* Update rubyzip requirement from ~> 2.3 to ~> 3.0 by @dependabot ([#194])
* Bump rubyzip from 3.0.0 to 3.0.2 by @dependabot ([#202], [#206])
* Exclude benchmarks from release ([#196])
* `Epoch` refactoring into `JulianDate` ([#197])
* Support Ruby 3.4.4 ([#198])
* Bump actions/checkout from 4 to 5 ([#203])
* Internal documentation ([#205])

### Backward-incompatible changes

* `Epoch` refactoring into `JulianDate` ([#197])
* `#angular_diameter` on Solar System bodies ([#207])
* Rename "epoch" ([#208])

### Closed issues

* Consider adding typical usage/deployment info ([#179])
* Performance degradation in v0.7 ([#180])

**Full Changelog**: v0.7.0...v0.8.0

[#177]: #177
[#178]: #178
[#179]: #179
[#180]: #180
[#181]: #181
[#182]: #182
[#183]: #183
[#184]: #184
[#185]: #185
[#186]: #186
[#187]: #187
[#188]: #188
[#189]: #189
[#190]: #190
[#191]: #191
[#193]: #193
[#194]: #194
[#196]: #196
[#197]: #197
[#198]: #198
[#199]: #199
[#200]: #200
[#201]: #201
[#202]: #202
[#203]: #203
[#204]: #204
[#205]: #205
[#206]: #206
[#207]: #207
[#208]: #208
[#209]: #209
[UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md
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