. currentmodule:: silx.io

commonh5: Helpers for writing h5py-like API

This module contains generic objects, emulating h5py groups, datasets and files. They are used in spech5 and fabioh5.

Classes

class Node(name, parent=None, attrs=None)[source]

This is the base class for all spech5 and fabioh5 classes. It represents a tree node, and knows its parent node (parent). The API mimics a h5py node, with following attributes: file, attrs, name, and basename.

h5_class

Returns the HDF5 class which is mimicked by this class.

Return type:H5Type
h5py_class

Returns the h5py classes which is mimicked by this class. It can be one of h5py.File, h5py.Group or h5py.Dataset

This should not be used anymore. Prefer using h5_class

Return type:Class
parent

Returns the parent of the node.

Return type:Node
file

Returns the file node of this node.

Return type:Node
attrs

Returns HDF5 attributes of this node.

Return type:dict
name

Returns the HDF5 name of this node.

basename

Returns the HDF5 basename of this node.

class File(name=None, mode=None, attrs=None)[source]

Bases: silx.io.commonh5.Group

This class is the special Group that is the root node of the tree structure. It mimics h5py.File.

h5_class

Returns the h5py.File class

close()[source]

Close the object, and free up associated resources.

class Group(name, parent=None, attrs=None)[source]

Bases: silx.io.commonh5.Node

This class mimics a h5py.Group.

get(name, default=None, getclass=False, getlink=False)[source]

Retrieve an item or other information.

If getlink only is true, the returned value is always h5py.HardLink, because this implementation do not use links. Like the original implementation.

Parameters:
  • name (str) – name of the item
  • default (object) – default value returned if the name is not found
  • getclass (bool) – if true, the returned object is the class of the object found
  • getlink (bool) – if true, links object are returned instead of the target
Returns:

An object, else None

Return type:

object

__getitem__(name)[source]

Return a child from his name.

Parameters:name (str) – name of a member or a path throug members using ‘/’ separator. A ‘/’ as a prefix access to the root item of the tree.
Return type:Node
__contains__(name)[source]

Returns true if name is an existing child of this group.

Return type:bool
__len__()[source]

Returns the number of children contained in this group.

Return type:int
__iter__()[source]

Iterate over member names

keys()[source]

Returns an iterator over the children’s names in a group.

values()[source]

Returns an iterator over the children nodes (groups and datasets) in a group.

New in version 0.6.

items()[source]

Returns items iterator containing name-node mapping.

Return type:iterator
visit(func, visit_links=False)[source]

Recursively visit all names in this group and subgroups. See the documentation for h5py.Group.visit for more help.

Parameters:func (callable) – Callable (function, method or callable object)
visititems(func, visit_links=False)[source]

Recursively visit names and objects in this group. See the documentation for h5py.Group.visititems for more help.

Parameters:
  • func (callable) – Callable (function, method or callable object)
  • visit_links (bool) – If False, ignore links. If True, call func(name) for links and recurse into target groups.
attrs

Returns HDF5 attributes of this node.

Return type:dict
basename

Returns the HDF5 basename of this node.

file

Returns the file node of this node.

Return type:Node
h5py_class

Returns the h5py classes which is mimicked by this class. It can be one of h5py.File, h5py.Group or h5py.Dataset

This should not be used anymore. Prefer using h5_class

Return type:Class
name

Returns the HDF5 name of this node.

parent

Returns the parent of the node.

Return type:Node
class Dataset(name, data, parent=None, attrs=None)[source]

Bases: silx.io.commonh5.Node

This class handles a numpy data object, as a mimicry of a h5py.Dataset.

h5_class

Returns the HDF5 class which is mimicked by this class.

Return type:H5Type
dtype

Returns the numpy datatype exposed by this dataset.

Return type:numpy.dtype
shape

Returns the shape of the data exposed by this dataset.

Return type:tuple
size

Returns the size of the data exposed by this dataset.

Return type:int
value

Returns the data exposed by this dataset.

Deprecated by h5py. It is prefered to use indexing [()].

Return type:numpy.ndarray
compression

Returns compression as provided by h5py.Dataset.

There is no compression.

compression_opts

Returns compression options as provided by h5py.Dataset.

There is no compression.

chunks

Returns chunks as provided by h5py.Dataset.

There is no chunks.

is_virtual

Checks virtual data as provided by h5py.Dataset

virtual_sources()[source]

Returns virtual dataset sources as provided by h5py.Dataset.

Return type:list
external

Returns external sources as provided by h5py.Dataset.

Return type:list or None