Class: Ephem::Segments::Segment
- Inherits:
-
BaseSegment
- Object
- BaseSegment
- Ephem::Segments::Segment
- Defined in:
- lib/ephem/segments/segment.rb
Overview
Manages data segments within SPICE kernel (SPK) files, providing methods to compute positions and velocities of celestial bodies using Chebyshev polynomial approximations.
Each segment contains data for a specific celestial body (target) relative to another body (center) within a specific time range. The data is stored as Chebyshev polynomial coefficients that can be evaluated to obtain position and velocity vectors.
The class provides thread-safe data loading and caching mechanisms to optimize performance while ensuring data consistency in multithreaded environments.
Constant Summary collapse
- COMPONENT_COUNTS =
{ 2 => 3, # Type 2: position (x, y, z) 3 => 6 # Type 3: position (x, y, z) and velocity (vx, vy, vz) }.freeze
Constants inherited from BaseSegment
Instance Attribute Summary
Attributes inherited from BaseSegment
#center, #daf, #source, #target
Instance Method Summary collapse
-
#clear_data ⇒ void
Clears cached coefficient data, forcing reload on next computation.
-
#compute(tdb, tdb2 = 0.0) ⇒ Ephem::Core::Vector
(also: #position_at)
Computes the position of the target body relative to the center body at the specified time.
-
#compute_and_differentiate(tdb, tdb2 = 0.0) ⇒ Ephem::Core::State+
(also: #state_at)
Computes both position and velocity vectors at the specified time.
-
#initialize(daf:, source:, descriptor:) ⇒ Segment
constructor
A new instance of Segment.
Methods inherited from BaseSegment
Methods included from Core::CalendarCalculations
format_date, julian_to_gregorian
Constructor Details
#initialize(daf:, source:, descriptor:) ⇒ Segment
Returns a new instance of Segment.
51 52 53 54 55 |
# File 'lib/ephem/segments/segment.rb', line 51 def initialize(daf:, source:, descriptor:) super @data_loaded = false @data_lock = Mutex.new end |
Instance Method Details
#clear_data ⇒ void
This method returns an undefined value.
Clears cached coefficient data, forcing reload on next computation.
This method is thread-safe and can be used to free memory or force fresh data loading if needed.
121 122 123 124 125 126 127 128 |
# File 'lib/ephem/segments/segment.rb', line 121 def clear_data @data_lock.synchronize do @data_loaded = false @midpoints = nil @radii = nil @coefficients = nil end end |
#compute(tdb, tdb2 = 0.0) ⇒ Ephem::Core::Vector Also known as: position_at
Computes the position of the target body relative to the center body at the specified time.
Uses Chebyshev polynomial approximation to interpolate the position from stored coefficients. The computation is thread-safe and uses cached data when available.
71 72 73 |
# File 'lib/ephem/segments/segment.rb', line 71 def compute(tdb, tdb2 = 0.0) Core::Vector.new(*generate(tdb, tdb2).first) end |
#compute_and_differentiate(tdb, tdb2 = 0.0) ⇒ Ephem::Core::State+ Also known as: state_at
Computes both position and velocity vectors at the specified time.
Uses Chebyshev polynomial approximation and its derivative to compute both position and velocity. The computation is thread-safe and uses cached data when available.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ephem/segments/segment.rb', line 93 def compute_and_differentiate(tdb, tdb2 = 0.0) load_data tdb_seconds = convert_to_seconds(tdb, tdb2) case tdb_seconds when Numeric pos_array, vel_array = generate_single(tdb_seconds) Core::State.new( Core::Vector.new(pos_array[0], pos_array[1], pos_array[2]), Core::Vector.new(vel_array[0], vel_array[1], vel_array[2]) ) else generate_multiple(tdb_seconds).map do |pos_array, vel_array| Core::State.new( Core::Vector.new(pos_array[0], pos_array[1], pos_array[2]), Core::Vector.new(vel_array[0], vel_array[1], vel_array[2]) ) end end end |