equationoftime 4.1.5 → 4.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/eot/angles.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # class Eot file = angles.rb
2
+ # methods for non delta angle calculations
2
3
  class Eot
3
- include Math
4
4
  # From angles.rb:
5
5
  # Apparent solar longitude = true longitude - aberation
6
6
  def al_sun
7
- Celes.anp(al(@ma, @ta, Celes.faom03(@ta)))
7
+ Celes.anp(al(@ma, @ta, omega))
8
8
  end
9
9
  alias_method :apparent_longitude, :al_sun
10
10
  alias_method :alsun, :al_sun
@@ -20,8 +20,7 @@ class Eot
20
20
  # From angles.rb:
21
21
  # solar declination
22
22
  def dec_sun
23
- asin(sin(Celes.nut06a(@ajd, 0)[1] + Celes.obl06(@ajd, 0)) *
24
- sin(al(@ma, @ta, Celes.faom03(@ta))))
23
+ sun_dec(al_sun, to_earth)
25
24
  end
26
25
  alias_method :declination, :dec_sun
27
26
 
@@ -37,10 +36,17 @@ class Eot
37
36
  # equation of equinox
38
37
  # used for true longitude of Aries
39
38
  # Depricated by Celes.gst06a()
39
+ # compinents are still used
40
+ # see: #cosine_to_earth and #angle_delta_psi
40
41
  def eq_of_equinox
41
- cos(Celes.nut06a(@ajd, 0)[1] +
42
- Celes.obl06(@ajd, 0)) *
43
- Celes.nut06a(@ajd, 0)[0]
42
+ Celes.ee06a(@ajd, 0.0)
43
+ end
44
+
45
+ # From angles.rb:
46
+ # Earth rotation angle (for comparison to tl_aries
47
+ # which uses gmst06)
48
+ def era
49
+ Celes.era00(@ajd, 0.0)
44
50
  end
45
51
 
46
52
  # From angles.rb:
@@ -50,17 +56,30 @@ class Eot
50
56
  ml(@ta)
51
57
  end
52
58
  alias_method :geometric_mean_longitude, :gml_sun
59
+ alias_method :ml_sun, :gml_sun
60
+
61
+ # From angles.rb:
62
+ # used by ha_sun method
63
+ # to select rise set and civil, nautical, astronomical twilights.
64
+ def choice(c)
65
+ case c
66
+ when 1
67
+ return 90.8333 # Sunrise and Sunset
68
+ when 2
69
+ return 96 # Civil Twilight
70
+ when 3
71
+ return 102 # Nautical Twilight
72
+ when 4
73
+ return 108 # Astronomical Twilight
74
+ end
75
+ end
53
76
 
54
77
  # From angles.rb:
55
78
  # horizon angle for provided geo coordinates
56
- # used for angles from transit to horizons
57
- def ha_sun
58
- zenith = 90.8333 # use other zeniths here for non commercial
59
- top = cosZ(zenith) - sin_dec_sun(dec_sun) * sin_lat(@latitude * D2R)
60
- bottom = cos_dec_sun(dec_sun) * cos_lat(@latitude * D2R)
61
- t_cosine = top / bottom
62
- t_cosine > 1.0 || t_cosine < -1.0 ? cos = 1.0 : cos = t_cosine
63
- acos(cos)
79
+ # used for angles from transit to horizons.
80
+ def ha_sun(c)
81
+ zenith = choice(c)
82
+ sun(zenith, dec_sun, @latitude)
64
83
  end
65
84
  alias_method :horizon_angle, :ha_sun
66
85
 
@@ -106,9 +125,10 @@ class Eot
106
125
  # From angles.rb:
107
126
  # solar right ascension
108
127
  def ra_sun
109
- y0 = sin(al(@ma, @ta, Celes.faom03(@ta))) * cos(Celes.nut06a(@ajd, 0)[1] +
110
- Celes.obl06(@ajd, 0))
111
- Celes.anp(PI + atan2(-y0, -cos(al(@ma, @ta, Celes.faom03(@ta)))))
128
+ y0 = sine_al_sun * cosine_to_earth
129
+ ra = sun_ra(y0, cosine_al_sun)
130
+ # Celes.anp(PI + atan2(-y0, -cosine_al_sun))
131
+ Celes.anp(PI + ra)
112
132
  end
