Skip to content

Instantly share code, notes, and snippets.

@chr5tphr
Last active October 10, 2019 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chr5tphr/a52489c560bf8bd6c4d8f654401ce635 to your computer and use it in GitHub Desktop.
Save chr5tphr/a52489c560bf8bd6c4d8f654401ce635 to your computer and use it in GitHub Desktop.
hdf5 tree visualizer
import h5py
def h5tree(base, key='/', depth=1):
if isinstance(base, h5py.Group):
return key + '\n' + '\n'.join(' ' * depth + h5tree(obj, key, depth + 1) for key, obj in base.items())
else:
blist = str(base[()]).split('\n', maxsplit=1)
return '{}: {}'.format(key, blist.pop(0) + (' (...)' if blist else ''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment