hdmf.spec.catalog module

class hdmf.spec.catalog.SpecCatalog

Bases: object

Create a new catalog for storing specifications

** Private Instance Variables **

Variables:
  • __specs – Dict with the specification of each registered type

  • __parent_types – Dict with parent types for each registered type

  • __spec_source_files – Dict with the path to the source files (if available) for each registered type

  • __hierarchy – Dict describing the hierarchy for each registered type. NOTE: Always use SpecCatalog.get_hierarchy(…) to retrieve the hierarchy as this dictionary is used like a cache, i.e., to avoid repeated calculation of the hierarchy but the contents are computed on first request by SpecCatalog.get_hierarchy(…)

register_spec(spec, source_file=None)

Associate a specified object type with a specification

Parameters:
  • spec (BaseStorageSpec) – a Spec object

  • source_file (str) – path to the source file from which the spec was loaded

get_spec(data_type)

Get the Spec object for the given type

Parameters:

data_type (str) – the data_type to get the Spec for

Returns:

the specification for writing the given object type to HDF5

Return type:

Spec

get_registered_types()

Return all registered specifications

get_spec_source_file(data_type)
Return the path to the source file from which the spec for the given

type was loaded from. None is returned if no file path is available for the spec. Note: The spec in the file may not be identical to the object in case the spec is modified after load.

Parameters:

data_type (str) – the data_type of the spec to get the source file for

Returns:

the path to source specification file from which the spec was originally loaded or None

Return type:

str

auto_register(spec, source_file=None)

Register this specification and all sub-specification using data_type as object type name

Parameters:
  • spec (BaseStorageSpec) – the Spec object to register

  • source_file (str) – path to the source file from which the spec was loaded

Returns:

the types that were registered with this spec

Return type:

tuple

get_hierarchy(data_type)

For a given type get the type inheritance hierarchy for that type.

E.g., if we have a type MyContainer that inherits from BaseContainer then the result will be a tuple with the strings (‘MyContainer’, ‘BaseContainer’)

Parameters:

data_type (str or type) – the data_type to get the hierarchy of

Returns:

Tuple of strings with the names of the types the given data_type inherits from.

Return type:

tuple

get_full_hierarchy()
Get the complete hierarchy of all types. The function attempts to sort types by name using

standard Python sorted.

Returns:

Hierarchically nested OrderedDict with the hierarchy of all the types

Return type:

OrderedDict

get_subtypes(data_type, recursive=True)

For a given data type recursively find all the subtypes that inherit from it.

E.g., assume we have the following inheritance hierarchy:

-BaseContainer--+-->AContainer--->ADContainer
                |
                +-->BContainer

In this case, the subtypes of BaseContainer would be (AContainer, ADContainer, BContainer), the subtypes of AContainer would be (ADContainer), and the subtypes of BContainer would be empty ().

Parameters:
  • data_type (str or type) – the data_type to get the subtypes for

  • recursive (bool) – recursively get all subtypes. Set to False to only get the direct subtypes

Returns:

Tuple of strings with the names of all types of the given data_type.

Return type:

tuple