Class: Ephem::Excerpt

Inherits:
Object
  • Object
show all
Defined in:
lib/ephem/excerpt.rb

Overview

The Excerpt class creates SPK file excerpts with reduced time spans and target bodies. This is useful for creating smaller files that focus only on the data needed for specific applications.

Examples:

Create an excerpt with specific time range and bodies

spk = Ephem::SPK.open("de421.bsp")
excerpt = Ephem::Excerpt.new(spk).extract(
  output_path: "excerpt.bsp",
  start_jd: 2458849.5,           # January 1, 2020
  end_jd: 2459580.5,             # December 31, 2021
  target_ids: [3, 10, 301, 399]  # Earth-Moon, Sun, Moon, Earth
)

Defined Under Namespace

Classes: DAFWriter

Constant Summary collapse

S_PER_DAY =

Constants for time calculations

Core::Constants::Time::SECONDS_PER_DAY
J2000_EPOCH =
Core::Constants::Time::J2000_EPOCH
RECORD_SIZE =
1024

Instance Method Summary collapse

Constructor Details

#initialize(spk) ⇒ Excerpt

Returns a new instance of Excerpt.

Parameters:

  • spk (Ephem::SPK)

    The SPK object to create an excerpt from



23
24
25
26
27
# File 'lib/ephem/excerpt.rb', line 23

def initialize(spk)
  @spk = spk
  @daf = spk.instance_variable_get(:@daf)
  @binary_reader = @daf.instance_variable_get(:@binary_reader)
end

Instance Method Details

#extract(output_path:, start_jd:, end_jd:, target_ids: nil, debug: false) ⇒ Ephem::SPK

Creates an excerpt of the SPK file

Parameters:

  • output_path (String)

    Path where the excerpt will be written

  • start_jd (Float)

    Start time as Julian Date

  • end_jd (Float)

    End time as Julian Date

  • target_ids (Array<Integer>, nil) (defaults to: nil)

    Optional list of target IDs to include

  • debug (Boolean) (defaults to: false)

    Whether to print debug information

Returns:

  • (Ephem::SPK)

    A new SPK instance for the excerpt file



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ephem/excerpt.rb', line 39

def extract(output_path:, start_jd:, end_jd:, target_ids: nil, debug: false)
  start_seconds = seconds_since_j2000(start_jd)
  end_seconds = seconds_since_j2000(end_jd)
  output_file = File.open(output_path, "wb+")
  copy_file_header(output_file)
  initialize_summary_section(output_file)
  writer = create_daf_writer(output_file, debug)
  process_segments(writer, start_seconds, end_seconds, target_ids, debug)
  output_file.close

  SPK.open(output_path)
end