"""Read one AlphaMotion H2 NPZ record from a tar.zst shard without pickle. Example: python load_motion.py data/shards/.tar.zst Use data/index.jsonl to find the archive and exact member path by clip ID. """ from __future__ import annotations import io import sys import tarfile from pathlib import Path import numpy as np import zstandard def load_motion(shard: Path, member: str) -> dict[str, np.ndarray]: with shard.open("rb") as file: with zstandard.ZstdDecompressor().stream_reader(file) as stream: with tarfile.open(fileobj=stream, mode="r|") as archive: for item in archive: if item.name == member: extracted = archive.extractfile(item) if extracted is None: raise ValueError(f"Not a regular file: {member}") with np.load(io.BytesIO(extracted.read()), allow_pickle=False) as record: return {name: record[name] for name in record.files} raise FileNotFoundError(member) if __name__ == "__main__": if len(sys.argv) != 3: raise SystemExit("usage: python load_motion.py ") arrays = load_motion(Path(sys.argv[1]), sys.argv[2]) print({name: (array.shape, str(array.dtype)) for name, array in arrays.items()})