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
@@ -38,7 +38,6 @@ module Ephem
38
38
  #
39
39
  # @api public
40
40
  class SummaryManager
41
- SUMMARY_RECORD_SIZE = 1024
42
41
  VALID_ENDIANNESS = [:little, :big].freeze
43
42
 
44
43
  # Initializes a new SummaryManager instance
@@ -92,19 +91,19 @@ module Ephem
92
91
  return if VALID_ENDIANNESS.include?(endianness)
93
92
 
94
93
  raise EndiannessError,
95
- "Invalid endianness: #{endianness}. Must be one of: #{VALID_ENDIANNESS.join(", ")}"
94
+ "Invalid endianness: #{endianness}. " \
95
+ "Must be one of: #{VALID_ENDIANNESS.join(", ")}"
96
96
  end
97
97
 
98
98
  def setup_summary_format
99
99
  @summary_format = build_summary_format
100
100
  @summary_length = calculate_summary_length
101
101
  @summary_step = calculate_summary_step
102
- @summaries_per_record = calculate_summaries_per_record
103
102
  end
104
103
 
105
104
  def build_summary_format
106
105
  doubles_format = "#{endian_double}#{@record_data.double_count}"
107
- integers_format = "#{endian_uint32}#{@record_data.integer_count}"
106
+ integers_format = "#{endian_int32}#{@record_data.integer_count}"
108
107
  doubles_format + integers_format
109
108
  end
110
109
 
@@ -118,14 +117,12 @@ module Ephem
118
117
  @summary_length + (-@summary_length % 8)
119
118
  end
120
119
 
121
- def calculate_summaries_per_record
122
- (
123
- SUMMARY_RECORD_SIZE - RecordParser::SUMMARY_CONTROL_SIZE
124
- ) / @summary_step
125
- end
126
-
127
120
  def iterate_summary_chain(record_number)
121
+ visited_records = {}
122
+
128
123
  while record_number != 0
124
+ validate_summary_record_number!(record_number, visited_records)
125
+ visited_records[record_number] = true
129
126
  record_number =
130
127
  process_summary_record(record_number) do |name, values|
131
128
  yield name, values
@@ -133,6 +130,18 @@ module Ephem
133
130
  end
134
131
  end
135
132
 
133
+ def validate_summary_record_number!(record_number, visited_records)
134
+ unless record_number.positive?
135
+ raise FileFormatError,
136
+ "Invalid summary record number: #{record_number}"
137
+ end
138
+
139
+ if visited_records.key?(record_number)
140
+ raise FileFormatError,
141
+ "Summary record chain loops back to record #{record_number}"
142
+ end
143
+ end
144
+
136
145
  def process_summary_record(record_number)
137
146
  data = @binary_reader.read_record(record_number)
138
147
  control = parse_control_data(data)
@@ -140,7 +149,7 @@ module Ephem
140
149
  name_data = @binary_reader.read_record(record_number + 1)
141
150
 
142
151
  process_summaries(
143
- control[:n_summaries],
152
+ control[:summary_count],
144
153
  summary_data,
145
154
  name_data
146
155
  ) do |name, values|
@@ -161,8 +170,8 @@ module Ephem
161
170
  end
162
171
 
163
172
  def process_summaries(count, summary_data, name_data)
164
- count.times do |i|
165
- offset = i * @summary_step
173
+ count.times do |summary_index|
174
+ offset = summary_index * @summary_step
166
175
  values = extract_values(summary_data[offset, @summary_length])
167
176
  name = extract_name(name_data[offset, @summary_step])
168
177
  yield name, values
@@ -185,8 +194,8 @@ module Ephem
185
194
  BinaryReader::ENDIANNESS_DOUBLE_FORMATS[@endianness]
186
195
  end
187
196
 
188
- def endian_uint32
189
- BinaryReader::ENDIANNESS_UINT32_FORMATS[@endianness]
197
+ def endian_int32
198
+ BinaryReader::ENDIANNESS_INT32_FORMATS[@endianness]
190
199
  end
191
200
  end
192
201
  end
data/lib/ephem/pck.rb CHANGED
@@ -22,22 +22,39 @@ module Ephem
22
22
 
23
23
  # Opens a binary PCK file.
24
24
  #
25
+ # Without a block, returns the open kernel; the caller must close it.
26
+ # With a block, yields the kernel, closes it when the block returns or
27
+ # raises, and returns the block's value, like +File.open+.
28
+ #
25
29
  # @param path [String] Path to the PCK (+.bpc+) file
