Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observation events dedicated and centralized class #60

Merged
merged 6 commits into from
Apr 15, 2024

Conversation

rhannequin
Copy link
Owner

This enables a new class Astronoby::Events::ObservationEvents to expose observation events such as rising time, setting azimuth, transit altitude, ...

It is not meant to be used directly (but it is technically possible) as it requires a set of equatorial coordinates for 3 consecutive days, which is not very convenient for the developer, but called by body classes (such as Astronoby::Sun and other classes coming soon) to expose a well documented object.

This change has two main goals:

  • Have a common API for all bodies regarding observation events: every body in the sky is entitled to expose these times and angles, but it doesn't make sense to have to implement these methods on each class. Instead, ObservationEvents acts like a common presenter.
  • This implementation allows for a natural memoization as calling sun.observation_events returns on object on which all the data is already computed and accessible.

To keep related tests together, the tests related to the Sun are still in sun_spec.rb. This avoid having observation_events_spec.rb having thousands of lines.

date = Date.new(2015, 2, 5)
epoch = Astronoby::Epoch.from_time(date)
observer = Astronoby::Observer.new(
  latitude: Astronoby::Angle.from_degrees(38),
  longitude: Astronoby::Angle.from_degrees(-78)
)
sun = Astronoby::Sun.new(epoch: epoch)
observation_events = sun.observation_events(observer: observer)

observation_events.rising_time
# => 2015-02-05 12:12:59 UTC

observation_events.rising_azimuth.str(:dms)
# => "+109° 46′ 43.1427″"

observation_events.transit_time
# => 2015-02-05 17:25:59 UTC

observation_events.transit_altitude.str(:dms)
# => "+36° 8′ 15.7669″"

observation_events.setting_time
# => 2015-02-05 22:39:27 UTC

observation_events.setting_azimuth.str(:dms)
# => "+250° 23′ 33.6177″"

This change opens new opportunities like creating a Star body class, and extracting the twilight methods from Sun into a similar class.

Fixes #58

@rhannequin rhannequin self-assigned this Apr 13, 2024
@rhannequin rhannequin marked this pull request as ready for review April 14, 2024 13:56
@rhannequin rhannequin merged commit 429c326 into main Apr 15, 2024
7 checks passed
@rhannequin rhannequin deleted the observation_events branch April 15, 2024 19:48
rhannequin added a commit that referenced this pull request Apr 29, 2024
 ## What's Changed

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

[UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md

 ### Bug fixes

* Fix ecliptic to equatorial epoch ([#56])

[#56]: #56

 ### Features

* Add twilight times ([#49])
* Add interpolation method ([#52])
* Add decimal_hour_to_time util ([#53])
* Calculate leap seconds for an instant ([#54])
* Add `Angle#-@` ([#55])
* Enable equivalence and hash equality to `Observer` ([#57])
* Twilight events dedicated class ([#61])

[#49]: #49
[#52]: #52
[#53]: #53
[#54]: #54
[#55]: #55
[#57]: #57
[#61]: #61

 ### Improvements

* Upgrade bundler from 2.3.11 to 2.5.7 by @dorianmariecom ([#45])
* Drop `BigDecimal` ([#46])
* Bump rake from 13.1.0 to 13.2.0 ([#47])
* Increase Ruby versions support ([#48])
* Bump rake from 13.2.0 to 13.2.1 ([#51])
* Dedicated constants class ([#62])
* Improve accuracy of equation of time ([#63])
* Twilight times better accuracy ([#65])
* Update UPGRADING.md ([#66])
* release: Bump version to 0.4.0 ([#67])

[#45]: #45
[#46]: #46
[#47]: #47
[#48]: #48
[#51]: #51
[#62]: #62
[#63]: #63
[#65]: #65
[#66]: #66
[#67]: #67

 ### Backward-incompatible changes

* More accurate rising, transit and setting times ([#50])
* Observation events dedicated and centralized class ([#60])
* Change `Astronoby::Sun` constructor ([#64])

[#50]: #50
[#60]: #60
[#64]: #64

 ## New Contributors

* @dorianmariecom made their first contribution in [#45]

[#45]: #45

**Full Changelog**: v0.3.0...v0.4.0
rhannequin added a commit that referenced this pull request Apr 29, 2024
## What's Changed

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

[UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md

 ### Bug fixes

* Fix ecliptic to equatorial epoch ([#56])

[#56]: #56

 ### Features

* Add twilight times ([#49])
* Add interpolation method ([#52])
* Add decimal_hour_to_time util ([#53])
* Calculate leap seconds for an instant ([#54])
* Add `Angle#-@` ([#55])
* Enable equivalence and hash equality to `Observer` ([#57])
* Twilight events dedicated class ([#61])

[#49]: #49
[#52]: #52
[#53]: #53
[#54]: #54
[#55]: #55
[#57]: #57
[#61]: #61

 ### Improvements

* Upgrade bundler from 2.3.11 to 2.5.7 by @dorianmariecom ([#45])
* Drop `BigDecimal` ([#46])
* Bump rake from 13.1.0 to 13.2.0 ([#47])
* Increase Ruby versions support ([#48])
* Bump rake from 13.2.0 to 13.2.1 ([#51])
* Dedicated constants class ([#62])
* Improve accuracy of equation of time ([#63])
* Twilight times better accuracy ([#65])
* Update UPGRADING.md ([#66])
* release: Bump version to 0.4.0 ([#67])

[#45]: #45
[#46]: #46
[#47]: #47
[#48]: #48
[#51]: #51
[#62]: #62
[#63]: #63
[#65]: #65
[#66]: #66
[#67]: #67

 ### Backward-incompatible changes

* More accurate rising, transit and setting times ([#50])
* Observation events dedicated and centralized class ([#60])
* Change `Astronoby::Sun` constructor ([#64])

[#50]: #50
[#60]: #60
[#64]: #64

 ## New Contributors

* @dorianmariecom made their first contribution in [#45]

[#45]: #45

**Full Changelog**: v0.3.0...v0.4.0
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.

More OOP for observation events
1 participant