Created
April 7, 2023 07:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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