Class: Ephem::Excerpt

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

Overview

The Excerpt class creates DAF excerpts (SPK or binary PCK) with reduced time spans and 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(kernel) ⇒ Excerpt

Returns a new instance of Excerpt.

Parameters:



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

def initialize(kernel)
  @kernel = kernel
  @daf = kernel.daf
  @binary_reader = @daf.binary_reader
end

Instance Method Details

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

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/body IDs to include

  • debug (Boolean) (defaults to: false)

    Whether to print debug information

Returns:



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

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

  reopen(output_path)
end