Skip to content

Instantly share code, notes, and snippets.

@jreadey
Created March 6, 2024 17:14
Show Gist options
  • Save jreadey/a8480213da527aafb0b383a6c01df9d2 to your computer and use it in GitHub Desktop.
Save jreadey/a8480213da527aafb0b383a6c01df9d2 to your computer and use it in GitHub Desktop.
nrel hsload smoke test
import sys
import h5pyd as h5py
h5path = "windspeed_10m"
tgt_row = 1234567
if len(sys.argv) == 1 or sys.argv[1] in ("-h", "--help"):
print(f"usage: {sys.argv[0]} <domain>")
sys.exit(1)
domain_path = sys.argv[1]
f = h5py.File(domain_path)
if h5path not in f:
print(f"{h5path} not found in {domain_path}")
sys.exit(1)
dset = f[h5path]
print(f"{h5path}: {dset}")
print(f"dset chunks: {dset.chunks}")
if len(dset.shape) != 2:
print(f"expected dataset to be rank 2 but got shape: {dset.shape}")
sys.exit(1)
if dset.shape[1] < tgt_row:
print(f"expected dim 2 extent to be greater than: {tgt_row}, but got: {dset.shape[1]}")
sys.exit(1)
dcpl_json = dset.id.dcpl_json
if "layout" not in dcpl_json:
print("expected layout key in dcpl_json")
sys.exit(1)
layout_json = dcpl_json["layout"]
layout_class = layout_json.get("class")
if layout_class != "H5D_CHUNKED_REF_INDIRECT":
print(f"expected layout class to be: H5D_CHUNKED_REF_INDIRECT, but got: {layout_class}")
sys.exit(1)
s3_uri = layout_json["file_uri"]
print(f"s3_uri: {s3_uri}")
chunk_shape = layout_json["dims"]
print(f"chunk_shape: {chunk_shape}")
chunk_table_id = layout_json["chunk_table"]
chunk_table = f["datasets/"+chunk_table_id]
print(f"chunk_table shape: {chunk_table.shape}")
chunk_table_row = tgt_row // chunk_shape[1]
chunk_table_data = chunk_table[:, chunk_table_row]
print(f"chunk_table data for row {chunk_table_row}:")
for item in chunk_table_data:
print(item)
print(f"fetching dataset data for {tgt_row}...")
arr = dset[:, tgt_row]
print(f"min: {arr.min()} max: {arr.max()}, mean: {arr.mean()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment