hdmf.container module

class hdmf.container.AbstractContainer(name)

Bases: object

Parameters

name (str) – the name of this container

classmethod get_fields_conf()
property name

The name of this Container

get_ancestor(data_type=None)

Traverse parent hierarchy and return first instance of the specified data_type

Parameters

data_type (str) – the data_type to search for

property fields
property object_id
generate_new_id(recurse=True)

Changes the object ID of this Container and all of its children to a new UUID string.

Parameters

recurse (bool) – whether or not to change the object ID of this container’s children

property modified
set_modified(modified=True)
Parameters

modified (bool) – whether or not this Container has been modified

property children
add_child(child=None)
Parameters

child (Container) – the child Container for this Container

classmethod type_hierarchy()
property container_source

The source of this Container

property parent

The parent Container of this Container

reset_parent()

Reset the parent of this Container to None and remove the Container from the children of its parent.

Use with caution. This can result in orphaned containers and broken links.

class hdmf.container.Container(name)

Bases: AbstractContainer

A container that can contain other containers and has special functionality for printing.

Parameters

name (str) – the name of this container

data_type = 'Container'
namespace = 'hdmf-common'
class hdmf.container.Data(name, data)

Bases: AbstractContainer

A class for representing dataset containers

Parameters
property data
property shape

Get the shape of the data represented by this container :return: Shape tuple :rtype: tuple of ints

set_dataio(dataio)

Apply DataIO object to the data held by this Data object

Parameters

dataio (DataIO) – the DataIO to apply to the data held by this Data

transform(func)

Transform data from the current underlying state.

This function can be used to permanently load data from disk, or convert to a different representation, such as a torch.Tensor

Parameters

func (function) – a function to transform data

__getitem__(args)
get(args)
append(arg)
extend(arg)

The extend_data method adds all the elements of the iterable arg to the end of the data of this Data container.

Parameters

arg – The iterable to add to the end of this VectorData

data_type = 'Data'
namespace = 'hdmf-common'
class hdmf.container.DataRegion(name, data)

Bases: Data

Parameters
abstract property data

The target data that this region applies to

abstract property region

The region that indexes into data e.g. slice or list of indices

class hdmf.container.MultiContainerInterface(name)

Bases: Container

Class that dynamically defines methods to support a Container holding multiple Containers of the same type.

To use, extend this class and create a dictionary as a class attribute with any of the following keys: * ‘attr’ to name the attribute that stores the Container instances * ‘type’ to provide the Container object type (type or list/tuple of types, type can be a docval macro) * ‘add’ to name the method for adding Container instances * ‘get’ to name the method for getting Container instances * ‘create’ to name the method for creating Container instances (only if a single type is specified)

If the attribute does not exist in the class, it will be generated. If it does exist, it should behave like a dict.

The keys ‘attr’, ‘type’, and ‘add’ are required.

Parameters

name (str) – the name of this container

class hdmf.container.Row

Bases: object

A class for representing rows from a Table.

The Table class can be indicated with the __table__. Doing so will set constructor arguments for the Row class and ensure that Row.idx is set appropriately when a Row is added to the Table. It will also add functionality to the Table class for getting Row objects.

Note, the Row class is not needed for working with Table objects. This is merely convenience functionality for working with Tables.

property idx

The index of this row in its respective Table

property table

The Table this Row comes from

class hdmf.container.RowGetter(table)

Bases: object

A simple class for providing __getitem__ functionality that returns Row objects to a Table.

__getitem__(idx)
class hdmf.container.Table(columns, name, data=[])

Bases: Data

Subclasses should specify the class attribute __columns__.

This should be a list of dictionaries with the following keys:

  • name the column name

  • type the type of data in this column

  • doc a brief description of what gets stored in this column

For reference, this list of dictionaries will be used with docval to autogenerate the add_row method for adding data to this table.

If __columns__ is not specified, no custom add_row method will be added.

The class attribute __defaultname__ can also be set to specify a default name for the table class. If __defaultname__ is not specified, then name will need to be specified when the class is instantiated.

A Table class can be paired with a Row class for conveniently working with rows of a Table. This pairing must be indicated in the Row class implementation. See Row for more details.

Parameters
property columns
add_row(values)
Parameters

values (dict) – the values for each column

which(**kwargs)

Query a table

__getitem__(args)
to_dataframe()

Produce a pandas DataFrame containing this table’s data.

classmethod from_dataframe(df, name=None, extra_ok=False)
Construct an instance of Table (or a subclass) from a pandas DataFrame. The columns of the dataframe

should match the columns defined on the Table subclass.

Parameters
  • df (DataFrame) – input data

  • name (str) – the name of this container

  • extra_ok (bool) – accept (and ignore) unexpected columns on the input dataframe