-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GreenwichSiderealTime and LocalSiderealTime
- Loading branch information
1 parent
591fb76
commit 96df8c4
Showing
11 changed files
with
340 additions
and
339 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# frozen_string_literal: true | ||
|
||
module Astronoby | ||
class GreenwichSiderealTime | ||
JULIAN_CENTURIES_EXPONENTS = [ | ||
BigDecimal("6.697374558"), | ||
BigDecimal("2400.051336"), | ||
BigDecimal("0.000025862") | ||
].freeze | ||
|
||
attr_reader :date, :time | ||
|
||
# Source: | ||
# Title: Practical Astronomy with your Calculator or Spreadsheet | ||
# Authors: Peter Duffett-Smith and Jonathan Zwart | ||
# Edition: Cambridge University Press | ||
# Chapter: 12 - Conversion of UT to Greenwich sidereal time (GST) | ||
def self.from_utc(utc) | ||
date = utc.to_date | ||
julian_day = utc.to_date.ajd | ||
t = (julian_day - Epoch::J2000) / Epoch::DAYS_PER_JULIAN_CENTURY | ||
t0 = ( | ||
(JULIAN_CENTURIES_EXPONENTS[0] + | ||
(JULIAN_CENTURIES_EXPONENTS[1] * t) + | ||
(JULIAN_CENTURIES_EXPONENTS[2] * t * t)) % 24 | ||
).abs | ||
|
||
ut_in_hours = utc.hour + | ||
utc.min / 60.0 + | ||
(utc.sec + utc.subsec) / 3600.0 | ||
|
||
gmst = BigDecimal("1.002737909") * ut_in_hours + t0 | ||
gmst += 24 if gmst.negative? | ||
gmst -= 24 if gmst > 24 | ||
|
||
new(date: date, time: gmst) | ||
end | ||
|
||
def initialize(date:, time:) | ||
@date = date | ||
@time = time | ||
end | ||
|
||
# Source: | ||
# Title: Practical Astronomy with your Calculator or Spreadsheet | ||
# Authors: Peter Duffett-Smith and Jonathan Zwart | ||
# Edition: Cambridge University Press | ||
# Chapter: 13 - Conversion of GST to UT | ||
def to_utc | ||
date = @date | ||
julian_day = @date.ajd | ||
t = (julian_day - Epoch::J2000) / Epoch::DAYS_PER_JULIAN_CENTURY | ||
|
||
t0 = ( | ||
(JULIAN_CENTURIES_EXPONENTS[0] + | ||
(JULIAN_CENTURIES_EXPONENTS[1] * t) + | ||
(JULIAN_CENTURIES_EXPONENTS[2] * t * t)) % 24 | ||
).abs | ||
|
||
a = @time - t0 | ||
a += 24 if a.negative? | ||
a -= 24 if a > 24 | ||
|
||
utc = BigDecimal("0.9972695663") * a | ||
|
||
decimal_hour_to_time(date, utc) | ||
end | ||
|
||
def to_lst(longitude:) | ||
LocalSiderealTime.from_gst(gst: self, longitude: longitude) | ||
end | ||
|
||
private | ||
|
||
def decimal_hour_to_time(date, decimal) | ||
absolute_hour = decimal.abs | ||
hour = absolute_hour.floor | ||
decimal_minute = 60 * (absolute_hour - hour) | ||
absolute_decimal_minute = (60 * (absolute_hour - hour)).abs | ||
minute = decimal_minute.floor | ||
second = 60 * (absolute_decimal_minute - absolute_decimal_minute.floor) | ||
|
||
::Time.utc(date.year, date.month, date.day, hour, minute, second) | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
module Astronoby | ||
class LocalSiderealTime | ||
attr_reader :date, :time, :longitude | ||
|
||
# Source: | ||
# Title: Practical Astronomy with your Calculator or Spreadsheet | ||
# Authors: Peter Duffett-Smith and Jonathan Zwart | ||
# Edition: Cambridge University Press | ||
# Chapter: 14 - Local sidereal time (LST) | ||
def self.from_gst(gst:, longitude:) | ||
date = gst.date | ||
time = gst.time + longitude.hours | ||
time += 24 if time.negative? | ||
time -= 24 if time > 24 | ||
|
||
new(date: date, time: time, longitude: longitude) | ||
end | ||
|
||
def initialize(date:, time:, longitude:) | ||
@date = date | ||
@time = time | ||
@longitude = longitude | ||
end | ||
|
||
# Source: | ||
# Title: Practical Astronomy with your Calculator or Spreadsheet | ||
# Authors: Peter Duffett-Smith and Jonathan Zwart | ||
# Edition: Cambridge University Press | ||
# Chapter: 15 - Converting LST to GST | ||
def to_gst | ||
date = @date | ||
time = @time - @longitude.hours | ||
time += 24 if time.negative? | ||
time -= 24 if time > 24 | ||
|
||
GreenwichSiderealTime.new(date: date, time: time) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.