hdmf.common package

Subpackages

Submodules

Module contents

This package will contain functions, classes, and objects for reading and writing data in according to the HDMF-common specification

hdmf.common.load_type_config(config_path, type_map=None)

This method will either load the config at the given path into either the global type map or a specific type map.

Parameters:
  • config_path (str) – Path to the configuration file.

  • type_map (TypeMap) – The TypeMap.

hdmf.common.get_loaded_type_config(type_map=None)

This method returns a dictionary with the configuration for each namespace and data type.

Parameters:

type_map (TypeMap) – The TypeMap.

hdmf.common.unload_type_config(type_map=None)

Unload all type configurations from the global type map or a specific type map.

Parameters:

type_map (TypeMap) – The TypeMap.

hdmf.common.register_class(data_type, namespace='hdmf-common', container_cls=None)
Register an Container class to use for reading and writing a data_type from a specification

If container_cls is not specified, returns a decorator for registering an Container subclass as the class for data_type in namespace.

Parameters:
  • data_type (str) – the data_type to get the spec for

  • namespace (str) – the name of the namespace

  • container_cls (type) – the class to map to the specified data_type

hdmf.common.register_map(container_cls, mapper_cls=None)
Register an ObjectMapper to use for a Container class type

If mapper_cls is not specified, returns a decorator for registering an ObjectMapper class as the mapper for container_cls. If mapper_cls specified, register the class as the mapper for container_cls

Parameters:
  • container_cls (type) – the Container class for which the given ObjectMapper class gets used for

  • mapper_cls (type) – the ObjectMapper class to use to map

hdmf.common.load_namespaces(namespace_path)

Load namespaces from file

Parameters:

namespace_path (str) – the path to the YAML with the namespace definition

Returns:

the namespaces loaded from the given file

Return type:

tuple

hdmf.common.available_namespaces()
hdmf.common.get_class(data_type, namespace, post_init_method=None)

Get the class object of the Container subclass corresponding to a given neurdata_type.

For developers: get_class can eventually lead to the ClassGeneratorManager.

  1. get_class calls get_dt_container_cls.

  2. get_dt_container_cls will get the container class from data type specification. If it is None, then one will be generated.

  3. if one is generated, then the spec is pulled from the catalog

  4. the parent class and attr_names are pulled from the spec

  5. generate_class is called from the ClassGeneratorManager

Remember that the generation of a class means the __init__ is being created for you. You don’t ever see it. The generation also builds the docval for the __init__ and prepares the __fields__ dict for creating setters, which are handled in AbstractContainer.

Parameters:
  • data_type (str) – the data_type to get the Container class for

  • namespace (str) – the namespace the data_type is defined in

  • post_init_method (Callable) – The function used as a post_init method to validate the class generation.

hdmf.common.get_type_map(extensions=None, copy=True)
Get a BuildManager to use for I/O using the given extensions. If no extensions are provided,

return a BuildManager that uses the core namespace

Parameters:
  • extensions (str or TypeMap or list) – a path to a namespace, a TypeMap, or a list consisting paths to namespaces and TypeMaps

  • copy (bool) – Whether to return a deepcopy of the TypeMap. If False, a direct reference may be returned (use with caution).

Returns:

the namespaces loaded from the given file

Return type:

tuple

hdmf.common.get_manager(extensions=None, copy=True)
Get a BuildManager to use for I/O using the given extensions. If no extensions are provided,

return a BuildManager that uses the core namespace

Parameters:
  • extensions (str or TypeMap or list) – a path to a namespace, a TypeMap, or a list consisting paths to namespaces and TypeMaps

  • copy (bool) – Whether to return a deepcopy of the TypeMap. If False, a direct reference may be returned (use with caution).

Returns:

a build manager with namespaces loaded from the given file

Return type:

BuildManager

hdmf.common.validate(io, namespace='hdmf-common', experimental=False)

Validate an file against a namespace

Parameters:
  • io (HDMFIO) – the HDMFIO object to read from

  • namespace (str) – the namespace to validate against

  • experimental (bool) – data type is an experimental data type

Returns:

errors in the file

Return type:

list

hdmf.common.get_hdf5io(path=None, mode='r', manager=None, comm=None, file=None, driver=None, aws_region=None, herd_path=None)

A convenience method for getting an HDF5IO object using an HDMF-common build manager if none is provided.

Parameters:
  • path (str or Path) – the path to the HDF5 file

  • mode (str) – the mode to open the HDF5 file with, one of (“w”, “r”, “r+”, “a”, “w-”, “x”). See h5py.File for more details.

  • manager (TypeMap or BuildManager) – the BuildManager or a TypeMap to construct a BuildManager to use for I/O

  • comm (Intracomm) – the MPI communicator to use for parallel I/O

  • file (File or S3File or RemFile) – a pre-existing h5py.File, S3File, or RemFile object

  • driver (str) – driver for h5py to use when opening HDF5 file

  • aws_region (str) – If driver is ros3, then specify the aws region of the url.

  • herd_path (str) – The path to read/write the HERD file