HDF5 IO

The CUDS to HDF5 file adapters.

Classes

H5CUDS(handle) Access to CUDS-hdf5 formatted files.
DataContainerTable(root[, name, record]) A proxy class to an HDF5 group node with serialised DataContainers.
IndexedDataContainerTable(root[, name, ...]) A proxy class to an HDF5 group node with serialised DataContainers.
H5Particles(group) An HDF5 backed particle container.
H5Lattice(group) H5Lattice object to use H5CUDS lattices.
H5Mesh(group, meshFile) H5Mesh.
H5CUDSItems(root, record[, name]) A proxy class to an HDF5 group node with serialised CUDS items.

Table descriptions

simphony.io.data_container_description.create_data_table(class_name, supported_cuba=<enum 'CUBA'>)[source]

Create tables.IsDescription class dynamically given a set of supported CUBA IntEnum

Parameters:
  • class_name (str) – Name of the created class
  • supported_cuba (iterable) – Supported CUBA IntEnum
Returns:

type

Return type:

tables.IsDescription

Data
Record
NoUIDRecord

Implementation

class simphony.io.h5_cuds.H5CUDS(handle)[source]

Bases: object

Access to CUDS-hdf5 formatted files.

add_dataset(container, cuba_keys=None)[source]

Add a CUDS container

Parameters:
  • container ({ABCMesh, ABCParticles, ABCLattice}) – The CUDS container to be added.
  • cuba_keys (dict of CUBAs (optional)) – Dictionary of CUBAs with lists of CUBA keys that are added to the H5CUDS container. All keys in the container are stored by default
Raises:
  • TypeError: – If the container type is not supported by the file.
  • ValueError: – If there is already a dataset with the given name.
close()[source]

Closes a file

get_dataset(name)[source]

Get the dataset

Parameters:name (str) – name of CUDS container to be retrieved.
Returns:A proxy of the dataset named name that is stored internally in the File.
Return type:container
Raises:ValueError: – If there is no dataset with the given name
get_dataset_names()[source]

Returns a list of the datasets’ names contained in the file.

iter_datasets(names=None)[source]

Returns an iterator over a subset or all of the containers.

Parameters:names (sequence of str, optional) – names of specific containers to be iterated over. If names is not given, then all containers will be iterated over.
classmethod open(filename, mode='a', title='', filters=None)[source]

Returns an opened SimPhoNy CUDS-hdf5 file

Parameters:
  • filename (str) – Name of file to be opened.
  • mode (str) –

    The mode to open the file:

    • w – Write; a new file is created (an existing file with the same name would be deleted).
    • a – Append; an existing file is opened for reading and writing, and if the file does not exist it is created.
    • r – ReadOnly; This is a very restrictive mode that will through errors at any attempt to modify the data.
  • title (str) – Title attribute of root node (only applies to a file which is being created)
  • filters (tables.Filter) – Filter options used in the HDF5 file. If none is selected default parameters are: complevel=1, complib=”zlib” and fletcher32=True. This only applies to newly created files.
Raises:

ValueError : – If the file has an incompatible version

remove_dataset(name)[source]

Remove a dataset from the file

Parameters:name (str) – name of CUDS container to be deleted
Raises:ValueError: – If there is no dataset with the given name
valid()[source]

Checks if file is valid (i.e. open)

class simphony.io.h5_particles.H5BondItems(root, name='bonds')[source]

Bases: simphony.io.h5_cuds_items.H5CUDSItems

A proxy class to an HDF5 group node with serialised Bonds

The class implements the Mutable-Mapping api where each Bond instance is mapped to uid.

class simphony.io.h5_particles.H5ParticleItems(root, name='particles')[source]

Bases: simphony.io.h5_cuds_items.H5CUDSItems

A proxy class to an HDF5 group node with serialised Particles

The class implements the Mutable-Mapping api where each Particle instance is mapped to uid.

class simphony.io.h5_particles.H5Particles(group)[source]

Bases: simphony.cuds.abc_particles.ABCParticles

An HDF5 backed particle container.

count_of(item_type)[source]

Return the count of item_type in the container.

Parameters:item_type (CUBA) – The CUBA enum of the type of the items to return the count of.
Returns:count – The number of items of item_type in the container.
Return type:int
Raises:ValueError : – If the type of the item is not supported in the current container.
data
name

The name of the container

class simphony.io.h5_lattice.H5Lattice(group)[source]

Bases: simphony.cuds.abc_lattice.ABCLattice

H5Lattice object to use H5CUDS lattices.

count_of(item_type)[source]

Return the count of item_type in the container.

Parameters:item_type (CUBA) – The CUBA enum of the type of the items to return the count of.
Returns:count – The number of items of item_type in the container.
Return type:int
Raises:ValueError : – If the type of the item is not supported in the current container.
classmethod create_new(group, primitive_cell, size, origin, record=None)[source]

