"""Read a capture manifest and its original numeric outputs."""
import argparse
import json
from pathlib import Path
import numpy as np


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("capture_dir", type=Path)
    args = parser.parse_args()
    manifest = json.loads((args.capture_dir / "capture_manifest.json").read_text(encoding="utf-8"))
    print("status:", manifest["status"])
    print("metric_depth_available:", manifest.get("metric_depth_available"))
    for key in ("disparity", "depth_m"):
        if key not in manifest["files"]:
            print(key, "not saved")
            continue
        array = np.load(args.capture_dir / manifest["files"][key], allow_pickle=False)
        print(key, "dtype:", array.dtype, "shape:", array.shape)
        if key == "depth_m":
            usable = np.isfinite(array) & (array > 0)
            print("finite positive depth fraction:", float(usable.mean()))
            filtered = np.where(usable, array, np.nan)
            # filtered is a new business-level view. The original NPY stays unchanged.
            print("filtered dtype:", filtered.dtype)


if __name__ == "__main__":
    main()
