ephem 0.5.2 → 0.6.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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +185 -0
  3. data/README.md +171 -15
  4. data/bin/ruby-ephem +1 -2
  5. data/lib/ephem/cli.rb +174 -100
  6. data/lib/ephem/computation/chebyshev_polynomial.rb +82 -110
  7. data/lib/ephem/core/calendar_calculations.rb +17 -26
  8. data/lib/ephem/core/constants/bodies.rb +2 -0
  9. data/lib/ephem/core/constants/time.rb +1 -1
  10. data/lib/ephem/core/orientation.rb +23 -7
  11. data/lib/ephem/core/state.rb +48 -13
  12. data/lib/ephem/core/vector.rb +92 -24
  13. data/lib/ephem/download.rb +77 -14
  14. data/lib/ephem/error.rb +3 -3
  15. data/lib/ephem/excerpt.rb +126 -105
  16. data/lib/ephem/io/binary_reader.rb +29 -8
  17. data/lib/ephem/io/daf.rb +1 -4
  18. data/lib/ephem/io/endianness_manager.rb +5 -18
  19. data/lib/ephem/io/record_data.rb +2 -20
  20. data/lib/ephem/io/record_parser.rb +1 -1
  21. data/lib/ephem/io/summary_manager.rb +24 -15
  22. data/lib/ephem/pck.rb +24 -7
  23. data/lib/ephem/segments/base_segment.rb +38 -20
  24. data/lib/ephem/segments/chebyshev_type2.rb +105 -58
  25. data/lib/ephem/segments/coverage.rb +66 -0
  26. data/lib/ephem/segments/orientation_segment.rb +17 -15
  27. data/lib/ephem/segments/orientation_source.rb +4 -2
  28. data/lib/ephem/segments/position_chain.rb +124 -0
  29. data/lib/ephem/segments/position_group.rb +24 -0
  30. data/lib/ephem/segments/segment.rb +87 -18
  31. data/lib/ephem/segments/segment_group.rb +19 -5
  32. data/lib/ephem/spk.rb +134 -11
  33. data/lib/ephem/version.rb +1 -1
  34. data/lib/ephem.rb +5 -3
  35. metadata +4 -10
  36. data/.rspec +0 -3
  37. data/.standard.yml +0 -3
  38. data/.tool-versions +0 -1
  39. data/CODE_OF_CONDUCT.md +0 -132
  40. data/Rakefile +0 -12
  41. data/benchmarks/run.rb +0 -431
  42. data/bin/console +0 -11
  43. data/bin/setup +0 -8
  44. data/lib/tasks/validate_accuracy.rake +0 -47
@@ -76,13 +76,13 @@ module Ephem
76
76
 
77
77
  # @param index [Integer] 0 for phi, 1 for theta, 2 for psi
78
78
  # @return [Numeric] the angle at the given index
79
- # @raise [Ephem::IndexError] if index is not 0, 1, or 2
79
+ # @raise [IndexError] if index is not 0, 1, or 2
80
80
  def [](index)
81
81
  case index
82
82
  when 0 then phi
83
83
  when 1 then theta
84
84
  when 2 then psi
85
- else raise IndexError, "Invalid index: #{index}"
85
+ else raise ::IndexError, "Invalid index: #{index}"
86
86
  end
87
87
  end
88
88
 
@@ -97,14 +97,30 @@ module Ephem
97
97
  [phi, theta, psi, rates, self.class].hash
98
98
  end
99
99
 
100
+ # @param other [Object] the object to compare with
101
+ # @return [Boolean] true if +other+ is an orientation with equal angles
102
+ # and rates (compared with +==+), false otherwise (including for
103
+ # objects of another class)
100
104
  def ==(other)
101
- unless other.is_a?(self.class)
102
- raise InvalidInputError, "Can only compare with another Orientation"
103
- end
105
+ return true if equal?(other)
106
+
107
+ other.instance_of?(self.class) &&
108
+ phi == other.phi && theta == other.theta && psi == other.psi &&
109
+ rates == other.rates
110
+ end
104
111
 
