hdfviewer.widgets package

Submodules

hdfviewer.widgets.HDFViewer module

class hdfviewer.widgets.HDFViewer.HDFViewer(hdf, startPath=None)

Bases: ipywidgets.widgets.widget_selectioncontainer.Accordion

This class allows to inspect HDF data in the context of Jupyter Lab

It represents each group found in the HDF file as an accordion made of the following subitems:

  • attributes: contains the HDF attributes of this group
  • groups: contains the HDF subgroups of this group
  • datasets: contains the HDF datasets of this group

If one of these subitems is empty (e.g. no attributes defined for a given group) the corresponding subitem is omitted. When one reaches a HDF dataset, informations about the dataset are collected (dimensionality, numeric type, attributes …) and displayed in a Jupyter output widget. In case of 1D, 2D or 3D dataset, a view of the dataset is also displayed. Depending on the dimensionality of the dataset the display will consist in:

  • 1D: simple MatPlotLib 1D plot
  • 2D: matrix view of the dataset
  • 3D: matrix view of the dataset

In case of 2D and 3D datasets, the matrix view is made of a 2D image of the selected frame of the dataset (always 0 for 2D datasets) with a 1D column-projection view of the dataset on its top and a 1D row-projection view of the dataset on its right. The matrix view is interactive with the following interactions:

  • 2D:
    • toggle between cross and integration 1D potting mode. In cross plot mode, the 1D projection views represents resp. the row and column of the matrix image point left-clicked by the user. In integration plot mode, the 1D projection views represents the sum over resp. the row and column of the image. To switch between those two modes, press the i key.
  • 3D:
    • toggle between cross and integration 1D potting mode. See above.
    • go to the last frame by pressing the pgdn key.
    • go to the first frame by pressing the pgup key.
    • go to the next frame by pressing the down or the right keys or wheeling down the mouse wheel
    • go to the previous frame by pressing the up or the left keys or wheeling up the mouse down
    • go the +n (n can be > 9) frame by pressing n number followed by the down or the right keys
    • go the -n (n can be > 9) frame by pressing n number followed by the up or the left keys
Usage in a Jupyter Lab notebook
%matplotlib ipympl

import h5py
from hdfviewer.widgets.HDFViewer import HDFViewer
from hdfviewer.widgets.PathSelector import PathSelector

path = PathSelector(extensions=[".hdf",".h5",".nxs"])
path.widget

if path.file:
    hdf5 = h5py.File(path.file,"r")
    display(HDFViewer(hdf5))
Parameters:
  • hdf (str or bytes or File) –

    the hdf Data to be inspected.

    • for str input type, this will be the path to the HDF datafile
    • for File, this will be the output of a prior HDF file opening in read mode
    • for bytes, this will the byte representation of athe HDF data
  • startPath (str or None) –

    the hdf path from where the HDF data will be inspected.

    If not set, the starting path will be the root of the HDF data

Raises:

HDFViewerError: if the HDF data could not be set properly

_onSelectDataset(change)

A callable that is called when a new dataset is selected

See here for more information

_trait_default_generators = {}
exception hdfviewer.widgets.HDFViewer.HDFViewerError

Bases: Exception

HDFViewer specific exception

hdfviewer.widgets.MplOutput module

class hdfviewer.widgets.MplOutput.MplOutput(figure=None, **kwargs)

Bases: ipywidgets.widgets.widget_output.Output

_trait_default_generators = {}
clear_output(**kwargs)

Clear the content of the output widget.

wait: bool
If True, wait to clear the output until new output is available to replace it. Default: False
figure

hdfviewer.widgets.PathSelector module

Adpated from the following code base

class hdfviewer.widgets.PathSelector.PathSelector(startDir=None, selectFile=True, extensions=None)

Bases: object

This class allows to create a file browser in the context of Jupyter Lab

Parameters:
  • start_dir (str or None) – the starting directory for the file browser. If not set, the current working directory will be used.
  • selectFile (bool) – if True the browser is used to select files otherwise it is used as to browse directories.
  • extensions (list[int]) – if set, only those files matching the defined extensions will be displayed otherwise all files are displayed.
_onUpdate(change)

A callable that is called when a new entry of the file browser is clicked

See here for more information

update(item)

Update the file browser widget with a new entry (file or directory name)

This will:

  1. update the name of the current selection on top of the file browser widget
  2. update the directory contents subwidget in case where the new entry is a directory
Parameters:entry (str) – the filename or directory name to update the file browser with
widget

Return the file browser widget

Returns:the file browser widget
Return type:ipywidgets.Accordion

Module contents