Debian Codegraph @

doc/demo/dump_dxfile.py

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 .. module:: dump_dxfile.py
6 :platform: Unix
7 :synopsis: Print an hdf5 file Group/Data dataset list.
8
9 """
10
11 from __future__ import print_function
12
13 import h5py
14 import dxchange.reader as dxreader
15
16
17 def print_hdf5_file_structure(file_name) :
18 """Prints the HDF5 file structure"""
19 filee = h5py.File(file_name, 'r') # open read-only
20 item = filee #["/Configure:0000/Run:0000"]
21 print_hdf5_item_structure(item)
22 filee.close()
23
24 def print_hdf5_item_structure(g, offset=' ') :
25 """Prints the input file/group/dataset (g) name and begin iterations on its content"""
26 if isinstance(g, h5py.File) :
27 print (g.file, 'File:', g.name)
28
29 elif isinstance(g, h5py.Dataset) :
30 #print ('Dataset: ', g.name) #, g.dtype
31 if g.name == '/exchange/theta':
32 print('theta array')
33 elif g.name == '/exchange/data':
34 print('data array')
35 elif g.name == '/exchange/data_white':
36 print('data white')
37 elif g.name == '/exchange/data_dark' :
38 print('data dark')
39 else:
40 print (g.name, '=', dxreader.read_hdf5(fname, g.name))
41
42 elif isinstance(g, h5py.Group) :
43 print ('Group:', g.name)
44
45 else :
46 print ('WORNING: UNKNOWN ITEM IN HDF5 FILE', g.name)
47 sys.exit ( "EXECUTION IS TERMINATED" )
48
49 if isinstance(g, h5py.File) or isinstance(g, h5py.Group) :
50 for key,val in dict(g).iteritems() :
51 subg = val
52 #print (offset, key )#," ", subg.name #, val, subg.len(), type(subg),
53 print_hdf5_item_structure(subg, offset + ' ')
54
55 if __name__ == "__main__" :
56
57 # Set path to the micro-CT data.
58 fname = '/tomobank/tomo_00001/tomo_00001.h5'
59 print_hdf5_file_structure(fname)
60