105
- to_a == other.to_a && rates == other.rates
112
+ # Strict equality, as used by Hash keys: angles and rates are compared
113
+ # with +eql?+, consistently with {#hash}.
114
+ #
115
+ # @param other [Object] the object to compare with
116
+ # @return [Boolean]
117
+ def eql?(other)
118
+ return true if equal?(other)
119
+
120
+ other.instance_of?(self.class) &&
121
+ phi.eql?(other.phi) && theta.eql?(other.theta) &&
122
+ psi.eql?(other.psi) && rates.eql?(other.rates)
106
123
  end
107
- alias_method :eql?, :==
108
124
 
109
125
  private
110
126
 
@@ -7,28 +7,29 @@ module Ephem
7
7
  # orbital motion and performing astronomical calculations.
8
8
  #
9
9
  # @example Create a state for a celestial object
10
- # position = Ephem::Vector.new(1.0, 2.0, 3.0)
11
- # velocity = Ephem::Vector.new(0.1, 0.2, 0.3)
12
- # state = Ephem::State.new(position, velocity)
10
+ # position = Ephem::Core::Vector.new(1.0, 2.0, 3.0)
11
+ # velocity = Ephem::Core::Vector.new(0.1, 0.2, 0.3)
12
+ # state = Ephem::Core::State.new(position, velocity)
13
13
  class State
14
- # @return [Ephem::Vector] The position vector of the object
14
+ # @return [Ephem::Core::Vector] The position vector of the object
15
15
  attr_reader :position
16
16
 
17
- # @return [Ephem::Vector] The velocity vector of the object
17
+ # @return [Ephem::Core::Vector] The velocity vector of the object
18
18
  attr_reader :velocity
19
19
 
20
20
  # Creates a new State instance.
21
21
  #
22
- # @param position [Ephem::Vector] The position vector
23
- # @param velocity [Ephem::Vector] The velocity vector
22
+ # @param position [Ephem::Core::Vector] The position vector
23
+ # @param velocity [Ephem::Core::Vector] The velocity vector
24
24
  #
25
- # @example Create a state at the solar system barycenter with zero velocity
26
- # position = Ephem::Vector.new(0.0, 0.0, 0.0)
27
- # velocity = Ephem::Vector.new(0.0, 0.0, 0.0)
28
- # state = Ephem::State.new(position, velocity)
25
+ # @example A state at the solar system barycenter with zero velocity
26
+ # position = Ephem::Core::Vector.new(0.0, 0.0, 0.0)
27
+ # velocity = Ephem::Core::Vector.new(0.0, 0.0, 0.0)
28
+ # state = Ephem::Core::State.new(position, velocity)
29
29
  def initialize(position, velocity)
30
30
  @position = position
31
31
  @velocity = velocity
32
+ freeze
32
33
  end
33
34
 
34
35
  # Creates a State instance from arrays of position and velocity
@@ -38,12 +39,12 @@ module Ephem
38
39
  # @param velocity [Array<Numeric>] Array of [vx, vy, vz] velocity
39
40
  # components
40
41
  #
41
- # @return [Ephem::State] A new State instance
42
+ # @return [Ephem::Core::State] A new State instance
42
43
  #
43
44
  # @example Create a state from arrays
44
45
  # position = [1.0, 2.0, 3.0]
45
46
  # velocity = [0.1, 0.2, 0.3]
46
- # state = Ephem::State.from_arrays(position, velocity)
47
+ # state = Ephem::Core::State.from_arrays(position, velocity)
47
48
  def self.from_arrays(position, velocity)
