Ruby SPICE Wrapper

Planetary Data Workshop, June 2017

Presented by Nick Estes

Lunar Reconnaissance Orbiter Camera SOC

Arizona State University


  • Development started before LRO launch in 2009
  • Wrapper around C-language SPICE toolkit
  • Released with Lunaserv for anyone to use in 2013

What is Ruby?

I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language.
Yukihiro "Matz" Matsumoto
  • Powerful language, simple syntax
  • Everything is an object
  • Everything is redefinable
  • Garbage collected
  • Typing: Strong & Dynamic
  • Blocks everywhere

Development Approach

To SWIG or not to SWIG?

  • SWIG can be very verbose and very heavy
  • Directly wrapped in C using native Ruby API
  • Signals disabled during many SPICE calls
  • Convenience functions for Time objects provided

Available Functions

  • bodn2c
  • bodvcd
  • ckgp
  • dpr
  • et2lst
  • et2rb
  • eul2m
  • furnsh
  • gdpool
  • getfov
  • gfdist
  • gfoclt
  • gfrfov
  • gfsep
  • gfsntc
  • gftfov
  • ilumin
  • kclear
  • ktotal
  • latrec
  • lspcn
  • m2eul
  • m2q
  • mxm
  • mxv
  • pxform
  • q2m
  • qxq
  • rb2et
  • reclat
  • recrad
  • rotate
  • rpd
  • sce2c
  • scs2e
  • sctiks
  • sincpt
  • spkcov
  • spkezp
  • spkezr
  • spkpos
  • str2et
  • subpnt
  • subslr
  • sxform
  • ucrss
  • unload
  • vcrss
  • vdist
  • vdot
  • vnorm
  • vperp
  • vsep
  • vsub
  • wn2rb
  • wninsd
  • xf2eul

Example Function: scs2e

VALUE scs2e(VALUE self, VALUE sc, VALUE sclk) {
  double et;

  Check_Type(sc, T_FIXNUM);
  Check_Type(sclk, T_STRING);

  scs2e_c(NUM2INT(sc), StringValuePtr(sclk), &et);


  return rb_float_new(et);

LROC Usage

  • Lunaserv
  • Processing Pipeline
  • "Where is LRO?": Near-Real-Time Portable Display
  • Ops Scripts:
    • Special observation planning (eg, pits, Earthrise, Oblique Images)
    • Predict kernel offset determination
    • Ops Reports
    • Orbit Information


  • Gem available at:
  • Install like any other Ruby library:
    $ gem install --local path/to/naif-spice.gem
  • Platforms Natively Supported by the Gem:
    • Linux (x86)
    • Linux (x86_64)
    • OS X (Darwin)
    • Raspbian (ARM)
  • Compilation for other platforms or SPICE toolkit versions simply by pointing to C-SPICE location:
    $ gem install --local /path/to/naif-spice.gem -- \
    > --with-cspice-dir=/path/to/cspice

Special note on ARM

TL;DR Test your code in ARM before relying on it.

NAIF has not released SPICE for the ARM architecture, the version included in the gem was compiled at the LROC SOC and has had only limited testing. The LROC SOC has successfully used this gem on multiple generations of the Raspberry Pi, but due to the complexity of floating point math in the ARM architecture, results may vary on a case-by-case basis.

Example of SPICE working on a Raspberry Pi with the Ruby SPICE wrapper is the "Where is LRO?" display in the hallway!


  • Using the right tool for the job is easier when fundamental libraries are available in multiple languages
  • Ruby SPICE wrapper doesn't support all SPICE functions, but adding functions is straight-forward
  • Ruby SPICE wrapper has been around for 8 years and is still actively developed and maintained