hdmf.spec.spec module

class hdmf.spec.spec.DtypeHelper

Bases: object

primary_dtype_synonyms = {'ascii': ['ascii', 'bytes'], 'bool': ['bool'], 'double': ['double', 'float64'], 'float': ['float', 'float32'], 'int': ['int32', 'int'], 'int8': ['int8'], 'isodatetime': ['isodatetime', 'datetime'], 'long': ['int64', 'long'], 'numeric': ['numeric'], 'object': ['object'], 'region': ['region'], 'short': ['int16', 'short'], 'uint16': ['uint16'], 'uint32': ['uint32', 'uint'], 'uint64': ['uint64'], 'uint8': ['uint8'], 'utf': ['text', 'utf', 'utf8', 'utf-8']}
recommended_primary_dtypes = ['float', 'double', 'short', 'int', 'long', 'utf', 'ascii', 'bool', 'int8', 'uint8', 'uint16', 'uint32', 'uint64', 'object', 'region', 'numeric', 'isodatetime']
valid_primary_dtypes = {'ascii', 'bool', 'bytes', 'datetime', 'double', 'float', 'float32', 'float64', 'int', 'int16', 'int32', 'int64', 'int8', 'isodatetime', 'long', 'numeric', 'object', 'region', 'short', 'text', 'uint', 'uint16', 'uint32', 'uint64', 'uint8', 'utf', 'utf-8', 'utf8'}
static simplify_cpd_type(cpd_type)

Transform a list of DtypeSpecs into a list of strings. Use for simple representation of compound type and validation.

Parameters:cpd_type (list) – The list of DtypeSpecs to simplify
class hdmf.spec.spec.ConstructableDict

Bases: dict

classmethod build_const_args(spec_dict)

Build constructor arguments for this ConstructableDict class from a dictionary

classmethod build_spec(spec_dict)

Build a Spec object from the given Spec dict

class hdmf.spec.spec.Spec(doc, name=None, required=True, parent=None)

Bases: hdmf.spec.spec.ConstructableDict

A base specification class

Parameters:
  • doc (str) – a description about what this specification represents
  • name (str) – The name of this attribute
  • required (bool) – whether or not this attribute is required
  • parent (Spec) – the parent of this spec
doc

Documentation on what this Spec is specifying

name

The name of the object being specified

parent

The parent specification of this specification

classmethod build_const_args(spec_dict)

Build constructor arguments for this Spec class from a dictionary

path
class hdmf.spec.spec.RefSpec(target_type, reftype)

Bases: hdmf.spec.spec.ConstructableDict

Parameters:
  • target_type (str) – the target type GroupSpec or DatasetSpec
  • reftype (str) – the type of references this is i.e. region or object
target_type

The data_type of the target of the reference

reftype

The type of reference

is_region()
Returns:True if this RefSpec specifies a region reference, False otherwise
Return type:bool
class hdmf.spec.spec.AttributeSpec(name, doc, dtype, shape=None, dims=None, required=True, parent=None, value=None, default_value=None)

Bases: hdmf.spec.spec.Spec

Specification for attributes

Parameters:
  • name (str) – The name of this attribute
  • doc (str) – a description about what this specification represents
  • dtype (str or RefSpec) – The data type of this attribute
  • shape (list or tuple) – the shape of this dataset
  • dims (list or tuple) – the dimensions of this dataset
  • required (bool) – whether or not this attribute is required. ignored when “value” is specified
  • parent (BaseStorageSpec) – the parent of this spec
  • value (None) – a constant value for this attribute
  • default_value (None) – a default value for this attribute
dtype

The data type of the attribute

value

The constant value of the attribute. “None” if this attribute is not constant

default_value

The default value of the attribute. “None” if this attribute has no default value

required

True if this attribute is required, False otherwise.

dims

The dimensions of this attribute’s value

shape

The shape of this attribute’s value

classmethod build_const_args(spec_dict)

Build constructor arguments for this Spec class from a dictionary

class hdmf.spec.spec.BaseStorageSpec(doc, name=None, default_name=None, attributes=[], linkable=True, quantity=1, data_type_def=None, data_type_inc=None)

Bases: hdmf.spec.spec.Spec

A specification for any object that can hold attributes.

Parameters:
  • doc (str) – a description about what this specification represents
  • name (str) – the name of this base storage container, allowed only if quantity is not ‘+’ or ‘*’
  • default_name (str) – The default name of this base storage container, used only if name is None
  • attributes (list) – the attributes on this group
  • linkable (bool) – whether or not this group can be linked
  • quantity (str or int) – the required number of allowed instance
  • data_type_def (str) – the data type this specification represents
  • data_type_inc (str or BaseStorageSpec) – the data type this specification extends
default_name

The default name for this spec

resolved
required

Whether or not the this spec represents a required field

resolve_spec(inc_spec)
Parameters:inc_spec (BaseStorageSpec) – the data type this specification represents
is_inherited_spec(spec)

Return True if this spec was inherited from the parent type, False otherwise

Parameters:spec (Spec or str) – the specification to check
is_overridden_spec(spec)

