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

error-handling.mddocs/

Error Handling and Utilities

Error management, debugging utilities, and general-purpose functions for SPICE operations. These functions help manage error conditions and provide useful utilities for SPICE programming.

Capabilities

Error Status Functions

Check and manage SPICE error conditions.

def failed() -> bool:
    """
    Check if a SPICE error has occurred.
    
    Returns:
    bool: True if SPICE error flag is set
    """

def reset() -> None:
    """
    Reset SPICE error status.
    
    Returns:
    None
    """

def getmsg(option: str, lenout: int) -> str:
    """
    Retrieve SPICE error message.
    
    Parameters:
    - option: str, message type ("SHORT", "EXPLAIN", "LONG")
    - lenout: int, maximum message length
    
    Returns:
    str: error message
    """

Utility Functions

General-purpose utility functions.

def exists(file: str) -> bool:
    """
    Test whether a file exists.
    
    Parameters:
    - file: str, file path
    
    Returns:
    bool: True if file exists
    """

def iswhsp(string: str) -> bool:
    """
    Test whether string is whitespace.
    
    Parameters:
    - string: str, input string
    
    Returns:
    bool: True if string contains only whitespace
    """

Context Managers

Context managers for error handling control.

def no_found_check():
    """
    Context manager to disable 'found' flag checking.
    
    Usage:
    with spice.no_found_check():
        # SPICE operations that might not find data
        pass
    """

def found_check():
    """
    Context manager to enable 'found' flag checking.
    
    Usage:
    with spice.found_check():
        # SPICE operations with strict error checking
        pass
    """

Common Usage Patterns

Basic Error Checking

import spiceypy as spice

# Perform SPICE operation
spice.furnsh("nonexistent.bsp")

# Check for errors
if spice.failed():
    error_msg = spice.getmsg("SHORT", 40)
    print(f"SPICE error: {error_msg}")
    spice.reset()  # Clear error status

Exception Handling

from spiceypy.utils.exceptions import SpiceyError

try:
    # SPICE operations
    position, lt = spice.spkpos("MARS", et, "J2000", "NONE", "EARTH")
except SpiceyError as e:
    print(f"SPICE error occurred: {e.short}")
    print(f"Explanation: {e.explain}")

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