48
49
  new(
49
50
  Vector.new(position[0], position[1], position[2]),
@@ -66,6 +67,40 @@ module Ephem
66
67
  def to_arrays
67
68
  [position.to_a, velocity.to_a]
68
69
  end
70
+
71
+ # Generates a hash value for the state.
72
+ #
73
+ # @return [Integer] Hash value based on position, velocity and class
74
+ def hash
75
+ [position, velocity, self.class].hash
76
+ end
77
+
78
+ # Checks equality with another state.
79
+ #
80
+ # @param other [Object] The object to compare with
81
+ #
82
+ # @return [Boolean] true if other is a State with equal position and
83
+ # velocity vectors, false otherwise
84
+ #
85
+ # @example Check if two states are equal
86
+ # state1 == state2
87
+ def ==(other)
88
+ other.instance_of?(self.class) &&
89
+ position == other.position &&
90
+ velocity == other.velocity
91
+ end
92
+
93
+ # Checks strict equality with another state, as used by Hash keys.
94
+ #
95
+ # @param other [Object] The object to compare with
96
+ #
97
+ # @return [Boolean] true if other is a State whose position and velocity
98
+ # vectors are eql?, false otherwise
99
+ def eql?(other)
100
+ other.instance_of?(self.class) &&
101
+ position.eql?(other.position) &&
102
+ velocity.eql?(other.velocity)
103
+ end
69
104
  end
70
105
  end
71
106
  end
@@ -7,11 +7,11 @@ module Ephem
7
7
  # mechanics and astronomical coordinate transformations.
8
8
  #
9
9
  # @example Create a vector representing a position in space
10
- # position = Ephem::Vector.new(1.0, 2.0, 3.0)
10
+ # position = Ephem::Core::Vector.new(1.0, 2.0, 3.0)
11
11
  #
12
12
  # @example Calculate the cross product of two vectors
13
- # pos = Ephem::Vector.new(1.0, 0.0, 0.0)
14
- # vel = Ephem::Vector.new(0.0, 1.0, 0.0)
13
+ # pos = Ephem::Core::Vector.new(1.0, 0.0, 0.0)
14
+ # vel = Ephem::Core::Vector.new(0.0, 1.0, 0.0)
15
15
  # angular_momentum = pos.cross(vel)
16
16
  class Vector
17
17
  # @return [Numeric] x component of the vector
@@ -32,7 +32,7 @@ module Ephem
32
32
  # @raise [Ephem::InvalidInputError] if any component is not numeric
33
33
  #
34
34
  # @example Create a vector at the origin
35
- # vector = Ephem::Vector.new(0, 0, 0)
35
+ # vector = Ephem::Core::Vector.new(0, 0, 0)
36
36
  def initialize(x, y, z)
37
37
  unless x.is_a?(Numeric) && y.is_a?(Numeric) && z.is_a?(Numeric)
38
38
  raise InvalidInputError, "Vector components must be numeric"
@@ -50,19 +50,19 @@ module Ephem
50
50
  # @param y [Numeric] The y component of the vector
51
51
  # @param z [Numeric] The z component of the vector
52
52
  #
53
- # @return [Ephem::Vector] A new vector instance
53
+ # @return [Ephem::Core::Vector] A new vector instance
54
54
  #
55
55
  # @example Create a vector using square bracket notation
56
- # vector = Ephem::Vector[1, 2, 3]
56
+ # vector = Ephem::Core::Vector[1, 2, 3]
57
57
  def self.[](x, y, z)
58
58
  new(x, y, z)
59
59
  end
60
60
 
61
61
  # Adds two vectors.
62
62
  #
63
- # @param other [Ephem::Vector] The vector to add
63
+ # @param other [Ephem::Core::Vector] The vector to add
64
64
  #
65
- # @return [Ephem::Vector] A new vector representing the sum
65
+ # @return [Ephem::Core::Vector] A new vector representing the sum
66
66
  #
67
67
  # @example Add two position vectors
68
68
  # sum = vector1 + vector2
@@ -72,9 +72,9 @@ module Ephem
72
72
 
73
73
  # Subtracts two vectors.
74
74
  #
75
- # @param other [Ephem::Vector] The vector to subtract
75
+ # @param other [Ephem::Core::Vector] The vector to subtract
76
76
  #
77
- # @return [Ephem::Vector] A new vector representing the difference
77
+ # @return [Ephem::Core::Vector] A new vector representing the difference
78
78
  #
79
79
  # @example Calculate relative position
80
80
  # relative_position = position1 - position2
@@ -82,9 +82,65 @@ module Ephem
82
82
  self.class.new(x - other.x, y - other.y, z - other.z)
83
83
  end
84
84
 
85
+ # Multiplies the vector by a scalar.
86
+ #
87
+ # @param other [Numeric] The factor to multiply each component by
88
+ #
89
+ # @return [Ephem::Core::Vector] A new vector scaled by the given factor
90
+ #
91
+ # @raise [Ephem::InvalidInputError] if other is not numeric
92
+ #
93
+ # @example Convert a velocity from km/s to km/day
94
+ # velocity_per_day = velocity_per_second * 86_400
95
+ def *(other)
96
+ unless other.is_a?(Numeric)
97
+ raise InvalidInputError, "Can only multiply a Vector by a Numeric"
98
+ end
99
+
100
+ self.class.new(x * other, y * other, z * other)
101
+ end
102
+
103
+ # Divides the vector by a scalar.
104
+ #
105
+ # Components are always divided as Floats, so
106
+ # +Vector[1, 2, 3] / 2+ is +Vector[0.5, 1.0, 1.5]+ whatever the
107
+ # component and divisor types.
108
+ #
109
+ # Dividing by zero never raises: like Float division, it yields
110
+ # Infinity, -Infinity or NaN components, for Integer and Float
111
+ # components alike.
112
+ #
113
+ # @param other [Numeric] The divisor applied to each component
114
+ #
115
+ # @return [Ephem::Core::Vector] A new vector with Float components
116
+ #
117
+ # @raise [Ephem::InvalidInputError] if other is not numeric
118
+ #
119
+ # @example Convert a velocity from km/day to km/s
120
+ # velocity_per_second = velocity_per_day / 86_400
121
+ def /(other)
122
+ unless other.is_a?(Numeric)
123
+ raise InvalidInputError, "Can only divide a Vector by a Numeric"
124
+ end
125
+
126
+ divisor = other.to_f
127
+ self.class.new(x / divisor, y / divisor, z / divisor)
128
+ end
129
+
130
+ # Negates the vector.
131
+ #
132
+ # @return [Ephem::Core::Vector] A new vector pointing in the opposite
133
+ # direction
134
+ #
135
+ # @example Reverse a center-to-target vector
136
+ # target_to_center = -center_to_target
137
+ def -@
138
+ self.class.new(-x, -y, -z)
139
+ end
140
+
85
141
  # Calculates the dot product with another vector.
86
142
  #
87
- # @param other [Ephem::Vector] The vector to calculate dot product with
143
+ # @param other [Ephem::Core::Vector] The vector to dot with
88
144
  #
89
145
  # @return [Numeric] The dot product of the two vectors
90
146
  #
@@ -96,9 +152,9 @@ module Ephem
96
152
 
97
153
  # Calculates the cross product with another vector.
98
154
  #
99
- # @param other [Ephem::Vector] The vector to calculate cross product with
155
+ # @param other [Ephem::Core::Vector] The vector to cross with
100
156
  #
101
- # @return [Ephem::Vector] A new vector representing the cross product
157
+ # @return [Ephem::Core::Vector] The cross product
102
158
  #
103
159
  # @example Calculate angular momentum (position × velocity)
104
160
  # angular_momentum = position.cross(velocity)
@@ -156,7 +212,7 @@ module Ephem
156
212
  when 0 then x
157
213
  when 1 then y
158
214
  when 2 then z
159
- else raise IndexError, "Invalid index: #{index}"
215
+ else raise ::IndexError, "Invalid index: #{index}"
160
216
  end
161
217
  end
162
218
 
@@ -167,24 +223,36 @@ module Ephem
167
223
  [x, y, z, self.class].hash
168
224
  end
169
225
 
170
- # Checks equality with another vector.
226
+ # Checks equality with another object. Components are compared with
227
+ # +==+, so +Vector[1, 2, 3] == Vector[1.0, 2.0, 3.0]+.
171
228
  #
172
- # @param other [Ephem::Vector] The vector to compare with
229
+ # @param other [Object] The object to compare with
173
230
  #
174
- # @return [Boolean] true if vectors are equal, false otherwise
175
- #
176
- # @raise [InvalidInputError] if comparing with non-Vector object
231
+ # @return [Boolean] true if +other+ is a vector with equal components,
232
+ # false otherwise (including for objects of another class)
177
233
  #
178
234
  # @example Check if two vectors are equal
179
235
  # vector1 == vector2
180
236
  def ==(other)
181
- unless other.is_a?(self.class)
182
- raise InvalidInputError, "Can only compare with another Vector"
183
- end
237
+ return true if equal?(other)
238
+
239
+ other.instance_of?(self.class) &&
240
+ x == other.x && y == other.y && z == other.z
241
+ end
242
+
243
+ # Checks strict equality, as used by Hash keys. Components are compared
244
+ # with +eql?+, consistently with {#hash}, so
245
+ # +Vector[1, 2, 3].eql?(Vector[1.0, 2.0, 3.0])+ is false.
246
+ #
247
+ # @param other [Object] The object to compare with
248
+ #
249
+ # @return [Boolean] true if +other+ is a vector with eql? components
250
+ def eql?(other)
251
+ return true if equal?(other)
184
252
 
185
- [x, y, z] == [other.x, other.y, other.z]
253
+ other.instance_of?(self.class) &&
254
+ x.eql?(other.x) && y.eql?(other.y) && z.eql?(other.z)
186
255
  end
187
- alias_method :eql?, :==
188
256
  end
189
257
  end
190
258
  end
@@ -36,7 +36,7 @@ module Ephem
36
36
  de430_1850-2150.bsp
37
37
  de430_plus_MarsPC.bsp
38
38
  de430t.bsp
39
- de431.bsp
39
+ de431t.bsp
40
40
  de432t.bsp
41
41
  de433.bsp
42
42
  de433_plus_MarsPC.bsp
@@ -59,6 +59,8 @@ module Ephem
59
59
  de440s_plus_MarsPC.bsp
60
60
  de440t.bsp
61
61
  de441.bsp
62
+ de442.bsp
63
+ de442t.bsp
62
64
  ].freeze
