File size: 3,639 Bytes
a207665
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Validate ShapeNetCar mlcfd_data structure and readable arrays."""

from __future__ import annotations

import argparse
import sys
from pathlib import Path

import numpy as np


STATS = {
    "mean_in.npy": (7,),
    "std_in.npy": (7,),
    "mean_out.npy": (4,),
    "std_out.npy": (4,),
}
TRAINING_FILES = ("Cd.npy", "I1.npy", "I2.npy", "Press.npy", "Velo.npy")
PREPROCESSED_FILES = ("x.npy", "y.npy", "pos.npy", "surf.npy", "edge_index.npy")


def fail(message: str) -> None:
    print(f"[FAIL] {message}", file=sys.stderr)
    raise SystemExit(1)


def load(path: Path) -> np.ndarray:
    try:
        return np.load(path, allow_pickle=False)
    except Exception as exc:  # pragma: no cover - diagnostic path
        fail(f"cannot read {path}: {exc}")


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--data-root", default="data/mlcfd_data")
    args = parser.parse_args()
    root = Path(args.data_root)

    if not root.is_dir():
        fail(f"data root not found: {root}")

    for subdir in ("training_data", "preprocessed_data", "stats"):
        if not (root / subdir).is_dir():
            fail(f"missing directory: {root / subdir}")

    for filename, shape in STATS.items():
        arr = load(root / "stats" / filename)
        if arr.shape != shape:
            fail(f"stats shape mismatch for {filename}: expected {shape}, got {arr.shape}")
        if not np.issubdtype(arr.dtype, np.floating):
            fail(f"stats dtype mismatch for {filename}: got {arr.dtype}")

    train_param_dirs = sorted(p for p in (root / "training_data").glob("param*") if p.is_dir())
    if not train_param_dirs:
        fail("no training_data/param* directories found")
    for param_dir in train_param_dirs:
        for filename in TRAINING_FILES:
            path = param_dir / filename
            if not path.is_file():
                fail(f"missing training file: {path}")
            arr = load(path)
            if arr.size == 0:
                fail(f"empty training array: {path}")

    sample_dirs = sorted(p for p in (root / "preprocessed_data").glob("param*/*") if p.is_dir())
    if not sample_dirs:
        fail("no preprocessed sample directories found")
    sample = sample_dirs[0]
    arrays = {name: load(sample / name) for name in PREPROCESSED_FILES}
    if arrays["x.npy"].ndim != 2 or arrays["x.npy"].shape[1] != 7:
        fail(f"x.npy schema mismatch in {sample}: {arrays['x.npy'].shape}")
    if arrays["y.npy"].ndim != 2 or arrays["y.npy"].shape[1] != 4:
        fail(f"y.npy schema mismatch in {sample}: {arrays['y.npy'].shape}")
    if arrays["pos.npy"].ndim != 2 or arrays["pos.npy"].shape[1] != 3:
        fail(f"pos.npy schema mismatch in {sample}: {arrays['pos.npy'].shape}")
    if arrays["surf.npy"].ndim != 1:
        fail(f"surf.npy schema mismatch in {sample}: {arrays['surf.npy'].shape}")
    if arrays["edge_index.npy"].ndim != 2 or arrays["edge_index.npy"].shape[0] != 2:
        fail(f"edge_index.npy schema mismatch in {sample}: {arrays['edge_index.npy'].shape}")

    node_count = arrays["x.npy"].shape[0]
    if arrays["y.npy"].shape[0] != node_count or arrays["pos.npy"].shape[0] != node_count:
        fail(f"node count mismatch in {sample}")
    if arrays["surf.npy"].shape[0] != node_count:
        fail(f"surface mask length mismatch in {sample}")

    print("[OK] ShapeNetCar data validation passed")
    print(f"[OK] training param dirs: {len(train_param_dirs)}")
    print(f"[OK] preprocessed samples: {len(sample_dirs)}")
    print(f"[OK] checked sample: {sample.relative_to(root)}")


if __name__ == "__main__":
    main()