hdmf.build.objectmapper module

class hdmf.build.objectmapper.ObjectMapper(spec)

Bases: object

A class for mapping between Spec objects and AbstractContainer attributes

Create a map from AbstractContainer attributes to specifications

Parameters:

spec (DatasetSpec or GroupSpec) – The specification for mapping objects to builders

classmethod no_convert(obj_type)

Specify an object type that ObjectMappers should not convert.

classmethod convert_dtype(spec, value, spec_dtype=None)

Convert values to the specified dtype. For example, if a literal int is passed in to a field that is specified as a unsigned integer, this function will convert the Python int to a numpy unsigned int.

Parameters:
  • spec – The DatasetSpec or AttributeSpec to which this value is being applied

  • value – The value being converted to the spec dtype

  • spec_dtype – Optional override of the dtype in spec.dtype. Used to specify the parent dtype when the given extended spec lacks a dtype.

Returns:

The function returns a tuple consisting of 1) the value, and 2) the data type. The value is returned as the function may convert the input value to comply with the dtype specified in the schema.

static constructor_arg(name)

Decorator to override the default mapping scheme for a given constructor argument.

Decorate ObjectMapper methods with this function when extending ObjectMapper to override the default scheme for mapping between AbstractContainer and Builder objects. The decorated method should accept as its first argument the Builder object that is being mapped. The method should return the value to be passed to the target AbstractContainer class constructor argument given by name.

Parameters:

name (str) – the name of the constructor argument

static object_attr(name)

Decorator to override the default mapping scheme for a given object attribute.

Decorate ObjectMapper methods with this function when extending ObjectMapper to override the default scheme for mapping between AbstractContainer and Builder objects. The decorated method should accept as its first argument the AbstractContainer object that is being mapped. The method should return the child Builder object (or scalar if the object attribute corresponds to an AttributeSpec) that represents the attribute given by name.

Parameters:

name (str) – the name of the constructor argument

property spec

the Spec used in this ObjectMapper

get_container_name(*args)
classmethod convert_dt_name(spec)

Construct the attribute name corresponding to a specification

Parameters:

spec (Spec) – the specification to get the name for

classmethod get_attr_names(spec)

Get the attribute names for each subspecification in a Spec

Parameters:

spec (Spec) – the specification to get the object attribute names for

map_attr(attr_name, spec)

Map an attribute to spec. Use this to override default behavior

Parameters:
  • attr_name (str) – the name of the object to map

  • spec (Spec) – the spec to map the attribute to

get_attr_spec(attr_name)

Return the Spec for a given attribute

Parameters:

attr_name (str) – the name of the attribute

get_carg_spec(carg_name)

Return the Spec for a given constructor argument

Parameters:

carg_name (str) – the name of the constructor argument

map_const_arg(const_arg, spec)

Map an attribute to spec. Use this to override default behavior

Parameters:
  • const_arg (str) – the name of the constructor argument to map

  • spec (Spec) – the spec to map the attribute to

unmap(spec)

Removing any mapping for a specification. Use this to override default mapping

Parameters:

spec (Spec) – the spec to map the attribute to

map_spec(attr_carg, spec)

Map the given specification to the construct argument and object attribute

Parameters:
  • attr_carg (str) – the constructor argument/object attribute to map this spec to

  • spec (Spec) – the spec to map the attribute to

get_attribute(spec)

Get the object attribute name for the given Spec

Parameters:

spec (Spec) – the spec to get the attribute for

Returns:

the attribute name

Return type:

str

get_attr_value(spec, container, manager)

Get the value of the attribute corresponding to this spec from the given container

Parameters:
  • spec (Spec) – the spec to get the attribute value for

  • container (AbstractContainer) – the container to get the attribute value from

  • manager (BuildManager) – the BuildManager used for managing this build

get_const_arg(spec)

Get the constructor argument for the given Spec

Parameters:

spec (Spec) – the spec to get the constructor argument for

Returns:

the name of the constructor argument

Return type:

str

build(container, manager, parent=None, source=None, builder=None, spec_ext=None, export=False)

Convert an AbstractContainer to a Builder representation.

References are not added but are queued to be added in the BuildManager.

Parameters:
  • container (AbstractContainer) – the container to convert to a Builder

  • manager (BuildManager) – the BuildManager to use for managing this build

  • parent (GroupBuilder) – the parent of the resulting Builder

  • source (str) – the source of container being built i.e. file path

  • builder (BaseBuilder) – the Builder to build on

  • spec_ext (BaseStorageSpec) – a spec extension

  • export (bool) – whether this build is for exporting

Returns:

the Builder representing the given AbstractContainer

Return type:

Builder

construct(builder, manager, parent=None)

Construct an AbstractContainer from the given Builder

Parameters:
get_builder_name(container)

Get the name of a Builder that represents a AbstractContainer

Parameters:

container (AbstractContainer) – the AbstractContainer to get the Builder name for

constructor_args = {'name': <function ObjectMapper.get_container_name>}
obj_attrs = {}