Class: Ephem::PCK
- Inherits:
-
Object
- Object
- Ephem::PCK
- Defined in:
- lib/ephem/pck.rb
Overview
Reads a binary PCK (DAF/PCK) orientation kernel: the orientation of one or more body frames over time, expressed as Euler angles.
Constant Summary collapse
- DATA_TYPE_IDENTIFIER =
Index of the data type within a PCK summary descriptor ([start, end, body, reference_frame, data_type, start_i, end_i]).
4
Instance Attribute Summary collapse
-
#daf ⇒ Object
readonly
Returns the value of attribute daf.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Class Method Summary collapse
-
.open(path) ⇒ PCK
Opens a binary PCK file.
Instance Method Summary collapse
-
#[](body) ⇒ Segments::OrientationSegment, Segments::OrientationGroup
Retrieves the orientation source for a body frame.
- #close ⇒ void
-
#comments ⇒ String
The comments stored in the PCK file.
-
#each_segment {|segment| ... } ⇒ Enumerator
If no block is given.
- #excerpt(output_path:, start_jd:, end_jd:, target_ids: nil, debug: false) ⇒ Object
-
#initialize(daf:) ⇒ PCK
constructor
A new instance of PCK.
-
#to_s ⇒ String
A description of the PCK file and its segments.
Constructor Details
#initialize(daf:) ⇒ PCK
Returns a new instance of PCK.
15 16 17 18 19 20 21 |
# File 'lib/ephem/pck.rb', line 15 def initialize(daf:) raise ArgumentError, "DAF cannot be nil" if daf.nil? @daf = daf @segments = load_segments @bodies = build_bodies end |
Instance Attribute Details
#daf ⇒ Object (readonly)
Returns the value of attribute daf.
11 12 13 |
# File 'lib/ephem/pck.rb', line 11 def daf @daf end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
11 12 13 |
# File 'lib/ephem/pck.rb', line 11 def segments @segments end |
Class Method Details
.open(path) ⇒ PCK
Opens a binary PCK file.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ephem/pck.rb', line 28 def self.open(path) daf = IO::DAF.new(File.open(path, "rb")) unless daf.file_type == :pck raise ArgumentError, "#{path} is not a binary PCK (DAF/PCK) file" end new(daf: daf) rescue Errno::EACCES => e raise ArgumentError, "File permission denied: #{path} (#{e.})" rescue daf&.close raise end |
Instance Method Details
#[](body) ⇒ Segments::OrientationSegment, Segments::OrientationGroup
Retrieves the orientation source for a body frame.
55 56 57 58 59 |
# File 'lib/ephem/pck.rb', line 55 def [](body) @bodies.fetch(body) do raise KeyError, "No orientation segment found for body: #{body}" end end |
#close ⇒ void
This method returns an undefined value.
43 44 45 46 |
# File 'lib/ephem/pck.rb', line 43 def close @daf&.close @segments&.each(&:clear_data) end |
#comments ⇒ String
Returns the comments stored in the PCK file.
62 63 64 |
# File 'lib/ephem/pck.rb', line 62 def comments @daf.comments end |
#each_segment {|segment| ... } ⇒ Enumerator
Returns if no block is given.
68 69 70 71 72 |
# File 'lib/ephem/pck.rb', line 68 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
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ephem/pck.rb', line 82 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 description of the PCK file and its segments.
75 76 77 78 79 80 |
# File 'lib/ephem/pck.rb', line 75 def to_s <<~DESCRIPTION PCK file with #{@segments.size} segments: #{@segments.join("\n")} DESCRIPTION end |