Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@ObjectMapper.constructor_arg('source')
def source_gettr(self, builder, manager):
if 'source' in builder.attributes:
return builder.attributes['source']
else:
return 'No known source'
@ObjectMapper.constructor_arg('table')
def carg_table(self, builder, manager):
return manager.construct(builder.data.builder)
from hdmf.build import ObjectMapper, TypeMap
from hdmf.build.builders import GroupBuilder
def decode(val):
if isinstance(val, bytes):
return val.decode('UTF-8')
else:
return val
class ObjectMapperLegacy(ObjectMapper):
@ObjectMapper.constructor_arg('source')
def source_gettr(self, builder, manager):
if 'source' in builder.attributes:
return builder.attributes['source']
else:
return 'No known source'
class TypeMapLegacy(TypeMap):
def get_builder_dt(self, builder): # noqa: C901
'''
For a given builder, return the neurodata_type. In this legacy
TypeMap, the builder may have out-of-spec neurodata_type; this
from dateutil.parser import parse as dateutil_parse
from hdmf.build import ObjectMapper
from .. import register_map
from ..file import NWBFile, Subject
from ..core import ScratchData
@register_map(NWBFile)
class NWBFileMap(ObjectMapper):
def __init__(self, spec):
super(NWBFileMap, self).__init__(spec)
acq_spec = self.spec.get_group('acquisition')
self.unmap(acq_spec)
self.map_spec('acquisition', acq_spec.get_neurodata_type('NWBDataInterface'))
self.map_spec('acquisition', acq_spec.get_neurodata_type('DynamicTable'))
self.map_spec('analysis', self.spec.get_group('analysis').get_neurodata_type('NWBContainer'))
self.map_spec('analysis', self.spec.get_group('analysis').get_neurodata_type('DynamicTable'))
# map constructor arg and property 'stimulus' -> stimulus__presentation
stimulus_spec = self.spec.get_group('stimulus')
self.unmap(stimulus_spec)
self.unmap(stimulus_spec.get_group('presentation'))
from hdmf.utils import docval, getargs
from hdmf.build import ObjectMapper, RegionBuilder, BuildManager
from hdmf.spec import Spec
from hdmf.container import Container
from .. import register_map
from pynwb.file import NWBFile
from pynwb.core import NWBData, DynamicTable, NWBContainer, VectorIndex
class NWBBaseTypeMapper(ObjectMapper):
@staticmethod
def get_nwb_file(container):
curr = container
while curr is not None:
if isinstance(curr, NWBFile):
return curr
curr = container.parent
@register_map(NWBContainer)
class NWBContainerMapper(NWBBaseTypeMapper):
pass
@ObjectMapper.constructor_arg('experimenter')
def experimenter_carg(self, builder, manager):
ret = None
exp_bldr = builder['general'].get('experimenter')
if exp_bldr is not None:
if isinstance(exp_bldr.data, str):
ret = (exp_bldr.data,)
else:
ret = tuple(exp_bldr.data)
return ret
if isinstance(pubs_bldr.data, str):
ret = (pubs_bldr.data,)
else:
ret = tuple(pubs_bldr.data)
return ret
@ObjectMapper.object_attr('related_publications')
def publication_obj_attr(self, container, manager):
ret = None
if isinstance(container.related_publications, str):
ret = (container.related_publications,)
return ret
@register_map(Subject)
class SubjectMap(ObjectMapper):
@ObjectMapper.constructor_arg('date_of_birth')
def dateconversion(self, builder, manager):
dob_builder = builder.get('date_of_birth')
if dob_builder is None:
return
else:
datestr = dob_builder.data
date = dateutil_parse(datestr)
return date