space_packet_parser.comparisons

Matching logical objects

Attributes

Anded

Ored

Classes

AttrComparable

Generic class that provides a notion of equality based on all non-callable, non-dunder attributes

MatchCriteria

<xtce:MatchCriteriaType>

Comparison

<xtce:Comparison>

Condition

<xtce:Condition>

BooleanExpression

<xtce:BooleanExpression>

DiscreteLookup

<xtce:DiscreteLookup>

Module Contents

class space_packet_parser.comparisons.AttrComparable

Generic class that provides a notion of equality based on all non-callable, non-dunder attributes

__eq__(other)
class space_packet_parser.comparisons.MatchCriteria

Bases: AttrComparable

<xtce:MatchCriteriaType> This class stores criteria for performing logical operations based on parameter values Classes that inherit from this ABC include those that represent <xtce:Comparison>, <xtce:ComparisonList>, <xtce:BooleanExpression> (not supported), and <xtce:CustomAlgorithm> (not supported)

_valid_operators
classmethod from_match_criteria_xml_element(element: lxml.etree.Element, ns: dict)
Abstractmethod:

Abstract classmethod to create a match criteria object from an XML element.

Parameters:
  • element (ElementTree.Element) – XML element

  • ns (dict) – XML namespace dict

Return type:

cls

abstract evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: int | float | None = None) bool

Evaluate match criteria down to a boolean.

Parameters:
  • packet (packets.CCSDSPacket) – Packet data used to evaluate truthyness of the match criteria.

  • current_parsed_value (any, Optional) – Uncalibrated value that is currently being matched (e.g. as a candidate for calibration). Used to resolve comparisons that reference their own raw value as a condition.

Returns:

Truthyness of this match criteria based on previously parsed values.

Return type:

bool

class space_packet_parser.comparisons.Comparison(required_value: any, referenced_parameter: str, operator: str = '==', use_calibrated_value: bool = True)

Bases: MatchCriteria

<xtce:Comparison>

required_value
referenced_parameter
operator
use_calibrated_value
__repr__()
_validate()

Validate state as logically consistent.

Return type:

None

classmethod from_match_criteria_xml_element(element: lxml.etree.Element, ns: dict) Comparison

Create

Parameters:
  • element (ElementTree.Element) – XML element

  • ns (dict) – XML namespace dict

Return type:

Comparison

evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: int | float | None = None) bool

Evaluate comparison down to a boolean. If the parameter to compare is not present in the parsed_data dict, we assume that we are comparing against the current raw value in current_parsed_value.

Parameters:
  • packet (packets.CCSDSPacket) – Packet data used to evaluate truthyness of the match criteria.

  • current_parsed_value (Union[int, float]) – Optional. Uncalibrated value that is currently a candidate for calibration and so has not yet been added to the packet. Used to resolve calibrator conditions that reference their own raw value as a comparate.

Returns:

Truthyness of this match criteria based on previously parsed values.

Return type:

bool

class space_packet_parser.comparisons.Condition(left_param: str, operator: str, *, right_param: str | None = None, right_value: Any | None = None, left_use_calibrated_value: bool = True, right_use_calibrated_value: bool = True)

Bases: MatchCriteria

<xtce:Condition> Note: This xtce model doesn’t actually inherit from MatchCriteria in the UML model but it’s functionally close enough that we inherit the class here.

left_param
right_param
right_value
operator
right_use_calibrated_value
left_use_calibrated_value
_validate()

Check that the instantiated object actually makes logical sense.

Return type:

None

static _parse_parameter_instance_ref(element: lxml.etree.Element)

Parse an xtce:ParameterInstanceRef element

Parameters:

element (ElementTree.Element) – xtce:ParameterInstanceRef element

Returns:

  • parameter_name (str) – Name of referenced parameter

  • use_calibrated_value (bool) – Whether to use the calibrated form of the referenced parameter

classmethod from_match_criteria_xml_element(element: lxml.etree.Element, ns: dict)

Classmethod to create a Condition object from an XML element.

Parameters:
  • element (ElementTree.Element) – XML element

  • ns (dict) – XML namespace dict

Return type:

cls

evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: int | float | None = None) bool

Evaluate match criteria down to a boolean.

Parameters:
  • packet (packets.CCSDSPacket) – Packet data used to evaluate truthyness of the match criteria.

  • current_parsed_value (Optional[Union[int, float]]) – Current value being parsed. NOTE: This is currently ignored. See the TODO item below.

Returns:

Truthyness of this match criteria based on previously parsed values.

Return type:

bool

space_packet_parser.comparisons.Anded
space_packet_parser.comparisons.Ored
class space_packet_parser.comparisons.BooleanExpression(expression: Condition | Anded | Ored)

Bases: MatchCriteria

<xtce:BooleanExpression>

expression
classmethod from_match_criteria_xml_element(element: lxml.etree.Element, ns: dict) BooleanExpression

Abstract classmethod to create a match criteria object from an XML element.

Parameters:
  • element (ElementTree.Element) – XML element

  • ns (dict) – XML namespace dict

Return type:

BooleanExpression

evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: int | float | None = None) bool

Evaluate the criteria in the BooleanExpression down to a single boolean.

Parameters:
  • packet (packets.CCSDSPacket) – Packet data used to evaluate truthyness of the match criteria.

  • current_parsed_value (Optional[Union[int, float]]) – Current value being parsed.

Returns:

Truthyness of this match criteria based on previously parsed values.

Return type:

bool

class space_packet_parser.comparisons.DiscreteLookup(match_criteria: list, lookup_value: int | float)

Bases: AttrComparable

<xtce:DiscreteLookup>

match_criteria
lookup_value
classmethod from_discrete_lookup_xml_element(element: lxml.etree.Element, ns: dict) DiscreteLookup

Create a DiscreteLookup object from an <xtce:DiscreteLookup> XML element

Parameters:
  • element (ElementTree.Element) – <xtce:DiscreteLookup> XML element from which to parse the DiscreteLookup object.

  • ns (dict) – Namespace dict for XML parsing

Return type:

DiscreteLookup

evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: int | float | None = None) Any

Evaluate the lookup to determine if it is valid.

Parameters:
  • packet (packets.CCSDSPacket) – Packet data used to evaluate truthyness of the match criteria.

  • current_parsed_value (Optional[Union[int, float]]) – If referenced parameter in criterion isn’t in the packet, we assume we are comparing against this currently parsed value.

Returns:

Return the lookup value if the match criteria evaluate true. Return None otherwise.

Return type:

any