Source code for

from import ObjectMapper, RegionBuilder
from hdmf.common import VectorData
from hdmf.utils import getargs, docval
from hdmf.spec import AttributeSpec
from import BuildManager

from .. import register_map

from pynwb.file import NWBFile
from pynwb.core import NWBData, NWBContainer, ScratchData
from pynwb.misc import Units

[docs] class NWBBaseTypeMapper(ObjectMapper):
[docs] @staticmethod def get_nwb_file(container): curr = container while curr is not None: if isinstance(curr, NWBFile): return curr curr = container.parent
[docs] @register_map(NWBContainer) class NWBContainerMapper(NWBBaseTypeMapper): pass
[docs] @register_map(NWBData) class NWBDataMap(NWBBaseTypeMapper): pass
[docs] @register_map(ScratchData) class ScratchDataMap(NWBContainerMapper): def __init__(self, spec): super().__init__(spec) self.map_spec('description', spec.get_attribute('notes'))
[docs] class NWBTableRegionMap(NWBDataMap):
[docs] @ObjectMapper.constructor_arg('table') def carg_table(self, builder, manager): return manager.construct(
[docs] @ObjectMapper.constructor_arg('region') def carg_region(self, builder, manager): if not isinstance(, RegionBuilder): raise ValueError("'builder' must be a RegionBuilder") return
[docs] @register_map(VectorData) class VectorDataMap(ObjectMapper):
[docs] @docval({"name": "spec", "type": AttributeSpec, "doc": "the spec to get the attribute value for"}, {"name": "container", "type": VectorData, "doc": "the container to get the attribute value from"}, {"name": "manager", "type": BuildManager, "doc": "the BuildManager used for managing this build"}, returns='the value of the attribute') def get_attr_value(self, **kwargs): ''' Get the value of the attribute corresponding to this spec from the given container ''' spec, container, manager = getargs('spec', 'container', 'manager', kwargs) # handle custom mapping of container Units.waveform_rate -> spec Units.waveform_mean.sampling_rate if isinstance(container.parent, Units): if == 'waveform_mean' or == 'waveform_sd': if == 'sampling_rate': return container.parent.waveform_rate if == 'unit': return container.parent.waveform_unit if == 'spike_times': if == 'resolution': return container.parent.resolution return super().get_attr_value(**kwargs)