Return True if this spec overrides a specification from the parent type, False otherwise

Parameters:spec (Spec or str) – the specification to check
is_inherited_attribute(name)

Return True if the attribute was inherited from the parent type, False otherwise

Parameters:name (str) – the name of the attribute to the Spec for
is_overridden_attribute(name)

Return True if the given attribute overrides the specification from the parent, False otherwise

Parameters:name (str) – the name of the attribute to the Spec for
is_many()
classmethod get_data_type_spec(data_type_def)
classmethod get_namespace_spec()
attributes

The attributes for this specification

linkable

True if object can be a link, False otherwise

classmethod id_key()

Get the key used to store data ID on an instance

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

classmethod type_key()

Get the key used to store data type on an instance

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

classmethod inc_key()

Get the key used to define a data_type include.

Override this method to use a different keyword for ‘data_type_inc’

classmethod def_key()

Get the key used to define a data_type definition.

Override this method to use a different keyword for ‘data_type_def’

data_type_inc

The data type of this specification

data_type_def

The data type this specification defines

quantity

The number of times the object being specified should be present

add_attribute(name, doc, dtype, shape=None, dims=None, required=True, parent=None, value=None, default_value=None)

Add an attribute to this specification

Parameters:
  • name (str) – The name of this attribute
  • doc (str) – a description about what this specification represents
  • dtype (str or RefSpec) – The data type of this attribute
  • shape (list or tuple) – the shape of this dataset
  • dims (list or tuple) – the dimensions of this dataset
  • required (bool) – whether or not this attribute is required. ignored when “value” is specified
  • parent (BaseStorageSpec) – the parent of this spec
  • value (None) – a constant value for this attribute
  • default_value (None) – a default value for this attribute
set_attribute(spec)

Set an attribute on this specification

Parameters:spec (AttributeSpec) – the specification for the attribute to add
get_attribute(name)

Get an attribute on this specification

Parameters:name (str) – the name of the attribute to the Spec for
classmethod build_const_args(spec_dict)

Build constructor arguments for this Spec class from a dictionary

class hdmf.spec.spec.DtypeSpec(name, doc, dtype)

Bases: hdmf.spec.spec.ConstructableDict

A class for specifying a component of a compound type

Parameters:
  • name (str) – the name of this column
  • doc (str) – a description about what this data type is
  • dtype (str or list or RefSpec) – the data type of this column
doc

Documentation about this component

name

The name of this component

dtype

The data type of this component

static assertValidDtype(dtype)
static is_ref(spec)
Parameters:spec (str or dict) – the spec object to check
classmethod build_const_args(spec_dict)

Build constructor arguments for this Spec class from a dictionary

class hdmf.spec.spec.DatasetSpec(doc, dtype=None, name=None, default_name=None, shape=None, dims=None, attributes=[], linkable=True, quantity=1, default_value=None, data_type_def=None, data_type_inc=None)

Bases: hdmf.spec.spec.BaseStorageSpec

Specification for datasets

To specify a table-like dataset i.e. a compound data type.

Parameters:
  • doc (str) – a description about what this specification represents
  • dtype (str or list or RefSpec) – The data type of this attribute. Use a list of DtypeSpecs to specify a compound data type.
  • name (str) – The name of this dataset
  • default_name (str) – The default name of this dataset
  • shape (list or tuple) – the shape of this dataset
  • dims (list or tuple) – the dimensions of this dataset
  • attributes (list) – the attributes on this group
  • linkable (bool) – whether or not this group can be linked
  • quantity (str or int) – the required number of allowed instance
  • default_value (None) – a default value for this dataset
  • data_type_def (str) – the data type this specification represents
  • data_type_inc (str or DatasetSpec) – the data type this specification extends
resolve_spec(inc_spec)
Parameters:inc_spec (DatasetSpec) – the data type this specification represents
dims

The dimensions of this Dataset

dtype

The data type of the Dataset

shape

The shape of the dataset

default_value

The default value of the dataset or None if not specified

classmethod dtype_spec_cls()

The class to use when constructing DtypeSpec objects

Override this if extending to use a class other than DtypeSpec to build dataset specifications

classmethod build_const_args(spec_dict)

Build constructor arguments for this Spec class from a dictionary

class hdmf.spec.spec.LinkSpec(doc, target_type, quantity=1, name=None)

Bases: hdmf.spec.spec.Spec

Parameters:
  • doc (str) – a description about what this link represents
  • target_type (str) – the target type GroupSpec or DatasetSpec
  • quantity (str or int) – the required number of allowed instance
  • name (str) – the name of this link
target_type

The data type of target specification

data_type_inc

The data type of target specification

is_many()
quantity

The number of times the object being specified should be present

required

Whether or not the this spec represents a required field

class hdmf.spec.spec.GroupSpec(doc, name=None, default_name=None, groups=[], datasets=[], attributes=[], links=[], linkable=True, quantity=1, data_type_def=None, data_type_inc=None)

Bases: hdmf.spec.spec.BaseStorageSpec

Specification for groups

