astronoby 0.6.0 → 0.8.0

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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/.standard.yml +1 -0
  4. data/CHANGELOG.md +203 -3
  5. data/README.md +69 -288
  6. data/UPGRADING.md +267 -0
  7. data/docs/README.md +196 -0
  8. data/docs/angles.md +137 -0
  9. data/docs/celestial_bodies.md +107 -0
  10. data/docs/configuration.md +98 -0
  11. data/docs/coordinates.md +167 -0
  12. data/docs/ephem.md +85 -0
  13. data/docs/equinoxes_solstices_times.md +31 -0
  14. data/docs/glossary.md +152 -0
  15. data/docs/instant.md +139 -0
  16. data/docs/moon_phases.md +79 -0
  17. data/docs/observer.md +65 -0
  18. data/docs/reference_frames.md +138 -0
  19. data/docs/rise_transit_set_times.md +119 -0
  20. data/docs/twilight_times.md +123 -0
  21. data/lib/astronoby/aberration.rb +56 -31
  22. data/lib/astronoby/angle.rb +20 -16
  23. data/lib/astronoby/angles/dms.rb +2 -2
  24. data/lib/astronoby/angles/hms.rb +2 -2
  25. data/lib/astronoby/bodies/earth.rb +62 -0
  26. data/lib/astronoby/bodies/jupiter.rb +28 -0
  27. data/lib/astronoby/bodies/mars.rb +28 -0
  28. data/lib/astronoby/bodies/mercury.rb +32 -0
  29. data/lib/astronoby/bodies/moon.rb +51 -298
  30. data/lib/astronoby/bodies/neptune.rb +32 -0
  31. data/lib/astronoby/bodies/saturn.rb +37 -0
  32. data/lib/astronoby/bodies/solar_system_body.rb +232 -0
  33. data/lib/astronoby/bodies/sun.rb +33 -214
  34. data/lib/astronoby/bodies/uranus.rb +16 -0
  35. data/lib/astronoby/bodies/venus.rb +36 -0
  36. data/lib/astronoby/cache.rb +188 -0
  37. data/lib/astronoby/configuration.rb +92 -0
  38. data/lib/astronoby/constants.rb +17 -2
  39. data/lib/astronoby/constellation.rb +12 -0
  40. data/lib/astronoby/constellations/data.rb +42 -0
  41. data/lib/astronoby/constellations/finder.rb +35 -0
  42. data/lib/astronoby/constellations/repository.rb +20 -0
  43. data/lib/astronoby/coordinates/ecliptic.rb +2 -37
  44. data/lib/astronoby/coordinates/equatorial.rb +28 -10
  45. data/lib/astronoby/coordinates/horizontal.rb +0 -46
  46. data/lib/astronoby/corrections/light_time_delay.rb +90 -0
  47. data/lib/astronoby/data/constellations/constellation_names.dat +88 -0
  48. data/lib/astronoby/data/constellations/indexed_abbreviations.dat +88 -0
  49. data/lib/astronoby/data/constellations/radec_to_index.dat +238 -0
  50. data/lib/astronoby/data/constellations/sorted_declinations.dat +202 -0
  51. data/lib/astronoby/data/constellations/sorted_right_ascensions.dat +237 -0
  52. data/lib/astronoby/deflection.rb +187 -0
  53. data/lib/astronoby/distance.rb +9 -0
  54. data/lib/astronoby/ephem.rb +39 -0
  55. data/lib/astronoby/equinox_solstice.rb +22 -19
  56. data/lib/astronoby/errors.rb +4 -0
  57. data/lib/astronoby/events/moon_phases.rb +15 -13
  58. data/lib/astronoby/events/rise_transit_set_calculator.rb +376 -0
  59. data/lib/astronoby/events/rise_transit_set_event.rb +13 -0
  60. data/lib/astronoby/events/rise_transit_set_events.rb +13 -0
  61. data/lib/astronoby/events/twilight_calculator.rb +221 -0
  62. data/lib/astronoby/events/twilight_event.rb +28 -0
  63. data/lib/astronoby/events/twilight_events.rb +22 -115
  64. data/lib/astronoby/instant.rb +176 -0
  65. data/lib/astronoby/julian_date.rb +78 -0
  66. data/lib/astronoby/mean_obliquity.rb +24 -13
  67. data/lib/astronoby/nutation.rb +235 -42
  68. data/lib/astronoby/observer.rb +55 -0
  69. data/lib/astronoby/precession.rb +102 -18
  70. data/lib/astronoby/reference_frame.rb +50 -0
  71. data/lib/astronoby/reference_frames/apparent.rb +60 -0
  72. data/lib/astronoby/reference_frames/astrometric.rb +21 -0
  73. data/lib/astronoby/reference_frames/geometric.rb +20 -0
  74. data/lib/astronoby/reference_frames/mean_of_date.rb +38 -0
  75. data/lib/astronoby/reference_frames/topocentric.rb +72 -0
  76. data/lib/astronoby/time/greenwich_sidereal_time.rb +2 -2
  77. data/lib/astronoby/true_obliquity.rb +3 -3
  78. data/lib/astronoby/util/maths.rb +70 -73
  79. data/lib/astronoby/util/time.rb +455 -32
  80. data/lib/astronoby/vector.rb +36 -0
  81. data/lib/astronoby/velocity.rb +116 -0
  82. data/lib/astronoby/version.rb +1 -1
  83. data/lib/astronoby.rb +33 -5
  84. metadata +117 -24
  85. data/.tool-versions +0 -1
  86. data/Gemfile +0 -5
  87. data/Gemfile.lock +0 -80
  88. data/benchmark/README.md +0 -131
  89. data/benchmark/benchmark.rb +0 -259
  90. data/benchmark/data/imcce.csv.zip +0 -0
  91. data/benchmark/data/sun_calc.csv.zip +0 -0
  92. data/lib/astronoby/astronomical_models/ephemeride_lunaire_parisienne.rb +0 -143
  93. data/lib/astronoby/epoch.rb +0 -22
  94. data/lib/astronoby/events/observation_events.rb +0 -285
  95. data/lib/astronoby/events/rise_transit_set_iteration.rb +0 -218
  96. data/lib/astronoby/util/astrodynamics.rb +0 -60
