equationoftime 4.1.1 → 4.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.autotest +39 -0
  3. data/.gemtest +0 -0
  4. data/.minitest.rb +2 -0
  5. data/.ruby-version +1 -0
  6. data/.settings/org.eclipse.ltk.core.refactoring.prefs +2 -0
  7. data/CHANGELOG.rdoc +6 -0
  8. data/Gemfile +12 -0
  9. data/Gemfile.lock +44 -3
  10. data/Guardfile +29 -0
  11. data/{LICENSE.md → LICENSE.rdoc} +0 -0
  12. data/Manifest.txt +82 -0
  13. data/README.rdoc +66 -0
  14. data/Rakefile +60 -45
  15. data/equationoftime.gemspec +17 -9
  16. data/examples/Equation_of_Time.jpg +0 -0
  17. data/examples/analemma_data_generator.rb +58 -0
  18. data/examples/check_date_type.rb +60 -0
  19. data/examples/compare_geoc_long_ra.rb +44 -0
  20. data/examples/data_table_for_astro_dog.rb +45 -0
  21. data/examples/earth_rotation.rb +42 -0
  22. data/examples/eot_methods_list.rb +48 -0
  23. data/examples/eot_plot.r +57 -0
  24. data/examples/eot_suntimes.rb +149 -0
  25. data/examples/equation_of_time.py +186 -0
  26. data/examples/figure_1.jpg +0 -0
  27. data/examples/file_converter.rb +31 -0
  28. data/examples/from_readme.rb +14 -0
  29. data/examples/from_wiki.rb +46 -0
  30. data/examples/geo_locator.rb +16 -0
  31. data/examples/getjd.rb +45 -0
  32. data/examples/gmst_gast_non_sofa.rb +406 -0
  33. data/examples/input_suntimes.rb +24 -0
  34. data/examples/julian_day_formula.rb +29 -0
  35. data/examples/julian_day_formula.txt +12 -0
  36. data/examples/my_time_conversion.rb +21 -0
  37. data/examples/nutation_series.txt +678 -0
  38. data/examples/nutation_table5_3a.txt +682 -0
  39. data/examples/ptime.rb +162 -0
  40. data/examples/suntimes.rb +30 -0
  41. data/examples/suntimes_test.rb +50 -0
  42. data/examples/t_sofa.rb +8228 -0
  43. data/examples/test_celes.rb +51 -0
  44. data/examples/test_ceot.rb +55 -0
  45. data/examples/test_poly_eval.rb +32 -0
  46. data/examples/time_scales.rb +29 -0
  47. data/examples/times_year.rb +53 -0
  48. data/examples/usage_example.rb +26 -0
  49. data/examples/use_angles.rb +222 -0
  50. data/ext/{ceot/eot.c → eot/ceot.c} +1 -1
  51. data/ext/{ceot/eot.h → eot/ceot.h} +0 -0
  52. data/ext/{ceot/ceot.c → eot/eot.c} +2 -2
  53. data/ext/{ceot → eot}/extconf.rb +1 -1
  54. data/lib/eot.rb +2 -1
  55. data/lib/eot/angles.rb +28 -28
  56. data/lib/eot/constants.rb +2 -0
  57. data/lib/eot/displays.rb +17 -17
  58. data/lib/eot/eot.so +0 -0
  59. data/lib/eot/geo_lat_lng_smt.rb +44 -31
  60. data/lib/eot/init.rb +20 -19
  61. data/lib/eot/nutation.rb +1 -1
  62. data/lib/eot/times.rb +22 -22
  63. data/lib/eot/utilities.rb +5 -5
  64. data/lib/eot/version.rb +2 -6
  65. data/test/aliased_angles_spec.rb +239 -0
  66. data/test/aliased_displays_spec.rb +105 -0
  67. data/test/aliased_utilities_spec.rb +36 -0
  68. data/test/angles_spec.rb +264 -0
  69. data/test/constants_spec.rb +20 -0
  70. data/test/displays_spec.rb +110 -0
  71. data/test/geo_spec.rb +38 -0
  72. data/test/init_spec.rb +44 -0
  73. data/test/nutation_spec.rb +37 -0
  74. data/test/spec_config.rb +8 -0
  75. data/test/times_spec.rb +133 -0
  76. data/test/utilities_spec.rb +35 -0
  77. metadata +109 -115
  78. data/.gitignore +0 -24
  79. data/.rvmrc +0 -1
  80. data/README.md +0 -83
  81. data/README2.txt +0 -70
  82. data/wiki.md +0 -43
  83. data/wiki2.md +0 -4
@@ -0,0 +1,51 @@
1
+ #require_relative 'celes_core'
2
+ require 'celes'
3
+
4
+ begin
5
+ require 'eot'
6
+ rescue LoadError
7
+ lib = File.expand_path('../../lib', __FILE__)
8
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
+ require 'eot'
10
+ end
11
+
12
+ eot = Eot.new
13
+
14
+ # Celes.methods.sort.each {|m| p m }
15
+
16
+ dt = DateTime.now.to_time.utc.to_datetime
17
+ jd = Celes.cal2jd(dt.year, dt.month, dt.day)
18
+
19
+ ajd = jd[0] + jd[1] + dt.day_fraction
20
+
21
+ p eot.ajd = ajd
22
+
23
+ p eot.delta_equinox()[0]
24
+ p Celes.nut06a(ajd,0)[0]
25
+
26
+ p eot.delta_equinox()[1]
27
+ p Celes.nut06a(ajd,0)[1]
28
+
29
+ p eot.delta_equinox()[2]
30
+ p Celes.falp03(eot.ta)
31
+
32
+ p eot.delta_equinox()[3]
33
+ p Celes.faom03(eot.ta)
34
+
35
+ require 'benchmark'
36
+
37
+ n = 5_000
38
+ Benchmark.bm do |x|
39
+ #~ x.report("celes") { n.times { Celes.cal2jd(dt.year, dt.month, dt.day) } }
40
+ #~ x.report("ruby") { n.times { DateTime.new(dt.year, dt.month, dt.day).jd } }
41
+ x.report("celes") { n.times { Celes.nut06a(ajd,0)[0] }}
42
+ x.report("celes") { n.times { Celes.nut06a(ajd,0)[1] }}
43
+ x.report("celes") { n.times { Celes.falp03(eot.ta) }}
44
+ x.report("celes") { n.times { Celes.faom03(eot.ta) }}
45
+
46
+ x.report("ruby") { n.times { eot.delta_equinox()[0] }}
47
+ x.report("ruby") { n.times { eot.delta_equinox()[1] }}
48
+ x.report("ruby") { n.times { eot.delta_equinox()[2] }}
49
+ x.report("ruby") { n.times { eot.delta_equinox()[3] }}
50
+ end
51
+
@@ -0,0 +1,55 @@
1
+ require 'benchmark'
2
+
3
+ begin
4
+ require 'eot'
5
+ rescue LoadError
6
+ lib = File.expand_path('../../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'eot'
9
+ end
10
+
11
+ require 'eot'
12
+
13
+ eot = Eot.new
14
+ eot.ajd = DateTime.now.to_time.utc.to_datetime.ajd
15
+ eot.ajd_to_datetime(eot.ajd)
16
+
17
+ p eot.eccentricity_Earth()
18
+ p eot.eoe(eot.ta)
19
+
20
+ n = 500_000
21
+ Benchmark.bm do |x|
22
+ x.report("reot") { n.times {eot.eccentricity_Earth()} }
23
+ x.report("ceot") { n.times {eot.eoe(eot.ta)} }
24
+ end
25
+ puts
26
+
27
+ p eot.center() * Eot::R2D
28
+ p eot.eqc(eot.ma, eot.ta) * Eot::R2D
29
+
30
+ Benchmark.bm do |x|
31
+ x.report("reot") {n.times {eot.center()}}
32
+ x.report("ceot") {n.times {eot.eqc(eot.ma, eot.ta)}}
33
+ end
34
+ puts
35
+
36
+ p eot.tl_Sun()
37
+ p eot.tl(eot.ma, eot.ta)
38
+
39
+ n = 500_000
40
+ Benchmark.bm do |x|
41
+ x.report("reot") { n.times {eot.tl_Sun()} }
42
+ x.report("ceot") { n.times {eot.tl(eot.ma, eot.ta)} }
43
+ end
44
+ puts
45
+
46
+ p eot.al_Sun()
47
+ p eot.al(eot.ma, eot.ta, eot.omega())
48
+
49
+ n = 500_000
50
+ Benchmark.bm do |x|
51
+ x.report("reot") { n.times {eot.al_Sun()} }
52
+ x.report("ceot") { n.times {eot.al(eot.ma, eot.ta, eot.omega())} }
53
+ end
54
+ puts
55
+
@@ -0,0 +1,32 @@
1
+ # test_poly_eval.rb
2
+
3
+ begin
4
+ require 'eot'
5
+ rescue LoadError
6
+ lib = File.expand_path('../../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'eot'
9
+ end
10
+
11
+ # From astro-algo gem
12
+ # class Array
13
+ # Evaluate polynomial using Horner's method.
14
+ # Array consists of coefficients of a polynomial, the
15
+ # coefficient of the highest order term first, the
16
+ # constant coefficient last.
17
+ # Returns evaluation of polynomial at +x+.
18
+ #
19
+ # Example: evaluate the polynomial x**2 - 0.5*x + 3.0 where x = 2.0
20
+ # [1.0, -0.5, 3.0].poly_eval(2.0) # => 6.0
21
+ # def poly_eval(x)
22
+ # self.inject(0.0) {|p, a|
23
+ # p*x + a}
24
+ # end
25
+ # end
26
+
27
+ my_array = [1.0, -0.5, 3.0]
28
+ my_array.inject(0.0) {|sum, n| p sum * 2.0 + n }
29
+
30
+ ecc = [-0.0000001235, -0.000042037, 0.016708617]
31
+ ta = 0.14
32
+ ecc.inject(0.0) {|sum, n| p sum * ta + n }
@@ -0,0 +1,29 @@
1
+ # eot_methods_list.rb
2
+
3
+ begin
4
+ require 'eot'
5
+ rescue LoadError
6
+ lib = File.expand_path('../../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'eot'
9
+ end
10
+ $DEBUG and set_trace_func proc { |event, file, line, id, binding, classname|
11
+ printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
12
+ }
13
+ eot = Eot.new
14
+ # puts eot.public_methods(false).sort
15
+ # puts eot.nil?
16
+ loop do
17
+ puts DateTime.now.to_time.utc.nsec.inspect
18
+ puts DateTime.jd(DateTime.now.to_time.utc.to_datetime.ajd + 0.5).to_time.nsec.inspect
19
+ sleep 0.7
20
+ puts
21
+ end
22
+
23
+ # puts Astro.solar_longitude(date)
24
+ # tjc = eot.time_julian_century( ajd)
25
+ # puts eot.tl_Sun(tjc)
26
+
27
+ # tjc = eot.time_julian_century( ajd + dt )
28
+ # puts eot.tl_Sun(tjc)
29
+
@@ -0,0 +1,53 @@
1
+ # a list of sunrise and sunset times for a year of dates.
2
+
3
+ begin
4
+ require 'eot'
5
+ rescue LoadError
6
+ lib = File.expand_path('../../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'eot'
9
+ end
10
+ require 'safe_yaml'
11
+ require 'time'
12
+
13
+ eot = Eot.new
14
+
15
+ # set your latitude and longitude first.
16
+ eot.latitude = 41.9474
17
+ eot.longitude = -88.74467
18
+
19
+ # make some start and finish dates.
20
+ start = "2014-1-1"
21
+ finish = "2014-12-31"
22
+
23
+ start_time = Time.utc( 2014, "jan", 1, 12, 0, 0 )
24
+ finish_time = Time.utc( 2014, "dec", 31, 12, 0, 0 )
25
+
26
+ start_jd = Date.parse(start).jd
27
+ finish_jd = Date.parse(finish).jd
28
+
29
+ fstr = "%b %d"
30
+
31
+ @data, @group, @group_id = [], {}, 1
32
+
33
+ (start_jd..finish_jd).each do |jd|
34
+ # date = DateTime.jd(jd + 0.5).to_date
35
+ eot.ajd = jd
36
+ rise = eot.sunrise_dt().to_time.to_json
37
+ trans = eot.local_noon_dt().to_time.to_json
38
+ set = eot.sunset_dt().to_time.to_json
39
+ @group = { "id" => @group_id,
40
+ "rise" => rise,
41
+ "noon" => trans,
42
+ "sset" => set
43
+ }
44
+ @data << @group
45
+ @group_id += 1
46
+ end
47
+
48
+ file_path = "rise_set_data.yml"
49
+ File::open( file_path, "w" ) do |f|
50
+ YAML.dump( @data, f )
51
+ end
52
+
53
+ puts "File rise_set_data.yml processed"
@@ -0,0 +1,26 @@
1
+ # usage_example.rb
2
+
3
+ begin
4
+ require 'eot'
5
+ rescue LoadError
6
+ lib = File.expand_path('../../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'eot'
9
+ end
10
+
11
+ eot = Eot.new()
12
+ # find what the defaults are set to
13
+ show = <<RAN
14
+ ajd = #{eot.ajd}
15
+ date = #{eot.date}
16
+ jd = #{eot.jd}
17
+ longitude = #{eot.longitude}
18
+ latitude = #{eot.latitude}
19
+ sunrise = #{eot.sunrise_dt}
20
+ trnasit = #{eot.local_noon_dt}
21
+ min eot = #{eot.time_eot}
22
+ sunset = #{eot.sunset_dt}
23
+ gasa = #{eot.tl_Aries}
24
+ RAN
25
+
26
+ puts show
@@ -0,0 +1,222 @@
1
+ # use_angles.rb
2
+
3
+ begin
4
+ require 'eot'
5
+ rescue LoadError
6
+ lib = File.expand_path('../../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'eot'
9
+ end
10
+
11
+
12
+ file = <<DISPLAY
13
+
14
+ This will explain how the equation of time is derived by showing each method that comprises the formula.
15
+
16
+ eot = Eot.new
17
+
18
+ Instance of Eot class eot = #{eot = Eot.new}
19
+
20
+
21
+ Set the class attribute ajd for the deisired date ex : eot.ajd = Date.parse("yyyy, mm, dd").jd.to_f
22
+
23
+ eot.ajd = Date.today.jd.to_f
24
+
25
+ eot.ajd = #{eot.ajd = Date.today.jd.to_f}
26
+
27
+ The class attribute ajd has been set to a nice whole number even though it is a Float class now.
28
+
29
+ The Astronomical Julian Day Number is a half day less than Julian Day Number with the fractional day time included when we DateTime class.
30
+
31
+ DateTime.now.day_fraction.to_f = #{DateTime.now.day_fraction.to_f}
32
+
33
+ DateTime class has the method day_fraction and Date class does not.
34
+
35
+ We used Date class which doesn't give us the UTC time of date. It yields your time zone date.
36
+
37
+ Let's just prove this.
38
+
39
+ Date.today.to_time.utc = #{Date.today.to_time.utc}
40
+
41
+ It looks like that was your midnight in UTC time.
42
+
43
+ Maybe we could get away with getting the ajd from that.
44
+
45
+ Date.today.to_time.utc.to_date.ajd.to_f = #{Date.today.to_time.utc.to_date.ajd.to_f}
46
+
47
+ No. That's a half day less than the Julian Day Number.
48
+
49
+ So let's start over setting the adj correctly for UTC using the DateTime class.
50
+
51
+ eot.ajd = DateTime.now.to_time.utc.to_datetime.ajd.to_f
52
+
53
+ eot.ajd = #{eot.ajd = DateTime.now.to_time.utc.to_datetime.ajd.to_f}
54
+
55
+
56
+ Because this gem is going to calculate the sunrise and sunset times it's okay to set the day for noon and is encouraged.
57
+
58
+ So go ahead and set the ajd using the Date class and jd method as was first done.
59
+
60
+ The class init.rb sets everything to defaults and one of them is today's datetime.jd
61
+
62
+ But for right now we won't do that so we get current angles of the present time UTC.
63
+
64
+
65
+
66
+ eot.ma is the solar Mean anomaly mu(M) and is called quite often hence the attribute.
67
+
68
+ eot.ma was set using eot.ma_Sun() method.
69
+
70
+ It is an angle with respect to perihelion of Earth orbit around Sun in an assumed circular orbit.
71
+
72
+ M is calculated within the nutation.rb file under delta_equinox() method and returned as the third element of an array.
73
+
74
+ eot.ma = #{eot.ma}
75
+
76
+ eot.ma_Sun() = #{eot.ma_Sun()}
77
+
78
+
79
+ angle one = eot.ma_Sun() - eot.ta_Sun()
80
+
81
+ a1 = #{eot.ma_Sun() - eot.ta_Sun()} degrees
82
+
83
+ a1 is a delta angle difference for mean and true anomalies in degrees.
84
+
85
+ True anomaly (nu) is the actual angle with respect to perihelion in an eliptical orbit.
86
+
87
+ It was calculated by using the equation of center formula which you may access also.
88
+
89
+ eot.center() = #{eot.center()} degrees.
90
+
91
+ nu = equation of center + M or mu or mean anomaly
92
+
93
+ The delta is M - nu.
94
+
95
+
96
+ The method inside the gem is called delta_orbit()
97
+
98
+ eot.delta_orbit = #{eot.delta_orbit} degrees
99
+
100
+ We could just change the sign of eot.center().
101
+
102
+ In fact let's just do that now. a1 = - eot.center()
103
+
104
+ - eot.center() = #{- eot.center()}
105
+
106
+
107
+ The next delta is calculated as follows.
108
+
109
+ lambda or apparent longitude of the Sun minus alpha or right ascension of the Sun.
110
+
111
+ a2 = lambda - alpha
112
+
113
+ lambda = mean longitude + equation of center
114
+
115
+ eot.gml_Sun() + eot.center() = #{eot.gml_Sun() + eot.center()} or
116
+
117
+ eot.tl_Sun = #{eot.tl_Sun}
118
+
119
+ Lambda is the \"ecliptic coordinate system\" angle of the sun.
120
+
121
+ Alpha is the Right Ascension of the sun in the celestial coordinate system.
122
+
123
+ alpha = eot.ra_Sun()
124
+
125
+ alpha = #{eot.ra_Sun()}
126
+
127
+ lambda - alpha = #{eot.tl_Sun - eot.ra_Sun()}
128
+
129
+ The method inside the gem is called delta_oblique.
130
+
131
+ eot.delta_oblique() = #{eot.delta_oblique()}
132
+
133
+
134
+ The sum of these two delta angles is the equation of time angle in degrees not time.
135
+
136
+ eot.eot() = #{eot.eot()}
137
+
138
+ That was for the time UTC now which was easy.
139
+
140
+
141
+ Now using your longitude to compute your mean solar transit from longitude / 15.0
142
+
143
+ my longitude is -88.74467 deg. so I'll set the longitude attribute in Eot class.
144
+
145
+ eot.longitude = #{eot.longitude = -88.74467}
146
+
147
+
148
+ So my mean solar transit UTC is 12.0 - my_longitude / 15.0
149
+
150
+ my_mean_noon = #{12.0 - -88.74467 / 15.0} hr.
151
+
152
+ Be sure to set everything for UTC noon before adding it to your longitude because we were doing angles for time now.
153
+
154
+ eot.ajd = #{eot.ajd = Date.today.jd.to_f}
155
+
156
+
157
+
158
+ Using the Eot class I may also compute it with eot.mean_local_noon_dt() method if I have the ajd set right.
159
+
160
+ eot.mean_local_noon_dt() = #{eot.mean_local_noon_dt()}
161
+
162
+ I'm showing what time mean noon for my_longitude normally is without the equation of time considered.
163
+
164
+ This time is true only four days a year. Lets get the right one for today to be sure.
165
+
166
+
167
+
168
+ We can add longitude plus equation of time as angles.
169
+
170
+ eot.longitude + eot.eot() = #{eot.longitude} + #{eot.eot()}
171
+
172
+ What's the time of solar transit here now?
173
+
174
+ 12.0 - (eot.longitude + eot.eot()) / 15.0 = #{12.0 - (eot.longitude + eot.eot()) / 15.0}
175
+
176
+ That looks about right.
177
+
178
+
179
+
180
+ Let's make a time out of that by converting it to a fractional day.
181
+
182
+ (12.0 - (eot.longitude + eot.eot()) / 15.0) / 24.0 = #{(12.0 - (eot.longitude + eot.eot()) / 15.0) / 24.0}
183
+
184
+ We'll add that to the ajd then.
185
+
186
+ ajd = Date.today.ajd.to_f
187
+
188
+ ajd = #{Date.today.ajd.to_f}
189
+
190
+ #{Date.today.ajd.to_f} + #{(12.0 - (eot.longitude + eot.eot()) / 15.0) / 24.0} = #{Date.today.ajd.to_f + (12.0 - (eot.longitude + eot.eot()) / 15.0) / 24.0}
191
+
192
+
193
+ There is a method in Eot class to make that a DateTime object.
194
+
195
+ eot.ajd_to_datetime(ajd + transit)
196
+
197
+ #{eot.ajd_to_datetime(Date.today.ajd.to_f + (12.0 - (eot.longitude + eot.eot()) / 15.0) / 24.0)}
198
+
199
+
200
+ Be sure to set your latitude attribute as well when you want to compute sunrise and sunset times for the days of interest.
201
+
202
+ eot.latitude = my_latitude
203
+
204
+
205
+ Your longitude and the GHA of the Sun will match at True Solar Transit time.
206
+
207
+ Check it here http://douglasallen.github.io/planets/ just put in the correct time and date then hit calculate.
208
+
209
+ Does GHA Sun = your longitude?
210
+
211
+ It's off a little bit because that site uses a different formula that is commonly used in older programs.
212
+
213
+ I get about 3 seconds difference in the EOT is all.
214
+ DISPLAY
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+ puts file