Thomas Kluyver, European XFEL
This project has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreement No. 823852.
I'll be introducing h5py properly in tomorrow's session.
import h5py
f = h5py.File('sample.h5', 'r')
f.keys()
<KeysViewHDF5 ['group', 'links']>
f['group']
<HDF5 group "/group" (4 members)>
f['group'].keys()
<KeysViewHDF5 ['complex', 'custom_float', 'integers', 'strings']>
This works, but it's not very convenient to inspect a file.
There are applications like HDFview, Vitables & h5web, but that means leaving your notebook context and opening the same file in a separate application. H5Glance is designed to fit into the notebook (or terminal) context.
from h5glance import H5Glance
H5Glance(f)
The whole structure is created up-front - this may be slower, but it just works in a static HTML export of the notebook, including on Nbviewer.
H5Glance doesn't show your data - it's easy & flexible to inspect data with other libraries, so we're not trying to cover that. But the clipboard icons by dataset names let you copy the path to the dataset, so you can paste it into code.
import matplotlib.pyplot as plt
plt.imshow(f['/group/integers'][0])
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7fcea6b5cd00>
This is the structure of our HDF5 files at European XFEL. We're often working through many layers of nested groups.
H5Glance('fxe_control_example.h5')
You can set h5glance to be used to display h5py Group and File objects.
import h5glance
h5glance.install_ipython_h5py_display()
f['group']
This was demoed separately. Features include:
--attrs
!h5glance sample.h5
sample.h5 ├group (2 attributes) │ ├complex [(r: float64, i: float64): 1024 × 1024] │ ├custom_float [custom 2-byte float: 4 × 7] │ ├integers [int64: 10 × 6 × 5] │ └strings [UTF-8 string: 4] └links ├external -> fxe_control_example.h5//INDEX/trainId ├hard = /group/integers └soft -> /group/integers