26
- # @return [PCK]
27
- # @raise [ArgumentError] if the file is not a binary PCK or cannot be read
30
+ # @yieldparam pck [PCK] the open kernel
31
+ # @return [PCK] the open kernel, if no block is given
32
+ # @return [Object] the block's value, if a block is given
33
+ # @raise [Ephem::FileFormatError] if the file is not a binary PCK
28
34
  def self.open(path)
29
- daf = IO::DAF.new(File.open(path, "rb"))
35
+ pck = load_kernel(path)
36
+ return pck unless block_given?
37
+
38
+ begin
39
+ yield pck
40
+ ensure
41
+ pck.close
42
+ end
43
+ end
44
+
45
+ def self.load_kernel(path)
46
+ file = File.open(path, "rb")
47
+ daf = IO::DAF.new(file)
30
48
  unless daf.file_type == :pck
31
- raise ArgumentError, "#{path} is not a binary PCK (DAF/PCK) file"
49
+ raise FileFormatError, "#{path} is not a binary PCK (DAF/PCK) file"
32
50
  end
33
51
 
34
52
  new(daf: daf)
35
- rescue Errno::EACCES => e
36
- raise ArgumentError, "File permission denied: #{path} (#{e.message})"
37
53
  rescue
38
- daf&.close
54
+ (daf || file)&.close
39
55
  raise
40
56
  end
57
+ private_class_method :load_kernel
41
58
 
42
59
  # @return [void]
43
60
  def close
@@ -27,7 +27,9 @@ module Ephem
27
27
  Bodies::SATURN => "Saturn",
28
28
  Bodies::URANUS => "Uranus",
29
29
  Bodies::NEPTUNE => "Neptune",
30
- Bodies::PLUTO => "Pluto"
30
+ Bodies::PLUTO => "Pluto",
31
+ Bodies::TIME_CENTER => "Time Center",
32
+ Bodies::TT_MINUS_TDB => "TT-TDB"
31
33
  }.freeze
32
34
 
33
35
  # @return [Ephem::IO::DAF] the DAF object representing the data file
@@ -79,13 +81,8 @@ module Ephem
79
81
  start_date = format_date(*julian_to_gregorian(@start_jd))
80
82
  end_date = format_date(*julian_to_gregorian(@end_jd))
81
83
 
82
- center_name = get_body_name(@center, "Unknown Center")
83
- target_name = get_body_name(@target, "Unknown Target")
84
-
85
84
  dates = "#{start_date}..#{end_date}"
86
- center = "#{center_name} (#{@center})"
87
- target = "#{target_name} (#{@target})"
88
- description = "#{dates} Type #{@data_type} #{center} -> #{target}"
85
+ description = "#{dates} Type #{@data_type} #{label}"
89
86
  return description unless verbose
90
87
 
91
88
  <<~DESCRIPTION.chomp
@@ -94,6 +91,16 @@ module Ephem
94
91
  DESCRIPTION
95
92
  end
96
93
 
94
+ # What the segment describes, as used in descriptions and errors.
95
+ #
96
+ # @return [String] e.g. "Earth-Moon Barycenter (3) -> Moon (301)"
97
+ def label
98
+ center_name = get_body_name(@center, "Unknown Center")
99
+ target_name = get_body_name(@target, "Unknown Target")
100
+
101
+ "#{center_name} (#{@center}) -> #{target_name} (#{@target})"
102
+ end
103
+
97
104
  # Whether the given time falls within this segment's coverage.
98
105
  #
99
106
  # @param tdb [Numeric] time in TDB Julian Date
@@ -103,22 +110,40 @@ module Ephem
103
110
  (tdb + tdb2).between?(@start_jd, @end_jd)
104
111
  end
105
112
 
113
+ # @raise [Ephem::UnsupportedError] the segment's data type has no
114
+ # implementation
106
115
  def compute(_tdb, _tdb2 = 0.0)
107
- raise NotImplementedError,
108
- "#{self.class} has not implemented compute() for data type #{@data_type}"
116
+ raise UnsupportedError, unsupported_message("compute")
109
117
  end
110
118
 
