A Python wrapper for the NAIF CSPICE Toolkit providing essential tools for spacecraft navigation and planetary science calculations
Functions for working with reference frames including transformations between frames, frame definitions, and orientation computations. Reference frames define coordinate system orientations and are essential for accurate space geometry calculations.
Compute transformation matrices between reference frames.
def pxform(from_frame: str, to_frame: str, et: Union[float, ndarray]) -> Union[ndarray, ndarray]:
"""
Return position transformation matrix from one frame to another.
Parameters:
- from_frame: str, source reference frame
- to_frame: str, target reference frame
- et: Union[float, ndarray], ephemeris time(s)
Returns:
Union[ndarray, ndarray]: 3x3 transformation matrix or array of matrices
"""
def sxform(from_frame: str, to_frame: str, et: Union[float, ndarray]) -> Union[ndarray, ndarray]:
"""
Return state transformation matrix from one frame to another.
Parameters:
- from_frame: str, source reference frame
- to_frame: str, target reference frame
- et: Union[float, ndarray], ephemeris time(s)
Returns:
Union[ndarray, ndarray]: 6x6 state transformation matrix or array of matrices
"""Query frame names, IDs, and properties.
def frmnam(frcode: int) -> str:
"""
Return frame name given frame ID code.
Parameters:
- frcode: int, frame ID code
Returns:
str: frame name
"""
def namfrm(frname: str) -> int:
"""
Return frame ID code given frame name.
Parameters:
- frname: str, frame name
Returns:
int: frame ID code
"""
def frinfo(frcode: int) -> Tuple[int, int, int, bool]:
"""
Return frame information.
Parameters:
- frcode: int, frame ID code
Returns:
Tuple[int, int, int, bool]: (cent, frclss, clssid, found)
"""Functions for working with built-in SPICE reference frames.
def builtin_frames() -> List[Tuple[int, str]]:
"""
Return list of built-in reference frames.
Returns:
List[Tuple[int, str]]: list of (frame_id, frame_name) tuples
"""
def cidfrm(cent: int) -> Tuple[int, str, bool]:
"""
Return body-fixed frame associated with an object.
Parameters:
- cent: int, central body ID
Returns:
Tuple[int, str, bool]: (frcode, frname, found)
"""import spiceypy as spice
# Transform from J2000 to IAU_EARTH frame
et = spice.str2et("2023-01-01T12:00:00")
transform = spice.pxform("J2000", "IAU_EARTH", et)
# Apply transformation to a vector
vector_j2000 = [1000.0, 0.0, 0.0] # X-axis in J2000
vector_earth = spice.mxv(transform, vector_j2000)
print(f"Vector in Earth frame: {vector_earth}")# Transform state vector (position + velocity)
state_transform = spice.sxform("J2000", "IAU_MARS", et)
state_j2000 = [1000.0, 0.0, 0.0, 0.0, 1.0, 0.0] # Example state
state_mars = spice.mxv(state_transform, state_j2000)Install with Tessl CLI
npx tessl i tessl/pypi-spiceypydocs