libera_utils.l1a.packet_slicing.sample_to_packet_index#

libera_utils.l1a.packet_slicing.sample_to_packet_index(dataset: Dataset, sample_dim: str) → ndarray#

Map every row of sample_dim to its originating row of PACKET.

Prefers the stored {sample_group}_packet_index variable, which stays correct when duplicate samples have been dropped. For CAMERA_TIME this is CAMERA_PACKET_INDEX, each image’s SOP packet. Falls back to positional arithmetic (sample i -> packet i // samples_per_packet) only when no index variable is present.

The mapping is not necessarily monotonically non-decreasing: sample axes are sorted by sample time, so skew between two adjacent packets’ sample clocks interleaves their sample blocks and the mapping steps backwards at those positions. Interleaving is logged, not raised.

Parameters:
  • dataset (xr.Dataset) – Decoded L1A Dataset.

  • sample_dim (str) – Name of the sample dimension.

Returns:

int64 array of length dataset.sizes[sample_dim].

Return type:

np.ndarray

Raises:

ValueError – If a stored packet index is out of range of the PACKET axis, which means the packet and sample axes describe different sets of packets.