119
+ # @raise [Ephem::UnsupportedError] the segment's data type has no
120
+ # implementation
121
+ def position_at(_tdb, _tdb2 = 0.0)
122
+ raise UnsupportedError, unsupported_message("position_at")
123
+ end
124
+
125
+ # @raise [Ephem::UnsupportedError] the segment's data type has no
126
+ # implementation
111
127
  def compute_and_differentiate(_tdb, _tdb2 = 0.0)
112
- raise NotImplementedError,
113
- "#{self.class} has not implemented compute_and_differentiate() for data type #{@data_type}"
128
+ raise UnsupportedError, unsupported_message("compute_and_differentiate")
129
+ end
130
+
131
+ # @raise [Ephem::UnsupportedError] the segment's data type has no
132
+ # implementation
133
+ def state_at(_tdb, _tdb2 = 0.0)
134
+ raise UnsupportedError, unsupported_message("state_at")
114
135
  end
115
136
 
116
137
  def clear_data
117
- # Placeholder method to clear any cached data
118
138
  end
119
139
 
120
140
  private
121
141
 
142
+ def unsupported_message(method_name)
143
+ "#{self.class} has not implemented #{method_name}() " \
144
+ "for data type #{@data_type}"
145
+ end
146
+
122
147
  def parse_descriptor(descriptor)
123
148
  @start_second,
124
149
  @end_second,
@@ -135,14 +160,7 @@ module Ephem
135
160
  end
136
161
 
137
162
  def get_body_name(id, default)
138
- name = TARGET_NAMES.fetch(id, default)
139
- titlecase(name)
140
- end
141
-
142
- def titlecase(name)
143
- return name if name.start_with?("1", "C/", "DSS-")
144
-
145
- name.split.then { |words| words.map(&:capitalize).join(" ") }
163
+ TARGET_NAMES.fetch(id, default)
146
164
  end
147
165
  end
148
166
  end
@@ -6,25 +6,30 @@ module Ephem
6
6
  module ChebyshevType2
7
7
  include Core::Constants
8
8
 
9
+ Records = Struct.new(
10
+ :midpoints,
11
+ :radii,
12
+ :coefficients,
13
+ :velocity_coefficients,
14
+ keyword_init: true
15
+ )
16
+
17
+ def initialize(...)
18
+ super
19
+ @records = nil
20
+ @data_lock = Mutex.new
21
+ end
22
+
9
23
  # @return [void]
10
24
  def clear_data
11
- @data_lock.synchronize do
12
- @data_loaded = false
13
- @midpoints = nil
14
- @radii = nil
15
- @coefficients = nil
16
- end
25
+ @data_lock.synchronize { @records = nil }
17
26
  end
18
27
 
19
28
  private
20
29
 
21
30
  def load_data
22
- @data_lock.synchronize do
23
- return if @data_loaded
24
-
25
- process_coefficient_data(load_coefficient_data)
26
-
27
- @data_loaded = true
31
+ @records || @data_lock.synchronize do
32
+ @records ||= process_coefficient_data(load_coefficient_data)
28
33
  end
29
34
  end
30
35
 
@@ -33,7 +38,7 @@ module Ephem
33
38
  _start_index, _end_index, record_size, segment_count = metadata
34
39
 
35
40
  coefficient_count = ((record_size - 2) / component_count).to_i
36
- coefficients_raw = @daf.map_array(@start_i, @end_i - 4)
41
+ coefficients_raw = @daf.read_array(@start_i, @end_i - 4)
37
42
 