Create a new lattice in H5CUDS file.

Parameters:
  • group (HDF5 group in PyTables file) – reference to a group (folder) in PyTables file where the tables for lattice and data will be located
  • primitive_cell (PrimitiveCell) – primitive cell specifying the 3D Bravais lattice
  • size (int[3]) – number of lattice nodes (in the direction of each axis).
  • origin (float[3]) – origin of lattice
  • record (tables.IsDescription) – A class that describes column types for PyTables table.
data
name
origin
size

Mesh File

This module contains the implentation to store, acces, and modify a file storing mesh data

class simphony.io.h5_mesh.H5Mesh(group, meshFile)[source]

Bases: simphony.cuds.abc_mesh.ABCMesh

H5Mesh.

Interface of the mesh file driver. Stores general mesh information Points and Elements such as Edges, Faces and Cells and provide the methods to interact with them. The methods are divided in four diferent blocks:

  1. methods to get the related item with the provided uid;
  2. methods to add a new item or replace;
  3. generator methods that return iterators over all or some of the mesh items and;
  4. inspection methods to identify if there are any edges, faces or cells described in the mesh.
data

Data

Data relative to the mesh

name

String

Name of the mesh

See also

get, add, update, iter, has, _create_points_table, _create_edges_table, _create_faces_table, _create_cells_table

count_of(item_type)[source]

Return the count of item_type in the container.

Parameters:item_type (CUBA) – The CUBA enum of the type of the items to return the count of.
Returns:count – The number of items of item_type in the container.
Return type:int
Raises:ValueError : – If the type of the item is not supported in the current container.
data
name
class simphony.io.h5_cuds_items.H5CUDSItems(root, record, name='items')[source]

Bases: _abcoll.MutableMapping

A proxy class to an HDF5 group node with serialised CUDS items.

The class implements the Mutable-Mapping api where each item instance is mapped to uuid.

__delitem__(uid)[source]

Delete the row.

__getitem__(uid)[source]

Return the Particle with the provided id.

__iter__()[source]

Iterate over all the rows

__len__()[source]

The number of rows in the table.

A runtime error is raised when the number of rows in the items and data tables is not equal.

__setitem__(uid, item)[source]

Set the particle in row with item.

  • If the uid does not exist in the Table a new row will be appended.
  • If the item.uid is None then item.uid = uid.
add_safe(item)[source]

Add item while checking for a unique uid.

Note

The item is expected to already have a uid set.

add_unsafe(item)[source]

Add item without checking for a unique uid.

Note

The item is expected to already have a uid set.

itersequence(sequence)[source]

Iterate over a sequence of row ids.

update_existing(item)[source]

Update an item if it already exists.

valid

A PyTables table is opened/created and the object is valid.

class simphony.io.data_container_table.DataContainerTable(root, name='data_containers', record=None)[source]

Bases: _abcoll.MutableMapping

A proxy class to an HDF5 group node with serialised DataContainers.

The class implements the Mutable-Mapping api where each DataContainer instance is mapped to uuid.

__delitem__(uid)[source]

Delete the row.

__getitem__(uid)[source]

Return the DataContainer in row.

__iter__()[source]

Iterate over all the rows

__len__()[source]

The number of rows in the table.

__setitem__(uid, data)[source]

Set the data in row from the DataContainer.

append(data)[source]

Append the data to the end of the table.

Parameters:data (DataContainer) – The DataContainer instance to save.
Returns:uid – The index of the saved row.
Return type:uuid.UUID
itersequence(sequence)[source]

Iterate over a sequence of row ids.

valid

A PyTables table is opened/created and the object is valid.

class simphony.io.indexed_data_container_table.IndexedDataContainerTable(root, name='data_containers', record=None, expected_number=None)[source]

Bases: _abcoll.Sequence

A proxy class to an HDF5 group node with serialised DataContainers.

The class implements the Sequence api where each DataContainer instance is mapped to the row. In addition the class implements update (i.e. __setitem__) and append.

__getitem__(index)[source]

Return the DataContainer in index.

__iter__()[source]

Iterate over all the rows

__len__()[source]

The number of rows in the table.

__setitem__(index, data)[source]

Update the data in index.

append(data)[source]

Append the data to the end of the table.

Parameters:data (DataContainer) – The DataContainer instance to save.
Returns:index – The index of the saved row.
Return type:int
valid
simphony.io.data_container_description.create_data_table(class_name, supported_cuba=<enum 'CUBA'>)[source]

Create tables.IsDescription class dynamically given a set of supported CUBA IntEnum

Parameters:
  • class_name (str) – Name of the created class
  • supported_cuba (iterable) – Supported CUBA IntEnum
Returns:

type

Return type:

tables.IsDescription