63
65
 
64
66
  NAIF_PCK_KERNELS = %w[
@@ -68,33 +70,78 @@ module Ephem
68
70
 
69
71
  IMCCE_KERNELS = {
70
72
  "inpop10b.bsp" => "inpop10b_TDB_m100_p100_spice.bsp",
73
+ "inpop10b.bpc" => "inpop10b_TDB_m100_p100_spice.bpc",
71
74
  "inpop10b_large.bsp" => "inpop10b_TDB_m1000_p1000_spice.bsp",
75
+ "inpop10b_large.bpc" => "inpop10b_TDB_m1000_p1000_spice.bpc",
72
76
  "inpop10e.bsp" => "inpop10e_TDB_m100_p100_spice.bsp",
77
+ "inpop10e.bpc" => "inpop10e_TDB_m100_p100_spice.bpc",
73
78
  "inpop10e_large.bsp" => "inpop10e_TDB_m1000_p1000_spice.bsp",
79
+ "inpop10e_large.bpc" => "inpop10e_TDB_m1000_p1000_spice.bpc",
74
80
  "inpop13c.bsp" => "inpop13c_TDB_m100_p100_spice.bsp",
81
+ "inpop13c.bpc" => "inpop13c_TDB_m100_p100_spice.bpc",
82
+ "inpop13c_time.bsp" => "inpop13c_TDB_m100_p100_spice_time.bsp",
75
83
  "inpop13c_large.bsp" => "inpop13c_TDB_m1000_p1000_spice.bsp",
84
+ "inpop13c_large.bpc" => "inpop13c_TDB_m1000_p1000_spice.bpc",
85
+ "inpop13c_large_time.bsp" => "inpop13c_TDB_m1000_p1000_spice_time.bsp",
76
86
  "inpop17a.bsp" => "inpop17a_TDB_m100_p100_spice.bsp",
87
+ "inpop17a.bpc" => "inpop17a_TDB_m100_p100_spice.bpc",
88
+ "inpop17a_time.bsp" => "inpop17a_TDB_m100_p100_spice_time.bsp",
77
89
  "inpop17a_large.bsp" => "inpop17a_TDB_m1000_p1000_spice.bsp",
90
+ "inpop17a_large.bpc" => "inpop17a_TDB_m1000_p1000_spice.bpc",
91
+ "inpop17a_large_time.bsp" => "inpop17a_TDB_m1000_p1000_spice_time.bsp",
78
92
  "inpop19a.bsp" => "inpop19a_TDB_m100_p100_spice.bsp",
93
+ "inpop19a.bpc" => "inpop19a_TDB_m100_p100_spice.bpc",
94
+ "inpop19a_time.bsp" => "inpop19a_TDB_m100_p100_spice_time.bsp",
79
95
  "inpop19a_large.bsp" => "inpop19a_TDB_m1000_p1000_spice.bsp",
96
+ "inpop19a_large.bpc" => "inpop19a_TDB_m1000_p1000_spice.bpc",
97
+ "inpop19a_large_time.bsp" => "inpop19a_TDB_m1000_p1000_spice_time.bsp",
80
98
  "inpop21a.bsp" => "inpop21a_TDB_m100_p100_spice.bsp",
81
- "inpop21a_large.bsp" => "inpop21a_TDB_m1000_p1000_spice.bsp"
99
+ "inpop21a.bpc" => "inpop21a_TDB_m100_p100_spice.bpc",
100
+ "inpop21a_time.bsp" => "inpop21a_TDB_m100_p100_spice_time.bsp",
101
+ "inpop21a_large.bsp" => "inpop21a_TDB_m1000_p1000_spice.bsp",
102
+ "inpop21a_large.bpc" => "inpop21a_TDB_m1000_p1000_spice.bpc",
103
+ "inpop21a_large_time.bsp" => "inpop21a_TDB_m1000_p1000_spice_time.bsp"
82
104
  }.freeze
83
105
 
84
106
  IMCCE_KERNELS_MATCHING = {
85
107
  "inpop10b.bsp" => "inpop10b/inpop10b_TDB_m100_p100_spice.tar.gz",
108
+ "inpop10b.bpc" => "inpop10b/inpop10b_TDB_m100_p100_spice.tar.gz",
86
109
  "inpop10b_large.bsp" => "inpop10b/inpop10b_TDB_m1000_p1000_spice.tar.gz",
110
+ "inpop10b_large.bpc" => "inpop10b/inpop10b_TDB_m1000_p1000_spice.tar.gz",
87
111
  "inpop10e.bsp" => "inpop10e/inpop10e_TDB_m100_p100_spice_release2.tar.gz",
112
+ "inpop10e.bpc" => "inpop10e/inpop10e_TDB_m100_p100_spice_release2.tar.gz",
88
113
  "inpop10e_large.bsp" =>
89
114
  "inpop10e/inpop10e_TDB_m1000_p1000_spice_release2.tar.gz",
115
+ "inpop10e_large.bpc" =>
116
+ "inpop10e/inpop10e_TDB_m1000_p1000_spice_release2.tar.gz",
90
117
  "inpop13c.bsp" => "inpop13c/inpop13c_TDB_m100_p100_spice.tar.gz",
118
+ "inpop13c.bpc" => "inpop13c/inpop13c_TDB_m100_p100_spice.tar.gz",
119
+ "inpop13c_time.bsp" => "inpop13c/inpop13c_TDB_m100_p100_spice.tar.gz",
91
120
  "inpop13c_large.bsp" => "inpop13c/inpop13c_TDB_m1000_p1000_spice.tar.gz",
121
+ "inpop13c_large.bpc" => "inpop13c/inpop13c_TDB_m1000_p1000_spice.tar.gz",
122
+ "inpop13c_large_time.bsp" =>
123
+ "inpop13c/inpop13c_TDB_m1000_p1000_spice.tar.gz",
92
124
  "inpop17a.bsp" => "inpop17a/inpop17a_TDB_m100_p100_spice.tar.gz",
125
+ "inpop17a.bpc" => "inpop17a/inpop17a_TDB_m100_p100_spice.tar.gz",
126
+ "inpop17a_time.bsp" => "inpop17a/inpop17a_TDB_m100_p100_spice.tar.gz",
93
127
  "inpop17a_large.bsp" => "inpop17a/inpop17a_TDB_m1000_p1000_spice.tar.gz",
128
+ "inpop17a_large.bpc" => "inpop17a/inpop17a_TDB_m1000_p1000_spice.tar.gz",
129
+ "inpop17a_large_time.bsp" =>
130
+ "inpop17a/inpop17a_TDB_m1000_p1000_spice.tar.gz",
94
131
  "inpop19a.bsp" => "inpop19a/inpop19a_TDB_m100_p100_spice.tar.gz",
132
+ "inpop19a.bpc" => "inpop19a/inpop19a_TDB_m100_p100_spice.tar.gz",
133
+ "inpop19a_time.bsp" => "inpop19a/inpop19a_TDB_m100_p100_spice.tar.gz",
95
134
  "inpop19a_large.bsp" => "inpop19a/inpop19a_TDB_m1000_p1000_spice.tar.gz",
135
+ "inpop19a_large.bpc" => "inpop19a/inpop19a_TDB_m1000_p1000_spice.tar.gz",
136
+ "inpop19a_large_time.bsp" =>
137
+ "inpop19a/inpop19a_TDB_m1000_p1000_spice.tar.gz",
96
138
  "inpop21a.bsp" => "inpop21a/inpop21a_TDB_m100_p100_spice.tar.gz",
97
- "inpop21a_large.bsp" => "inpop21a/inpop21a_TDB_m1000_p1000_spice.tar.gz"
139
+ "inpop21a.bpc" => "inpop21a/inpop21a_TDB_m100_p100_spice.tar.gz",
140
+ "inpop21a_time.bsp" => "inpop21a/inpop21a_TDB_m100_p100_spice.tar.gz",
141
+ "inpop21a_large.bsp" => "inpop21a/inpop21a_TDB_m1000_p1000_spice.tar.gz",
142
+ "inpop21a_large.bpc" => "inpop21a/inpop21a_TDB_m1000_p1000_spice.tar.gz",
143
+ "inpop21a_large_time.bsp" =>
144
+ "inpop21a/inpop21a_TDB_m1000_p1000_spice.tar.gz"
98
145
  }.freeze
99
146
 
100
147
  SUPPORTED_KERNELS =
@@ -179,22 +226,31 @@ module Ephem
179
226
 
180
227
  def extract_imcce_kernel(archive_path, file)
181
228
  kernel_path = IMCCE_KERNELS[@name]
182
- kernel_found = false
183
- Zlib::GzipReader.open(archive_path) do |gz|
184
- Gem::Package::TarReader.new(gz) do |tar|
185
- tar.each_entry do |entry|
186
- next unless entry.full_name == kernel_path
187
-
188
- copy_entry(entry, file)
189
- kernel_found = true
190
- break
191
- end
192
- end
229
+ kernel_found = Zlib::GzipReader.open(archive_path) do |gzip_reader|
230
+ copy_tar_entry(gzip_reader, kernel_path, file)
193
231
  end
194
232
  return if kernel_found
195
233
 
196
234
  raise DownloadError,
197
235
  "#{IMCCE_KERNELS_MATCHING[@name]} does not contain #{kernel_path}"
236
+ rescue Zlib::Error, Gem::Package::Error => error
237
+ raise DownloadError,
238
+ "#{IMCCE_KERNELS_MATCHING[@name]} is not a valid archive: " \
239
+ "#{error.message}"
240
+ end
241
+
242
+ def copy_tar_entry(gzip_reader, kernel_path, file)
243
+ Gem::Package::TarReader.new(gzip_reader) do |tar_reader|
244
+ tar_reader.each_entry do |entry|
245
+ next unless entry.full_name == kernel_path
246
+
247
+ copy_entry(entry, file)
248
+ return true
249
+ end
250
+ end
251
+ false
252
+ rescue ArgumentError => error
253
+ raise Gem::Package::TarInvalidError, error.message
198
254
  end
199
255
 
200
256
  def copy_entry(entry, file)
@@ -220,6 +276,13 @@ module Ephem
220
276
  response.read_body { |chunk| file.write(chunk) }
221
277
  end
222
278
  end
279
+ rescue SocketError, Net::OpenTimeout, Net::ReadTimeout,
280
+ Net::WriteTimeout, Net::HTTPBadResponse, Net::ProtocolError,
281
+ OpenSSL::SSL::SSLError, EOFError, Errno::ECONNRESET,
282
+ Errno::ECONNREFUSED, Errno::ECONNABORTED, Errno::EHOSTUNREACH,
283
+ Errno::EHOSTDOWN, Errno::ENETUNREACH, Errno::ENETDOWN,
284
+ Errno::ETIMEDOUT, Errno::EPIPE => error
285
+ raise DownloadError, "Failed to download #{uri}: #{error.message}"
223
286
  end
224
287
  end
225
288
  end
data/lib/ephem/error.rb CHANGED
@@ -13,11 +13,11 @@ module Ephem
13
13
 
14
14
  class InvalidInputError < Error; end
15
15
 
16
- class IndexError < Error; end
17
-
18
16
  class DownloadError < Error; end
19
17
 
20
- class OutOfRangeError < StandardError
18
+ class ClosedKernelError < Error; end
19
+
20
+ class OutOfRangeError < Error
21
21
  attr_reader :out_of_range_times
22
22
 
23
23
  def initialize(message, out_of_range_times)