113
133
  alias_method :right_ascension, :ra_sun
114
134
 
@@ -143,7 +163,7 @@ class Eot
143
163
  # From angles.rb:
144
164
  # true obliquity considers nutation
145
165
  def to_earth
146
- Celes.nut06a(@ajd, 0)[1] + Celes.obl06(@ajd, 0)
166
+ mo_earth + angle_delta_epsilon
147
167
  end
148
168
  alias_method :obliquity_correction, :to_earth
149
169
  alias_method :true_obliquity, :to_earth
data/lib/eot/constants.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # class Eot file = constants.rb
2
+ # has the constants used and more
2
3
  class Eot
3
4
  # Array result for time_julian_century default = [0.0, 0.0, 0.0, 0.0, 0.0]
4
5
  # A2000 = [0.0, 0.0, 0.0, 0.0, 0.0]
@@ -121,7 +122,7 @@ class Eot
121
122
 
122
123
  # Julian Date of Modified Julian Date zero
123
124
  # 1858, 11, 17, 0.0 midnight start of calendar reform = 2400000.5
124
- # MJD0 = 2400000.5
125
+ # MJD0 = 2400000.5
125
126
 
126
127
  # from desktop calculator PI = 3.1415926535897932384626433832795
127
128
  PI = 3.1415926535897932384626433832795
data/lib/eot/deltas.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # class Eot file = deltas.rb
2
+ # methods for angle deltas
2
3
  class Eot
3
4
  # From deltas.rb:
4
5
  # delta epsilon
@@ -1,6 +1,5 @@
1
1
  # class GeoLatLng file = geo_lat_lng_smt.rb
2
- # class for location lookup
3
- # in geo_lat_lng_smt.rb
2
+ # class for location coordinates lookup
4
3
  class GeoLatLng
5
4
  # Base address for Google maps api
6
5
  attr_reader :base_json
data/lib/eot/init.rb CHANGED
@@ -1,67 +1,71 @@
1
1
  # class Eot file = int.rb
2
+ # attributes, a setter and init method
2
3
  class Eot
3
4
  # From init.rb:
4
- # address used for GeoLatLng.addr
5
+ # address is a String ex: "houston, tx"
5
6
  attr_accessor :addr
6
7
 
7
8
  # From init.rb:
8
- # Astronomical Julian Day Number is an instance of DateTime class.
9
- # ajd or jd. Use ajd for time now and jd for suntimes. Initially
10
- # @ajd = DateTime.now.to_time.utc.to_datetime.jd.to_f
11
- attr_reader :ajd
9
+ # Astronomical Julian Day Number
10
+ # instance of Float class.
11
+ # ajd or jd. Use ajd for time now and jd for noon
12
+ # init sets ajd = DateTime.now.to_time.utc.to_datetime.jd.to_f
13
+ attr_accessor :ajd
12
14
 
13
- def ajd=(ajd)
14
- @ajd = ajd
15
- @ta = ((ajd - DJ00) / DJC).to_f
16
- @ma = Celes.falp03(@ta)
15
+ # From init.rb
16
+ # method to reset ma and ta after initialization
17
+ # init sets them using ajd initial Float value
18
+ # see: :ajd attribute
19
+ def ma_ta_set
20
+ @ta = ((@ajd - DJ00) / DJC).to_f
21
+ @ma = Celes.falp03(@ta)
17
22
  end
18
23
 
19
24
  # From init.rb:
20
- # @date is an instance of DateTime class.
21
- # When new Eot class is initialized @date = ajd_to_datetime(@ajd)
25
+ # Date
26
+ # instance of DateTime class
27
+ # initialized to = ajd_to_datetime(@ajd)
22
28
  attr_accessor :date
23
29
 
24
30
  # From init.rb:
