spice

This submodule contains Tudat’s direct SPICE interface. It provides utilities for loading and clearing SPICE kernels, converting SPICE time representations, retrieving ephemeris and frame data, and querying body properties from the loaded kernel pool.

SPICE data are used directly by several environment setup functions, including direct_spice(), interpolated_spice(), keplerian_from_spice(), spice(), simple_from_spice(), central_spice(), spherical_spice(), and oblate_spherical_spice(). SPICE kernels are also used extensively in Tudat’s default body settings, as described in the user guide section on default environment models.

Time Conversions

convert_julian_date_to_ephemeris_time(...)

Convert a Julian date to ephemeris time (equivalent to TDB in Spice).

convert_ephemeris_time_to_julian_date(...)

Convert ephemeris time (equivalent to TDB) to a Julian date.

convert_date_string_to_ephemeris_time(...)

Converts a date string to ephemeris time.

get_approximate_utc_from_tdb(ephemeris_time)

Get an approximate UTC time from ephemeris time (TDB).

convert_julian_date_to_ephemeris_time(julian_date: float) → float

Convert a Julian date to ephemeris time (equivalent to TDB in Spice).

Function to convert a Julian date to ephemeris time, which is equivalent to barycentric dynamical time. A leap second kernel must have been loaded to use this function.

Parameters:

julian_date (float) – Julian date that is to be converted to ephemeris time.

Returns:

Ephemeris time corresponding to the given Julian date.

Return type:

float

convert_ephemeris_time_to_julian_date(ephemeris_time: float) → float

Convert ephemeris time (equivalent to TDB) to a Julian date.

Function to convert ephemeris time, which is nearly equal to barycentric dynamical time, to the Julian date. A leap second kernel must have been loaded to use this function.

Parameters:

ephemeris_time (float) – Ephemeris time that is to be converted to Julian date.

Returns:

Julian date calculated from ephemeris time.

Return type:

float

convert_date_string_to_ephemeris_time(date_string: str) → float

Converts a date string to ephemeris time.

Function to convert a date string, for instance 1988 June 13, 3:29:48 to ephemeris time, wrapper for str2et_c spice function.

Parameters:

date_string (str) – String representing the date. See documentation of spice function str2et_c for details on supported formats.

Returns:

Ephemeris time corresponding to the given date string.

Return type:

float

get_approximate_utc_from_tdb(ephemeris_time: float) → float

Get an approximate UTC time from ephemeris time (TDB).

This function computes an approximate UTC time from the given ephemeris time (TDB). It uses the deltet_c Spice function to calculate the offset between TDB and UTC.

Parameters:

ephemeris_time (float) – Ephemeris time (TDB) to be converted to UTC.

Returns:

Approximate UTC time corresponding to the given ephemeris time.

Return type:

float

Ephemerides And Frames

get_body_cartesian_position_at_epoch(...)

Get Cartesian position of a body, as observed from another body.

get_body_cartesian_state_at_epoch(...)

Get Cartesian state of a body, as observed from another body.

get_cartesian_state_from_tle_at_epoch(epoch, tle)

Get Cartesian state of a satellite from its two-line element set at a specified epoch.

compute_rotation_matrix_between_frames(...)

Computes rotation matrix between two frames.

compute_state_rotation_matrix_between_frames(...)

Computes state rotation matrix between two frames.

compute_rotation_matrix_derivative_between_frames(...)

Computes time derivative of rotation matrix between two frames.

get_angular_velocity_vector_of_frame_in_original_frame(...)

Computes the angular velocity of one frame w.r.t.

get_body_cartesian_position_at_epoch(target_body_name: str, observer_body_name: str, reference_frame_name: str, aberration_corrections: str, ephemeris_time: float) → numpy.ndarray[numpy.float64[3, 1]]

Get Cartesian position of a body, as observed from another body.

This function returns the position of a body, relative to another body, in a frame specified by the user. Corrections for light-time correction and stellar aberration can be applied to obtain the state of one of the bodies, as observed from the other. Wrapper for spkpos_c spice function.

Parameters:
  • target_body_name (str) – Name of the body of which the state is to be obtained. A kernel with the ephemeris of this body must have been loaded. The string must be a spice-recognized name or ID.

  • observer_body_name (str) – Name of the body relative to which the state is to be obtained. A kernel with the ephemeris of this body must have been loaded. The string must be a spice-recognized name or ID.

  • reference_frame_name (str) – The spice-recognized name of the reference frame in which the state is to be returned. Spice kernel(s) required to perform the necessary conversion from the states of the target and observer bodies to this frame need to have been loaded.

  • aberration_corrections (str) –

    Setting for correction for setting corrections. See Spice documentation for extended discussion. Short summary:

    • NONE: none

    • LT: light time corrected (one iteration for calculation)

    • CN: light time corrected (multiple iterations, max 3) for calculation,

    • S: Stellar aberration corrected.

    • XLT and XCN: can be provided to make the ephemeris time input argument the transmission time, instead of reception time. Arguments can be combined (i.e.”LT+S” or “XCN+S”).

  • ephemeris_time (float) – Observation time (or transmission time of observed light, see description of aberrationCorrections).

Returns:

Cartesian position vector of the target body relative to the observer.

Return type:

numpy.ndarray[3, 1]

get_body_cartesian_state_at_epoch(target_body_name: str, observer_body_name: str, reference_frame_name: str, aberration_corrections: str, ephemeris_time: float) → numpy.ndarray[numpy.float64[6, 1]]

Get Cartesian state of a body, as observed from another body.

This function returns the state of a body, relative to another body, in a frame specified by the user. Corrections for light-time correction and stellar aberration can be applied to obtain the state of one of the bodies, as observed from the other. Wrapper for spkezr_c spice function.

Parameters:
  • target_body_name (str) – Name of the body of which the state is to be obtained. A kernel with the ephemeris of this body must have been loaded. The string must be a spice-recognized name or ID.

  • observer_body_name (str) – Name of the body relative to which the state is to be obtained. A kernel with the ephemeris of this body must have been loaded. The string must be a spice-recognized name or ID.

  • reference_frame_name (str) – The spice-recognized name of the reference frame in which the state is to be returned. Spice kernel(s) required to perform the necessary conversion from the states of the target and observer bodies to this frame need to have been loaded.

  • aberration_corrections (str) –

    Setting for correction for setting corrections. See Spice documentation for extended discussion. Short summary:

    • NONE: none

    • LT: light time corrected (one iteration for calculation)

    • CN: light time corrected (multiple iterations, max 3) for calculation

    • S: Stellar aberration corrected.

    • XLT and XCN: can be provided to make the ephemeris time input argument the transmission time, instead of reception time. Arguments can be combined (i.e.”LT+S” or “XCN+S”).

  • ephemeris_time (float) – Observation time (or transmission time of observed light, see description of aberrationCorrections).

Returns:

Cartesian state vector containing position and velocity.

Return type:

numpy.ndarray[6, 1]

get_cartesian_state_from_tle_at_epoch(epoch: float, tle: tudatpy.kernel.dynamics.environment_setup.ephemeris.Tle) → numpy.ndarray[numpy.float64[6, 1]]

Get Cartesian state of a satellite from its two-line element set at a specified epoch.

This function retrieves the state of a satellite at a certain epoch by propagating the SGP or SDP models (near-Earth resp. deep space) with the given two-line elements (TLE). This function serves as a wrapper for the ev2lin function in CSpice.

Parameters:
  • epoch (float) – Time in seconds since J2000 at which the state is to be retrieved.

  • tle (Tle) – Tle object containing the SGP/SDP model parameters as derived from the element set.

Returns:

Cartesian state vector containing position and velocity.

Return type:

numpy.ndarray[6, 1]

compute_rotation_matrix_between_frames(original_frame: str, new_frame: str, ephemeris_time: float) → numpy.ndarray[numpy.float64[3, 3]]

Computes rotation matrix between two frames.

This function computes the rotation matrix between two frames at a given time instant. Kernels defining the two frames, as well as any required intermediate frames, at the requested time must have been loaded. Wrapper for pxform_c spice function.

Parameters:
  • original_frame – Reference frame from which the rotation is made.

  • new_frame – Reference frame to which the rotation is made.

  • ephemeris_time – Value of ephemeris time at which rotation is to be determined.

Returns:

Rotation matrix from the original to the new frame at the given time.

Return type:

numpy.ndarray[3, 3]

compute_state_rotation_matrix_between_frames(original_frame: str, new_frame: str, ephemeris_time: float) → numpy.ndarray[numpy.float64[6, 6]]

Computes state rotation matrix between two frames.

This function computes the 6-by-6 state rotation matrix between two frames at a given time instant. Kernels defining the two frames, as well as any required intermediate frames, at the requested time must have been loaded. Wrapper for sxform_c spice function.

Parameters:
  • original_frame – Reference frame from which the rotation is made.

  • new_frame – Reference frame to which the rotation is made.

  • ephemeris_time – Value of ephemeris time at which rotation is to be determined.

Returns:

State rotation matrix from the original to the new frame at the given time.

Return type:

numpy.ndarray[6, 6]

compute_rotation_matrix_derivative_between_frames(original_frame: str, new_frame: str, ephemeris_time: float) → numpy.ndarray[numpy.float64[3, 3]]

Computes time derivative of rotation matrix between two frames.

This function computes the derivative of the rotation matrix between two frames at a given time instant. kernels defining the two frames, as well as any required intermediate frames, at the requested time must have been loaded. Wrapper for (part of) sxform_c spice function.

Parameters:
  • original_frame – Reference frame from which the rotation is made.

  • new_frame – Reference frame to which the rotation is made.

  • ephemeris_time – Value of ephemeris time at which rotation is to be determined.

Returns:

Time derivative of the rotation matrix from the original to the new frame at the given time.

Return type:

numpy.ndarray[3, 3]

get_angular_velocity_vector_of_frame_in_original_frame(original_frame: str, new_frame: str, ephemeris_time: float) → numpy.ndarray[numpy.float64[3, 1]]

Computes the angular velocity of one frame w.r.t. to another frame.

Computes the angular velocity of one frame w.r.t. to another frame. at a given time instant. kernels defining the two frames, as well as any required intermediate frames, at the requested time must have been loaded. Wrapper for xf2rav_c spice function (utilizing sxform_c).

Parameters:
  • original_frame – Reference frame from which the rotation is made.

  • new_frame – Reference frame to which the rotation is made.

  • ephemeris_time – Value of ephemeris time at which rotation is to be determined.

Returns:

Angular velocity of the new frame with respect to the original frame, expressed in the original frame.

Return type:

numpy.ndarray[3, 1]

Body Properties

get_body_properties(body_name, property, ...)

Get property of a body from Spice.

get_body_gravitational_parameter(body_name)

Get gravitational parameter of a body.

get_average_radius(body_name)

Get the (arithmetic) mean of the three principal axes of the tri-axial ellipsoid shape.

convert_body_name_to_naif_id(body_name)

Convert a body name to its NAIF identification number.

convert_naif_id_to_body_name(naif_id)

Function that converts the NAIF ID (used internally in Spice) to the name of the body

check_body_property_in_kernel_pool(...)

Check if a certain property of a body is in the kernel pool.

get_body_properties(body_name: str, property: str, max_n_val: int) → list[float]

Get property of a body from Spice.

Function to retrieve a property of a body from Spice, wraps the bodvrd_c Spice function.

Parameters:
  • body_name – Name of the body of which the property is to be retrieved.

  • property –

    Name of the property that is to be retrieved. Naming conventions can be found in the bodvrd_c function documentation.

  • maximum_number_of_values (int) – Number of values by which the property is expressed (i.e. 1 for gravitational parameter, 3 for tri-axial ellipsoid principal axes).

Returns:

Requested property values.

Return type:

list[float]

Notes

Function returns values with distance unit km, not m!

get_body_gravitational_parameter(body_name: str) → float

Get gravitational parameter of a body.

This function retrieves the gravitational parameter of a body. Wraps the bodvrd_c spice function with “GM” as property type.

Note

The gravitational parameter returned is directly retrieved from the loaded SPICE kernels. This value does not necessarily correspond to the gravitational parameter used in Tudat’s default models, as retrieved from e.g. get_default_body_settings(). For more information on the default gravity models, see the user guide.

Parameters:

body – Name of the body of which the parameter is to be retrieved.

Returns:

Gravitational parameter of the requested body.

Return type:

float

get_average_radius(body_name: str) → float

Get the (arithmetic) mean of the three principal axes of the tri-axial ellipsoid shape.

Returns the (arithmetic) mean of the three principal axes of the tri-axial ellipsoid shape of the requested body. Uses the bodvrd_c spice function with “RADII” as property type.

Parameters:

body – Name of the body of which the average radius is to be retrieved.

Returns:

Arithmetic mean of the principal axes of the body’s tri-axial ellipsoid shape model.

Return type:

float

convert_body_name_to_naif_id(body_name: str) → int

Convert a body name to its NAIF identification number.

This function converts a body name to its NAIF identification number. The NAIF id number is required for a number of spice functions, whereas the name is easily interpretable by the user. Wrapper for the bods2c_c function.

Parameters:

body_name – Name of the body for which NAIF id is to be retrieved.

Returns:

NAIF identification number for the body.

Return type:

int

convert_naif_id_to_body_name(naif_id: int) → str

Function that converts the NAIF ID (used internally in Spice) to the name of the body

Parameters:

naif_id (int) – Identification number of the body

Returns:

Name of body corresponding to provided ID

Return type:

str

check_body_property_in_kernel_pool(body_name: str, body_property: str) → bool

Check if a certain property of a body is in the kernel pool.

This function checks if a certain property of a body is in the kernel pool. These properties are defined in PCK kernels. Their names are given in the kernel file, typical names can be found in the Spice documentation. Wrapper for the bodfnd_c function.

Parameters:
  • body_name – Name of the body of which the property is to be checked.

  • body_property – Name of the property of which the presence is to be checked, not case-sensitive.

Returns:

True if property is in pool, false if not.

Return type:

bool

Kernel Management

load_standard_kernels([alternative_kernels])

Loads the default spice kernels shipped with tudat.

load_standard_deprecated_kernels([...])

load_kernel(kernel_file)

Loads a Spice kernel into the pool.

clear_kernels()

Clear all loaded spice kernels.

get_total_count_of_kernels_loaded()

Get the number of spice kernels currently loaded.

get_loaded_kernels()

Get the file names of the Spice kernels currently loaded.

load_standard_kernels(alternative_kernels: list[str] = []) → None

Loads the default spice kernels shipped with tudat.

