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
- SEGMENT_CLASSES =
{}
Instance Attribute Summary collapse
-
#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::BaseSegment
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.
37 38 39 40 41 42 43 |
# File 'lib/ephem/spk.rb', line 37 def initialize(daf:) raise ArgumentError, "DAF cannot be nil" if daf.nil? @daf = daf @segments = load_segments @pairs = build_pairs end |
Instance Attribute Details
#pairs ⇒ Object (readonly)
Returns the value of attribute pairs.
30 31 32 |
# File 'lib/ephem/spk.rb', line 30 def pairs @pairs end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
30 31 32 |
# File 'lib/ephem/spk.rb', line 30 def segments @segments end |
Class Method Details
Instance Method Details
#[](center, target) ⇒ Segments::BaseSegment
Retrieves the segment for a specific center-target pair.
83 84 85 86 87 88 |
# File 'lib/ephem/spk.rb', line 83 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.
61 62 63 64 |
# File 'lib/ephem/spk.rb', line 61 def close @daf&.close @segments&.each(&:clear_data) end |
#comments ⇒ String
Returns the comments stored in the SPK file.
105 106 107 |
# File 'lib/ephem/spk.rb', line 105 def comments @daf.comments end |
#each_segment {|segment| ... } ⇒ Enumerator, void
Iterates through all segments in the SPK file.
115 116 117 118 119 |
# File 'lib/ephem/spk.rb', line 115 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
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ephem/spk.rb', line 121 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.
69 70 71 72 73 74 |
# File 'lib/ephem/spk.rb', line 69 def to_s <<~DESCRIPTION SPK file with #{@segments.size} segments: #{@segments.map(&:to_s).join("\n")} DESCRIPTION end |
#type ⇒ String?
Type of SPK file to make the difference between JPL DE and IMCCE INPOP
93 94 95 96 97 98 99 100 |
# File 'lib/ephem/spk.rb', line 93 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 |