25
- # Julian Day Number is an instance of DateTime class.
26
- # When new Eot class is initialized @jd = @ajd
31
+ # Julian Day Number
32
+ # instance of Float class
33
+ # initialized to = ajd
27
34
  attr_accessor :jd
28
35
 
29
36
  # From init.rb:
30
- # Latitude input is an instance of Float class.
31
- # When new Eot class is initialized @latitude = 0.0
32
- # if GeoLatLng class can't set it.
37
+ # Latitude input
38
+ # instance of Float class
39
+ # initialized to = 0.0
33
40
  attr_accessor :latitude
34
41
 
35
42
  # From init.rb:
36
- # Longitude input is an instance of Float class.
37
- # When new Eot class is initialized @longitude = 0.0
38
- # if GeoLatLng class can't set it.
43
+ # Longitude input
44
+ # instance of Float class
45
+ # initialized to = 0.0
39
46
  attr_accessor :longitude
40
47
 
41
48
  # From init.rb:
42
- # JCT gets called a lot so class attribute it.
43
- # Setting @ajd will set this and @ma
44
- # @ta = (( @ajd - DJ00 ) / DJC).to_f
49
+ # Julian Century gets called often
50
+ # instance of Float class
51
+ # ta = (( @ajd - DJ00 ) / DJC).to_f
45
52
  attr_accessor :ta
46
53
 
47
54
  # From init.rb:
48
- # Mean Anomaly gets called a lot so class attribute saves it.
49
- # @ma = Celes.falp03(@ta)
55
+ # Mean Anomaly gets called often
56
+ # instance of Float class
57
+ # ma = Celes.falp03(@ta) see: celes gem
50
58
  attr_accessor :ma
51
59
 
52
60
  # From init.rb:
53
61
  # Initialize to set attributes
54
- # You may use GeoLatLng to set up @latitude and @longitude
55
62
  def initialize
56
- @geo = GeoLatLng.new
57
- @addr = @geo.default_int
58
- @geo.addr = @addr
59
- @ajd = DateTime.now.to_time.utc.to_datetime.jd.to_f
60
- @date, @jd = ajd_to_datetime(@ajd), @ajd
61
- @geo.set_coordinates
62
- # queries could excede quotas or you get disconnected.
63
- @geo.lat.zero? ? @latitude = 0.0 : @latitude = @geo.lat
64
- @geo.lng.zero? ? @longitude = 0.0 : @longitude = @geo.lng
63
+ d = DateTime.now.to_time.utc.to_datetime
64
+ djm0, djm = Celes::cal2jd(d.year, d.month, d.day + d.day_fraction)
65
+ @ajd = djm0 + djm + 0.5
66
+ ma_ta_set
67
+ @date, @jd = ajd_to_datetime(@ajd), @ajd
68
+ @latitude, @longitude = 0.0, 0.0
65
69
  end
66
70
  end
67
71
 
@@ -79,8 +83,10 @@ if __FILE__ == $PROGRAM_NAME
79
83
  p eot.addr
80
84
  p eot.latitude
81
85
  p eot.longitude
86
+ list = eot.public_methods(false).sort
87
+ list.each { |i| puts i.to_sym }
82
88
  spec = File.expand_path('../../../test/eot', __FILE__)
83
89
  $LOAD_PATH.unshift(spec) unless $LOAD_PATH.include?(spec)
84
90
  require 'init_spec'
85
- system 'bundle exec ruby ~/workspace/equationoftime/test/eot/init_spec.rb'
91
+ # bundle exec rake
86
92
  end
@@ -1,4 +1,5 @@
1
1
  # class Eot file = time_displays.rb
2
+ # methods for time displays
2
3
  class Eot
3
4
  # From displays.rb
4
5
  # String formatter for + and - time
@@ -24,14 +25,24 @@ class Eot
24
25
  h = Integer(fraction * DAY_HOURS)
25
26
  m = Integer((fraction - h / DAY_HOURS) * DAY_MINUTES)
