Skip to content

Instantly share code, notes, and snippets.

@Abir-Tx
Created April 7, 2023 07:41
Show Gist options
  • Save Abir-Tx/72c4ec9b42c341c74d9b9a475d1971dc to your computer and use it in GitHub Desktop.
Save Abir-Tx/72c4ec9b42c341c74d9b9a475d1971dc to your computer and use it in GitHub Desktop.
The script will take a `.h5` file as input and print the full file. It will show the data from all the dataset withing the `.h5` file you specify it to open
#!/bin/env python3
# Script By Mushfiqur Rahman Abir
import h5py
import sys
def print_h5_data(file):
"""Recursively print all groups and datasets in an HDF5 file"""
for name in file:
obj = file[name]
if isinstance(obj, h5py.Group):
print("Group: ", name)
print_h5_data(obj)
elif isinstance(obj, h5py.Dataset):
print("Dataset: ", name)
print("Shape: ", obj.shape)
print("Data: ", obj[()])
# take the file name from the command line argument
filename = sys.argv[1]
# Open the HDF5 file
with h5py.File(filename, 'r') as f:
# Print all the data in the file
print_h5_data(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment