apptools.io.h5.file module

class apptools.io.h5.file.H5Attrs(node_attrs)[source]

Bases: MutableMapping

An attributes dictionary for an h5 node.

This intercepts __setitem__ so that python sequences can be converted to numpy arrays. This helps preserve the readability of our HDF5 files by other (non-python) programs.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.[source]
items() a set-like object providing a view on D's items[source]
keys() a set-like object providing a view on D's keys[source]
values() an object providing a view on D's values[source]
class apptools.io.h5.file.H5File(filename, mode='r+', delete_existing=False, auto_groups=True, auto_open=True, h5filters=None)[source]

Bases: Mapping

File object for HDF5 files.

This class wraps PyTables to provide a cleaner, but only implements an interface for accessing arrays.

Parameters
  • filename (str or a tables.File instance) – Filename for an HDF5 file, or a PyTables File object.

  • mode (str) –

    Mode to open the file:

    ’r’ : Read-only ‘w’ : Write; create new file (an existing file would be deleted). ‘a’ : Read and write to file; create if not existing ‘r+’: Read and write to file; must already exist

  • delete_existing (bool) – If True, an existing node will be deleted when a create_* method is called. Otherwise, a ValueError will be raise.

  • auto_groups (bool) – If True, create_array will automatically create parent groups.

  • auto_open (bool) – If True, open the file automatically on initialization. Otherwise, you can call H5File.open() explicitly after initialization.

  • chunked (bool) – If True, the default behavior of create_array will be a chunked array (see PyTables create_carray).

close()[source]
create_array(node_path, array_or_shape, dtype=None, chunked=False, extendable=False, **kwargs)[source]

Create node to store an array.

Parameters
  • node_path (str) – PyTable node path; e.g. ‘/path/to/node’.

  • array_or_shape (array or shape tuple) – Array or shape tuple for an array. If given a shape tuple, the dtype parameter must also specified.

  • dtype (str or numpy.dtype) – Data type of array. Only necessary if array_or_shape is a shape.

  • chunked (bool) – Controls whether the array is chunked.

  • extendable ({None | bool}) – Controls whether the array is extendable.

  • kwargs (key/value pairs) – Keyword args passed to PyTables File.create_(c|e)array.

create_dict(node_path, data=None, **kwargs)[source]

Create dict node at the specified path.

Parameters
  • node_path (str) – Path to node where data is stored (e.g. ‘/path/to/my_dict’)

  • data (dict) – Data for initialization, if desired.

create_group(group_path, **kwargs)[source]

Create group.

Parameters
  • group_path (str) – PyTable group path; e.g. ‘/path/to/group’.

  • kwargs (key/value pairs) – Keyword args passed to PyTables File.create_group.

create_table(node_path, description, **kwargs)[source]

Create table node at the specified path.

Parameters
  • node_path (str) – Path to node where data is stored (e.g. ‘/path/to/my_dict’)

  • description (dict or numpy dtype object) – The description of the columns in the table. This is either a dict of column name -> dtype items or a numpy record array dtype. For more information, see the documentation for Table in pytables.

exists_error = "'{}' exists in '{}'; set `delete_existing` attribute to True to overwrite existing calculations."
property is_open
iteritems(path='/')[source]

Iterate over node paths and nodes of the h5 file.

classmethod join_path(*args)[source]

Join parts of an h5 path.

For example, the 3 argmuments ‘path’, ‘to’, ‘node’ will return ‘/path/to/node’.

Parameters

args (str) – Parts of path to be joined.

open()[source]
remove_group(group_path, **kwargs)[source]

Remove group

Parameters

group_path (str) – PyTable group path; e.g. ‘/path/to/group’.

remove_node(node_path)[source]

Remove node

Parameters

node_path (str) – PyTable node path; e.g. ‘/path/to/node’.

property root
classmethod split_path(node_path)[source]

Split node path returning the base path and node name.

For example: ‘/path/to/node’ will return ‘/path/to’ and ‘node’

Parameters

node_path (str) – PyTable node path; e.g. ‘/path/to/node’.

class apptools.io.h5.file.H5Group(pytables_group)[source]

Bases: Mapping

A group node in an H5File.

This is a thin wrapper around PyTables’ Group object to expose attributes and maintain the dict interface of H5File.

property children_names
create_array(node_subpath, array_or_shape, dtype=None, chunked=False, extendable=False, **kwargs)[source]

** H5Group wrapper for H5File.create_array: ** Note that the first argument is a nodepath relative to the group, rather than an absolute path. Below is the original docstring:

Create node to store an array.

Parameters
  • node_path (str) – PyTable node path; e.g. ‘/path/to/node’.

  • array_or_shape (array or shape tuple) – Array or shape tuple for an array. If given a shape tuple, the dtype parameter must also specified.

  • dtype (str or numpy.dtype) – Data type of array. Only necessary if array_or_shape is a shape.

  • chunked (bool) – Controls whether the array is chunked.

  • extendable ({None | bool}) – Controls whether the array is extendable.

  • kwargs (key/value pairs) – Keyword args passed to PyTables File.create_(c|e)array.

create_dict(node_subpath, data=None, **kwargs)[source]

** H5Group wrapper for H5File.create_dict: ** Note that the first argument is a nodepath relative to the group, rather than an absolute path. Below is the original docstring:

Create dict node at the specified path.

Parameters
  • node_path (str) – Path to node where data is stored (e.g. ‘/path/to/my_dict’)

  • data (dict) – Data for initialization, if desired.

create_group(group_subpath, delete_existing=False, **kwargs)[source]

** H5Group wrapper for H5File.create_group: ** Note that the first argument is a nodepath relative to the group, rather than an absolute path. Below is the original docstring:

Create group.

Parameters
  • group_path (str) – PyTable group path; e.g. ‘/path/to/group’.

  • kwargs (key/value pairs) – Keyword args passed to PyTables File.create_group.

create_table(node_subpath, description, *args, **kwargs)[source]

** H5Group wrapper for H5File.create_table: ** Note that the first argument is a nodepath relative to the group, rather than an absolute path. Below is the original docstring:

Create table node at the specified path.

Parameters
  • node_path (str) – Path to node where data is stored (e.g. ‘/path/to/my_dict’)

  • description (dict or numpy dtype object) – The description of the columns in the table. This is either a dict of column name -> dtype items or a numpy record array dtype. For more information, see the documentation for Table in pytables.

property filename
iter_groups()[source]

Iterate over H5Group nodes that are children of this group.

property name
property pathname
remove_group(group_subpath, **kwargs)[source]

** H5Group wrapper for H5File.remove_group: ** Note that the first argument is a nodepath relative to the group, rather than an absolute path. Below is the original docstring:

Remove group

Parameters

group_path (str) – PyTable group path; e.g. ‘/path/to/group’.

remove_node(node_subpath, **kwargs)[source]

** H5Group wrapper for H5File.remove_node: ** Note that the first argument is a nodepath relative to the group, rather than an absolute path. Below is the original docstring:

Remove node

Parameters

node_path (str) – PyTable node path; e.g. ‘/path/to/node’.

property root
property subgroup_names
apptools.io.h5.file.get_atom(dtype)[source]

Return a PyTables Atom for the given dtype or dtype string.

apptools.io.h5.file.h5_group_wrapper(original)[source]
apptools.io.h5.file.iterator_length(iterator)[source]