-
Notifications
You must be signed in to change notification settings - Fork 0
/
listH5.py
executable file
·65 lines (56 loc) · 2.12 KB
/
listH5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/home/dev/pyenvs/ocl/bin/python
import h5py
import matplotlib.pyplot as plt
import argparse
def visitFunction(name, obj, plotp, match):
print(name)
for key, val in obj.attrs.items():
print(' ' + str(key) + ': ' + str(val))
matching = True
if(isinstance(match, str) and
name.find(match) == -1):
matching = False
if(type(obj) == h5py._hl.dataset.Dataset and
matching and
plotp):
print(obj)
if(len(obj[:].shape) == 2):
plt.matshow(obj[:])
plt.colorbar()
plt.show()
if(len(obj[:].shape) == 1):
dim = obj.len()
if(obj.attrs.get('pvname') and
obj.attrs['pvname'].find('CCS1') == 0):
dim = 3600
plt.plot(obj[0:dim])
plt.show()
def top_level(fname, plotp, matching):
with h5py.File('/tmp/image0.h5', 'r') as f:
root = f.get('/')
print('/')
for key, val in root.attrs.items():
print(' ' + str(key) + ': ' + str(val))
f.visititems(lambda obj, name: visitFunction(obj, name, True, None))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='List contents of HDF5 file. ')
parser.add_argument('filename')
parser.add_argument('-p', '--plot', action='store_true', default=False, help="Plot data")
parser.add_argument('-m', '--match', default=None,
help="Print things where the full pathname contains MATCH")
args = parser.parse_args()
if(args.match):
args.plot = True
with h5py.File(args.filename, 'r') as f:
root = f.get('/')
print('/')
for key, val in root.attrs.items():
print(' ' + str(key) + ': ' + str(val))
f.visititems(lambda obj, name: visitFunction(obj, name, args.plot, args.match))
# filename = '/tmp/0000000000000014-Chromox.h5'
# with h5py.File(filename, 'r') as f:
# root = f.get('/')
# print('/')
# for key, val in root.attrs.items():
# print(' ' + str(key) + ': ' + str(val))
# f.visititems(lambda obj, name: visitFunction(obj, name, True, False))