spac_kit.parser

The parser module provides tools for parsing CCSDS binary files and converting them to structured data formats.

spac_kit.parser

Generic code to parse a downlink binary file encoded using CCSDS.

spac_kit.parser.Packets

CCSDSpy packet specialized for configurable APID parsing.

class spac_kit.parser.Packets.ParserSubAPIDPacket(fields: list[PacketField], name: str, apid: int, sub_apid: int)

Bases: SimpleAPIDPacket

Packet definition associated to a specific flavor of structure within a single APID.

__init__(fields: list[PacketField], name: str, apid: int, sub_apid: int)

Constructor.

class spac_kit.parser.Packets.PreParserAPIDPacket(fields: list[~ccsdspy.packet_fields.PacketField], name: str, apid: int, decision_field: str = None, decision_fun: ~typing.Callable = <function PreParserAPIDPacket.<lambda>>)

Bases: SimpleAPIDPacket

Packet definition used to pre-parse packets.

This is used when the structure vary for a single APID depending on one field in this packet.

__init__(fields: list[~ccsdspy.packet_fields.PacketField], name: str, apid: int, decision_field: str = None, decision_fun: ~typing.Callable = <function PreParserAPIDPacket.<lambda>>)

Constructor.

class spac_kit.parser.Packets.SimpleAPIDPacket(fields: list[PacketField], name: str, apid: int)

Bases: VariableLength

Simple Packet definition, with name and associated APID.

__init__(fields: list[PacketField], name: str, apid: int)

Constructor.

spac_kit.parser.util

Utilities shared.

spac_kit.parser.util.import_ccsds_packet_packages()

Import subpackages of ccsds.packets containing CCSDSpy definitions.

Stolen from https://packaging.python.org/en/latest/guides/ creating-and-discovering-plugins/#using-namespace-packages

Returns:

‘packet’ (the packet object), ‘variable_name’, ‘module_path’

Return type:

List of dictionaries with keys

spac_kit.parser.remove_non_ccsds_headers

Remove non CCSDS binary code from input streams.

spac_kit.parser.remove_non_ccsds_headers.remove_bdsem(f)

Remove BDSEM headers.

spac_kit.parser.remove_non_ccsds_headers.remove_bdsem_and_message_headers(f)

Removes extra headers provided by the BDSEM data generation.

Parameters:

f – file handler

Returns:

File handler

spac_kit.parser.remove_non_ccsds_headers.remove_mise_and_headers(f)

Remove packet markers from Raw mode file.

spac_kit.parser.remove_non_ccsds_headers.start_sequence(seq)

Returns True if seq is on the beginning of a marker between CCSDS packets.

spac_kit.parser.remove_non_ccsds_headers.strip_non_ccsds_headers(file_handler, is_bdsem: bool = False, has_pkt_header: bool = False, has_json_header: bool = False)

Remove all cases of non CCSDS headers which can occur in Europa-Clipper SDS inputs.

Mostly used in test cases.

Parameters:
  • file_handler – input binary file handler

  • is_bdsem – file coming from BDSEM, else RAW

  • has_pkt_header – whether the file has packet headers

  • has_json_header – whether the file has a JSON header

Returns:

The file handler where the CCSDS packets start

spac_kit.parser.spac_ls

Command line utility to list available CCSDS packet packages.

spac_kit.parser.spac_ls.format_packet_info(packet_info, long_format=False)

Format packet information into a row for display.

Parameters:
  • packet_info – Either a dict with ‘packet’, ‘variable_name’, ‘module_path’ keys, or a packet object for backward compatibility

  • long_format – If True, include additional fields like packet type and field count

spac_kit.parser.spac_ls.get_parser()

Parser for the command line utility.

spac_kit.parser.spac_ls.list_packages(delimiter=None, long_format=False)

List all available CCSDS packet packages.

Parameters:
  • delimiter – If specified, output as delimited format (e.g., ‘,’ for CSV, ‘ ‘ for TSV)

  • long_format – If True, display additional fields like packet type and field information

spac_kit.parser.spac_ls.main()

Command line interface to list CCSDS packet packages.

spac_kit.parser.test_utils

Utilities to test the packet parsing.

spac_kit.parser.test_utils.compare(local_dir: str, is_bdsem: bool = False, has_pkt_header: bool = False, has_json_header: bool = False, create_output: bool = False, create_spreadsheet: bool = False)

Run parsing and compare results with a reference.

Parameters:
  • local_dir – local directory containing input file

  • is_bdsem – whether file is from BDSEM

  • has_pkt_header – whether file has packet headers

  • has_json_header – whether file has JSON header

  • create_output – whether to create output pickle file

  • create_spreadsheet – whether to create Excel spreadsheet

spac_kit.parser.test_utils.recursive_compare(dfs, dfs_expected)

Compare embedded dictionary of dictionaries of pandas dataframes.

Compare the keys and the actual dataframes. None should be missing and all should match.

Parameters:
  • dfs – dictionary of dictionaries of dataframes

  • dfs_expected – expected dictionary of dictionaries

Returns:

True if the pandas dataframes are identical at the same location