libera_utils.l1a.packets.parse_packets_to_l1a_dataset#
- libera_utils.l1a.packets.parse_packets_to_l1a_dataset(packet_files: list[PathLike | str], apid: int, *, ground_data: bool = False, verbose: bool = False, skip_header_bytes: int | None = None, max_workers: int = 1) Dataset#
Parse packets to L1A dataset with configurable sample expansion.
This function parses binary packet files and expands multi-sample fields according to the a configuration identified by APID. It creates proper xarray Datasets with time coordinates as dimensions.
- Parameters:
packet_files (list[PathLike | str]) – List of filepaths to packet files, in any order. They are parsed in file name order, which is time order for ground CCSDS names and creation order for flight PDS names.
apid (int) – The APID (Application Process Identifier) value for the packet type. Used to select the appropriate configuration for generating the L1A Dataset structure.
ground_data (bool, optional) – If True, packets that repeat a
SRC_SEQ_CTRwith differing contents, or samples that repeat a sample time with differing data, produce a warning instead of a ValueError. This is useful for ground test data where such repeats may be expected. Default is False.verbose (bool, optional) – If True and ground_data is True, a warning will be issued for each such repeat. Default is False.
skip_header_bytes (int | None, optional) – Bytes to skip before each CCSDS primary header. When
None, usesSKIP_PACKET_HEADER_BYTESfrom config (default0, correct for flight PDS and demuxed ground CCSDS; raw ground captures that still carry a per-packet record header need8).max_workers (int, optional) – Files to parse concurrently, in worker processes. Default 1 (in-process); must be at least 1. See
parse_packets_to_dataset; peak memory rises by one in-flight parse per worker, and workers start withfork, which Windows does not provide.
- Returns:
xarray Dataset with: - Main packet data array with packet timestamp dimension - Separate arrays for each sample group with optional multi-field expansion - All time coordinates properly set as dimensions
- Return type:
xr.Dataset
- Raises:
ValueError – If the decoded packets have no
SRC_SEQ_CTR; if packets adjacent in an input file with consecutiveSRC_SEQ_CTRwould be placed a counter wrap apart, other than around a single packet whose packet time is wrong, which is dropped with aUserWarning; ifground_datais False and packets with the sameSRC_SEQ_CTRdiffer; as_drop_duplicatesraises for samples; or asparse_packets_to_datasetraises, including formax_workersbelow 1 or a platform withoutfork.OSError – If a packet file cannot be opened or read.
RuntimeError – If a worker process exits without reporting a result (
max_workersabove 1).Exception – Any exception raised while parsing a file in a worker process is re-raised in the caller, with the worker’s traceback attached as a note.
Notes
The
PACKETaxis is inSRC_SEQ_CTRorder, with the counter’s wraps resolved by packet time (seelibera_utils.l1a.packet_ordering), whatever the order of the input files. A packet received twice is kept once. Packet time is not monotonic along the axis;check_packet_order()warns where it steps backward. Input files are parsed in file name order, whichinput_fileslists.For APID 1040 (ICIE WFOV SCI), the packet dataset is post-processed by
enhance_wfov_l1a_dataset: complete SOP→EOP images are stitched onto aCAMERA_TIMEdimension, compressed payloads and decoded header metadata are attached,ICIE__WFOV_DATAis dropped, andPACKET_IMAGE_IDtraces packets back to stitched images.