Skip to content

Commit

Permalink
Compute the equation of time
Browse files Browse the repository at this point in the history
The equation of time is the difference of the real Sun time and the mean
Sun time. This difference is due to the elliptical shape of the Earth's
orbit, and the obliquity of the orbit.

`Sun` now has a `#equation_of_time` method that returns an integer: the
time difference in seconds.

```rb
time = Time.utc(2010, 7, 27, 12, 0, 0)
epoch = Astronoby::Epoch.from_time(time)
sun = Astronoby::Sun.new(epoch: epoch)

sun.equation_of_time
```
  • Loading branch information
rhannequin committed Mar 22, 2024
1 parent 09e3762 commit 40311a9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/astronoby/bodies/sun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ def orbital_eccentricity
)
end

def equation_of_time
date = Epoch.to_utc(@epoch).to_date
equatorial_hours = ecliptic_coordinates
.to_equatorial(epoch: @epoch)
.right_ascension
.hours
gst = GreenwichSiderealTime
.new(date: date, time: equatorial_hours)
.to_utc
noon = Time.utc(date.year, date.month, date.day, 12)

(noon - gst).to_i
end

private

def mean_anomaly
Expand Down
57 changes: 57 additions & 0 deletions spec/astronoby/bodies/sun_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,61 @@
# Time from IMCCE: +266° 52′
end
end

describe "#equation_of_time" do
it "returns an Integer" do
time = Time.now
epoch = Astronoby::Epoch.from_time(time)
sun = described_class.new(epoch: epoch)

equation_of_time = sun.equation_of_time

expect(equation_of_time).to be_an Integer
end

# Source:
# Title: Practical Astronomy with your Calculator or Spreadsheet
# Authors: Peter Duffett-Smith and Jonathan Zwart
# Edition: Cambridge University Press
# Chapter: 51 - The equation of time
it "returns the right value of 2010-07-27" do
time = Time.utc(2010, 7, 27, 12, 0, 0)
epoch = Astronoby::Epoch.from_time(time)
sun = described_class.new(epoch: epoch)

equation_of_time = sun.equation_of_time

expect(equation_of_time).to eq(-392)
end

# Source:
# Title: Celestial Calculations
# Author: J. L. Lawrence
# Edition: MIT Press
# Chapter: 6 - The Sun
it "returns the right value of 2016-05-25" do
time = Time.utc(2016, 5, 5, 12, 0, 0)
epoch = Astronoby::Epoch.from_time(time)
sun = described_class.new(epoch: epoch)

equation_of_time = sun.equation_of_time

expect(equation_of_time).to eq(199)
end

# Source:
# Title: Astronomical Algorithms
# Author: Jean Meeus
# Edition: 2nd edition
# Chapter: 28 - Equation of Time
it "returns the right value of 1992-10-13" do
time = Time.utc(1992, 10, 13, 0, 0, 0)
epoch = Astronoby::Epoch.from_time(time)
sun = described_class.new(epoch: epoch)

equation_of_time = sun.equation_of_time

expect(equation_of_time).to eq(937)
end
end
end

0 comments on commit 40311a9

Please sign in to comment.