@@ -0,0 +1,202 @@
1
+ -85.0
2
+ -82.5
3
+ -76.0
4
+ -75.0
5
+ -70.0
6
+ -67.5
7
+ -65.0
8
+ -64.0
9
+ -63.583333333333336
10
+ -61.0
11
+ -60.0
12
+ -59.0
13
+ -58.5
14
+ -58.0
15
+ -57.5
16
+ -57.0
17
+ -56.5
18
+ -55.0
19
+ -54.5
20
+ -54.0
21
+ -53.5
22
+ -53.166666666666664
23
+ -53.0
24
+ -52.5
25
+ -51.5
26
+ -51.0
27
+ -50.75
28
+ -50.0
29
+ -49.0
30
+ -48.166666666666664
31
+ -48.0
32
+ -46.5
33
+ -46.0
34
+ -45.5
35
+ -44.0
36
+ -43.0
37
+ -42.0
38
+ -40.0
39
+ -39.75
40
+ -39.583333333333336
41
+ -37.0
42
+ -36.75
43
+ -36.0
44
+ -35.0
45
+ -33.0
46
+ -31.166666666666668
47
+ -30.0
48
+ -29.5
49
+ -29.166666666666668
50
+ -28.0
51
+ -27.25
52
+ -26.5
53
+ -25.5
54
+ -24.583333333333332
55
+ -24.5
56
+ -24.383333333333333
57
+ -24.0
58
+ -22.0
59
+ -20.0
60
+ -19.25
61
+ -19.0
62
+ -18.25
63
+ -17.0
64
+ -16.0
65
+ -15.0
66
+ -14.5
67
+ -12.033333333333333
68
+ -11.666666666666666
69
+ -11.0
70
+ -10.0
71
+ -9.0
72
+ -8.0
73
+ -7.0
74
+ -6.0
75
+ -4.0
76
+ -3.25
77
+ -1.75
78
+ 0.0
79
+ 1.5
80
+ 1.75
81
+ 2.0
82
+ 2.75
83
+ 3.0
84
+ 4.0
85
+ 4.5
86
+ 5.5
87
+ 6.0
88
+ 6.25
89
+ 7.0
90
+ 7.5
91
+ 8.0
92
+ 8.5
93
+ 9.916666666666666
94
+ 10.0
95
+ 11.0
96
+ 11.833333333333334
97
+ 12.0
98
+ 12.5
99
+ 12.833333333333334
100
+ 13.5
101
+ 14.0
102
+ 14.333333333333334
103
+ 15.0
104
+ 15.5
105
+ 15.75
106
+ 16.0
107
+ 16.166666666666668
108
+ 17.5
109
+ 18.0
110
+ 18.5
111
+ 19.0
112
+ 19.166666666666668
113
+ 19.5
114
+ 20.0
115
+ 20.5
116
+ 21.0
117
+ 21.083333333333332
118
+ 21.25
119
+ 21.5
120
+ 22.0
121
+ 22.833333333333332
122
+ 23.5
123
+ 23.75
124
+ 25.0
125
+ 25.5
126
+ 26.0
127
+ 27.0
128
+ 27.25
129
+ 27.5
130
+ 28.0
131
+ 28.5
132
+ 29.0
133
+ 30.0
134
+ 30.666666666666668
135
+ 30.75
136
+ 31.333333333333332
137
+ 32.0
138
+ 32.083333333333336
139
+ 33.0
140
+ 33.5
141
+ 34.0
142
+ 34.5
143
+ 35.0
144
+ 35.5
145
+ 36.0
146
+ 36.5
147
+ 36.75
148
+ 39.75
149
+ 40.0
150
+ 42.0
151
+ 43.5
152
+ 43.75
153
+ 44.0
154
+ 44.5
155
+ 45.0
156
+ 46.0
157
+ 47.0
158
+ 47.5
159
+ 48.0
160
+ 48.5
161
+ 50.0
162
+ 50.5
163
+ 51.5
164
+ 52.5
165
+ 52.75
166
+ 53.0
167
+ 54.0
168
+ 54.833333333333336
169
+ 55.0
170
+ 55.5
171
+ 56.0
172
+ 56.25
173
+ 57.0
174
+ 57.5
175
+ 58.0
176
+ 58.5
177
+ 59.083333333333336
178
+ 59.5
179
+ 60.0
180
+ 60.916666666666664
181
+ 61.5
182
+ 62.0
183
+ 63.0
184
+ 64.0
185
+ 66.0
186
+ 66.5
187
+ 67.0
188
+ 68.0
189
+ 70.0
190
+ 73.5
191
+ 75.0
192
+ 77.0
193
+ 80.0
194
+ 82.0
195
+ 85.0
196
+ 86.0
197
+ 86.16666666666667
198
+ 86.5
199
+ 88.0
200
+ 89.0
201
+ 89.5
202
+ 90.0
@@ -0,0 +1,237 @@
1
+ 0.06666666666666667
2
+ 0.14166666666666666
3
+ 0.16666666666666666
4
+ 0.3333333333333333
5
+ 0.7166666666666667
6
+ 0.75
7
+ 0.85
8
+ 0.8666666666666667
9
+ 1.1166666666666667
10
+ 1.3333333333333333
11
+ 1.3666666666666667
12
+ 1.4083333333333334
13
+ 1.5833333333333333
14
+ 1.6666666666666667
15
+ 1.7
16
+ 1.8333333333333333
17
+ 1.9083333333333334
18
+ 1.9166666666666667
19
+ 2.0
20
+ 2.0416666666666665
21
+ 2.1666666666666665
22
+ 2.3333333333333335
23
+ 2.4166666666666665
24
+ 2.433333333333333
25
+ 2.5166666666666666
26
+ 2.566666666666667
27
+ 2.65
28
+ 2.6666666666666665
29
+ 2.716666666666667
30
+ 3.0
31
+ 3.1
32
+ 3.1666666666666665
33
+ 3.2
34
+ 3.283333333333333
35
+ 3.3333333333333335
36
+ 3.3666666666666667
37
+ 3.4166666666666665
38
+ 3.5
39
+ 3.5083333333333333
40
+ 3.5833333333333335
41
+ 3.75
42
+ 3.8333333333333335
43
+ 3.8666666666666667
44
+ 4.0
45
+ 4.083333333333333
46
+ 4.266666666666667
47
+ 4.333333333333333
48
+ 4.5
49
+ 4.583333333333333
50
+ 4.616666666666666
51
+ 4.666666666666667
52
+ 4.691666666666666
53
+ 4.7
54
+ 4.75
55
+ 4.833333333333333
56
+ 4.916666666666667
57
+ 4.966666666666667
58
+ 5.0
59
+ 5.083333333333333
60
+ 5.333333333333333
61
+ 5.5
62
+ 5.6
63
+ 5.7
64
+ 5.766666666666667
65
+ 5.833333333333333
66
+ 5.883333333333334
67
+ 6.0
68
+ 6.1
69
+ 6.116666666666666
70
+ 6.166666666666667
71
+ 6.216666666666667
72
+ 6.241666666666666
73
+ 6.308333333333334
74
+ 6.5
75
+ 6.533333333333333
76
+ 6.583333333333333
77
+ 6.8
78
+ 6.833333333333333
79
+ 6.933333333333334
80
+ 7.0
81
+ 7.016666666666667
82
+ 7.2
83
+ 7.366666666666666
84
+ 7.5
85
+ 7.666666666666667
86
+ 7.75
87
+ 7.808333333333334
88
+ 7.883333333333334
89
+ 7.925
90
+ 7.966666666666667
91
+ 8.0
92
+ 8.083333333333334
93
+ 8.166666666666666
94
+ 8.366666666666667
95
+ 8.416666666666666
96
+ 8.45
97
+ 8.583333333333334
98
+ 8.833333333333334
99
+ 9.033333333333333
100
+ 9.083333333333334
101
+ 9.166666666666666
102
+ 9.25
103
+ 9.366666666666667
104
+ 9.583333333333334
105
+ 9.75
106
+ 9.883333333333333
107
+ 10.166666666666666
108
+ 10.25
109
+ 10.5
110
+ 10.583333333333334
111
+ 10.666666666666666
112
+ 10.75
113
+ 10.783333333333333
114
+ 10.833333333333334
115
+ 11.0
116
+ 11.25
117
+ 11.333333333333334
118
+ 11.5
119
+ 11.516666666666667
120
+ 11.833333333333334
121
+ 11.866666666666667
122
+ 12.0
123
+ 12.083333333333334
124
+ 12.25
125
+ 12.333333333333334
126
+ 12.583333333333334
127
+ 12.833333333333334
128
+ 13.0
129
+ 13.25
130
+ 13.5
131
+ 13.583333333333334
132
+ 13.666666666666666
133
+ 13.958333333333334
134
+ 14.0
135
+ 14.033333333333333
136
+ 14.166666666666666
137
+ 14.25
138
+ 14.416666666666666
139
+ 14.5
140
+ 14.533333333333333
141
+ 14.666666666666666
142
+ 14.75
143
+ 14.916666666666666
144
+ 15.05
145
+ 15.083333333333334
146
+ 15.166666666666666
147
+ 15.183333333333334
148
+ 15.25
149
+ 15.333333333333334
150
+ 15.433333333333334
151
+ 15.666666666666666
152
+ 15.75
153
+ 15.916666666666666
154
+ 16.0
155
+ 16.033333333333335
156
+ 16.083333333333332
157
+ 16.166666666666668
158
+ 16.266666666666666
159
+ 16.333333333333332
160
+ 16.375
161
+ 16.420833333333334
162
+ 16.533333333333335
163
+ 16.583333333333332
164
+ 16.75
165
+ 16.833333333333332
166
+ 17.0
167
+ 17.166666666666668
168
+ 17.25
169
+ 17.5
170
+ 17.583333333333332
171
+ 17.6
172
+ 17.666666666666668
173
+ 17.833333333333332
174
+ 17.966666666666665
175
+ 18.0
176
+ 18.175
177
+ 18.233333333333334
178
+ 18.25
179
+ 18.366666666666667
180
+ 18.425
181
+ 18.583333333333332
182
+ 18.662222222222223
183
+ 18.866666666666667
184
+ 19.0
185
+ 19.083333333333332
186
+ 19.166666666666668
187
+ 19.25
188
+ 19.258333333333333
189
+ 19.358333333333334
190
+ 19.4
191
+ 19.416666666666668
192
+ 19.666666666666668
193
+ 19.766666666666666
194
+ 19.833333333333332
195
+ 20.0
196
+ 20.141666666666666
197
+ 20.166666666666668
198
+ 20.25
199
+ 20.3
200
+ 20.333333333333332
201
+ 20.416666666666668
202
+ 20.533333333333335
203
+ 20.536666666666665
204
+ 20.566666666666666
205
+ 20.6
206
+ 20.666666666666668
207
+ 20.833333333333332
208
+ 20.875
209
+ 20.916666666666668
210
+ 21.0
211
+ 21.05
212
+ 21.116666666666667
213
+ 21.25
214
+ 21.333333333333332
215
+ 21.416666666666668
216
+ 21.466666666666665
217
+ 21.666666666666668
218
+ 21.733333333333334
219
+ 21.866666666666667
220
+ 21.875
221
+ 21.908333333333335
222
+ 21.966666666666665
223
+ 22.0
224
+ 22.133333333333333
225
+ 22.316666666666666
226
+ 22.75
227
+ 22.816666666666666
228
+ 22.866666666666667
229
+ 23.0
230
+ 23.166666666666668
231
+ 23.333333333333332
232
+ 23.5
233
+ 23.583333333333332
234
+ 23.75
235
+ 23.833333333333332
236
+ 23.916666666666668
237
+ 24.0
@@ -0,0 +1,187 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Astronoby
4
+ class Deflection
5
+ # Solar gravitational constant (m^3/s^2)
6
+ SOLAR_GRAVITATION_CONSTANT = 1.32712440017987e+20
7
+
8
+ # @param instant [Astronoby::Instant] the instant of the observation
9
+ # @param target_astrometric_position [Astronoby::Vector<Distance>] the
10
+ # astrometric position of the target
11
+ # @param ephem [Astronoby::Ephemeris] the ephemeris to use for the
12
+ # computation
13
+ def initialize(instant:, target_astrometric_position:, ephem:)
14
+ @instant = instant
15
+ @target_astrometric_position = target_astrometric_position
16
+ @ephem = ephem
17
+ end
18
+
19
+ # @return [Astronoby::Vector<Distance>] corrected position of the target
20
+ def corrected_position
21
+ Astronoby::Vector[
22
+ *(target_position + deflection_vector)
23
+ .map { |au| Astronoby::Distance.from_au(au) }
24
+ ]
25
+ end
26
+
27
+ private
28
+
29
+ def tt
30
+ @tt ||= @instant.tt
31
+ end
32
+
33
+ def earth_geometric
34
+ Earth.compute_geometric(ephem: @ephem, instant: @instant)
35
+ end
36
+
37
+ def sun_geometric
38
+ Sun.compute_geometric(ephem: @ephem, instant: @instant)
39
+ end
40
+
41
+ def observer_position
42
+ @observer_position ||= earth_geometric.position.map(&:au)
43
+ end
44
+
45
+ def target_position
46
+ @target_position ||= @target_astrometric_position.map(&:au)
47
+ end
48
+
49
+ def sun_position
50
+ @sun_position ||= sun_geometric.position.map(&:au)
51
+ end
52
+
53
+ def light_travel_time
54
+ @light_travel_time ||=
55
+ target_position.magnitude / Astronoby::Velocity.light_speed.aupd
56
+ end
57
+
58
+ def deflector_to_observer_position
59
+ sun_position - observer_position
60
+ end
61
+
62
+ def closest_deflector_to_target_position
63
+ observer_position + target_position - deflector_position_at_closest
64
+ end
65
+
66
+ def closest_deflector_to_observer_position
67
+ @closest_deflector_to_observer_position ||=
68
+ observer_position - deflector_position_at_closest
69
+ end
70
+
71
+ # Compute light-time difference for the point where light ray is closest to
72
+ # deflector
73
+ def closest_approach_time_diff
74
+ @closest_approach_time_diff ||=
75
+ Util::Maths.dot_product(
76
+ target_position / target_position.magnitude,
77
+ deflector_to_observer_position
78
+ ) / Astronoby::Velocity.light_speed.aupd
79
+ end
80
+
81
+ # Determine time when incoming photons were closest to the deflecting body
82
+ def time_at_closest_approach
83
+ @time_at_closest_approach ||= if closest_approach_time_diff > 0.0
84
+ tt - closest_approach_time_diff
85
+ elsif light_travel_time < closest_approach_time_diff
86
+ tt - light_travel_time
87
+ else
88
+ tt
89
+ end
90
+ end
91
+
92
+ # Get position of deflecting body at the time of closest approach
93
+ def deflector_position_at_closest
94
+ @deflector_position_at_closest ||=
95
+ Sun.compute_geometric(
96
+ ephem: @ephem,
97
+ instant: Instant.from_terrestrial_time(time_at_closest_approach)
98
+ ).position.map(&:au)
99
+ end
100
+
101
+ def observer_to_target_distance
102
+ @observer_to_target_distance ||= target_position.magnitude
103
+ end
104
+
105
+ def closest_deflector_to_target_distance
106
+ @closest_deflector_to_target_distance ||=
107
+ closest_deflector_to_target_position.magnitude
108
+ end
109
+
110
+ def closest_deflector_to_observer_distance
111
+ @closest_deflector_to_observer_distance ||=
112
+ closest_deflector_to_observer_position.magnitude
113
+ end
114
+
115
+ def observer_to_target_unit
116
+ @observer_to_target_unit ||=
117
+ target_position / observer_to_target_distance
118
+ end
119
+
120
+ def closest_deflector_to_target_unit
121
+ @closest_deflector_to_target_unit ||=
122
+ closest_deflector_to_target_position / closest_deflector_to_target_distance
123
+ end
124
+
125
+ def closest_deflector_to_observer_unit
126
+ @closest_deflector_to_observer_unit ||=
127
+ closest_deflector_to_observer_position / closest_deflector_to_observer_distance
128
+ end
129
+
130
+ def cos_angle_target
131
+ Util::Maths.dot_product(
132
+ observer_to_target_unit,
133
+ closest_deflector_to_target_unit
134
+ )
135
+ end
136
+
137
+ def cos_angle_deflector
138
+ Util::Maths.dot_product(
139
+ closest_deflector_to_target_unit,
140
+ closest_deflector_to_observer_unit
141
+ )
142
+ end
143
+
144
+ def cos_angle_observer
145
+ @cos_angle_observer ||= Util::Maths.dot_product(
146
+ closest_deflector_to_observer_unit,
147
+ observer_to_target_unit
148
+ )
149
+ end
150
+
151
+ # Calculate the relativistic deflection coefficient
152
+ # This implements Einstein's light deflection formula: α = 4GM/(c²r)
153
+ # where:
154
+ # - G is the gravitational constant
155
+ # - M is the mass of the deflecting body
156
+ # - c is the speed of light
157
+ # - r is the impact parameter (closest approach distance)
158
+ def relativistic_factor
159
+ 2.0 * SOLAR_GRAVITATION_CONSTANT / (
160
+ Astronoby::Velocity.light_speed.mps *
161
+ Astronoby::Velocity.light_speed.mps *
162
+ closest_deflector_to_observer_distance *
163
+ Constants::ASTRONOMICAL_UNIT_IN_METERS
164
+ )
165
+ end
166
+
167
+ def geometry_factor
168
+ 1.0 + cos_angle_deflector
169
+ end
170
+
171
+ def deflection_vector
172
+ return 0 if colinear?
173
+
174
+ relativistic_factor *
175
+ (
176
+ cos_angle_target * closest_deflector_to_observer_unit -
177
+ cos_angle_observer * closest_deflector_to_target_unit
178
+ ) / geometry_factor * observer_to_target_distance
179
+ end
180
+
181
+ # If deflector is nearly in line with target, make no correction
182
+ # (avoids numerical instability in nearly-collinear cases)
183
+ def colinear?
184
+ cos_angle_observer.abs > 0.99999999999
185
+ end
186
+ end
187
+ end
@@ -25,6 +25,11 @@ module Astronoby
25
25
  from_meters(meters)