Loads the default spice kernels shipped with tudat. The kernels that are loaded are (in order):

  • pck00010.tpc - Orientation and size/shape data for natural bodies, based mainly on IAU Working Group on Cartographic Coordinates and Rotational Elements, obtained from here

  • inpop19a_TDB_m100_p100_spice.tpc - Masses of solar system planets and large asteroids, as determined in INPOP19a ephemerides, obtained from here. Modified w.r.t. the original file: gravitational parameters of Mercury, Venus, Uranus and Neptune (BODY199_GM, BODY299_GM, BODY799_GM, BODY899_GM) are added, equal to those of their system barycenters

  • NOE-4-2020.tpc - Mars and Martian moon masses, as determined/used in NOE Martian satellite ephemerides, obtained from here. Modified w.r.t. the original file: the Mars rotation model is removed

  • NOE-5-2021.tpc - Jupiter and selected Jovian moon (Io, Europa, Ganymede, Callisto, Amalthea) masses; Jupiter rotation model, as determined/used in NOE Jovian satellite ephemerides, obtained from here

  • NOE-6-2018-MAIN-v2.tpc - Saturn and selected Saturnian moon (Mimas, Enceladus, Tethys, Dione, Rhea, Titan, Hyperion, Iapetus) masses; Saturn rotation model, as determined/used in NOE Saturnian satellite ephemerides, obtained from here

  • codes_300ast_20100725.bsp - Ephemerides of 300 of the largest asteroids, obtained from here

  • codes_300ast_20100725.tf - Frame kernel defining the names and NAIF IDs of the asteroids in codes_300ast_20100725.bsp, obtained from here

  • inpop19a_TDB_m100_p100_spice.bsp - Ephemerides of Solar system planetary system barycenters, Sun, Moon, Earth and Pluto, as determined in INPOP19a ephemerides, obtained from here

  • NOE-4-2020.bsp - Mars, Phobos and Deimos ephemerides (w.r.t. Martian system barycenter), as determined/used in NOE Martian satellite ephemerides, obtained from here

  • NOE-5-2021.bsp - Jupiter, Io, Europa, Ganymede, Callisto, Amalthea ephemerides (w.r.t. Jovian system barycenter), as determined/used in NOE Jovian satellite ephemerides, obtained from here

  • NOE-6-2018-MAIN-v2.bsp - Saturn, Mimas, Enceladus, Tethys, Dione, Rhea, Titan, Hyperion, Iapetus ephemerides (w.r.t. Saturnian system barycenter), as determined/used in NOE Saturnian satellite ephemerides, obtained from here

  • juice_mat_crema_4_0_20220601_20330626_v01.bsp - JUICE trajectory for CReMA 4.0 (2022-06-01 to 2033-06-26)

  • naif0012.tls - Leap second kernel, obtained from here

Parameters:

alternative_kernels (list[str], default = []) – Optional alternative ephemeris kernels to be loaded, instead of the default ephemeris kernels. Note that using this input automatically prevents all of the above .bsp (ephemeris) kernels, and codes_300ast_20100725.tf, from loading.

load_standard_deprecated_kernels(alternative_kernels: list[str] = []) → None
load_kernel(kernel_file: str) → None

Loads a Spice kernel into the pool.

This function loads a Spice kernel into the kernel pool, from which it can be used by the various internal spice routines. Matters regarding the manner in which Spice handles different kernels containing the same information can be found in the spice required reading documentation, kernel section. Wrapper for the furnsh_c function.

Parameters:

file_path (str) – Path to the spice kernel to be loaded.

clear_kernels() → None

Clear all loaded spice kernels.

This function removes all Spice kernels from the kernel pool. Wrapper for the kclear_c function.

Returns:

None

Return type:

None

get_total_count_of_kernels_loaded() → int

Get the number of spice kernels currently loaded.

This function returns the amount of Spice kernels that are loaded into the kernel pool. The same kernel can be loaded multiple times. Wrapper for the ktotal_c function.

Returns:

Number of Spice kernels currently loaded.

Return type:

int

get_loaded_kernels() → list[str]

Get the file names of the Spice kernels currently loaded.

This function returns the file names of the Spice kernels that are loaded into the kernel pool. Kernels loaded through a meta-kernel are included, as is the meta-kernel itself. Wrapper for the kdata_c function.

Returns:

File names of the Spice kernels currently loaded.

Return type:

list[str]

Error Management

continue_after_errors()

Configure SPICE to return control to the caller after an error instead of aborting the process.

suppress_error_output()

Suppress SPICE error messages emitted to its output stream.

continue_after_errors() → None

Configure SPICE to return control to the caller after an error instead of aborting the process.

suppress_error_output() → None

Suppress SPICE error messages emitted to its output stream.