hdmf.spec.namespace module

class hdmf.spec.namespace.SpecNamespace(doc, name, schema, full_name=None, version=None, date=None, author=None, contact=None, catalog=None)

Bases: dict

A namespace for specifications

Parameters
  • doc (str) – a description about what this namespace represents

  • name (str) – the name of this namespace

  • schema (list) – location of schema specification files or other Namespaces

  • full_name (str) – extended full name of this namespace

  • version (str or tuple or list) – Version number of the namespace

  • date (datetime or str) – Date last modified or released. Formatting is %Y-%m-%d %H:%M:%S, e.g, 2017-04-25 17:14:13

  • author (str or list) – Author or list of authors.

  • contact (str or list) – List of emails. Ordering should be the same as for author

  • catalog (SpecCatalog) – The SpecCatalog object for this SpecNamespace

UNVERSIONED = None
classmethod types_key()

Get the key used for specifying types to include from a file or namespace

Override this method to use a different name for ‘data_types’

property full_name

String with full name or None

property contact

String or list of strings with the contacts or None

property author

String or list of strings with the authors or None

property version

String, list, or tuple with the version or SpecNamespace.UNVERSIONED if the version is missing or empty

property date

Date last modified or released.

Returns

datetime object, string, or None

property name

String with short name or None

property doc
property schema
get_source_files()

Get the list of names of the source files included the schema of the namespace

get_source_description(sourcefile)
Get the description of a source file as described in the namespace. The result is a

dict which contains the ‘source’ and optionally ‘title’, ‘doc’ and ‘data_types’ imported from the source file

Parameters

sourcefile (str) – Name of the source file

Returns

Dict with the source file documentation

Return type

dict

property catalog

The SpecCatalog containing all the Specs

get_spec(data_type)

Get the Spec object for the given data type

Parameters

data_type (str or type) – the data_type to get the spec for

get_registered_types()

Get the available types in this namespace

Returns

the a tuple of the available data types

Return type

tuple

get_hierarchy(data_type)

Get the extension hierarchy for the given data_type in this namespace

Parameters

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

Returns

a tuple with the type hierarchy

Return type

tuple

classmethod build_namespace(**spec_dict)
class hdmf.spec.namespace.SpecReader(source)

Bases: object

Parameters

source (str) – the source from which this reader reads from

property source
abstract read_spec()
abstract read_namespace()
class hdmf.spec.namespace.YAMLSpecReader(indir='.')

Bases: SpecReader

Parameters

indir (str) – the path spec files are relative to

read_namespace(namespace_path)
read_spec(spec_path)
class hdmf.spec.namespace.NamespaceCatalog(group_spec_cls=<class 'hdmf.spec.spec.GroupSpec'>, dataset_spec_cls=<class 'hdmf.spec.spec.DatasetSpec'>, spec_namespace_cls=<class 'hdmf.spec.namespace.SpecNamespace'>)

Bases: object

Create a catalog for storing multiple Namespaces

Parameters
  • group_spec_cls (type) – the class to use for group specifications

  • dataset_spec_cls (type) – the class to use for dataset specifications

  • spec_namespace_cls (type) – the class to use for specification namespaces

merge(ns_catalog)
property namespaces

The namespaces in this NamespaceCatalog

Returns

a tuple of the available namespaces

Return type

tuple

property dataset_spec_cls

The DatasetSpec class used in this NamespaceCatalog

property group_spec_cls

The GroupSpec class used in this NamespaceCatalog

property spec_namespace_cls

The SpecNamespace class used in this NamespaceCatalog

add_namespace(name, namespace)

Add a namespace to this catalog

Parameters
  • name (str) – the name of this namespace

  • namespace (SpecNamespace) – the SpecNamespace object

get_namespace(name)

Get the a SpecNamespace

Parameters

name (str) – the name of this namespace

Returns

the SpecNamespace with the given name

Return type

SpecNamespace

get_spec(namespace, data_type)

Get the Spec object for the given type from the given Namespace

Parameters
  • namespace (str) – the name of the namespace

  • data_type (str or type) – the data_type to get the spec for

Returns

the specification for writing the given object type to HDF5

Return type

Spec

get_hierarchy(namespace, data_type)

Get the type hierarchy for a given data_type in a given namespace

Parameters
  • namespace (str) – the name of the namespace

  • data_type (str or type) – the data_type to get the spec for

Returns

a tuple with the type hierarchy

Return type

tuple

is_sub_data_type(namespace, data_type, parent_data_type)

Return whether or not data_type is a sub data_type of parent_data_type

Parameters
  • namespace (str) – the name of the namespace containing the data_type

  • data_type (str) – the data_type to check

  • parent_data_type (str) – the potential parent data_type

Returns

True if data_type is a sub data_type of parent_data_type, False otherwise

Return type

bool

get_sources()

Get all the source specification files that were loaded in this catalog

get_namespace_sources(namespace)

Get all the source specifications that were loaded for a given namespace

Parameters

namespace (str) – the name of the namespace

get_types(source)

Get the types that were loaded from a given source

Parameters

source (str) – the name of the source

load_namespaces(namespace_path, resolve=True, reader=None)

Load the namespaces in the given file

Parameters
  • namespace_path (str) – the path to the file containing the namespaces(s) to load

  • resolve (bool) – whether or not to include objects from included/parent spec objects

  • reader (SpecReader) – the class to user for reading specifications

Returns

a dictionary describing the dependencies of loaded namespaces

Return type

dict