Parameters:
  • doc (str) – a description about what this specification represents
  • name (str) – the name of this group
  • default_name (str) – The default name of this group
  • groups (list) – the subgroups in this group
  • datasets (list) – the datasets in this group
  • attributes (list) – the attributes on this group
  • links (list) – the links in this group
  • linkable (bool) – whether or not this group can be linked
  • quantity (str or int) – the required number of allowed instance
  • data_type_def (str) – the data type this specification represents
  • data_type_inc (str or GroupSpec) – the data type this specification data_type_inc
resolve_spec(inc_spec)
Parameters:inc_spec (GroupSpec) – the data type this specification represents
is_inherited_dataset(name)

Return true if a dataset with the given name was inherited

Parameters:name (str) – the name of the dataset
is_overridden_dataset(name)

Return true if a dataset with the given name overrides a specification from the parent type

Parameters:name (str) – the name of the dataset
is_inherited_group(name)

Return true if a group with the given name was inherited

Parameters:name (str) – the name of the group
is_overridden_group(name)

Return true if a group with the given name overrides a specification from the parent type

Parameters:name (str) – the name of the group

Return true if a link with the given name was inherited

Parameters:name (str) – the name of the link

Return true if a link with the given name overrides a specification from the parent type

Parameters:name (str) – the name of the link
is_inherited_spec(spec)

Returns ‘True’ if specification was inherited from a parent type

Parameters:spec (Spec or str) – the specification to check
is_overridden_spec(spec)

Returns ‘True’ if specification was inherited from a parent type

Parameters:spec (Spec or str) – the specification to check
is_inherited_type(spec)

Returns True if spec represents a spec that was inherited from an included data_type

Parameters:spec (BaseStorageSpec or str) – the specification to check
is_overridden_type(spec)

Returns True if spec represents a spec that was overriden by the subtype

Parameters:spec (BaseStorageSpec or str) – the specification to check
get_data_type(data_type)

Get a specification by “data_type”

Parameters:data_type (str) – the data_type to retrieve
groups

The groups specificed in this GroupSpec

datasets

The datasets specificed in this GroupSpec

The links specificed in this GroupSpec

add_group(doc, name=None, default_name=None, groups=[], datasets=[], attributes=[], links=[], linkable=True, quantity=1, data_type_def=None, data_type_inc=None)

Add a new specification for a subgroup to this group specification

Parameters:
  • doc (str) – a description about what this specification represents
  • name (str) – the name of this group
  • default_name (str) – The default name of this group
  • groups (list) – the subgroups in this group
  • datasets (list) – the datasets in this group
  • attributes (list) – the attributes on this group
  • links (list) – the links in this group
  • linkable (bool) – whether or not this group can be linked
  • quantity (str or int) – the required number of allowed instance
  • data_type_def (str) – the data type this specification represents
  • data_type_inc (str or GroupSpec) – the data type this specification data_type_inc
set_group(spec)

Add the given specification for a subgroup to this group specification

Parameters:spec (GroupSpec) – the specification for the subgroup
get_group(name)

Get a specification for a subgroup to this group specification

Parameters:name (str) – the name of the group to the Spec for
add_dataset(doc, dtype=None, name=None, default_name=None, shape=None, dims=None, attributes=[], linkable=True, quantity=1, default_value=None, data_type_def=None, data_type_inc=None)

Add a new specification for a dataset to this group specification

Parameters:
  • doc (str) – a description about what this specification represents
  • dtype (str or list or RefSpec) – The data type of this attribute. Use a list of DtypeSpecs to specify a compound data type.
  • name (str) – The name of this dataset
  • default_name (str) – The default name of this dataset
  • shape (list or tuple) – the shape of this dataset
  • dims (list or tuple) – the dimensions of this dataset
  • attributes (list) – the attributes on this group
  • linkable (bool) – whether or not this group can be linked
  • quantity (str or int) – the required number of allowed instance
  • default_value (None) – a default value for this dataset
  • data_type_def (str) – the data type this specification represents
  • data_type_inc (str or DatasetSpec) – the data type this specification extends
set_dataset(spec)

Add the given specification for a dataset to this group specification

Parameters:spec (DatasetSpec) – the specification for the dataset
get_dataset(name)

Get a specification for a dataset to this group specification

Parameters:name (str) – the name of the dataset to the Spec for

Add a new specification for a link to this group specification

Parameters:
  • doc (str) – a description about what this link represents
  • target_type (str) – the target type GroupSpec or DatasetSpec
  • quantity (str or int) – the required number of allowed instance
  • name (str) – the name of this link

Add a given specification for a link to this group specification

Parameters:spec (LinkSpec) – the specification for the object to link to

Get a specification for a link to this group specification

Parameters:name (str) – the name of the link to the Spec for
classmethod dataset_spec_cls()

The class to use when constructing DatasetSpec objects

Override this if extending to use a class other than DatasetSpec to build dataset specifications

The class to use when constructing LinkSpec objects

Override this if extending to use a class other than LinkSpec to build link specifications

classmethod build_const_args(spec_dict)

Build constructor arguments for this Spec class from a dictionary