CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-spiceypy

A Python wrapper for the NAIF CSPICE Toolkit providing essential tools for spacecraft navigation and planetary science calculations

Overview
Eval results
Files

kernel-management.mddocs/

Kernel Management

Essential functions for loading and managing SPICE data files (kernels) that contain ephemeris, attitude, instrument, and reference frame information. Kernel management is fundamental to all SPICE operations as kernels provide the data needed for computations.

Capabilities

Loading Kernels

Load SPICE kernels (data files) into the kernel pool for use by other SPICE functions.

def furnsh(kernel: str) -> None:
    """
    Load a SPICE kernel file into the kernel pool.
    
    Parameters:
    - kernel: str, path to kernel file or meta-kernel file
    
    Returns:
    None
    
    Raises:
    SpiceyError: if kernel file cannot be loaded
    """

Usage example:

import spiceypy as spice

# Load a single kernel file
spice.furnsh("de430.bsp")

# Load a meta-kernel (contains list of other kernels to load)
spice.furnsh("cassini_metakernel.mk")

Unloading Kernels

Remove specific kernels or clear all loaded kernels from memory.

def unload(kernel: str) -> None:
    """
    Unload a specific SPICE kernel file from the kernel pool.
    
    Parameters:
    - kernel: str, path to kernel file to unload
    
    Returns:
    None
    """

def kclear() -> None:
    """
    Clear the kernel pool by unloading all loaded kernels.
    
    Parameters:
    None
    
    Returns:
    None
    """

Usage example:

# Unload a specific kernel
spice.unload("de430.bsp")

# Clear all loaded kernels (recommended cleanup)
spice.kclear()

Kernel Information

Query information about loaded kernels and kernel pool contents.

def ktotal(kind: str) -> int:
    """
    Return the number of loaded kernels of a specified type.
    
    Parameters:
    - kind: str, kernel type ("SPK", "CK", "PCK", "EK", "IK", "LSK", "SCLK", "META", "TEXT", "ALL")
    
    Returns:
    int: number of loaded kernels of specified type
    """

def kdata(which: int, kind: str) -> Tuple[str, str, str, bool]:
    """
    Return data for the nth kernel of a specified type.
    
    Parameters:
    - which: int, index of kernel (0-based)
    - kind: str, kernel type
    
    Returns:
    Tuple[str, str, str, bool]: (file, filetype, source, found)
    """

def kinfo(file: str) -> Tuple[str, str, int, bool]:
    """
    Return information about a loaded kernel file.
    
    Parameters:
    - file: str, kernel file path
    
    Returns:
    Tuple[str, str, int, bool]: (filetype, source, handle, found)
    """

Kernel Pool Variables

Access and modify variables stored in the kernel pool.

def gcpool(name: str, start: int, room: int) -> Tuple[int, List[str], bool]:
    """
    Get character data from the kernel pool.
    
    Parameters:
    - name: str, variable name
    - start: int, starting index
    - room: int, maximum number of values to return
    
    Returns:
    Tuple[int, List[str], bool]: (n, cvals, found)
    """

def gdpool(name: str, start: int, room: int) -> Tuple[int, ndarray, bool]:
    """
    Get double precision data from the kernel pool.
    
    Parameters:
    - name: str, variable name  
    - start: int, starting index
    - room: int, maximum number of values to return
    
    Returns:
    Tuple[int, ndarray, bool]: (n, values, found)
    """

def gipool(name: str, start: int, room: int) -> Tuple[int, List[int], bool]:
    """
    Get integer data from the kernel pool.
    
    Parameters:
    - name: str, variable name
    - start: int, starting index  
    - room: int, maximum number of values to return
    
    Returns:
    Tuple[int, List[int], bool]: (n, ivals, found)
    """

Kernel Pool Management

Advanced kernel pool operations for watching variables and managing updates.

def swpool(agent: str, nnames: int, names: List[str]) -> None:
    """
    Set up watchers for kernel pool variables.
    
    Parameters:
    - agent: str, name of the agent watching variables
    - nnames: int, number of variable names
    - names: List[str], variable names to watch
    
    Returns:
    None
    """

def cvpool(agent: str) -> bool:
    """
    Check if any watched variables have been updated.
    
    Parameters:
    - agent: str, name of the watching agent
    
    Returns:
    bool: True if watched variables were updated
    """

def clpool() -> None:
    """
    Clear the kernel pool of all variables.
    
    Returns:
    None
    """

Common Usage Patterns

Basic Kernel Loading Workflow

import spiceypy as spice

try:
    # Load kernels
    spice.furnsh("metakernel.mk")
    
    # Perform SPICE computations here
    # ...
    
finally:
    # Always clean up
    spice.kclear()

Checking Loaded Kernels

# Check how many SPK kernels are loaded
n_spk = spice.ktotal("SPK")
print(f"Loaded SPK kernels: {n_spk}")

# Get information about the first SPK kernel
if n_spk > 0:
    file, filetype, source, found = spice.kdata(0, "SPK")
    print(f"First SPK kernel: {file}")

Context Manager Pattern

from spiceypy import KernelPool

# Temporary kernel loading
with KernelPool("metakernel.mk"):
    # Kernels are loaded for this block
    position, lt = spice.spkpos("MARS", et, "J2000", "NONE", "EARTH")
    # Kernels are automatically unloaded when exiting the block

Install with Tessl CLI

npx tessl i tessl/pypi-spiceypy

docs

ck-orientation.md

coordinate-systems.md

data-structures.md

dsk-shape-models.md

e-kernels.md

ephemeris-trajectories.md

error-handling.md

event-finding.md

geometry-surface.md

index.md

kernel-management.md

low-level-file-access.md

physical-constants.md

reference-frames.md

spacecraft-clock.md

time-systems.md

vector-matrix.md

tile.json