Class: Ephem::PCK

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(daf:) ⇒ PCK

Returns a new instance of PCK.

Parameters:

Raises:

  • (ArgumentError)

    if the DAF is nil



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

#dafObject (readonly)

Returns the value of attribute daf.



11
12
13
# File 'lib/ephem/pck.rb', line 11

def daf
  @daf
end

#segmentsObject (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.

Parameters:

  • path (String)

    Path to the PCK (.bpc) file

Returns:

Raises:

  • (ArgumentError)

    if the file is not a binary PCK or cannot be read



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.message})"
rescue
  daf&.close
  raise
end

Instance Method Details

#[](body) ⇒ Segments::OrientationSegment, Segments::OrientationGroup

Retrieves the orientation source for a body frame.

Parameters:

  • body (Integer)

    NAIF frame ID of the oriented body

Returns:

Raises:

  • (KeyError)

    if no segment is found for the given body



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

#closevoid

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

#commentsString

Returns the comments stored in the PCK file.

Returns:

  • (String)

    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.

Yield Parameters:

Returns:

  • (Enumerator)

    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_sString

Returns a description of the PCK file and its segments.

Returns:

  • (String)

    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