26
27
  s = Integer((fraction - h / 24.0 - m / DAY_MINUTES) * DAY_SECONDS)
27
- format('%02d', h) +
28
- ':' +
28
+ format('%02d:', h) +
29
+ # ':' +
29
30
  format('%02d', m) +
30
- ':' +
31
+ ':' +
31
32
  format('%02d', s)
32
33
  end
33
34
  alias_method :julian_period_day_fraction_to_time, :string_day_fraction_to_time
34
35
 
36
+ # From displays.rb
37
+ # radians to time method
38
+ def string_deg_to_time(radians = 0.0)
39
+ radians.nil? ? radians = 0.0 : radians
40
+ s, ihmsf = Celes.a2tf(3, radians)
41
+ f_string(s, ihmsf[0], ihmsf[1], ihmsf[2], ihmsf[3])
42
+ end
43
+
44
+ # From displays.rb
45
+ # displays + or - sign
35
46
  def sign_min(min)
36
47
  if min < 0.0
37
48
  sign = '-'
@@ -65,6 +76,8 @@ class Eot
65
76
  end
66
77
  alias_method :jd_to_date_string, :string_jd_to_date
67
78
 
79
+ # From displays.rb
80
+ # formats time components
68
81
  def format_time(h, m, s, ds)
69
82
  format('%02d', h) +
70
83
  ':' +
@@ -75,8 +88,10 @@ class Eot
75
88
  format('%3.3d', ds)
76
89
  end
77
90
 
91
+ # From displays.rb
92
+ # creates [h,m,s,ds] array from Time or DateTime
78
93
  def dt_parts(val)
79
- h = val.hour
94
+ h = val.hour
80
95
  m = val.min
81
96
  s = val.sec
82
97
  is = Integer(s)
@@ -84,6 +99,8 @@ class Eot
84
99
  [h, m, is, ds]
85
100
  end
86
101
 
102
+ # From displays.rb
103
+ # creates [h,m,s,ds] from hours Float
87
104
  def float_parts(val)
88
105
  hours = Integer(val % DAY_HOURS)
89
106
  mins = 60.0 * (val % DAY_HOURS - hours)
data/lib/eot/times.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # class Eot file = times.rb
2
+ # methods calculating times
2
3
  class Eot
3
4
  # From times.rb:
4
5
  # Pass in an AJD number
@@ -9,104 +10,75 @@ class Eot
9
10
 
10
11
  # From times.rb:
11
12
  # Uses @ajd attribute
12
- # Returns EOT as an AJD Julian number
13
- def eot_jd
14
- time_eot / DAY_MINUTES
13
+ # Returns astronomical twilight end as a DateTime
14
+ def astronomical_twilight_end_dt
15
+ ajd_to_datetime(astronomical_twilight_end_jd)
15
16
  end
16
17
 
17
18
  # From times.rb:
18
- # Uses @ajd and @longitude attributes
19
- # Returns DateTime object of local noon or solar transit
20
- def local_noon_dt
21
- ajd_to_datetime(@ajd - @longitude / 360.0 - eot_jd)
22
- end
23
-
24
- # From times.rb:
25
- # Uses @ajd and @longitude attributes
26
- # Returns DateTime object of local mean noon or solar transit
27
- def mean_local_noon_dt
28
- ajd_to_datetime(@ajd - @longitude / 360.0)
29
- end
30
-
31
- # From times.rb:
32
- # sets @ajd to DateTime.now
33
- # Returns EOT (equation of time) now in decimal minutes form
34
- def now
35
- @ajd = DateTime.now.to_time.utc.to_datetime.ajd
36
- @ta = (@ajd - DJ00) / DJC
37
- time_eot
19
+ # Uses @ajd attribute
20
+ # Returns astronomical twilight start as a DateTime
21
+ def astronomical_twilight_start_dt
22
+ ajd_to_datetime(astronomical_twilight_start_jd)
38
23
  end
39
24
 
40
25
  # From times.rb:
41
26
  # Uses @ajd attribute
