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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +185 -0
- data/README.md +171 -15
- data/bin/ruby-ephem +1 -2
- data/lib/ephem/cli.rb +174 -100
- data/lib/ephem/computation/chebyshev_polynomial.rb +82 -110
- data/lib/ephem/core/calendar_calculations.rb +17 -26
- data/lib/ephem/core/constants/bodies.rb +2 -0
- data/lib/ephem/core/constants/time.rb +1 -1
- data/lib/ephem/core/orientation.rb +23 -7
- data/lib/ephem/core/state.rb +48 -13
- data/lib/ephem/core/vector.rb +92 -24
- data/lib/ephem/download.rb +77 -14
- data/lib/ephem/error.rb +3 -3
- data/lib/ephem/excerpt.rb +126 -105
- data/lib/ephem/io/binary_reader.rb +29 -8
- data/lib/ephem/io/daf.rb +1 -4
- data/lib/ephem/io/endianness_manager.rb +5 -18
- data/lib/ephem/io/record_data.rb +2 -20
- data/lib/ephem/io/record_parser.rb +1 -1
- data/lib/ephem/io/summary_manager.rb +24 -15
- data/lib/ephem/pck.rb +24 -7
- data/lib/ephem/segments/base_segment.rb +38 -20
- data/lib/ephem/segments/chebyshev_type2.rb +105 -58
- data/lib/ephem/segments/coverage.rb +66 -0
- data/lib/ephem/segments/orientation_segment.rb +17 -15
- data/lib/ephem/segments/orientation_source.rb +4 -2
- data/lib/ephem/segments/position_chain.rb +124 -0
- data/lib/ephem/segments/position_group.rb +24 -0
- data/lib/ephem/segments/segment.rb +87 -18
- data/lib/ephem/segments/segment_group.rb +19 -5
- data/lib/ephem/spk.rb +134 -11
- data/lib/ephem/version.rb +1 -1
- data/lib/ephem.rb +5 -3
- metadata +4 -10
- data/.rspec +0 -3
- data/.standard.yml +0 -3
- data/.tool-versions +0 -1
- data/CODE_OF_CONDUCT.md +0 -132
- data/Rakefile +0 -12
- data/benchmarks/run.rb +0 -431
- data/bin/console +0 -11
- data/bin/setup +0 -8
- data/lib/tasks/validate_accuracy.rake +0 -47
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ephem
|
|
4
|
+
module Segments
|
|
5
|
+
# Position of a target relative to a center that no single SPK pair
|
|
6
|
+
# stores, built by adding and subtracting the stored pairs along the path
|
|
7
|
+
# between the two bodies. Earth relative to the Solar System Barycenter,
|
|
8
|
+
# for instance, is (0 -> 3) + (3 -> 399), and the Moon relative to the
|
|
9
|
+
# Earth is (3 -> 301) - (3 -> 399). Built by SPK#position_at and
|
|
10
|
+
# SPK#state_at.
|
|
11
|
+
class PositionChain
|
|
12
|
+
Link = Struct.new(:source, :forward)
|
|
13
|
+
|
|
14
|
+
ZERO_VECTOR = Core::Vector.new(0.0, 0.0, 0.0)
|
|
15
|
+
ZERO_STATE = Core::State.new(ZERO_VECTOR, ZERO_VECTOR)
|
|
16
|
+
|
|
17
|
+
# @return [Array<Link>] the stored pairs on the path
|
|
18
|
+
attr_reader :links
|
|
19
|
+
|
|
20
|
+
# @param links [Array<Link>] the stored pairs on the path, in any order
|
|
21
|
+
def initialize(links)
|
|
22
|
+
forward_links, backward_links = links.partition(&:forward)
|
|
23
|
+
@links = (forward_links + backward_links).freeze
|
|
24
|
+
@sources = @links.map(&:source).freeze
|
|
25
|
+
@signs = @links.map { |link| link.forward ? 1.0 : -1.0 }.freeze
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Position of the target relative to the center.
|
|
29
|
+
#
|
|
30
|
+
# @param tdb [Numeric, Array<Numeric>] Time(s) in TDB Julian Date
|
|
31
|
+
# @param tdb2 [Numeric] Optional fractional part of TDB date
|
|
32
|
+
# @return [Core::Vector, Array<Core::Vector>] Position(s) in km
|
|
33
|
+
# @raise [Ephem::OutOfRangeError] if a pair on the path does not cover
|
|
34
|
+
# the time
|
|
35
|
+
def compute(tdb, tdb2 = 0.0)
|
|
36
|
+
return compute_many(tdb, tdb2) if tdb.is_a?(Array)
|
|
37
|
+
return ZERO_VECTOR if @sources.empty?
|
|
38
|
+
|
|
39
|
+
total_x = total_y = total_z = 0.0
|
|
40
|
+
link_index = 0
|
|
41
|
+
while link_index < @sources.size
|
|
42
|
+
position = @sources[link_index].position_components(tdb, tdb2)
|
|
43
|
+
sign = @signs[link_index]
|
|
44
|
+
total_x += sign * position[0]
|
|
45
|
+
total_y += sign * position[1]
|
|
46
|
+
total_z += sign * position[2]
|
|
47
|
+
link_index += 1
|
|
48
|
+
end
|
|
49
|
+
Core::Vector.new(total_x, total_y, total_z)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Position and velocity of the target relative to the center.
|
|
53
|
+
#
|
|
54
|
+
# @param tdb [Numeric, Array<Numeric>] Time(s) in TDB Julian Date
|
|
55
|
+
# @param tdb2 [Numeric] Optional fractional part of TDB date
|
|
56
|
+
# @return [Core::State, Array<Core::State>] State(s) in km and km/day
|
|
57
|
+
# @raise [Ephem::OutOfRangeError] if a pair on the path does not cover
|
|
58
|
+
# the time
|
|
59
|
+
def compute_and_differentiate(tdb, tdb2 = 0.0)
|
|
60
|
+
if tdb.is_a?(Array)
|
|
61
|
+
return compute_and_differentiate_many(tdb, tdb2)
|
|
62
|
+
end
|
|
63
|
+
return ZERO_STATE if @sources.empty?
|
|
64
|
+
|
|
65
|
+
position_x = position_y = position_z = 0.0
|
|
66
|
+
velocity_x = velocity_y = velocity_z = 0.0
|
|
67
|
+
link_index = 0
|
|
68
|
+
while link_index < @sources.size
|
|
69
|
+
position, velocity =
|
|
70
|
+
@sources[link_index].state_components(tdb, tdb2)
|
|
71
|
+
sign = @signs[link_index]
|
|
72
|
+
position_x += sign * position[0]
|
|
73
|
+
position_y += sign * position[1]
|
|
74
|
+
position_z += sign * position[2]
|
|
75
|
+
velocity_x += sign * velocity[0]
|
|
76
|
+
velocity_y += sign * velocity[1]
|
|
77
|
+
velocity_z += sign * velocity[2]
|
|
78
|
+
link_index += 1
|
|
79
|
+
end
|
|
80
|
+
Core::State.new(
|
|
81
|
+
Core::Vector.new(position_x, position_y, position_z),
|
|
82
|
+
Core::Vector.new(velocity_x, velocity_y, velocity_z)
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def compute_many(times, tdb2)
|
|
89
|
+
return Array.new(times.size, ZERO_VECTOR) if @sources.empty?
|
|
90
|
+
|
|
91
|
+
terms = @sources.map { |source| source.compute(times, tdb2) }
|
|
92
|
+
Array.new(times.size) do |time_index|
|
|
93
|
+
signed_sum(terms.map { |positions| positions[time_index] })
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def compute_and_differentiate_many(times, tdb2)
|
|
98
|
+
return Array.new(times.size, ZERO_STATE) if @sources.empty?
|
|
99
|
+
|
|
100
|
+
terms = @sources.map do |source|
|
|
101
|
+
source.compute_and_differentiate(times, tdb2)
|
|
102
|
+
end
|
|
103
|
+
Array.new(times.size) do |time_index|
|
|
104
|
+
states = terms.map { |source_states| source_states[time_index] }
|
|
105
|
+
Core::State.new(
|
|
106
|
+
signed_sum(states.map(&:position)),
|
|
107
|
+
signed_sum(states.map(&:velocity))
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def signed_sum(vectors)
|
|
113
|
+
total_x = total_y = total_z = 0.0
|
|
114
|
+
vectors.each_with_index do |vector, link_index|
|
|
115
|
+
sign = @signs[link_index]
|
|
116
|
+
total_x += sign * vector.x
|
|
117
|
+
total_y += sign * vector.y
|
|
118
|
+
total_z += sign * vector.z
|
|
119
|
+
end
|
|
120
|
+
Core::Vector.new(total_x, total_y, total_z)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -41,6 +41,30 @@ module Ephem
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
alias_method :state_at, :compute_and_differentiate
|
|
44
|
+
|
|
45
|
+
# See {Segment#position_components}.
|
|
46
|
+
#
|
|
47
|
+
# @api private
|
|
48
|
+
# @param tdb [Numeric] Time in TDB Julian Date
|
|
49
|
+
# @param tdb2 [Numeric] Optional fractional part of TDB date
|
|
50
|
+
# @return [Array<Float>]
|
|
51
|
+
def position_components(tdb, tdb2 = 0.0)
|
|
52
|
+
query(tdb, tdb2) do |segment, time, fraction|
|
|
53
|
+
segment.position_components(time, fraction)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# See {Segment#state_components}.
|
|
58
|
+
#
|
|
59
|
+
# @api private
|
|
60
|
+
# @param tdb [Numeric] Time in TDB Julian Date
|
|
61
|
+
# @param tdb2 [Numeric] Optional fractional part of TDB date
|
|
62
|
+
# @return [Array(Array<Float>, Array<Float>)]
|
|
63
|
+
def state_components(tdb, tdb2 = 0.0)
|
|
64
|
+
query(tdb, tdb2) do |segment, time, fraction|
|
|
65
|
+
segment.state_components(time, fraction)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
44
68
|
end
|
|
45
69
|
end
|
|
46
70
|
end
|
|
@@ -28,12 +28,6 @@ module Ephem
|
|
|
28
28
|
3 => 6 # Type 3: position (x, y, z) and velocity (vx, vy, vz)
|
|
29
29
|
}.freeze
|
|
30
30
|
|
|
31
|
-
def initialize(daf:, source:, descriptor:)
|
|
32
|
-
super
|
|
33
|
-
@data_loaded = false
|
|
34
|
-
@data_lock = Mutex.new
|
|
35
|
-
end
|
|
36
|
-
|
|
37
31
|
# Computes the position of the target body relative to the center body at
|
|
38
32
|
# the specified time.
|
|
39
33
|
#
|
|
@@ -42,19 +36,21 @@ module Ephem
|
|
|
42
36
|
# @return [Ephem::Core::Vector] Position vector in kilometers
|
|
43
37
|
# @raise [Ephem::OutOfRangeError] if time is outside segment coverage
|
|
44
38
|
def compute(tdb, tdb2 = 0.0)
|
|
45
|
-
load_data
|
|
39
|
+
records = load_data
|
|
46
40
|
tdb_seconds = convert_to_seconds(tdb, tdb2)
|
|
47
41
|
|
|
48
42
|
case tdb_seconds
|
|
49
43
|
when Numeric
|
|
50
|
-
position = generate_position(tdb_seconds)
|
|
44
|
+
position = generate_position(records, tdb_seconds)
|
|
51
45
|
Core::Vector.new(position[0], position[1], position[2])
|
|
52
46
|
else
|
|
53
|
-
tdb_seconds.map do |
|
|
54
|
-
position = generate_position(
|
|
47
|
+
tdb_seconds.map do |time|
|
|
48
|
+
position = generate_position(records, time)
|
|
55
49
|
Core::Vector.new(position[0], position[1], position[2])
|
|
56
50
|
end
|
|
57
51
|
end
|
|
52
|
+
rescue OutOfRangeError => error
|
|
53
|
+
raise request_out_of_range_error(records, error, tdb, tdb2), cause: nil
|
|
58
54
|
end
|
|
59
55
|
alias_method :position_at, :compute
|
|
60
56
|
|
|
@@ -67,32 +63,105 @@ module Ephem
|
|
|
67
63
|
# array if the input is an array.
|
|
68
64
|
# @raise [Ephem::OutOfRangeError] if time is outside segment coverage
|
|
69
65
|
def compute_and_differentiate(tdb, tdb2 = 0.0)
|
|
70
|
-
load_data
|
|
66
|
+
records = load_data
|
|
71
67
|
tdb_seconds = convert_to_seconds(tdb, tdb2)
|
|
72
68
|
|
|
73
69
|
case tdb_seconds
|
|
74
70
|
when Numeric
|
|
75
|
-
|
|
71
|
+
position, velocity = generate_single(records, tdb_seconds)
|
|
76
72
|
Core::State.new(
|
|
77
|
-
Core::Vector.new(
|
|
78
|
-
Core::Vector.new(
|
|
73
|
+
Core::Vector.new(position[0], position[1], position[2]),
|
|
74
|
+
Core::Vector.new(velocity[0], velocity[1], velocity[2])
|
|
79
75
|
)
|
|
80
76
|
else
|
|
81
|
-
generate_multiple(tdb_seconds).map do |
|
|
77
|
+
generate_multiple(records, tdb_seconds).map do |position, velocity|
|
|
82
78
|
Core::State.new(
|
|
83
|
-
Core::Vector.new(
|
|
84
|
-
Core::Vector.new(
|
|
79
|
+
Core::Vector.new(position[0], position[1], position[2]),
|
|
80
|
+
Core::Vector.new(velocity[0], velocity[1], velocity[2])
|
|
85
81
|
)
|
|
86
82
|
end
|
|
87
83
|
end
|
|
84
|
+
rescue OutOfRangeError => error
|
|
85
|
+
raise request_out_of_range_error(records, error, tdb, tdb2), cause: nil
|
|
88
86
|
end
|
|
89
87
|
alias_method :state_at, :compute_and_differentiate
|
|
90
88
|
|
|
89
|
+
# Position at a single time as an [x, y, z] Array, without building a
|
|
90
|
+
# Vector. Used by {PositionChain} to sum the pairs on a path.
|
|
91
|
+
#
|
|
92
|
+
# @api private
|
|
93
|
+
# @param tdb [Numeric] Time in TDB Julian Date
|
|
94
|
+
# @param tdb2 [Numeric] Optional fractional part of TDB date
|
|
95
|
+
# @return [Array<Float>] Position in km
|
|
96
|
+
# @raise [Ephem::OutOfRangeError] if time is outside segment coverage
|
|
97
|
+
def position_components(tdb, tdb2 = 0.0)
|
|
98
|
+
records = load_data
|
|
99
|
+
generate_position(records, time_to_seconds(tdb, tdb2))
|
|
100
|
+
rescue OutOfRangeError => error
|
|
101
|
+
raise request_out_of_range_error(records, error, tdb, tdb2), cause: nil
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Position and velocity at a single time as two [x, y, z] Arrays,
|
|
105
|
+
# without building a State. Used by {PositionChain} to sum the pairs on
|
|
106
|
+
# a path.
|
|
107
|
+
#
|
|
108
|
+
# @api private
|
|
109
|
+
# @param tdb [Numeric] Time in TDB Julian Date
|
|
110
|
+
# @param tdb2 [Numeric] Optional fractional part of TDB date
|
|
111
|
+
# @return [Array(Array<Float>, Array<Float>)] Position in km and
|
|
112
|
+
# velocity in km/day
|
|
113
|
+
# @raise [Ephem::OutOfRangeError] if time is outside segment coverage
|
|
114
|
+
def state_components(tdb, tdb2 = 0.0)
|
|
115
|
+
records = load_data
|
|
116
|
+
generate_single(records, time_to_seconds(tdb, tdb2))
|
|
117
|
+
rescue OutOfRangeError => error
|
|
118
|
+
raise request_out_of_range_error(records, error, tdb, tdb2), cause: nil
|
|
119
|
+
end
|
|
120
|
+
|
|
91
121
|
private
|
|
92
122
|
|
|
123
|
+
def process_coefficient_data(data)
|
|
124
|
+
records = super
|
|
125
|
+
return records unless @data_type == 3
|
|
126
|
+
|
|
127
|
+
velocity_coefficients = records.coefficients.map do |terms|
|
|
128
|
+
terms.map do |term|
|
|
129
|
+
[
|
|
130
|
+
term[3] * Time::SECONDS_PER_DAY,
|
|
131
|
+
term[4] * Time::SECONDS_PER_DAY,
|
|
132
|
+
term[5] * Time::SECONDS_PER_DAY
|
|
133
|
+
]
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
position_coefficients = records.coefficients.map do |terms|
|
|
137
|
+
terms.map { |term| term.first(3) }
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
Records.new(
|
|
141
|
+
midpoints: records.midpoints,
|
|
142
|
+
radii: records.radii,
|
|
143
|
+
coefficients: position_coefficients.freeze,
|
|
144
|
+
velocity_coefficients: velocity_coefficients.freeze
|
|
145
|
+
).freeze
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def generate_single(records, tdb_seconds)
|
|
149
|
+
return super unless @data_type == 3
|
|
150
|
+
|
|
151
|
+
interval = find_interval(records, tdb_seconds)
|
|
152
|
+
normalized_time =
|
|
153
|
+
compute_normalized_time(records, tdb_seconds, interval)
|
|
154
|
+
[
|
|
155
|
+
Computation::ChebyshevPolynomial
|
|
156
|
+
.evaluate(records.coefficients[interval], normalized_time),
|
|
157
|
+
Computation::ChebyshevPolynomial
|
|
158
|
+
.evaluate(records.velocity_coefficients[interval], normalized_time)
|
|
159
|
+
]
|
|
160
|
+
end
|
|
161
|
+
|
|
93
162
|
def component_count
|
|
94
163
|
COMPONENT_COUNTS.fetch(@data_type) do
|
|
95
|
-
raise "Unsupported data type: #{@data_type}"
|
|
164
|
+
raise UnsupportedError, "Unsupported SPK data type: #{@data_type}"
|
|
96
165
|
end
|
|
97
166
|
end
|
|
98
167
|
|
|
@@ -53,7 +53,10 @@ module Ephem
|
|
|
53
53
|
if tdb.is_a?(Array)
|
|
54
54
|
query_many(tdb, tdb2) { |segment, times| yield segment, times, tdb2 }
|
|
55
55
|
else
|
|
56
|
-
|
|
56
|
+
segment = segment_for(tdb, tdb2)
|
|
57
|
+
raise out_of_range_error([tdb + tdb2]) unless segment
|
|
58
|
+
|
|
59
|
+
yield segment, tdb, tdb2
|
|
57
60
|
end
|
|
58
61
|
end
|
|
59
62
|
|
|
@@ -63,6 +66,12 @@ module Ephem
|
|
|
63
66
|
segment_for(times[index], tdb2)
|
|
64
67
|
end
|
|
65
68
|
|
|
69
|
+
if (uncovered_indices = indices_by_segment[nil])
|
|
70
|
+
raise out_of_range_error(
|
|
71
|
+
uncovered_indices.map { |index| times[index] + tdb2 }
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
66
75
|
indices_by_segment.each do |segment, indices|
|
|
67
76
|
segment_results = yield(segment, indices.map { |index| times[index] })
|
|
68
77
|
indices.each_with_index do |original_index, position|
|
|
@@ -74,10 +83,15 @@ module Ephem
|
|
|
74
83
|
end
|
|
75
84
|
|
|
76
85
|
def segment_for(tdb, tdb2)
|
|
77
|
-
@segments.reverse_each.find { |segment| segment.covers?(tdb, tdb2) }
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
@segments.reverse_each.find { |segment| segment.covers?(tdb, tdb2) }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def out_of_range_error(times)
|
|
90
|
+
Coverage.out_of_range_error(
|
|
91
|
+
times: times,
|
|
92
|
+
label: @segments.first.label,
|
|
93
|
+
ranges: @segments.map { |segment| [segment.start_jd, segment.end_jd] }
|
|
94
|
+
)
|
|
81
95
|
end
|
|
82
96
|
end
|
|
83
97
|
end
|
data/lib/ephem/spk.rb
CHANGED
|
@@ -14,11 +14,14 @@ module Ephem
|
|
|
14
14
|
# segment = spk[0, 10]
|
|
15
15
|
# spk.close
|
|
16
16
|
#
|
|
17
|
+
# @example Opening an SPK file with a block, closed automatically
|
|
18
|
+
# Ephem::SPK.open("de421.bsp") { |spk| spk[0, 10].position_at(2451545.0) }
|
|
19
|
+
#
|
|
17
20
|
class SPK
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
INPOP = "IMCCE INPOP"
|
|
22
|
+
JPL_DE = "JPL DE"
|
|
23
|
+
TYPES = [INPOP, JPL_DE].freeze
|
|
24
|
+
deprecate_constant :TYPES
|
|
22
25
|
|
|
23
26
|
INPOP_REGEXP = /^\s+\d{4}\.\d{5}0+$/
|
|
24
27
|
DE_REGEXP = /^[A-Z]E-(\d{4})LE-\1$/
|
|
@@ -39,26 +42,46 @@ module Ephem
|
|
|
39
42
|
@daf = daf
|
|
40
43
|
@segments = load_segments
|
|
41
44
|
@pairs = build_pairs
|
|
45
|
+
@neighbor_links = build_neighbor_links
|
|
46
|
+
@chains = {}
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
# Opens an SPK file at the specified path.
|
|
45
50
|
#
|
|
51
|
+
# Without a block, returns the open kernel; the caller must close it.
|
|
52
|
+
# With a block, yields the kernel, closes it when the block returns or
|
|
53
|
+
# raises, and returns the block's value, like +File.open+.
|
|
54
|
+
#
|
|
46
55
|
# @param path [String] Path to the SPK file
|
|
47
|
-
# @
|
|
48
|
-
# @
|
|
56
|
+
# @yieldparam spk [SPK] the open kernel
|
|
57
|
+
# @return [SPK] the open kernel, if no block is given
|
|
58
|
+
# @return [Object] the block's value, if a block is given
|
|
59
|
+
# @raise [Ephem::FileFormatError] If the file is a binary PCK
|
|
49
60
|
def self.open(path)
|
|
50
|
-
|
|
61
|
+
spk = load_kernel(path)
|
|
62
|
+
return spk unless block_given?
|
|
63
|
+
|
|
64
|
+
begin
|
|
65
|
+
yield spk
|
|
66
|
+
ensure
|
|
67
|
+
spk.close
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.load_kernel(path)
|
|
72
|
+
file = File.open(path, "rb")
|
|
73
|
+
daf = IO::DAF.new(file)
|
|
51
74
|
if daf.file_type == :pck
|
|
52
|
-
raise
|
|
75
|
+
raise FileFormatError,
|
|
76
|
+
"#{path} is a binary PCK file, use Ephem::PCK.open"
|
|
53
77
|
end
|
|
54
78
|
|
|
55
79
|
new(daf: daf)
|
|
56
|
-
rescue Errno::EACCES => e
|
|
57
|
-
raise ArgumentError, "File permission denied: #{path} (#{e.message})"
|
|
58
80
|
rescue
|
|
59
|
-
daf&.close
|
|
81
|
+
(daf || file)&.close
|
|
60
82
|
raise
|
|
61
83
|
end
|
|
84
|
+
private_class_method :load_kernel
|
|
62
85
|
|
|
63
86
|
# Closes the SPK file and cleans up resources.
|
|
64
87
|
# This method should be called when you're done using the SPK file.
|
|
@@ -94,6 +117,45 @@ module Ephem
|
|
|
94
117
|
end
|
|
95
118
|
end
|
|
96
119
|
|
|
120
|
+
# Position of a target body relative to a center body, at the given time.
|
|
121
|
+
#
|
|
122
|
+
# Unlike {#[]}, the pair does not have to be stored in the kernel: the
|
|
123
|
+
# position is chained through the stored pairs that link the two bodies.
|
|
124
|
+
# Earth relative to the Solar System Barycenter is (0 -> 3) + (3 -> 399)
|
|
125
|
+
# in a JPL DE kernel, and the Moon relative to the Earth is
|
|
126
|
+
# (3 -> 301) - (3 -> 399). A pair that is stored is read directly. A
|
|
127
|
+
# body relative to itself is a zero vector, whatever the time.
|
|
128
|
+
#
|
|
129
|
+
# @example Moon relative to the Earth
|
|
130
|
+
# spk.position_at(target: 301, center: 399, tdb: 2460676.5)
|
|
131
|
+
#
|
|
132
|
+
# @param target [Integer] NAIF ID of the target body
|
|
133
|
+
# @param center [Integer] NAIF ID of the center body
|
|
134
|
+
# @param tdb [Numeric, Array<Numeric>] Time(s) in TDB Julian Date
|
|
135
|
+
# @param tdb2 [Numeric] Optional fractional part of TDB date
|
|
136
|
+
# @return [Core::Vector, Array<Core::Vector>] Position(s) in km
|
|
137
|
+
# @raise [KeyError] If no chain of stored pairs links the two bodies
|
|
138
|
+
# @raise [Ephem::OutOfRangeError] If a pair on the chain does not cover
|
|
139
|
+
# the time
|
|
140
|
+
def position_at(target:, center:, tdb:, tdb2: 0.0)
|
|
141
|
+
chain(target, center).compute(tdb, tdb2)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Position and velocity of a target body relative to a center body, at
|
|
145
|
+
# the given time. See {#position_at} for how the two bodies are linked.
|
|
146
|
+
#
|
|
147
|
+
# @param target [Integer] NAIF ID of the target body
|
|
148
|
+
# @param center [Integer] NAIF ID of the center body
|
|
149
|
+
# @param tdb [Numeric, Array<Numeric>] Time(s) in TDB Julian Date
|
|
150
|
+
# @param tdb2 [Numeric] Optional fractional part of TDB date
|
|
151
|
+
# @return [Core::State, Array<Core::State>] State(s) in km and km/day
|
|
152
|
+
# @raise [KeyError] If no chain of stored pairs links the two bodies
|
|
153
|
+
# @raise [Ephem::OutOfRangeError] If a pair on the chain does not cover
|
|
154
|
+
# the time
|
|
155
|
+
def state_at(target:, center:, tdb:, tdb2: 0.0)
|
|
156
|
+
chain(target, center).compute_and_differentiate(tdb, tdb2)
|
|
157
|
+
end
|
|
158
|
+
|
|
97
159
|
# Type of SPK file to make the difference between JPL DE and IMCCE INPOP
|
|
98
160
|
#
|
|
99
161
|
# @return [String, nil] The type of the SPK file
|
|
@@ -151,6 +213,67 @@ module Ephem
|
|
|
151
213
|
.transform_values { |segments| Segments::PositionGroup.wrap(segments) }
|
|
152
214
|
end
|
|
153
215
|
|
|
216
|
+
def chain(target, center)
|
|
217
|
+
centers = @chains[target] ||= {}
|
|
218
|
+
centers[center] ||= build_chain(target, center)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def build_chain(target, center)
|
|
222
|
+
links = path_links(target, center)
|
|
223
|
+
if links.one? && links.first.forward
|
|
224
|
+
links.first.source
|
|
225
|
+
else
|
|
226
|
+
Segments::PositionChain.new(links)
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def path_links(target, center)
|
|
231
|
+
unless @neighbor_links.key?(center) && @neighbor_links.key?(target)
|
|
232
|
+
raise_no_chain(target, center)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
previous_links = {center => nil}
|
|
236
|
+
queue = [center]
|
|
237
|
+
until queue.empty? || previous_links.key?(target)
|
|
238
|
+
body = queue.shift
|
|
239
|
+
@neighbor_links.fetch(body).each do |neighbor, link|
|
|
240
|
+
next if previous_links.key?(neighbor)
|
|
241
|
+
|
|
242
|
+
previous_links[neighbor] = [body, link]
|
|
243
|
+
queue << neighbor
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
raise_no_chain(target, center) unless previous_links.key?(target)
|
|
248
|
+
|
|
249
|
+
links = []
|
|
250
|
+
body = target
|
|
251
|
+
until body == center
|
|
252
|
+
body, link = previous_links.fetch(body)
|
|
253
|
+
links.unshift(link)
|
|
254
|
+
end
|
|
255
|
+
links
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def raise_no_chain(target, center)
|
|
259
|
+
raise KeyError,
|
|
260
|
+
"No chain of segments links center: #{center}, target: #{target}"
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def build_neighbor_links
|
|
264
|
+
neighbors = Hash.new { |hash, body| hash[body] = [] }
|
|
265
|
+
@pairs.each do |(center, target), source|
|
|
266
|
+
neighbors[center] << [
|
|
267
|
+
target, Segments::PositionChain::Link.new(source, true)
|
|
268
|
+
]
|
|
269
|
+
neighbors[target] << [
|
|
270
|
+
center, Segments::PositionChain::Link.new(source, false)
|
|
271
|
+
]
|
|
272
|
+
end
|
|
273
|
+
neighbors.default_proc = nil
|
|
274
|
+
neighbors
|
|
275
|
+
end
|
|
276
|
+
|
|
154
277
|
def build_segment(source:, descriptor:)
|
|
155
278
|
data_type = descriptor[DATA_TYPE_IDENTIFIER]
|
|
156
279
|
segment_class = Segments::Registry.lookup(
|
data/lib/ephem/version.rb
CHANGED
data/lib/ephem.rb
CHANGED
|
@@ -11,7 +11,6 @@ require_relative "ephem/core/rotation"
|
|
|
11
11
|
require_relative "ephem/error"
|
|
12
12
|
require_relative "ephem/io/binary_reader"
|
|
13
13
|
require_relative "ephem/io/daf"
|
|
14
|
-
require_relative "ephem/download"
|
|
15
14
|
require_relative "ephem/io/endianness_manager"
|
|
16
15
|
require_relative "ephem/io/record_data"
|
|
17
16
|
require_relative "ephem/io/record_parser"
|
|
@@ -19,6 +18,7 @@ require_relative "ephem/io/summary_manager"
|
|
|
19
18
|
require_relative "ephem/spk"
|
|
20
19
|
require_relative "ephem/pck"
|
|
21
20
|
require_relative "ephem/segments/base_segment"
|
|
21
|
+
require_relative "ephem/segments/coverage"
|
|
22
22
|
require_relative "ephem/segments/registry"
|
|
23
23
|
require_relative "ephem/segments/chebyshev_type2"
|
|
24
24
|
require_relative "ephem/segments/orientation_source"
|
|
@@ -26,10 +26,12 @@ require_relative "ephem/segments/segment"
|
|
|
26
26
|
require_relative "ephem/segments/orientation_segment"
|
|
27
27
|
require_relative "ephem/segments/segment_group"
|
|
28
28
|
require_relative "ephem/segments/position_group"
|
|
29
|
+
require_relative "ephem/segments/position_chain"
|
|
29
30
|
require_relative "ephem/segments/orientation_group"
|
|
30
|
-
require_relative "ephem/excerpt"
|
|
31
|
-
require_relative "ephem/cli"
|
|
32
31
|
require_relative "ephem/version"
|
|
33
32
|
|
|
34
33
|
module Ephem
|
|
34
|
+
autoload :CLI, File.expand_path("ephem/cli", __dir__)
|
|
35
|
+
autoload :Download, File.expand_path("ephem/download", __dir__)
|
|
36
|
+
autoload :Excerpt, File.expand_path("ephem/excerpt", __dir__)
|
|
35
37
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ephem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rémy Hannequin
|
|
@@ -130,18 +130,10 @@ executables:
|
|
|
130
130
|
extensions: []
|
|
131
131
|
extra_rdoc_files: []
|
|
132
132
|
files:
|
|
133
|
-
- ".rspec"
|
|
134
|
-
- ".standard.yml"
|
|
135
|
-
- ".tool-versions"
|
|
136
133
|
- CHANGELOG.md
|
|
137
|
-
- CODE_OF_CONDUCT.md
|
|
138
134
|
- LICENSE.txt
|
|
139
135
|
- README.md
|
|
140
|
-
- Rakefile
|
|
141
|
-
- benchmarks/run.rb
|
|
142
|
-
- bin/console
|
|
143
136
|
- bin/ruby-ephem
|
|
144
|
-
- bin/setup
|
|
145
137
|
- lib/ephem.rb
|
|
146
138
|
- lib/ephem/cli.rb
|
|
147
139
|
- lib/ephem/computation/chebyshev_polynomial.rb
|
|
@@ -164,16 +156,17 @@ files:
|
|
|
164
156
|
- lib/ephem/pck.rb
|
|
165
157
|
- lib/ephem/segments/base_segment.rb
|
|
166
158
|
- lib/ephem/segments/chebyshev_type2.rb
|
|
159
|
+
- lib/ephem/segments/coverage.rb
|
|
167
160
|
- lib/ephem/segments/orientation_group.rb
|
|
168
161
|
- lib/ephem/segments/orientation_segment.rb
|
|
169
162
|
- lib/ephem/segments/orientation_source.rb
|
|
163
|
+
- lib/ephem/segments/position_chain.rb
|
|
170
164
|
- lib/ephem/segments/position_group.rb
|
|
171
165
|
- lib/ephem/segments/registry.rb
|
|
172
166
|
- lib/ephem/segments/segment.rb
|
|
173
167
|
- lib/ephem/segments/segment_group.rb
|
|
174
168
|
- lib/ephem/spk.rb
|
|
175
169
|
- lib/ephem/version.rb
|
|
176
|
-
- lib/tasks/validate_accuracy.rake
|
|
177
170
|
homepage: https://github.com/rhannequin/ruby-ephem
|
|
178
171
|
licenses:
|
|
179
172
|
- MIT
|
|
@@ -181,6 +174,7 @@ metadata:
|
|
|
181
174
|
homepage_uri: https://github.com/rhannequin/ruby-ephem
|
|
182
175
|
source_code_uri: https://github.com/rhannequin/ruby-ephem
|
|
183
176
|
changelog_uri: https://github.com/rhannequin/ruby-ephem/blob/main/CHANGELOG.md
|
|
177
|
+
rubygems_mfa_required: 'true'
|
|
184
178
|
rdoc_options: []
|
|
185
179
|
require_paths:
|
|
186
180
|
- lib
|
data/.rspec
DELETED
data/.standard.yml
DELETED
data/.tool-versions
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ruby 4.0.5
|