libera_utils.l1a.packet_ordering.sort_by_sequence_counter#
- libera_utils.l1a.packet_ordering.sort_by_sequence_counter(packet_ds: Dataset, packet_time_coordinate: str, *, ground_data: bool = False, verbose: bool = False) Dataset#
Order the
PACKETaxis bySRC_SEQ_CTRand drop repeated packets.The key is each packet’s
SRC_SEQ_CTRwith its wraps counted, as_unwrap_sequence_counterreturns it. Packets with the same key are the same packet counter: when everyPACKETdata variable agrees they are one packet received twice, and the first is kept. The rows are compared here rather than by_drop_duplicatesbecause the key is not a coordinate of the dataset and the error names the raw counter and packet times.packet_dsis consumed: eachPACKETvariable is removed from it as its reordered copy is made, so at most one variable is held twice. Use the returned dataset.A packet whose packet time would place it a counter wrap away from both of its neighbors in the input, whose counters continue its own, has a wrong packet time: it is dropped, with a
UserWarningand a logged warning.- Parameters:
packet_ds (xr.Dataset) – Single-APID packet dataset with
SRC_SEQ_CTRandpacket_time_coordinateonPACKET.packet_time_coordinate (str) – Name of the packet time coordinate.
ground_data (bool, optional) – If True, a repeated counter whose packets differ keeps its first packet instead of raising. Default is False.
verbose (bool, optional) – If True and
ground_datais True, warn for each repeated counter whose packets differ. Default is False.
- Returns:
The packets in
SRC_SEQ_CTRorder, one per counter.- Return type:
xr.Dataset
- Raises:
ValueError – If
packet_dshas noSRC_SEQ_CTRor nopacket_time_coordinatevariable, if packets adjacent in the input with consecutive counters would be placed a counter wrap apart other than around one such dropped packet, or, withground_dataFalse, if packets with the same counter differ.