Class: Ephem::SPK
- Inherits:
-
Object
- Object
- Ephem::SPK
- Defined in:
- lib/ephem/spk.rb
Overview
The SPK class represents a SPICE Kernel (SPK) file, which contains ephemeris data for solar system bodies. It manages segments of trajectory data and provides methods to access and manipulate this data.
SPK files contain segments of ephemeris data, where each segment represents the motion of one body (target) with respect to another body (center) over a specific time period.
Constant Summary collapse
- TYPES =
[ INPOP = "IMCCE INPOP", JPL_DE = "JPL DE" ].freeze
- INPOP_REGEXP =
/^\s+\d{4}\.\d{5}0+$/- DE_REGEXP =
/^[A-Z]E-(\d{4})LE-\1$/- DE_FILENAME =
"NIO2SPK"- DATA_TYPE_IDENTIFIER =
5
Instance Attribute Summary collapse
-
#daf ⇒ Object
readonly
Returns the value of attribute daf.
-
#pairs ⇒ Object
readonly
Returns the value of attribute pairs.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Class Method Summary collapse
-
.open(path) ⇒ SPK
Opens an SPK file at the specified path.
Instance Method Summary collapse
-
#[](center, target) ⇒ Segments::Segment, Segments::PositionGroup
Retrieves the segment for a specific center-target pair.
-
#close ⇒ void
Closes the SPK file and cleans up resources.
-
#comments ⇒ String
Returns the comments stored in the SPK file.
-
#each_segment {|segment| ... } ⇒ Enumerator, void
Iterates through all segments in the SPK file.
- #excerpt(output_path:, start_jd:, end_jd:, target_ids: nil, debug: false) ⇒ Object
-
#initialize(daf:) ⇒ SPK
constructor
Creates a new SPK instance with the given DAF.
-
#to_s ⇒ String
Returns a string representation of the SPK file.
-
#type ⇒ String?
Type of SPK file to make the difference between JPL DE and IMCCE INPOP.
Constructor Details
#initialize(daf:) ⇒ SPK
Creates a new SPK instance with the given DAF.
36 37 38 39 40 41 42 |
# File 'lib/ephem/spk.rb', line 36 def initialize(daf:) raise ArgumentError, "DAF cannot be nil" if daf.nil? @daf = daf @segments = load_segments @pairs = build_pairs end |
Instance Attribute Details
#daf ⇒ Object (readonly)
Returns the value of attribute daf.
29 30 31 |
# File 'lib/ephem/spk.rb', line 29 def daf @daf end |
#pairs ⇒ Object (readonly)
Returns the value of attribute pairs.
29 30 31 |
# File 'lib/ephem/spk.rb', line 29 def pairs @pairs end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
29 30 31 |
# File 'lib/ephem/spk.rb', line 29 def segments @segments end |
Class Method Details
.open(path) ⇒ SPK
Opens an SPK file at the specified path.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ephem/spk.rb', line 49 def self.open(path) daf = IO::DAF.new(File.open(path, "rb")) if daf.file_type == :pck raise ArgumentError, "#{path} is a binary PCK file, use Ephem::PCK.open" end new(daf: daf) rescue Errno::EACCES => e raise ArgumentError, "File permission denied: #{path} (#{e.})" rescue daf&.close raise end |
Instance Method Details
#[](center, target) ⇒ Segments::Segment, Segments::PositionGroup
Retrieves the segment for a specific center-target pair.
90 91 92 93 94 95 |
# File 'lib/ephem/spk.rb', line 90 def [](center, target) @pairs.fetch([center, target]) do raise KeyError, "No segment found for center: #{center}, target: #{target}" end end |
#close ⇒ void
This method returns an undefined value.
Closes the SPK file and cleans up resources. This method should be called when you’re done using the SPK file.
67 68 69 70 |
# File 'lib/ephem/spk.rb', line 67 def close @daf&.close @segments&.each(&:clear_data) end |
#comments ⇒ String
Returns the comments stored in the SPK file.
112 113 114 |
# File 'lib/ephem/spk.rb', line 112 def comments @daf.comments end |
#each_segment {|segment| ... } ⇒ Enumerator, void
Iterates through all segments in the SPK file.
122 123 124 125 126 |
# File 'lib/ephem/spk.rb', line 122 def each_segment(&block) return enum_for(:each_segment) unless block_given? @segments.each(&block) end |
#excerpt(output_path:, start_jd:, end_jd:, target_ids: nil, debug: false) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/ephem/spk.rb', line 128 def excerpt(output_path:, start_jd:, end_jd:, target_ids: nil, debug: false) Excerpt .new(self) .extract( output_path: output_path, start_jd: start_jd, end_jd: end_jd, target_ids: target_ids, debug: debug ) end |
#to_s ⇒ String
Returns a string representation of the SPK file.
75 76 77 78 79 80 |
# File 'lib/ephem/spk.rb', line 75 def to_s <<~DESCRIPTION SPK file with #{@segments.size} segments: #{@segments.join("\n")} DESCRIPTION end |
#type ⇒ String?
Type of SPK file to make the difference between JPL DE and IMCCE INPOP
100 101 102 103 104 105 106 107 |
# File 'lib/ephem/spk.rb', line 100 def type @type ||= if @daf.record_data.internal_filename.match?(INPOP_REGEXP) INPOP elsif @daf.record_data.internal_filename == DE_FILENAME || segments.first&.source&.match?(DE_REGEXP) JPL_DE end end |