Download scripts/validate_eagle_dataset.py from OneScience-Group/eagle: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/datasets/OneScience-Group/eagle/resolve/main/scripts/validate_eagle_dataset.py
- Command line
-
hf download hf://datasets/OneScience-Group/eagle/scripts/validate_eagle_dataset.py
-
curl -L -o validate_eagle_dataset.py https://huggingface.co/datasets/OneScience-Group/eagle/resolve/main/scripts/validate_eagle_dataset.py
4.9 kB
| #!/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() | |