space_packet_parser.xtce.comparisons

Matching logical objects

Classes

MatchCriteria

<xtce:MatchCriteriaType>

Comparison

<xtce:Comparison>

Condition

<xtce:Condition>

Anded

Tuple object for AND operations in BooleanExpression

Ored

Tuple object for OR operations in BooleanExpression

BooleanExpression

<xtce:BooleanExpression>

DiscreteLookup

<xtce:DiscreteLookup>

Module Contents

class space_packet_parser.xtce.comparisons.MatchCriteria

Bases: space_packet_parser.common.AttrComparable, space_packet_parser.common.XmlObject

<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:BooleanExpression>, and <xtce:CustomAlgorithm> (not supported)

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

Evaluate match criteria down to a boolean.

Parameters:
  • packet (space_packet_parser.SpacePacket) – 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.xtce.comparisons.Comparison(required_value: str, referenced_parameter: str, operator: str = '==', use_calibrated_value: bool = True)

Bases: MatchCriteria

<xtce:Comparison>

required_value
referenced_parameter
operator = '=='
use_calibrated_value = True
__repr__()
_validate()

Validate state as logically consistent.

Return type:

None

classmethod from_xml(element: lxml.etree.Element, *, tree: lxml.etree.Element | None = None, parameter_lookup: dict[str, any] | None = None, parameter_type_lookup: dict[str, any] | None = None, container_lookup: dict[str, any] | None = None) Comparison

Create

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

  • tree (Optional[ElementTree.Element]) – Ignored

  • parameter_lookup (Optional[dict]) – Ignored

  • parameter_type_lookup (Optional[dict]) – Ignored

  • container_lookup (Optional[dict[str, SequenceContainer]]) – Ignored

Return type:

Comparison

to_xml(*, elmaker: lxml.builder.ElementMaker) lxml.etree.Element

Create a Comparison XML element

Parameters:

elmaker (ElementMaker) – Element factory with predefined namespace

Return type:

ElementTree.Element

evaluate(packet: space_packet_parser.SpacePacket, 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 (space_packet_parser.SpacePacket) – 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.xtce.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 = None
right_value = None
operator
right_use_calibrated_value = True
left_use_calibrated_value = True
__repr__()
_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_xml(element: lxml.etree.Element, *, tree: lxml.etree.Element | None = None, parameter_lookup: dict[str, any] | None = None, parameter_type_lookup: dict[str, any] | None = None, container_lookup: dict[str, any] | None = None) Condition

Classmethod to create a Condition object from an XML element.

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

  • tree (Optional[ElementTree.Element]) – Ignored

  • parameter_lookup (Optional[dict]) – Ignored

  • parameter_type_lookup (Optional[dict]) – Ignored

  • container_lookup (Optional[dict[str, SequenceContainer]]) – Ignored

Return type:

cls

to_xml(*, elmaker: lxml.builder.ElementMaker) lxml.etree.Element

Create a Condition XML element

Parameters:

elmaker (ElementMaker) – Element factory with predefined namespace

Return type:

ElementTree.Element

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

Evaluate match criteria down to a boolean.

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

  • current_parsed_value (Optional[Union[int, float]]) – Ignored.

Returns:

Truthyness of this match criteria based on previously parsed values.

Return type:

bool

class space_packet_parser.xtce.comparisons.Anded

Bases: namedtuple('Anded', ['conditions', 'ors'])

Tuple object for AND operations in BooleanExpression

__repr__()

Return repr(self).

class space_packet_parser.xtce.comparisons.Ored

Bases: namedtuple('Ored', ['conditions', 'ands'])

Tuple object for OR operations in BooleanExpression

__repr__()

Return repr(self).

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

Bases: MatchCriteria

<xtce:BooleanExpression>

expression
__repr__()
classmethod from_xml(element: lxml.etree.Element, *, tree: lxml.etree.Element | None = None, parameter_lookup: dict[str, any] | None = None, parameter_type_lookup: dict[str, any] | None = None, container_lookup: dict[str, any] | None = None) BooleanExpression

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

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

  • tree (Optional[ElementTree.Element]) – Ignored

  • parameter_lookup (Optional[dict]) – Ignored

  • parameter_type_lookup (Optional[dict]) – Ignored

  • container_lookup (Optional[dict[str, SequenceContainer]]) – Ignored

Return type:

BooleanExpression

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

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

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

  • current_parsed_value (Optional[Union[int, float]]) – Ignored.

Returns:

Truthyness of this match criteria based on previously parsed values.

Return type:

bool

to_xml(*, elmaker: lxml.builder.ElementMaker) lxml.etree.Element

Create a Condition XML element

Parameters:

elmaker (ElementMaker) – Element factory with predefined namespace

Return type:

ElementTree.Element

class space_packet_parser.xtce.comparisons.DiscreteLookup(match_criteria: list[Comparison], lookup_value: int | float)

Bases: space_packet_parser.common.AttrComparable, space_packet_parser.common.XmlObject

<xtce:DiscreteLookup>

match_criteria
lookup_value
classmethod from_xml(element: lxml.etree.Element, *, tree: lxml.etree.ElementTree | None = None, parameter_lookup: dict[str, any] | None = None, parameter_type_lookup: dict[str, any] | None = None, container_lookup: dict[str, any] | None = None) 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.

  • tree (Optional[ElementTree.Element]) – Ignored

  • parameter_lookup (Optional[dict]) – Ignored

  • parameter_type_lookup (Optional[dict]) – Ignored

  • container_lookup (Optional[dict[str, SequenceContainer]]) – Ignored

Return type:

DiscreteLookup

to_xml(*, elmaker: lxml.builder.ElementMaker) lxml.etree.Element

Create a DiscreteLookup XML element

Parameters:

elmaker (ElementMaker) – ElementMaker factory

Return type:

ElementTree.Element

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

Evaluate the lookup to determine if it is valid.

Parameters:
  • packet (space_packet_parser.SpacePacket) – 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