libera_utils.l1a.packet_slicing.select_packets#

libera_utils.l1a.packet_slicing.select_packets(dataset: Dataset, keep_packets: slice | ndarray) → Dataset#

Subset a decoded L1A Dataset along PACKET, carrying its sample axes along.

Every sample of a selected packet is kept and every sample of an unselected packet is dropped, so whole packets survive. Each *_packet_index variable, and CAMERA_PACKET_INDEX, is renumbered from 0 against the surviving packet axis. A CAMERA_TIME row survives when its SOP packet does; keeping an image’s other packets is the caller’s job, as slice_l1a_dataset_to_time_window() does. PACKET_IMAGE_ID is renumbered from 0 against the surviving CAMERA_TIME axis; a kept packet whose image row was dropped gets -1.

Packet order is preserved; an unordered integer indexer is sorted rather than applied as a reordering.

Parameters:
  • dataset (xr.Dataset) – Decoded L1A Dataset with a PACKET dimension.

  • keep_packets (slice or np.ndarray) – Packets to keep, as a slice, a boolean mask over PACKET, or an integer array of packet indices.

Returns:

Subset Dataset. May be empty along PACKET if nothing was selected; callers decide whether that is an error.

Return type:

xr.Dataset

Raises:

ValueError – If dataset has no PACKET dimension, or if a sample axis cannot be mapped back to the packet axis.