Created
May 9, 2017 23:28
-
-
Save cpascual/342ca09e86d081ddaae1011cc96bbaf3 to your computer and use it in GitHub Desktop.
my_nxshow.py
This file contains 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
"""A nexus file summary tool implemented with h5py""" | |
import h5py | |
import sys | |
def print_dset(dset): | |
print '\t', dset | |
for k, v in sorted(dset.attrs.iteritems()): | |
print "\t\t@%s=%s" % (k,v) | |
def print_grp(grp): | |
print "\n%s (%s)" % (grp.name, grp.attrs.get('NX_class', '')) | |
for k, v in sorted(grp.attrs.iteritems()): | |
print "\t@%s=%s" % (k, v) | |
datasets = [] | |
groups = [] | |
for k, v in grp.iteritems(): | |
if isinstance(v, h5py.Group): | |
groups.append((k, v)) | |
elif isinstance(v, h5py.Dataset): | |
datasets.append((k, v)) | |
for k, v in sorted(datasets): | |
print_dset(v) | |
for k, v in sorted(groups): | |
print_grp(v) | |
fname = '/tmp/kk1.hdf5' | |
if len(sys.argv) >= 2: | |
fname = sys.argv[1] | |
f = h5py.File(fname, mode='r') | |
print_grp(f['/']) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment