SPICE Kernels¶
Native SPICE kernel registry: loading/unloading SPK and binary PCK kernels, and generic NAIF-ID ephemeris/orientation queries. For the per-body *_spice convenience functions, see the Ephemerides reference.
Kernel Registry¶
load_spice_kernel builtin ¶
Load a SPICE kernel into the global registry.
Known kernel names are downloaded from NAIF and cached: the planetary (DE) ephemerides "de430", "de432s", "de435", "de438", "de440", "de440s", "de442", "de442s"; the satellite ephemeris kernels "mar099", "mar099s", "jup365", "sat441", "ura184", "nep097", "plu060"; and the binary PCK "moon_pa_de440". Any other argument is treated as a local file path. SPK (.bsp) and binary PCK (.bpc) kernels are detected automatically from the file header. Loading is idempotent; kernels stay resident until unloaded, and later loads take precedence for overlapping coverage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_or_path | str | Kernel name or filesystem path | required |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the kernel cannot be downloaded, read, or parsed |
unload_spice_kernel builtin ¶
Unload a SPICE kernel from the global registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_or_path | str | The name or path the kernel was loaded under | required |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no kernel is loaded under that name |
loaded_spice_kernels builtin ¶
load_common_spice_kernels builtin ¶
load_common_spice_kernels() -> Any
Load the kernels most applications need: "de440s" (planetary ephemeris) and "moon_pa_de440" (lunar principal-axes orientation).
~46 MB total on first download; cached thereafter. Each kernel load is idempotent, so calling this alongside other load_spice_kernel calls is safe.
Loading is not atomic: on error, kernels already loaded before the failure remain resident, so the call can be safely retried.
Raises:
| Type | Description |
|---|---|
RuntimeError | If a kernel cannot be downloaded, read, or parsed |
load_all_spice_kernels builtin ¶
load_all_spice_kernels() -> Any
Load every kernel brahe knows how to download: "de440s", "moon_pa_de440", and the satellite ephemeris kernels "mar099s", "jup365", "sat441", "ura184", "nep097", "plu060".
~2.5 GB total on first download; cached thereafter. Prefer load_common_spice_kernels unless outer-planet body centers or moons are needed.
Loading is not atomic: on error, kernels already loaded before the failure remain resident, so the call can be safely retried.
Raises:
| Type | Description |
|---|---|
RuntimeError | If a kernel cannot be downloaded, read, or parsed |
Generic SPK Queries¶
spk_position builtin ¶
Position of a target body relative to a center body from loaded SPK kernels.
The result is expressed in the kernel's inertial frame (ICRF axes; NAIF labels this "J2000"). If no kernels are loaded, DE440s is loaded automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target | int | NAIF ID of the target body (e.g. bh.NAIFId.MOON) | required |
center | int | NAIF ID of the center body (e.g. bh.NAIFId.EARTH) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Position of target relative to center. Units: (m) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no ephemeris path exists between the bodies or the epoch is outside kernel coverage |
spk_velocity builtin ¶
Velocity of a target body relative to a center body from loaded SPK kernels.
The result is expressed in the kernel's inertial frame (ICRF axes; NAIF labels this "J2000"). If no kernels are loaded, DE440s is loaded automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target | int | NAIF ID of the target body (e.g. bh.NAIFId.MOON) | required |
center | int | NAIF ID of the center body (e.g. bh.NAIFId.EARTH) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Velocity of target relative to center. Units: (m/s) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no ephemeris path exists between the bodies or the epoch is outside kernel coverage |
spk_state builtin ¶
State (position and velocity) of a target body relative to a center body from loaded SPK kernels.
The result is expressed in the kernel's inertial frame (ICRF axes; NAIF labels this "J2000"). Computing the state shares a single record lookup between position and velocity. If no kernels are loaded, DE440s is loaded automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target | int | NAIF ID of the target body (e.g. bh.NAIFId.MOON) | required |
center | int | NAIF ID of the center body (e.g. bh.NAIFId.EARTH) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: State [x, y, z, vx, vy, vz] of target relative to center. Units: (m, m/s) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no ephemeris path exists between the bodies or the epoch is outside kernel coverage |
spk_acceleration builtin ¶
Acceleration of a target body relative to a center body from loaded SPK kernels.
The result is expressed in the kernel's inertial frame (ICRF axes), evaluated by analytically differentiating the kernel's Chebyshev polynomials (twice for Type 2 segments; once, of the stored velocity polynomials, for Type 3). If no kernels are loaded, DE440s is loaded automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target | int | NAIF ID of the target body (e.g. bh.NAIFId.MOON) | required |
center | int | NAIF ID of the center body (e.g. bh.NAIFId.EARTH) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Acceleration [ax, ay, az] of target relative to center. Units: (m/s^2) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no ephemeris path exists between the bodies or the epoch is outside kernel coverage |
Kernel-Scoped SPK Queries¶
spk_position_from_kernel builtin ¶
Position of a target body relative to a center body, queried from a single named kernel.
Queries that kernel only — no cross-kernel chaining is performed and the registry's last-loaded-wins precedence semantics do not apply. The kernel is auto-loaded by name or path if not already loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_name | str | A known DE kernel name (e.g. "de440s", "de440"), or a path to a .bsp file | required |
target | int | NAIF ID of the target body (e.g. bh.NAIFId.MOON) | required |
center | int | NAIF ID of the center body (e.g. bh.NAIFId.EARTH) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Position of target relative to center in the kernel's inertial frame (ICRF axes). Units: (m) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the kernel cannot be loaded, does not contain the requested bodies, or does not cover the epoch |
spk_velocity_from_kernel builtin ¶
Velocity of a target body relative to a center body, queried from a single named kernel.
Queries that kernel only — no cross-kernel chaining is performed and the registry's last-loaded-wins precedence semantics do not apply. The kernel is auto-loaded by name or path if not already loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_name | str | A known DE kernel name (e.g. "de440s", "de440"), or a path to a .bsp file | required |
target | int | NAIF ID of the target body (e.g. bh.NAIFId.MOON) | required |
center | int | NAIF ID of the center body (e.g. bh.NAIFId.EARTH) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Velocity of target relative to center in the kernel's inertial frame (ICRF axes). Units: (m/s) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the kernel cannot be loaded, does not contain the requested bodies, or does not cover the epoch |
spk_state_from_kernel builtin ¶
State (position and velocity) of a target body relative to a center body, queried from a single named kernel.
Queries that kernel only — no cross-kernel chaining is performed and the registry's last-loaded-wins precedence semantics do not apply. The kernel is auto-loaded by name or path if not already loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_name | str | A known DE kernel name (e.g. "de440s", "de440"), or a path to a .bsp file | required |
target | int | NAIF ID of the target body (e.g. bh.NAIFId.MOON) | required |
center | int | NAIF ID of the center body (e.g. bh.NAIFId.EARTH) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: State [x, y, z, vx, vy, vz] of target relative to center in the kernel's inertial frame (ICRF axes). Units: (m, m/s) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the kernel cannot be loaded, does not contain the requested bodies, or does not cover the epoch |
spk_acceleration_from_kernel builtin ¶
Acceleration of a target body relative to a center body, queried from a single named kernel.
Queries that kernel only — no cross-kernel chaining is performed and the registry's last-loaded-wins precedence semantics do not apply. The kernel is auto-loaded by name or path if not already loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_name | str | A known DE kernel name (e.g. "de440s", "de440"), or a path to a .bsp file | required |
target | int | NAIF ID of the target body (e.g. bh.NAIFId.MOON) | required |
center | int | NAIF ID of the center body (e.g. bh.NAIFId.EARTH) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Acceleration [ax, ay, az] of target relative to center in the kernel's inertial frame (ICRF axes). Units: (m/s^2) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the kernel cannot be loaded, does not contain the requested bodies, or does not cover the epoch |
PCK Orientation Queries¶
pck_euler_angles builtin ¶
3-1-3 Euler angles and rates of a PCK body-fixed frame relative to ICRF.
PCKs are never auto-initialized; a PCK kernel must be explicitly loaded via bh.load_spice_kernel(...) first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_id | int | Body-frame class ID (e.g. 31008 for MOON_PA_DE440) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
Tuple | tuple[np.ndarray, np.ndarray]: (angles [phi, delta, w] in rad, rates in rad/s) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no loaded binary PCK provides the frame at the epoch |
pck_euler_angle builtin ¶
pck_euler_angle(frame_id: int, epc: Epoch) -> EulerAngle
3-1-3 Euler angle of a PCK body-fixed frame relative to ICRF.
PCKs are never auto-initialized; a PCK kernel must be explicitly loaded via bh.load_spice_kernel(...) first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_id | int | Body-frame class ID (e.g. 31008 for MOON_PA_DE440) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Name | Type | Description |
|---|---|---|
EulerAngle | EulerAngle | ICRF to body-fixed orientation (order ZXZ, radians) |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no loaded binary PCK provides the frame at the epoch |
pck_euler_rates builtin ¶
Time derivatives of the 3-1-3 Euler angles of a PCK body-fixed frame.
PCKs are never auto-initialized; a PCK kernel must be explicitly loaded via bh.load_spice_kernel(...) first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_id | int | Body-frame class ID (e.g. 31008 for MOON_PA_DE440) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: [phi_dot, delta_dot, w_dot] in rad/s |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no loaded binary PCK provides the frame at the epoch |
pck_euler_angle_and_rates builtin ¶
Typed Euler angle and its rates for a PCK body-fixed frame, from a single shared segment lookup.
PCKs are never auto-initialized; a PCK kernel must be explicitly loaded via bh.load_spice_kernel(...) first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_id | int | Body-frame class ID (e.g. 31008 for MOON_PA_DE440) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple | Tuple | (EulerAngle, np.ndarray) — orientation (order ZXZ, radians) and rates [phi_dot, delta_dot, w_dot] in rad/s |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no loaded binary PCK provides the frame at the epoch |
pck_quaternion builtin ¶
pck_quaternion(frame_id: int, epc: Epoch) -> Quaternion
Orientation of a PCK body-fixed frame relative to ICRF, as a unit quaternion.
PCKs are never auto-initialized; a PCK kernel must be explicitly loaded via bh.load_spice_kernel(...) first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_id | int | Body-frame class ID (e.g. 31008 for MOON_PA_DE440) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Name | Type | Description |
|---|---|---|
Quaternion | Quaternion | Unit quaternion (ICRF to body-fixed). Dimensionless. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no loaded binary PCK provides the frame at the epoch |
pck_rotation_matrix builtin ¶
pck_rotation_matrix(frame_id: int, epc: Epoch) -> RotationMatrix
Rotation matrix from ICRF to a PCK body-fixed frame.
PCKs are never auto-initialized; a PCK kernel must be explicitly loaded via bh.load_spice_kernel(...) first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_id | int | Body-frame class ID (e.g. 31008 for MOON_PA_DE440) | required |
epc | Epoch | Epoch of the query | required |
Returns:
| Name | Type | Description |
|---|---|---|
RotationMatrix | RotationMatrix | 3x3 rotation matrix (ICRF to body-fixed). Dimensionless. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If no loaded binary PCK provides the frame at the epoch |
NAIFId¶
Full NAIF integer ID listing: NAIF Integer ID Codes.
NAIFId ¶
NAIF integer ID codes for solar-system bodies.
Values pass directly to any function taking a NAIF ID; arbitrary raw integer IDs are equally accepted by those functions. Full ID list: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/naif_ids.html
Any other NAIF ID present in a loaded kernel (e.g. a spacecraft or minor body) also works — pass the raw integer directly. In Rust the equivalent catch-all is NAIFId::Id(i32).
FrameId¶
FrameId ¶
PCK body-frame class IDs. Raw integer IDs are equally accepted.
Any other frame class ID present in a loaded binary PCK also works — pass the raw integer directly. In Rust the equivalent catch-all is FrameId::Id(i32). Full frame reference: NAIF Frames Required Reading.
See Also¶
- SPICE Kernels Guide - Kernel loading, registry behavior, and PCK orientation
- Ephemerides - Per-body position/velocity/state functions
- NAIF Functions - Downloading and caching kernel files
- EulerAngle - Type returned by
pck_euler_angle/pck_euler_angle_and_rates - Quaternion - Type returned by
pck_quaternion - RotationMatrix - Type returned by
pck_rotation_matrix