#!/usr/bin/env python # coding: utf-8 # # Using H5Web in the notebook # ## Display a simple HDF5 file # In[ ]: import numpy as np import h5py with h5py.File("simple.h5", "w") as h5file: X = np.arange(-5, 5, 0.25) Y = np.arange(-5, 5, 0.25) Xg, Yg = np.meshgrid(X, Y) h5file['threeD'] = [np.sin(2*np.pi*f*np.sqrt(Xg**2 + Yg**2)) for f in np.arange(0.1, 1.1, 0.1)] h5file['twoD'] = np.sin(np.sqrt(Xg**2 + Yg**2)) h5file.create_dataset('oneD', data=X, dtype='>f4') h5file['scalar'] = 42 h5file['complex'] = X + 2j * Y # In[ ]: from jupyterlab_h5web import H5Web H5Web('simple.h5') # ## Display a NeXus file # In[ ]: import numpy as np import h5py with h5py.File("nexus.nx", "w") as h5file: root_group = h5file root_group.attrs["NX_class"] = "NXroot" root_group.attrs["default"] = "entry" entry = root_group.create_group("entry") entry.attrs["NX_class"] = "NXentry" entry.attrs["default"] = "process/spectrum" process = entry.create_group("process") process.attrs["NX_class"] = "NXprocess" process.attrs["default"] = "spectrum" spectrum = process.create_group("spectrum") spectrum.attrs["NX_class"] = "NXdata" spectrum.attrs["signal"] = "data" spectrum.attrs["auxiliary_signals"] = ["aux1", "aux2"] data = np.array([np.linspace(-x, x, 10) for x in range(1, 6)]) spectrum["data"] = data ** 2 spectrum["aux1"] = -(data ** 2) spectrum["aux2"] = -data spectrum["data"].attrs["interpretation"] = "spectrum" image = process.create_group("image") image.attrs["NX_class"] = "NXdata" image.attrs["signal"] = "data" x = np.linspace(-5, 5, 50) x0 = np.linspace(10, 100, 10) image["data"] = [a*x**2 for a in x0] image["X"] = np.linspace(-2, 2, 50, endpoint=False) image["X"].attrs["units"] = u"µm" image["Y"] = np.linspace(0, 0.1, 10, endpoint=False) image["Y"].attrs["units"] = "s" image.attrs["axes"] = ["X"] image.attrs["axes"] = ["Y", "X"] # In[ ]: from jupyterlab_h5web import H5Web H5Web('nexus.nx') # In[ ]: