UrbanFlow-oneObstacle-NoTrip / load_example.py
abvish's picture
Add minimal data loading example
d3340e9 verified
Raw
History Blame Contribute Delete
1.21 kB
#!/usr/bin/env python3
"""Minimal example: inspect and load slices from the UrbanFlow-oneObstacle-NoTrip HDF5 files.
Usage:
python load_example.py path/to/file.h5
"""
import sys
import h5py
def inspect(path):
with h5py.File(path, "r") as f:
print(f"File: {path}\n")
def walk(group, prefix=""):
for key in group.keys():
item = group[key]
if isinstance(item, h5py.Dataset):
print(f"{prefix}{key}: shape={item.shape} dtype={item.dtype}")
else:
print(f"{prefix}{key}/")
walk(item, prefix + " ")
walk(f)
if f.attrs:
print("\nattrs:", dict(f.attrs))
# Datasets are large (the 3D Train file is ~2.1 TB) -- always slice,
# never f["U"][:], which would try to load the whole array into RAM.
if "U" in f:
print("\nFirst snapshot of U, shape:", f["U"][0].shape)
print("Sample values U[0, 0, :5, :5]:\n", f["U"][0, 0, :5, :5] if f["U"].ndim == 4 else f["U"][0, :5, :5])
if __name__ == "__main__":
if len(sys.argv) != 2:
print(__doc__)
sys.exit(1)
inspect(sys.argv[1])