File size: 1,470 Bytes
4977b39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Load and summarize one released OpenLB multigeometry trajectory."""

from __future__ import annotations

import argparse
import json
from pathlib import Path

import h5py
import numpy as np


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("trajectory", type=Path)
    parser.add_argument("--frame", type=int, default=0)
    args = parser.parse_args()

    with h5py.File(args.trajectory, "r") as handle:
        uvp = handle["uvp"]
        if not 0 <= args.frame < uvp.shape[0]:
            raise IndexError(f"frame {args.frame} is outside [0, {uvp.shape[0]})")
        frame = np.asarray(uvp[args.frame], dtype=np.float32)
        report = {
            "file": str(args.trajectory),
            "case_id": str(handle.attrs["case_id"]),
            "family": str(handle.attrs["geometry_family"]),
            "split": str(handle.attrs["split"]),
            "uvp_shape": list(uvp.shape),
            "points_shape": list(handle["points"].shape),
            "cells_shape": list(handle["cells"].shape),
            "time_shape": list(handle["time"].shape),
            "frame": args.frame,
            "frame_finite": bool(np.isfinite(frame).all()),
            "frame_channel_min": frame.min(axis=0).tolist(),
            "frame_channel_max": frame.max(axis=0).tolist(),
        }
    print(json.dumps(report, indent=2, sort_keys=True))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())