"""Validate every corrected row, source mapping, seed, composition and checksum.""" from __future__ import annotations import argparse import json from pathlib import Path import numpy as np import pyarrow.parquet as pq from kitti_c2l.release import require, sha256, validate_table def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[1]) parser.add_argument("--raw-root", type=Path) args = parser.parse_args() report = json.loads((args.root / "release/v1.1.0/calibration_audit.json").read_text()) source_root = args.raw_root or args.root / "release/v1.1.0/source_calibration" for relative, expected in report["source_calibration_sha256"].items(): require( sha256(source_root / relative) == expected, f"Source calibration checksum: {relative}" ) require( report["status"] == "pass" and not report["parameters_estimated_from_recordings"], "Calibration claim mismatch", ) for item in report["files"]: path = args.root / item["path"] require(sha256(path) == item["sha256"], f"Corrected checksum mismatch: {path}") legacy_path = args.root / "data" / path.name require( sha256(legacy_path) == item["legacy_sha256"], f"Legacy checksum mismatch: {path.name}" ) actual = validate_table( path, kitti_calib_root=source_root, camera_model="full_projection_v1_1" ) require(actual["rows"] == item["rows"], f"Row count mismatch: {path.name}") table, legacy = pq.read_table(path), pq.read_table(legacy_path) require( table.select(item["unchanged_columns"]).equals( legacy.select(item["unchanged_columns"]) ), f"Unexpected non-translation change: {path.name}", ) for date, calibration in report["per_date"].items(): mask = np.asarray(table["raw_date"].to_pylist()) == date if mask.any(): translation = np.asarray(table["gt_t_cam_from_velo_cm"].to_pylist())[mask] require( np.allclose( translation, calibration["full_projection_translation_cm"], atol=2e-5, rtol=0, ), f"Calibration manifest mismatch: {date}", ) print(f"Validated {path.name}: {actual['rows']} rows", flush=True) print("Full-projection v1.1 release: pass") if __name__ == "__main__": main()