Class: Astronoby::Ephem

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

Class Method Summary collapse

Class Method Details

.download(name:, target:) ⇒ Boolean

Download an ephemeris file.

Examples:

Downloading de440t SPK from NASA JPL

Astronoby::Ephem.download(name: "de440t.bsp", target: "tmp/de440t.bsp")

Parameters:

  • name (String)

    Name of the ephemeris file, supported by the Ephem gem

  • target (String)

    Location where to store the file

Returns:

  • (Boolean)

    true if the download was successful, false otherwise



16
17
18
# File 'lib/astronoby/ephem.rb', line 16

def self.download(name:, target:)
  ::Ephem::Download.call(name: name, target: target)
end

.load(target) ⇒ ::Ephem::SPK

Load an ephemeris file.

Examples:

Loading previously downloaded de440t SPK from NASA JPL

Astronoby::Ephem.load("tmp/de440t.bsp")

Parameters:

  • target (String)

    Path of the ephemeris file

Returns:

  • (::Ephem::SPK)

    Ephemeris object from the Ephem gem



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/astronoby/ephem.rb', line 27

def self.load(target)
  spk = ::Ephem::SPK.open(target)
  unless ::Ephem::SPK::TYPES.include?(spk&.type)
    raise(
      EphemerisError,
      "#{target} is not a valid type. Accepted: #{::Ephem::SPK::TYPES.join(", ")}"
    )
  end

  spk
end