File size: 4,902 Bytes
e9aca9c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | #!/usr/bin/env python3
import argparse
import hashlib
import json
from pathlib import Path
import numpy as np
REQUIRED_KEYS = ["pointcloud", "mask", "VX", "VY", "PS", "PG"]
REQUIRED_FILES = [
"sim.npz",
"triangles.npy",
"constrained_kmeans_10.npy",
"constrained_kmeans_20.npy",
"constrained_kmeans_30.npy",
"constrained_kmeans_40.npy",
]
def fail(message):
raise SystemExit(f"[ERROR] {message}")
def sha256_file(path):
h = hashlib.sha256()
with path.open("rb") as f:
for chunk in iter(lambda: f.read(1024 * 1024), b""):
h.update(chunk)
return h.hexdigest()
def iter_inventory(path):
with path.open("r", encoding="utf-8") as f:
for line in f:
if line.strip():
yield json.loads(line)
def inspect_sample(sample_dir):
for name in REQUIRED_FILES:
if not (sample_dir / name).exists():
fail(f"missing required file: {sample_dir / name}")
with np.load(sample_dir / "sim.npz", mmap_mode="r") as data:
missing = [key for key in REQUIRED_KEYS if key not in data.files]
if missing:
fail(f"{sample_dir / 'sim.npz'} missing keys: {missing}")
pointcloud = data["pointcloud"]
mask = data["mask"]
if pointcloud.ndim != 3 or pointcloud.shape[-1] != 2:
fail(f"unexpected pointcloud shape: {pointcloud.shape}")
if pointcloud.dtype != np.float32:
fail(f"unexpected pointcloud dtype: {pointcloud.dtype}")
if mask.shape != pointcloud.shape[:2]:
fail(f"mask shape {mask.shape} does not match pointcloud {pointcloud.shape[:2]}")
for key in ["VX", "VY", "PS", "PG"]:
arr = data[key]
if arr.shape != pointcloud.shape[:2]:
fail(f"{key} shape {arr.shape} does not match pointcloud {pointcloud.shape[:2]}")
if arr.dtype != np.float32:
fail(f"{key} dtype should be float32, got {arr.dtype}")
triangles = np.load(sample_dir / "triangles.npy", mmap_mode="r")
if triangles.ndim != 3 or triangles.shape[0] != pointcloud.shape[0] or triangles.shape[-1] != 3:
fail(f"unexpected triangles shape: {triangles.shape}")
for n_cluster in [10, 20, 30, 40]:
clusters = np.load(sample_dir / f"constrained_kmeans_{n_cluster}.npy", mmap_mode="r")
if clusters.ndim != 3 or clusters.shape[0] != pointcloud.shape[0] or clusters.shape[-1] != n_cluster:
fail(f"unexpected constrained_kmeans_{n_cluster}.npy shape: {clusters.shape}")
def validate_inventory(dataset_root, inventory_path, full_hash):
checked = 0
for item in iter_inventory(inventory_path):
rel = item["path"]
path = dataset_root / rel
if not path.exists():
fail(f"inventory path missing: {path}")
size = path.stat().st_size
if size != item["size"]:
fail(f"size mismatch for {rel}: expected {item['size']}, got {size}")
if full_hash:
digest = sha256_file(path)
if digest != item["sha256"]:
fail(f"sha256 mismatch for {rel}: expected {item['sha256']}, got {digest}")
checked += 1
return checked
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--data-root", default="data/Eagle_dataset")
parser.add_argument("--sample-limit", type=int, default=3)
parser.add_argument("--full-hash", action="store_true")
args = parser.parse_args()
repo_root = Path.cwd()
dataset_root = repo_root / args.data_root
inventory_path = repo_root / "files_sha256.jsonl"
summary_path = repo_root / "data_integrity_summary.json"
if not dataset_root.exists():
fail(f"dataset root not found: {dataset_root}")
if not inventory_path.exists():
fail(f"inventory not found: {inventory_path}")
if not summary_path.exists():
fail(f"summary not found: {summary_path}")
for geom in ["Cre", "Spl", "Tri"]:
geom_dir = dataset_root / geom
if not geom_dir.exists():
fail(f"missing geometry directory: {geom_dir}")
sample_dirs = sorted(p for p in dataset_root.glob("*/*/*") if p.is_dir())
if len(sample_dirs) != 1200:
fail(f"expected 1200 sample directories, got {len(sample_dirs)}")
for sample_dir in sample_dirs[: args.sample_limit]:
inspect_sample(sample_dir)
checked = validate_inventory(dataset_root, inventory_path, args.full_hash)
if checked != 7200:
fail(f"expected 7200 inventory files, got {checked}")
if args.full_hash:
print(f"[OK] checksum manifest verified in size+sha256 mode: {checked} files")
else:
print(f"[OK] checksum manifest verified in size mode: {checked} files")
print(f"[OK] dataset validation completed: {len(sample_dirs)} samples, sampled {args.sample_limit}")
if __name__ == "__main__":
main()
|