42
- # Returns a DateTime object of local sunrise
43
- def sunrise_dt
44
- ajd_to_datetime(sunrise_jd)
27
+ # Returns civil twilight end as a DateTime
28
+ def civil_twilight_end_dt
29
+ ajd_to_datetime(civil_twilight_end_jd)
45
30
  end
46
31
 
47
32
  # From times.rb:
48
33
  # Uses @ajd attribute
49
- # Returns Sunrise as a Julian Day Number
50
- def sunrise_jd
51
- local_noon_dt.ajd - ha_sun / P2
34
+ # Returns civil twilight start as a DateTime
35
+ def civil_twilight_start_dt
36
+ ajd_to_datetime(civil_twilight_start_jd)
52
37
  end
53
38
 
54
39
  # From times.rb:
55
- # Uses @ajd attribute
56
- # Returns a DateTime object of local sunset
57
- def sunset_dt
58
- ajd_to_datetime(sunset_jd)
40
+ # Uses @ajd and @longitude attributes
41
+ # Returns DateTime object of local noon or solar transit
42
+ def local_noon_dt
43
+ ajd_to_datetime(mean_local_noon_jd - eot_jd)
59
44
  end
60
45
 
61
46
  # From times.rb:
62
47
  # Uses @ajd attribute
63
- # Returns Sunset as a Julian Day Number
64
- def sunset_jd
65
- local_noon_dt.ajd + ha_sun / P2
48
+ # Returns nautical twilight end as a DateTime
49
+ def nautical_twilight_end_dt
50
+ ajd_to_datetime(nautical_twilight_end_jd)
66
51
  end
67
52
 
68
53
  # From times.rb:
69
54
  # Uses @ajd attribute
70
- # Returns Oblique component of EOT in decimal minutes time
71
- def time_delta_oblique
72
- (tl_sun - ra_sun) * R2D * SM
55
+ # Returns nautical twilight start as a DateTime
56
+ def nautical_twilight_start_dt
57
+ ajd_to_datetime(nautical_twilight_start_jd)
73
58
  end
74
59
 
75
60
  # From times.rb:
76
- # Uses @ajd attribute
77
- # Returns Orbit component of EOT in decimal minutes time
78
- def time_delta_orbit
79
- (@ma - ta_sun) * R2D * SM
61
+ # sets @ajd to DateTime.now
62
+ # Returns EOT (equation of time) now in decimal minutes form
63
+ def now
64
+ @ajd = DateTime.now.to_time.utc.to_datetime.ajd
65
+ @ta = (@ajd - DJ00) / DJC
66
+ time_eot
80
67
  end
81
68
 
82
69
  # From times.rb:
83
70
  # Uses @ajd attribute
84
- # Returns EOT as a float for decimal minutes time
85
- def time_eot
86
- eot * R2D * SM
71
+ # Returns a DateTime object of local sunrise
72
+ def sunrise_dt
73
+ ajd_to_datetime(sunrise_jd)
87
74
  end
88
75
 
89
76
  # From times.rb:
90
- # All calculations with ( ta ) were based on this.
91
- # Julian Century Time is a fractional century
92
- # Julian Day Number DJ00 is subtracted from the JDN or AJDN and then divided
93
- # by days in a Julian Century.
94
- # Deprecated
95
- def time_julian_century
96
- t1 = (@ajd - DJ00) / DJC
97
- # t2 = t1 * t1
98
- # t3 = t1 * t2
99
- # t4 = t2 * t2
100
- # t5 = t2 * t3
101
- # t6 = t3 * t3
102
- # t7 = t3 * t4
103
- # t8 = t4 * t4
104
- # t9 = t4 * t5
105
- # t10 = t5 * t5
106
- # @ta = [ t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ]
107
- @ta = t1
77
+ # Uses @ajd attribute
78
+ # Returns a DateTime object of local sunset
79
+ def sunset_dt
80
+ ajd_to_datetime(sunset_jd)
108
81
  end
109
- alias_method :time_julian_centurey, :time_julian_century
110
82
  end
111
83
 
112
84
  if __FILE__ == $PROGRAM_NAME