Condition

class missiontools.AbstractCondition(cache_size=16)[source]

Bases: ABC

Base class for boolean time-domain conditions.

Subclasses implement _compute() and __repr__(). The base class handles input coercion, scalar/array shape tracking, and a small per-instance count-based LRU cache keyed on the SHA-256 digest of the requested time array.

Parameters:

cache_size (int, optional) – Maximum number of distinct time arrays whose results are cached. Default 16. Set to 0 to disable caching.

Parameters:

cache_size (int)

Notes

Subclasses can bypass caching entirely by overriding at() rather than _compute().

Boolean operators &, |, ^, ~ return new composite conditions:

at(t)[source]

Evaluate the condition at one or more times.

Parameters:

t (array_like of datetime64, shape (N,) or scalar) – Time(s) at which to evaluate.

Returns:

ndarray of bool, shape (N,) or scalar bool – True where the condition holds.

Parameters:

t (ArrayLike)

Return type:

ndarray[tuple[Any, …], dtype[bool]]

intervals(t_start, t_end, *, max_step=np.timedelta64(10, 's'), tolerance=np.timedelta64(1, 's'))[source]

Return edge-refined intervals where the condition is True.

Scans [t_start, t_end] at max_step resolution, detects rising/falling edges, then bisects each edge to tolerance precision.

Parameters:
  • t_start (np.datetime64) – Start of the time window.

  • t_end (np.datetime64) – End of the time window (inclusive).

  • max_step (np.timedelta64, optional) – Scan step for the initial coarse pass (default 10 s).

  • tolerance (np.timedelta64, optional) – Bisection refinement tolerance (default 1 s).

Returns:

list[tuple[np.datetime64, np.datetime64]] – Sorted, non-overlapping [(t0, t1), ...] intervals where the condition is True. Empty when the condition is never True.

Parameters:
Return type:

list[tuple[datetime64, datetime64]]

class missiontools.SunlightCondition(obj)[source]

Bases: AbstractCondition

True when the object is in sunlight.

Uses a cylindrical shadow model centred on the central body. For a spacecraft the position is propagated analytically; for a ground station the fixed ECEF position is converted to ECI.

Parameters:

obj (Spacecraft | GroundStation) – The object whose sunlight status is being tested.

Raises:

TypeError – If obj is not a Spacecraft or GroundStation.

class missiontools.SubSatelliteRegionCondition(spacecraft, aoi)[source]

Bases: AbstractCondition

True when the spacecraft’s sub-satellite point falls inside an AoI.

Parameters:
  • spacecraft (Spacecraft) – The spacecraft whose sub-satellite point is tested.

  • aoi (AoI) – Area of interest with a geometry (aoi.geometry is not None).

Raises:
class missiontools.VisibilityCondition(obj1, obj2)[source]

Bases: AbstractCondition

True when two objects have unobstructed line-of-sight.

Earth blockage is modelled as a sphere with radius equal to the spacecraft’s central_body_radius (or the default mean Earth radius when neither object is a spacecraft).

Parameters:

obj1, obj2 (Spacecraft | GroundStation) – The two objects whose mutual visibility is tested. At least one should be a Spacecraft for meaningful results (ground-station-to-ground-station visibility is almost always blocked by Earth).

Raises:

TypeError – If either argument is not a Spacecraft or GroundStation.

class missiontools.SpaceGroundAccessCondition(spacecraft, ground_station, el_min_deg=5.0)[source]

Bases: AbstractCondition

True when a spacecraft is visible from a ground station.

Visibility is the standard above-horizon test: the elevation angle from the geodetic up-direction at the ground station to the spacecraft must meet or exceed el_min_deg. Earth blockage is implicit for el_min_deg >= 0.

Parameters:
  • spacecraft (Spacecraft) – The spacecraft whose visibility is being tested.

  • ground_station (GroundStation) – The observing ground station.

  • el_min_deg (float, optional) – Minimum elevation angle (degrees). Default 5.0.

Raises:

TypeError – If spacecraft is not a Spacecraft or ground_station is not a GroundStation.

Parameters:

el_min_deg (float)

Examples

from missiontools import Spacecraft, GroundStation
from missiontools.condition import SpaceGroundAccessCondition

sc = Spacecraft(...)
gs = GroundStation(lat=51.5, lon=-0.1)
cond = SpaceGroundAccessCondition(sc, gs, el_min_deg=5.0)
cond.at(np.datetime64('2025-01-01', 'us'))   # -> bool
class missiontools.AndCondition(condition1, condition2)[source]

Bases: AbstractCondition

True when both child conditions are true (logical AND).

Parameters:

condition1, condition2 (AbstractCondition) – Child conditions.

Raises:

TypeError – If either argument is not an AbstractCondition.

Parameters:
class missiontools.OrCondition(condition1, condition2)[source]

Bases: AbstractCondition

True when either child condition is true (logical OR).

Parameters:

condition1, condition2 (AbstractCondition) – Child conditions.

Raises:

TypeError – If either argument is not an AbstractCondition.

Parameters:
class missiontools.NotCondition(condition)[source]

Bases: AbstractCondition

True when the child condition is false (logical NOT).

Parameters:

condition (AbstractCondition) – Child condition to invert.

Raises:

TypeError – If condition is not an AbstractCondition.

Parameters:

condition (AbstractCondition)

class missiontools.XorCondition(condition1, condition2)[source]

Bases: AbstractCondition

True when exactly one child condition is true (logical XOR).

Parameters:

condition1, condition2 (AbstractCondition) – Child conditions.

Raises:

TypeError – If either argument is not an AbstractCondition.

Parameters: