hdmf.container module
- class hdmf.container.HERDManager
Bases:
object
This class manages whether to set/attach an instance of HERD to the subclass.
- link_resources(herd)
Method to attach an instance of HERD in order to auto-add terms/references to data.
- Parameters:
herd (
HERD
) – The external resources to be used for the container.
- get_linked_resources()
- class hdmf.container.AbstractContainer(name)
Bases:
object
- Parameters:
name (
str
) – the name of this container
- property data_type
Return the spec data type associated with this container.
- classmethod get_fields_conf()
- property read_io
The
HDMFIO
object used for reading the container.This property will typically be None if this Container is not a root Container (i.e., if parent is not None). Use get_read_io instead if you want to retrieve the
HDMFIO
object used for reading from the parent container.
- get_read_io()
Get the io object used to read this container.
If self.read_io is None, this function will iterate through the parents and return the first io object found on a parent container
- Returns:
The
HDMFIO
object used to read this container. Returns None in case no io object is found, e.g., in case this container has not been read from file.
- 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
- all_children()
Get a list of all child objects and their child objects recursively.
If the object has an object_id, the object will be added to “ret” to be returned. If that object has children, they will be added to the “stack” in order to be: 1) Checked to see if has an object_id, if so then add to “ret” 2) Have children that will also be checked
- property all_objects
Get a LabelledDict that indexed all child objects and their children by object ID.
- get_ancestors()
- property fields
Subclasses use this class attribute to add properties to autogenerate. fields allows for lists and for dicts with the keys {‘name’, ‘child’, ‘required_name’, ‘doc’, ‘settable’}. 1. name: The name of the field property 2. child: A boolean value to set the parent/child relationship between the field property and the container. 3. required_name: The name the field property must have such that name matches required_name. 4. doc: Documentation of the field property 5. settable: If true, a setter function is created so that the field can be changed after creation.
- 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
- 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
- set_data_io(dataset_name: str, data_io_class: Type[DataIO], data_io_kwargs: dict = None, data_chunk_iterator_class: Type[AbstractDataChunkIterator] | None = None, data_chunk_iterator_kwargs: dict = None, **kwargs)
Apply DataIO object to a dataset field of the Container.
- Parameters:
dataset_name (str) – Name of dataset to wrap in DataIO
data_io_class (Type[DataIO]) – Class to use for DataIO, e.g. H5DataIO or ZarrDataIO
data_io_kwargs (dict) – keyword arguments passed to the constructor of the DataIO class.
data_chunk_iterator_class (Type[AbstractDataChunkIterator]) – Class to use for DataChunkIterator. If None, no DataChunkIterator is used.
data_chunk_iterator_kwargs (dict) – keyword arguments passed to the constructor of the DataChunkIterator class.
**kwargs – DEPRECATED. Use data_io_kwargs instead. kwargs are passed to the constructor of the DataIO class.
Notes
If data_chunk_iterator_class is not None, the data is wrapped in the DataChunkIterator before being wrapped in the DataIO. This allows for rewriting the backend configuration of hdf5 datasets.
- data_type = 'Container'
- namespace = 'hdmf-common'
- class hdmf.container.Data(name, data)
Bases:
AbstractContainer
A class for representing dataset containers
- Parameters:
name (
str
) – the name of this containerdata (
str
orint
orfloat
orbytes
orbool
orndarray
orlist
ortuple
orDataset
orArray
orStrDataset
orHDMFDataset
orAbstractDataChunkIterator
orDataIO
) – the source of the data
- property data
- property shape
Get the shape of the data represented by this container :return: Shape tuple :rtype: tuple of ints
- set_data_io(data_io_class: Type[DataIO], data_io_kwargs: dict, data_chunk_iterator_class: Type[AbstractDataChunkIterator] | None = None, data_chunk_iterator_kwargs: dict = None) None
Apply DataIO object to the data held by this Data object.
- Parameters:
data_io_class (Type[DataIO]) – The DataIO to apply to the data held by this Data.
data_io_kwargs (dict) – The keyword arguments to pass to the DataIO.
data_chunk_iterator_class (Type[AbstractDataChunkIterator]) – The DataChunkIterator to use for the DataIO. If None, no DataChunkIterator is used.
data_chunk_iterator_kwargs (dict) – The keyword arguments to pass to the DataChunkIterator.
Notes
If data_chunk_iterator_class is not None, the data is wrapped in the DataChunkIterator before being wrapped in the DataIO. This allows for rewriting the backend configuration of hdf5 datasets.
- 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.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 nametype
the type of data in this columndoc
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:
columns (
list
ortuple
) – a list of the columns in this tablename (
str
) – the name of this containerdata (
ndarray
orlist
ortuple
orDataset
orArray
orStrDataset
orHDMFDataset
orAbstractDataChunkIterator
orDataIO
) – the source of the data
- property columns
- 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.