38
43
  [
39
44
  coefficients_raw,
@@ -48,25 +53,31 @@ module Ephem
48
53
 
49
54
  coefficients = coefficients_raw.each_slice(record_size).to_a
50
55
 
51
- @midpoints = coefficients.map { |row| row[0] }
52
- @radii = coefficients.map { |row| row[1] }
53
- n_terms = coefficient_count
54
- n_components = component_count
56
+ midpoints = coefficients.map { |row| row[0] }.freeze
57
+ radii = coefficients.map { |row| row[1] }.freeze
58
+ dimension_count = component_count
55
59
 
56
- @coefficients = Array.new(segment_count) do |i|
57
- row = coefficients[i][2..]
58
- Array.new(n_terms) do |k|
59
- Array.new(n_components) do |j|
60
- row[k + j * n_terms]
60
+ terms = Array.new(segment_count) do |record_index|
61
+ row = coefficients[record_index][2..]
62
+ Array.new(coefficient_count) do |degree|
63
+ Array.new(dimension_count) do |component|
64
+ row[degree + component * coefficient_count]
61
65
  end
62
66
  end
63
67
  end
68
+
69
+ Records.new(
70
+ midpoints: midpoints,
71
+ radii: radii,
72
+ coefficients: terms.freeze,
73
+ velocity_coefficients: nil
74
+ ).freeze
64
75
  end
65
76
 
66
77
  def convert_to_seconds(tdb, tdb2)
67
78
  case tdb
68
79
  when Array
69
- tdb.map { |t| time_to_seconds(t, tdb2) }
80
+ tdb.map { |time| time_to_seconds(time, tdb2) }
70
81
  else
71
82
  time_to_seconds(tdb, tdb2)
72
83
  end
@@ -76,66 +87,102 @@ module Ephem
76
87
  (time - Time::J2000_EPOCH + offset) * Time::SECONDS_PER_DAY
77
88
  end
78
89
 
79
- def generate_position(tdb_seconds)
80
- interval = find_interval(tdb_seconds)
81
- normalized_time = compute_normalized_time(tdb_seconds, interval)
82
- coeffs = @coefficients[interval]
83
- Computation::ChebyshevPolynomial.evaluate(coeffs, normalized_time)
90
+ def generate_position(records, tdb_seconds)
91
+ interval = find_interval(records, tdb_seconds)
92
+ normalized_time =
93
+ compute_normalized_time(records, tdb_seconds, interval)
94
+ coefficients = records.coefficients[interval]
95
+ Computation::ChebyshevPolynomial.evaluate(coefficients, normalized_time)
84
96
  end
85
97
 
86
- def generate_single(tdb_seconds)
87
- interval = find_interval(tdb_seconds)
88
- normalized_time = compute_normalized_time(tdb_seconds, interval)
98
+ def generate_single(records, tdb_seconds)
99
+ interval = find_interval(records, tdb_seconds)
100
+ normalized_time =
101
+ compute_normalized_time(records, tdb_seconds, interval)
89
102
 
90
- coeffs = @coefficients[interval] # already [n_terms][3]
103
+ coefficients = records.coefficients[interval]
91
104
  Computation::ChebyshevPolynomial.evaluate_with_derivative(
92
- coeffs,
105
+ coefficients,
93
106
  normalized_time,
94
- @radii[interval]
107
+ records.radii[interval]
95
108
  )
96
109
  end
97
110
 
98
- def generate_multiple(tdb_seconds)
99
- tdb_seconds.map { |time| generate_single(time) }
111
+ def generate_multiple(records, tdb_seconds)
112
+ tdb_seconds.map { |time| generate_single(records, time) }
100
113
  end
101
114
 
102
- def find_interval(tdb_seconds)
103
- left = 0
104
- right = @midpoints.size - 1
105
-
106
- if @last_interval && time_in_interval?(tdb_seconds, @last_interval)
107
- return @last_interval
115
+ def find_interval(records, tdb_seconds)
116
+ last_interval = @last_interval
117
+ if last_interval &&
118
+ time_in_interval?(records, tdb_seconds, last_interval)
119
+ return last_interval
108
120
  end
109
121
 
122
+ midpoints = records.midpoints
123
+ radii = records.radii
124
+ left = 0
125
+ right = midpoints.size - 1
126
+
110
127
  while left <= right
111
- mid = (left + right) / 2
112
- min_time = @midpoints[mid] - @radii[mid]
113
- max_time = @midpoints[mid] + @radii[mid]
128
+ middle = (left + right) / 2
129
+ midpoint = midpoints[middle]
130
+ radius = radii[middle]
131
+ min_time = midpoint - radius
132
+ max_time = midpoint + radius
114
133
 
115
134
  if tdb_seconds < min_time
116
- right = mid - 1
135
+ right = middle - 1
117
136
  elsif tdb_seconds > max_time
118
- left = mid + 1
137
+ left = middle + 1
119
138
  else
120
- @last_interval = mid
121
- return mid
139
+ @last_interval = middle
140
+ return middle
122
141
  end
123
142
  end
124
143
 
125
- raise OutOfRangeError.new(
126
- "Time #{tdb_seconds} is outside the coverage of this segment",
127
- tdb_seconds
144
+ raise out_of_range_error(
145
+ [Time::J2000_EPOCH + tdb_seconds / Time::SECONDS_PER_DAY]
128
146
  )
129
147
  end
130
148
 
131
- def time_in_interval?(time, interval)
132
- min_time = @midpoints[interval] - @radii[interval]
133
- max_time = @midpoints[interval] + @radii[interval]
134
- time.between?(min_time, max_time)
149
+ def out_of_range_error(times)
150
+ Coverage.out_of_range_error(
151
+ times: times,
152
+ label: label,
153
+ ranges: [[@start_jd, @end_jd]]
154
+ )
155
+ end
156
+
157
+ def request_out_of_range_error(records, error, tdb, tdb2)
158
+ times = uncovered_times(records, tdb, tdb2)
159
+ times.empty? ? error : out_of_range_error(times)
160
+ end
161
+
162
+ def uncovered_times(records, tdb, tdb2)
163
+ Array(tdb).filter_map do |time|
164
+ tdb_seconds = time_to_seconds(time, tdb2)
165
+ time + tdb2 unless covered_by_records?(records, tdb_seconds)
166
+ end
167
+ end
168
+
169
+ def covered_by_records?(records, tdb_seconds)
170
+ midpoints = records.midpoints
171
+ radii = records.radii
172
+ interval = (0...midpoints.size).bsearch do |index|
173
+ midpoints[index] + radii[index] >= tdb_seconds
174
+ end
175
+ interval && time_in_interval?(records, tdb_seconds, interval)
176
+ end
177
+
178
+ def time_in_interval?(records, time, interval)
179
+ midpoint = records.midpoints[interval]
180
+ radius = records.radii[interval]
181
+ time.between?(midpoint - radius, midpoint + radius)
135
182
  end
136
183
 
137
- def compute_normalized_time(time_seconds, interval)
138
- (time_seconds - @midpoints[interval]) / @radii[interval]
184
+ def compute_normalized_time(records, time_seconds, interval)
185
+ (time_seconds - records.midpoints[interval]) / records.radii[interval]
139
186
  end
140
187
  end
141
188
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ephem
4
+ module Segments
5
+ # Builds the error raised when a query asks for times a segment, or a
6
+ # group of segments, does not cover.
7
+ module Coverage
8
+ extend Core::CalendarCalculations
9
+
10
+ # @param times [Array<Numeric>] the uncovered times, as TDB Julian Dates
11
+ # @param label [String] what the segments describe, e.g.
12
+ # "Solar System Barycenter (0) -> Earth-Moon Barycenter (3)"
13
+ # @param ranges [Array<Array(Float, Float)>] the covered Julian Date
14
+ # ranges, as [start_jd, end_jd] pairs
15
+ # @return [Ephem::OutOfRangeError]
16
+ def self.out_of_range_error(times:, label:, ranges:)
17
+ message = "#{describe_times(times)} outside the coverage of " \
18
+ "#{label}, which covers #{describe_ranges(ranges)}"
19
+ OutOfRangeError.new(message, times)
20
+ end
21
+
22
+ def self.describe_times(times)
23
+ first_time = describe_time(times.first)
24
+ other_count = times.size - 1
25
+ return "#{first_time} is" if other_count.zero?
26
+
27
+ noun = (other_count == 1) ? "time" : "times"
28
+ "#{first_time} and #{other_count} other #{noun} are"
29
+ end
30
+
31
+ def self.describe_time(julian_date)
32
+ return "JD #{julian_date}" unless julian_date.finite?
33
+
34
+ "JD #{julian_date} (#{calendar_date(julian_date)})"
35
+ end
36
+
37
+ def self.describe_ranges(ranges)
38
+ merge(ranges).map do |start_jd, end_jd|
39
+ "JD #{start_jd}..#{end_jd} " \
40
+ "(#{calendar_date(start_jd)}..#{calendar_date(end_jd)})"
41
+ end.join(", ")
42
+ end
43
+
44
+ def self.merge(ranges)
45
+ ranges.sort.each_with_object([]) do |(start_jd, end_jd), merged|
46
+ last_range = merged.last
47
+ if last_range && start_jd <= last_range[1]
48
+ last_range[1] = [last_range[1], end_jd].max
49
+ else
50
+ merged << [start_jd, end_jd]
51
+ end
52
+ end
53
+ end
54
+
55
+ def self.calendar_date(julian_date)
56
+ format_date(*julian_to_gregorian(julian_date))
57
+ end
58
+
59
+ private_class_method :describe_times,
60
+ :describe_time,
61
+ :describe_ranges,
62
+ :merge,
63
+ :calendar_date
64
+ end
65
+ end
66
+ end
@@ -11,12 +11,6 @@ module Ephem
11
11
 
12
12
  COMPONENT_COUNT = 3 # phi, theta, psi
13
13
 
14
- def initialize(daf:, source:, descriptor:)
15
- super
16
- @data_loaded = false
17
- @data_lock = Mutex.new
18
- end
19
-
20
14
  # @return [Integer] NAIF frame ID of the oriented body frame
21
15
  alias_method :body, :target
22
16
  # @return [Integer] NAIF ID of the inertial reference frame
@@ -29,17 +23,19 @@ module Ephem
29
23
  # @return [Core::Orientation, Array<Core::Orientation>] angles in radians
30
24
  # @raise [Ephem::OutOfRangeError] if time is outside segment coverage
31
25
  def angles_at(tdb, tdb2 = 0.0)
32
- load_data
26
+ records = load_data
33
27
  tdb_seconds = convert_to_seconds(tdb, tdb2)
34
28
 
35
29
  case tdb_seconds
36
30
  when Numeric
37
- to_orientation(generate_position(tdb_seconds))
31
+ to_orientation(generate_position(records, tdb_seconds))
38
32
  else
39
33
  tdb_seconds.map do |seconds|
40
- to_orientation(generate_position(seconds))
34
+ to_orientation(generate_position(records, seconds))
41
35
  end
42
36
  end
37
+ rescue OutOfRangeError => error
38
+ raise request_out_of_range_error(records, error, tdb, tdb2), cause: nil
43
39
  end
44
40
 
45
41
  # Euler angles and their rates at the given time.
@@ -50,17 +46,19 @@ module Ephem
50
46
  # carrying rates (radians/day)
51
47
  # @raise [Ephem::OutOfRangeError] if time is outside segment coverage
52
48
  def orientation_at(tdb, tdb2 = 0.0)
53
- load_data
49
+ records = load_data
54
50
  tdb_seconds = convert_to_seconds(tdb, tdb2)
55
51
 
56
52
  case tdb_seconds
57
53
  when Numeric
58
- to_orientation(*generate_single(tdb_seconds))
54
+ to_orientation(*generate_single(records, tdb_seconds))
59
55
  else
60
- generate_multiple(tdb_seconds).map do |angles, rates|
56
+ generate_multiple(records, tdb_seconds).map do |angles, rates|
61
57
  to_orientation(angles, rates)
62
58
  end
63
59
  end
60
+ rescue OutOfRangeError => error
61
+ raise request_out_of_range_error(records, error, tdb, tdb2), cause: nil
64
62
  end
65
63
 
66
64
  # The reference-frame to body-fixed rotation matrix at the given time,
@@ -76,13 +74,17 @@ module Ephem
76
74
  angles.is_a?(Array) ? angles.map(&:to_matrix) : angles.to_matrix
77
75
  end
78
76
 
77
+ # @return [String] e.g. "frame 31008 relative to frame 1"
78
+ def label
79
+ "frame #{body} relative to frame #{reference_frame}"
80
+ end
81
+
79
82
  def describe(verbose: false)
80
83
  start_date = format_date(*julian_to_gregorian(@start_jd))
81
84
  end_date = format_date(*julian_to_gregorian(@end_jd))
82
85
 
83
- description =
84
- "#{start_date}..#{end_date} Type #{@data_type} orientation of " \
85
- "frame #{body} relative to frame #{reference_frame}"
86
+ dates = "#{start_date}..#{end_date}"
87
+ description = "#{dates} Type #{@data_type} orientation of #{label}"
86
88
  return description unless verbose
87
89
 
88
90
  <<~DESCRIPTION.chomp
@@ -4,14 +4,16 @@ module Ephem
4
4
  module Segments
5
5
  module OrientationSource
6
6
  def compute(*)
7
- raise NotImplementedError,
7
+ raise UnsupportedError,
8
8
  "Use #angles_at or #orientation_at for orientation kernels"
9
9
  end
10
+ alias_method :position_at, :compute
10
11
 
11
12
  def compute_and_differentiate(*)
12
- raise NotImplementedError,
13
+ raise UnsupportedError,
13
14
  "Use #orientation_at for orientation kernels"
14
15
  end
16
+ alias_method :state_at, :compute_and_differentiate
15
17
  end
16
18
  end
17
19
  end