SPICE Interface

namespace spice

SPICE ephemeris and time interface for huira.

Provides wrappers for CSPICE kernel loading, time conversion, and state/rotation queries. All units are SI unless otherwise noted. Functions are thread-safe and handle SPICE error management.

Functions

inline void furnsh(const fs::path &file_path)

Load a SPICE kernel file.

Parameters:

file_path – Path to kernel file

inline void furnsh_relative_to_file(const fs::path &kernel_path)

Load a SPICE kernel file, resolving relative to its parent directory.

Parameters:

kernel_path – Path to kernel file

inline fs::path get_default_lsk_path()

Get the default LSK (leap seconds kernel) path.

Returns:

fs::path Path to default LSK

inline void ensure_lsk_loaded()

Ensure the default LSK is loaded.

inline fs::path get_default_pck_path()

Get the default PCK (planetary constants kernel) path.

Returns:

fs::path Path to default PCK

inline void load_default_pck()

Load the default PCK.

inline double str2et(const std::string &time_string)

Convert a time string to ephemeris time (ET, seconds past J2000).

Parameters:

time_stringTime string (e.g., “2000-001T12:00:00”)

Returns:

double Ephemeris time (seconds past J2000)

inline double deltet(double epoch, const std::string &eptype)

Compute delta ET for a given epoch and type.

Parameters:
  • epoch – Epoch (seconds past J2000)

  • eptype – Type of delta (e.g., “DELTET”)

Returns:

double Delta ET

inline double unitim(double epoch, const std::string &insys, const std::string &outsys)

Convert an epoch from one time system to another.

Parameters:
  • epoch – Epoch (seconds)

  • insys – Input time system

  • outsys – Output time system

Returns:

double Converted epoch

inline std::string timout(double et, const std::string &pictur, int lenout)

Format ephemeris time as a string.

Parameters:
  • et – Ephemeris time (seconds past J2000)

  • pictur – Output format string

  • lenout – Output string length

Returns:

std::string Formatted time string

template<huira::IsFloatingPoint T>
inline std::tuple<Vec3<T>, Vec3<T>, double> spkezr(const std::string &TARGET, const huira::Time &time, const std::string &FRAME, const std::string &ABCORR, const std::string &OBSERVER)

Get the state (position, velocity, light time) of a target relative to an observer.

returns the state (position and velocity) of a target body relative to an observer.

Template Parameters:

T – Floating point type

Parameters:
  • TARGET – Target body name

  • time – Observation time

  • FRAME – Reference frame

  • ABCORR – Aberration correction

  • OBSERVER – Observer body name

  • TARGET – The name of the target body.

  • time – The time of observation.

  • FRAME – The reference frame relative to which the output vectors are expressed.

  • ABCORR – Aberration correction flag.

  • OBSERVER – The name of the observing body.

Returns:

std::tuple<Vec3<T>, Vec3<T>, double> {position [m], velocity [m/s], light time [s]}

Returns:

std::tuple<Vec3<T>, Vec3<T>, double> {Position, Velocity, LightTime}

  • Position is in km (SPICE default).

  • Velocity is in km/s (SPICE default).

template<huira::IsFloatingPoint T>
inline huira::Rotation<T> pxform(const std::string &FROM, const std::string &TO, const huira::Time &time)

Get the rotation from one frame to another at a given time.

Template Parameters:

T – Floating point type

Parameters:
  • FROM – Source frame

  • TO – Destination frame

  • time – Observation time

Returns:

huira::Rotation<T> Rotation object

template<huira::IsFloatingPoint T>
inline std::pair<huira::Rotation<T>, huira::Vec3<T>> sxform(const std::string &FROM, const std::string &TO, const huira::Time &time)

Get the rotation and angular velocity from one frame to another at a given time.

Template Parameters:

T – Floating point type

Parameters:
  • FROM – Source frame

  • TO – Destination frame

  • time – Observation time

Returns:

std::pair<huira::Rotation<T>, huira::Vec3<T>> {rotation, angular velocity}

inline void check_spice_error()
template<typename Func, typename ...Args>
auto call_spice(Func func, Args&&... args)

Variables

std::once_flag lsk_init_flag
std::atomic<bool> lsk_loaded = {false}
class SpiceError : public std::runtime_error

Public Functions

inline explicit SpiceError(const std::string &msg)