Condition¶
- class missiontools.AbstractCondition(cache_size=16)[source]¶
Bases:
ABCBase 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:a & b→AndConditiona | b→OrConditiona ^ b→XorCondition~a→NotCondition
- 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]atmax_stepresolution, detects rising/falling edges, then bisects each edge totoleranceprecision.- 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:
t_start (datetime64)
t_end (datetime64)
max_step (timedelta64)
tolerance (timedelta64)
- Return type:
- class missiontools.SunlightCondition(obj)[source]¶
Bases:
AbstractConditionTrue 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
SpacecraftorGroundStation.
- class missiontools.SubSatelliteRegionCondition(spacecraft, aoi)[source]¶
Bases:
AbstractConditionTrue 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:
TypeError – If spacecraft is not a
Spacecraft.ValueError – If aoi does not have a geometry defined.
- class missiontools.VisibilityCondition(obj1, obj2)[source]¶
Bases:
AbstractConditionTrue 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 aSpacecraftfor meaningful results (ground-station-to-ground-station visibility is almost always blocked by Earth).- Raises:
TypeError – If either argument is not a
SpacecraftorGroundStation.
- class missiontools.SpaceGroundAccessCondition(spacecraft, ground_station, el_min_deg=5.0)[source]¶
Bases:
AbstractConditionTrue 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 forel_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
spacecraftis not aSpacecraftorground_stationis not aGroundStation.- 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:
AbstractConditionTrue when both child conditions are true (logical AND).
- Parameters:
condition1, condition2 (
AbstractCondition) – Child conditions.- Raises:
TypeError – If either argument is not an
AbstractCondition.- Parameters:
condition1 (AbstractCondition)
condition2 (AbstractCondition)
- class missiontools.OrCondition(condition1, condition2)[source]¶
Bases:
AbstractConditionTrue when either child condition is true (logical OR).
- Parameters:
condition1, condition2 (
AbstractCondition) – Child conditions.- Raises:
TypeError – If either argument is not an
AbstractCondition.- Parameters:
condition1 (AbstractCondition)
condition2 (AbstractCondition)
- class missiontools.NotCondition(condition)[source]¶
Bases:
AbstractConditionTrue 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:
AbstractConditionTrue 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:
condition1 (AbstractCondition)
condition2 (AbstractCondition)