Download examples/load_one_case.py from DingDong1921/openlb-multigeometry-flow: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/datasets/DingDong1921/openlb-multigeometry-flow/resolve/main/examples/load_one_case.py
- Command line
-
hf download hf://datasets/DingDong1921/openlb-multigeometry-flow/examples/load_one_case.py
-
curl -L -o load_one_case.py https://huggingface.co/datasets/DingDong1921/openlb-multigeometry-flow/resolve/main/examples/load_one_case.py
1.47 kB
| #!/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()) | |