Class: DateTime
- Inherits:
-
Object
- Object
- DateTime
- Defined in:
- lib/miriad.rb
Overview
The MIRIAD package adds astronomy-related and other utilty methods to the DateTime
class.
Constant Summary collapse
- J2000 =
The J2000 epoch
civil(2000,1,1,12)
- OMEGA =
The sidereal rotation rate of Earth in radians per second
7.29211538e-5
Class Method Summary collapse
-
.ajd(d) ⇒ Object
Create a
DateTime
object from a numeric Astronomical Julian Date. -
.ut1 ⇒ Object
UT1 (expressed in hours) at the current time.
-
.utc ⇒ Object
Create a
DateTime
object from a numeric Astronomical Julian Date.
Instance Method Summary collapse
-
#by ⇒ Object
Besselian year at the time represented by
self
. -
#eqeq ⇒ Object
Equation of the Equinoxes at the time represented by
self
. -
#gast ⇒ Object
Greenwich Apparent Sidereal Time at the time represented by
self
. -
#gmst ⇒ Object
Greenwich Mean Sidereal Time at the time represented by
self
. -
#last(longitude = 0.0) ⇒ Object
Local Apparent Sidereal Time in hours at the time represented by
self
. -
#lmst(longitude = 0.0) ⇒ Object
Local Mean Sidereal Time in hours at the time represented by
self
. -
#to_utc ⇒ Object
A
DateTime
object corresponding to the same time asself
, but with an offset of 0. -
#ut1 ⇒ Object
UT1 (expressed in hours) at the time represented by
self
. -
#ut1_utc ⇒ Object
UT1-UTC (unit is seconds) at the time represented by
self
. -
#ut2_ut1 ⇒ Object
UT2-UT1 (unit is seconds) at the time represented by
self
.
Class Method Details
.ajd(d) ⇒ Object
Create a DateTime
object from a numeric Astronomical Julian Date.
138 139 140 |
# File 'lib/miriad.rb', line 138 def self.ajd(d) J2000 + d - J2000.ajd end |
.ut1 ⇒ Object
UT1 (expressed in hours) at the current time.
190 191 192 |
# File 'lib/miriad.rb', line 190 def self.ut1 now.ut1 end |
.utc ⇒ Object
Create a DateTime
object from a numeric Astronomical Julian Date.
180 181 182 |
# File 'lib/miriad.rb', line 180 def self.utc now.to_utc end |
Instance Method Details
#by ⇒ Object
Besselian year at the time represented by self
.
Adapted from hpiers.obspm.fr/eop-pc/models/constants.html
145 146 147 |
# File 'lib/miriad.rb', line 145 def by 2000+(amjd-51544.5)/365.242189813 end |
#eqeq ⇒ Object
Equation of the Equinoxes at the time represented by self
.
Adapted from aa.usno.navy.mil/faq/docs/GAST.php
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/miriad.rb', line 228 def eqeq # The local variables here have been slightly renamed from the reference to # be more ruby-esque. Here is the mapping... # # Local Reference # jdut1 JD # d D # omega Omega (Greek letter) # dpsi Delta Psi (Greek letters) # eps epsilon (Greek letter) # The UT Julian date of the time of interest jdut1 = ajd + ut1_utc/(24*60*60) # Days and fraction of day since J2000 epoch d = jdut1 - J2000.ajd # Longitude of the ascending node of the Moon omega = 125.04 - 0.052954 * d # Mean Longitude of the Sun l = 280.47 + 0.98565 * d # Delta psi dpsi = -0.000319 * Math.sin(omega.d2r) \ -0.000024 * Math.sin(2*l.d2r) # Obliquity eps = 23.4393 - 0.0000004 * d # eqeq dpsi * Math.cos(eps.d2r) end |
#gast ⇒ Object
Greenwich Apparent Sidereal Time at the time represented by self
.
257 258 259 |
# File 'lib/miriad.rb', line 257 def gast (gmst + eqeq) % 24.0 end |
#gmst ⇒ Object
Greenwich Mean Sidereal Time at the time represented by self
.
Adapted from aa.usno.navy.mil/faq/docs/GAST.php
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/miriad.rb', line 197 def gmst # The local variables here have been slightly renamed from the reference to # be more ruby-esque. Here is the mapping... # # Local Reference # jdut1 JD # jd0 JD0 # h H # d D # d0 D0 # t T # The UT Julian date of the time of interest jdut1 = ajd + ut1_utc/(24*60*60) # Julian date of the previous midnight (0h) UT jd0 = (jdut1-0.5).floor + 0.5 # Hours of UT elapsed since jd0 h = (jdut1 - jd0) * 24.0 # Days and fraction of day since J2000 epoch d = jdut1 - J2000.ajd # Integer days (and a half) since epoch d0 = jd0 - J2000.ajd # Fractional centuries since epoch t = d/36525.0 # gmst (6.697374558 + 0.06570982441908 * d0 + 1.00273790935 * h + 0.000026 * t**2) % 24.0 end |
#last(longitude = 0.0) ⇒ Object
Local Apparent Sidereal Time in hours at the time represented by self
. longitude
is in degrees.
269 270 271 |
# File 'lib/miriad.rb', line 269 def last(longitude=0.0) (gast + longitude.d2h) % 24.0 end |
#lmst(longitude = 0.0) ⇒ Object
Local Mean Sidereal Time in hours at the time represented by self
. longitude
is in degrees.
263 264 265 |
# File 'lib/miriad.rb', line 263 def lmst(longitude=0.0) (gmst + longitude.d2h) % 24.0 end |
#to_utc ⇒ Object
A DateTime
object corresponding to the same time as self
, but with an offset of 0. Returns self
if self.offset == 0
.
175 176 177 |
# File 'lib/miriad.rb', line 175 def to_utc (offset == 0) ? self : new_offset(0) end |
#ut1 ⇒ Object
UT1 (expressed in hours) at the time represented by self
185 186 187 |
# File 'lib/miriad.rb', line 185 def ut1 ((amjd % 1) * 24 + ut1_utc/(60*60)) % 24 end |
#ut1_utc ⇒ Object
UT1-UTC (unit is seconds) at the time represented by self
This is an increasingly out-of-date approximation only. Taken from www.iers.org/products/6/11769/orig/bulletina-xxi-052.txt
165 166 167 168 169 170 171 |
# File 'lib/miriad.rb', line 165 def ut1_utc # TODO Get more accurate measurement of this value from usno d = ENV.has_key?('UT1_UTC') ? ENV['UT1_UTC'].to_f : 0.3987 - 0.00094 * (amjd - 54832) - ut2_ut1 d -= 1 if amjd < 54832 # 2009/01/01 (hack for leap second) d end |
#ut2_ut1 ⇒ Object
UT2-UT1 (unit is seconds) at the time represented by self
Taken from www.iers.org/products/6/11136/orig/bulletina-xx-042.txt
153 154 155 156 157 158 159 |
# File 'lib/miriad.rb', line 153 def ut2_ut1 pi2t=Math::PI*2*(by%1) ENV['UT2_UT1'] || 0.022 * Math.sin(pi2t) \ - 0.012 * Math.cos(pi2t) \ - 0.006 * Math.sin(2*pi2t) \ + 0.007 * Math.cos(2*pi2t) end |