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 a Julian date to ephemeris time (equivalent to TDB in Spice). |
|
Convert ephemeris time (equivalent to TDB) to a Julian date. |
|
Converts a date string to 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.
- 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.
- 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.
Ephemerides And Frames¶
Get Cartesian position of a body, as observed from another body. |
|
Get Cartesian state of a body, as observed from another body. |
|
|
Get Cartesian state of a satellite from its two-line element set at a specified epoch. |
Computes rotation matrix between two frames. |
|
Computes state rotation matrix between two frames. |
|
Computes time derivative of rotation matrix between two frames. |
|
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:
- 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 property of a body from Spice. |
|
Get gravitational parameter of a body. |
|
Get the (arithmetic) mean of the three principal axes of the tri-axial ellipsoid shape. |
|
Convert a body name to its NAIF identification number. |
|
Function that converts the NAIF ID (used internally in Spice) to the name of the body |
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:
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:
- 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:
- 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:
- 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
- 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:
Kernel Management¶
|
Loads the default spice kernels shipped with tudat. |
|
Loads a Spice kernel into the pool. |
Clear all loaded spice kernels. |
|
Get the number of spice kernels currently loaded. |
|
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
- 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:
- 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.
Error Management¶
Configure SPICE to return control to the caller after an error instead of aborting the process. |
|
Suppress SPICE error messages emitted to its output stream. |