A Python wrapper for the NAIF CSPICE Toolkit providing essential tools for spacecraft navigation and planetary science calculations
Error management, debugging utilities, and general-purpose functions for SPICE operations. These functions help manage error conditions and provide useful utilities for SPICE programming.
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
"""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 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
"""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 statusfrom 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-spiceypydocs