rhannequin / astronoby

Ruby library based on astronomy and astrometry books
https://dev.to/rhannequin/series/17782
MIT License
59 stars 2 forks source link

Observation events dedicated and centralized class #60

Closed rhannequin closed 7 months ago

rhannequin commented 7 months ago

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:

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