A Python wrapper for the NAIF CSPICE Toolkit providing essential tools for spacecraft navigation and planetary science calculations
SPICE-specific data structures including cells, windows, and containers for managing sets of data. These structures provide efficient storage and manipulation of collections commonly used in SPICE operations.
Create SPICE cells for different data types.
def cell_double(cell_size: int) -> SpiceCell:
"""
Create a double precision cell.
Parameters:
- cell_size: int, maximum number of elements
Returns:
SpiceCell: empty double precision cell
"""
def cell_int(cell_size: int) -> SpiceCell:
"""
Create an integer cell.
Parameters:
- cell_size: int, maximum number of elements
Returns:
SpiceCell: empty integer cell
"""
def cell_char(cell_size: int, length: int) -> SpiceCell:
"""
Create a character string cell.
Parameters:
- cell_size: int, maximum number of strings
- length: int, maximum length of each string
Returns:
SpiceCell: empty character cell
"""Basic operations on SPICE cells.
def card(cell: SpiceCell) -> int:
"""
Return cardinality (number of elements) of a cell.
Parameters:
- cell: SpiceCell, input cell
Returns:
int: number of elements in cell
"""
def size(cell: SpiceCell) -> int:
"""
Return size (maximum capacity) of a cell.
Parameters:
- cell: SpiceCell, input cell
Returns:
int: maximum number of elements cell can hold
"""
def copy(cell: SpiceCell) -> SpiceCell:
"""
Copy a cell.
Parameters:
- cell: SpiceCell, input cell
Returns:
SpiceCell: copy of input cell
"""Specialized operations for time windows (double precision cells).
def wninsd(left: float, right: float, window: SpiceCell) -> None:
"""
Insert interval into window.
Parameters:
- left: float, left endpoint of interval
- right: float, right endpoint of interval
- window: SpiceCell, window to modify
Returns:
None (window is modified in place)
"""
def wncard(window: SpiceCell) -> int:
"""
Return number of intervals in window.
Parameters:
- window: SpiceCell, input window
Returns:
int: number of intervals
"""
def wnfetd(window: SpiceCell, n: int) -> Tuple[float, float]:
"""
Fetch nth interval from window.
Parameters:
- window: SpiceCell, input window
- n: int, interval index (0-based)
Returns:
Tuple[float, float]: (left, right) endpoints of interval
"""
def wnunid(a: SpiceCell, b: SpiceCell, c: SpiceCell) -> None:
"""
Union two windows into a third window.
Parameters:
- a: SpiceCell, first input window
- b: SpiceCell, second input window
- c: SpiceCell, output window (a ∪ b)
Returns:
None (output window modified in place)
"""
def wnintd(a: SpiceCell, b: SpiceCell, c: SpiceCell) -> None:
"""
Intersect two windows into a third window.
Parameters:
- a: SpiceCell, first input window
- b: SpiceCell, second input window
- c: SpiceCell, output window (a ∩ b)
Returns:
None (output window modified in place)
"""
def wndifd(a: SpiceCell, b: SpiceCell, c: SpiceCell) -> None:
"""
Difference of two windows into a third window.
Parameters:
- a: SpiceCell, first input window
- b: SpiceCell, second input window
- c: SpiceCell, output window (a - b)
Returns:
None (output window modified in place)
"""
def wnexpd(left: float, right: float, window: SpiceCell) -> None:
"""
Expand intervals in window by specified amounts.
Parameters:
- left: float, expansion amount for left endpoints
- right: float, expansion amount for right endpoints
- window: SpiceCell, window to expand (modified in place)
Returns:
None
"""
def wncond(left: float, right: float, window: SpiceCell) -> None:
"""
Contract intervals in window by specified amounts.
Parameters:
- left: float, contraction amount for left endpoints
- right: float, contraction amount for right endpoints
- window: SpiceCell, window to contract (modified in place)
Returns:
None
"""
def wnfild(small: float, window: SpiceCell) -> None:
"""
Fill small gaps in window.
Parameters:
- small: float, maximum gap size to fill
- window: SpiceCell, window to modify (modified in place)
Returns:
None
"""
def wnfltd(small: float, window: SpiceCell) -> None:
"""
Filter small intervals from window.
Parameters:
- small: float, minimum interval size to keep
- window: SpiceCell, window to filter (modified in place)
Returns:
None
"""
def wnsumd(window: SpiceCell) -> float:
"""
Compute total measure (sum of interval lengths) of window.
Parameters:
- window: SpiceCell, input window
Returns:
float: total measure of all intervals
"""
def wnelmd(point: float, window: SpiceCell) -> bool:
"""
Test whether point is element of window.
Parameters:
- point: float, test point
- window: SpiceCell, input window
Returns:
bool: True if point is in window
"""
def wnincd(left: float, right: float, window: SpiceCell) -> bool:
"""
Test whether interval is included in window.
Parameters:
- left: float, left endpoint of test interval
- right: float, right endpoint of test interval
- window: SpiceCell, input window
Returns:
bool: True if interval is completely contained in window
"""
def wnreld(a: SpiceCell, op: str, b: SpiceCell) -> bool:
"""
Compare two windows using relational operator.
Parameters:
- a: SpiceCell, first window
- op: str, relational operator ("=", "<>", "<=", ">=", "<", ">")
- b: SpiceCell, second window
Returns:
bool: result of comparison
"""
def wnvald(window: SpiceCell) -> None:
"""
Validate window (remove invalid intervals, merge overlaps).
Parameters:
- window: SpiceCell, window to validate (modified in place)
Returns:
None
"""
def wnextd(side: str, window: SpiceCell) -> float:
"""
Extract leftmost or rightmost endpoint from window.
Parameters:
- side: str, which endpoint ("L" for left, "R" for right)
- window: SpiceCell, input window
Returns:
float: leftmost left endpoint or rightmost right endpoint
"""
def wncomd(left: float, right: float, window: SpiceCell, result: SpiceCell) -> None:
"""
Complement of window over specified interval.
Parameters:
- left: float, left endpoint of complement interval
- right: float, right endpoint of complement interval
- window: SpiceCell, input window
- result: SpiceCell, complement window (modified)
Returns:
None
"""import spiceypy as spice
# Create a double precision cell for time windows
window = spice.cell_double(100)
# Insert time intervals
start1 = spice.str2et("2023-01-01T00:00:00")
end1 = spice.str2et("2023-01-01T12:00:00")
spice.wninsd(start1, end1, window)
start2 = spice.str2et("2023-01-02T00:00:00")
end2 = spice.str2et("2023-01-02T12:00:00")
spice.wninsd(start2, end2, window)
# Query window properties
num_intervals = spice.wncard(window)
print(f"Number of intervals: {num_intervals}")
# Extract intervals
for i in range(num_intervals):
left, right = spice.wnfetd(window, i)
print(f"Interval {i}: {spice.et2utc(left, 'C', 0)} to {spice.et2utc(right, 'C', 0)}")import spiceypy as spice
# Create two windows
window_a = spice.cell_double(100)
window_b = spice.cell_double(100)
result = spice.cell_double(100)
# Add intervals to first window
spice.wninsd(spice.str2et("2023-01-01T00:00:00"), spice.str2et("2023-01-01T12:00:00"), window_a)
spice.wninsd(spice.str2et("2023-01-02T00:00:00"), spice.str2et("2023-01-02T12:00:00"), window_a)
# Add intervals to second window
spice.wninsd(spice.str2et("2023-01-01T06:00:00"), spice.str2et("2023-01-01T18:00:00"), window_b)
spice.wninsd(spice.str2et("2023-01-03T00:00:00"), spice.str2et("2023-01-03T12:00:00"), window_b)
# Union of windows
spice.wnunid(window_a, window_b, result)
print(f"Union has {spice.wncard(result)} intervals")
# Intersection of windows
spice.wnintd(window_a, window_b, result)
print(f"Intersection has {spice.wncard(result)} intervals")
# Difference (A - B)
spice.wndifd(window_a, window_b, result)
print(f"Difference has {spice.wncard(result)} intervals")import spiceypy as spice
# Create window with some intervals
window = spice.cell_double(100)
spice.wninsd(100.0, 200.0, window)
spice.wninsd(205.0, 210.0, window) # Small gap of 5 seconds
spice.wninsd(215.0, 217.0, window) # Short interval of 2 seconds
print(f"Original window measure: {spice.wnsumd(window)} seconds")
# Fill small gaps (less than 10 seconds)
spice.wnfild(10.0, window)
print(f"After filling gaps: {spice.wncard(window)} intervals")
# Filter out small intervals (less than 5 seconds)
spice.wnfltd(5.0, window)
print(f"After filtering small intervals: {spice.wncard(window)} intervals")
# Test point membership
test_time = 150.0
if spice.wnelmd(test_time, window):
print(f"Time {test_time} is covered by window")
# Expand intervals by 30 seconds on each side
spice.wnexpd(30.0, 30.0, window)
print(f"After expansion: total measure = {spice.wnsumd(window)} seconds")Install with Tessl CLI
npx tessl i tessl/pypi-spiceypydocs