across.tools.visibility.constraints.logical
Logical operators for combining constraints.
This module provides classes to combine multiple constraints using logical operators: - AndConstraint: Combines constraints with AND logic - OrConstraint: Combines constraints with OR logic - NotConstraint: Negates a constraint with NOT logic
Classes
Coerce constraint inputs into ConstraintABC instances. |
|
Combines two or more constraints with AND logic. |
|
Combines two or more constraints with OR logic. |
|
Negates a constraint with NOT logic. |
|
Combines two or more constraints with XOR (exclusive OR) logic. |
Functions
Module Contents
- class ConstraintCoercionMixin[source]
Coerce constraint inputs into ConstraintABC instances.
Accepts either already-instantiated ConstraintABC objects or JSON-like dicts that are parsed through the Constraint discriminated union.
- classmethod validate_constraint(v)[source]
Coerce single constraint input into ConstraintABC instance.
- class AndConstraint(/, **data)[source]
Bases:
ConstraintCoercionMixin,across.tools.visibility.constraints.base.ConstraintABCCombines two or more constraints with AND logic.
Since constraints represent when a target is NOT visible, this constraint is violated only if ALL constituent constraints are violated. This is rarely used in practice since typical visibility calculations combine constraints with OR logic instead. Use AND only when you need ALL specified blocking conditions to occur simultaneously (e.g., both Sun AND Moon must be blocking the target).
The constraints are stored as ConstraintABC instances internally but are serialized as part of the Constraint discriminated union for JSON serialization/deserialization.
- Parameters:
constraints (list[ConstraintABC]) – List of constraints to combine with AND logic. All constraints must be violated for the combined constraint to be violated.
Examples
Create an AND constraint using the & operator (rarely used):
>>> from across.tools.visibility.constraints import ( ... SunAngleConstraint, MoonAngleConstraint, EarthLimbConstraint ... ) >>> sun = SunAngleConstraint(min_angle=45) >>> moon = MoonAngleConstraint(min_angle=10) >>> earth = EarthLimbConstraint(min_angle=33) >>> # Target not visible only when BOTH Sun AND Moon AND Earth all block it >>> combined = sun & moon & earth
Notes
For typical visibility calculations, use OR logic (|) instead of AND. The | operator combines constraints so that ANY constraint violation blocks visibility, which is the standard behavior for combining multiple visibility constraints.
- constraints: list[across.tools.visibility.constraints.base.ConstraintABC][source]
- class OrConstraint(/, **data)[source]
Bases:
ConstraintCoercionMixin,across.tools.visibility.constraints.base.ConstraintABCCombines two or more constraints with OR logic.
Since constraints represent when a target is NOT visible, this constraint is violated if ANY constituent constraint is violated. This is the typical and recommended way to combine multiple visibility constraints: the target is NOT visible if ANY of the constraints block it (Sun OR Moon OR Earth blocking, etc.).
The constraints are stored as ConstraintABC instances internally but are serialized as part of the Constraint discriminated union for JSON serialization/deserialization.
- Parameters:
constraints (list[ConstraintABC]) – List of constraints to combine with OR logic. If any constraint is violated, the combined constraint is violated.
Examples
Create an OR constraint using the | operator (recommended for typical use):
>>> from across.tools.visibility.constraints import ( ... SunAngleConstraint, MoonAngleConstraint ... ) >>> sun = SunAngleConstraint(min_angle=45) >>> moon = MoonAngleConstraint(min_angle=10) >>> # Target not visible if Sun OR Moon blocks it >>> combined = sun | moon
More complex example with three constraints:
>>> from across.tools.visibility.constraints import EarthLimbConstraint >>> earth = EarthLimbConstraint(min_angle=33) >>> # Target not visible if ANY constraint blocks it >>> all_constraints = sun | moon | earth
Notes
OR logic is the standard way to combine constraints. Use this when you want observations blocked if ANY of the specified conditions are violated.
- constraints: list[across.tools.visibility.constraints.base.ConstraintABC][source]
- class NotConstraint(/, **data)[source]
Bases:
ConstraintCoercionMixin,across.tools.visibility.constraints.base.ConstraintABCNegates a constraint with NOT logic.
Since constraints represent when a target is NOT visible, negating a constraint means it is violated when the original constraint is NOT violated. This is useful for expressing “target must be in this region” constraints, which act as visibility constraints (blocking observations outside that region).
The constraint is stored as a ConstraintABC instance internally but is serialized as part of the Constraint discriminated union for JSON serialization/deserialization.
- Parameters:
constraint (ConstraintABC) – The constraint to negate. Can be an atomic constraint or another logical constraint.
Examples
Create a NOT constraint using the ~ operator:
>>> from across.tools.visibility.constraints import EarthLimbConstraint >>> earth = EarthLimbConstraint(min_angle=33) >>> # Violated when target is NOT >33° above Earth's limb >>> # (i.e., target must stay <33° above limb) >>> not_earth = ~earth
Complex example with combination:
>>> from across.tools.visibility.constraints import SunAngleConstraint >>> sun = SunAngleConstraint(min_angle=45) >>> # Target must be >45° from Sun OR must be <33° above Earth limb >>> complex_constraint = sun | ~earth
Notes
NOT logic is rarely used in typical visibility calculations. It’s primarily useful for inverting specific constraints to express regional requirements.
- class XorConstraint(/, **data)[source]
Bases:
ConstraintCoercionMixin,across.tools.visibility.constraints.base.ConstraintABCCombines two or more constraints with XOR (exclusive OR) logic.
Since constraints represent when a target is NOT visible, this constraint is violated when an odd number of constituent constraints are violated. For two constraints, it’s violated when exactly one is violated but not when both are violated or neither is violated. This is useful for expressing “either A or B but not both” logic.
The constraints are stored as ConstraintABC instances internally but are serialized as part of the Constraint discriminated union for JSON serialization/deserialization.
- Parameters:
constraints (list[ConstraintABC]) – List of constraints to combine with XOR logic. The combined constraint is violated when an odd number of constituent constraints are violated.
Examples
Create an XOR constraint using the ^ operator:
>>> from across.tools.visibility.constraints import ( ... SunAngleConstraint, MoonAngleConstraint ... ) >>> sun = SunAngleConstraint(min_angle=45) >>> moon = MoonAngleConstraint(min_angle=10) >>> # Target not visible if exactly one (but not both) blocks it >>> combined = sun ^ moon
More complex example with three constraints:
>>> from across.tools.visibility.constraints import EarthLimbConstraint >>> earth = EarthLimbConstraint(min_angle=33) >>> # Violated when odd number of constraints are violated >>> all_constraints = sun ^ moon ^ earth
Notes
XOR logic is rarely used in typical visibility calculations but can be useful for specific edge cases where you need exclusive conditions.
- constraints: list[across.tools.visibility.constraints.base.ConstraintABC][source]