26
26
  end
27
27
  alias_method :from_au, :from_astronomical_units
28
+
29
+ def vector_from_meters(array)
30
+ Vector.elements(array.map { from_meters(_1) })
31
+ end
32
+ alias_method :vector_from_m, :vector_from_meters
28
33
  end
29
34
 
30
35
  attr_reader :meters
@@ -69,6 +74,10 @@ module Astronoby
69
74
  meters.zero?
70
75
  end
71
76
 
77
+ def abs2
78
+ meters**2
79
+ end
80
+
72
81
  def hash
73
82
  [meters, self.class].hash
74
83
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ephem"
4
+
5
+ module Astronoby
6
+ class Ephem
7
+ # Download an ephemeris file.
8
+ #
9
+ # @param name [String] Name of the ephemeris file, supported by the Ephem
10
+ # gem
11
+ # @param target [String] Location where to store the file
12
+ # @return [Boolean] true if the download was successful, false otherwise
13
+ #
14
+ # @example Downloading de440t SPK from NASA JPL
15
+ # Astronoby::Ephem.download(name: "de440t.bsp", target: "tmp/de440t.bsp")
16
+ def self.download(name:, target:)
17
+ ::Ephem::Download.call(name: name, target: target)
18
+ end
19
+
20
+ # Load an ephemeris file.
21
+ #
22
+ # @param target [String] Path of the ephemeris file
23
+ # @return [::Ephem::SPK] Ephemeris object from the Ephem gem
24
+ #
25
+ # @example Loading previously downloaded de440t SPK from NASA JPL
26
+ # Astronoby::Ephem.load("tmp/de440t.bsp")
27
+ def self.load(target)
28
+ spk = ::Ephem::SPK.open(target)
29
+ unless ::Ephem::SPK::TYPES.include?(spk&.type)
30
+ raise(
31
+ EphemerisError,
32
+ "#{target} is not a valid type. Accepted: #{::Ephem::SPK::TYPES.join(", ")}"
33
+ )
34
+ end
35
+
36
+ spk
37
+ end
38
+ end
39
+ end