本文整理汇总了Python中neo.core.Block.create_many_to_one_relationship方法的典型用法代码示例。如果您正苦于以下问题:Python Block.create_many_to_one_relationship方法的具体用法?Python Block.create_many_to_one_relationship怎么用?Python Block.create_many_to_one_relationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neo.core.Block
的用法示例。
在下文中一共展示了Block.create_many_to_one_relationship方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read_block(self, lazy=False, group=None, reader=None):
"""
Read a Block from the file
:param lazy: Enables lazy reading
:param group: HDF5 Group representing the block in NSDF model tree (optional)
:param reader: NSDFReader instance (optional)
:return: Read block
"""
assert not lazy, 'Do not support lazy'
block = Block()
group, reader = self._select_first_container(group, reader, 'block')
if group is None:
return None
attrs = group.attrs
self._read_block_children(block, group, reader)
block.create_many_to_one_relationship()
self._read_container_metadata(attrs, block)
return block
示例2: read_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read_block(self, lazy=False, cascade=True, channel_index=None):
"""
Arguments:
Channel_index: can be int, iterable or None to select one, many or all channel(s)
"""
blk = Block()
if cascade:
seg = Segment(file_origin=self._filename)
blk.segments += [seg]
if channel_index:
if type(channel_index) is int:
channel_index = [channel_index]
if type(channel_index) is list:
channel_index = np.array(channel_index)
else:
channel_index = np.arange(0, self._attrs["shape"][1])
chx = ChannelIndex(name="all channels", index=channel_index)
blk.channel_indexes.append(chx)
ana = self.read_analogsignal(channel_index=channel_index, lazy=lazy, cascade=cascade)
ana.channel_index = chx
seg.duration = (self._attrs["shape"][0] / self._attrs["kwik"]["sample_rate"]) * pq.s
# neo.tools.populate_RecordingChannel(blk)
blk.create_many_to_one_relationship()
return blk
示例3: proc_dam
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def proc_dam(filename):
'''Load an dam file that has already been processed by the official matlab
file converter. That matlab data is saved to an m-file, which is then
converted to a numpy '.npz' file. This numpy file is the file actually
loaded. This function converts it to a neo block and returns the block.
This block can be compared to the block produced by BrainwareDamIO to
make sure BrainwareDamIO is working properly
block = proc_dam(filename)
filename: The file name of the numpy file to load. It should end with
'*_dam_py?.npz'. This will be converted to a neo 'file_origin' property
with the value '*.dam', so the filename to compare should fit that pattern.
'py?' should be 'py2' for the python 2 version of the numpy file or 'py3'
for the python 3 version of the numpy file.
example: filename = 'file1_dam_py2.npz'
dam file name = 'file1.dam'
'''
with np.load(filename) as damobj:
damfile = damobj.items()[0][1].flatten()
filename = os.path.basename(filename[:-12]+'.dam')
signals = [res.flatten() for res in damfile['signal']]
stimIndexes = [int(res[0, 0].tolist()) for res in damfile['stimIndex']]
timestamps = [res[0, 0] for res in damfile['timestamp']]
block = Block(file_origin=filename)
chx = ChannelIndex(file_origin=filename,
index=np.array([0]),
channel_ids=np.array([1]),
channel_names=np.array(['Chan1'], dtype='S'))
block.channel_indexes.append(chx)
params = [res['params'][0, 0].flatten() for res in damfile['stim']]
values = [res['values'][0, 0].flatten() for res in damfile['stim']]
params = [[res1[0] for res1 in res] for res in params]
values = [[res1 for res1 in res] for res in values]
stims = [dict(zip(param, value)) for param, value in zip(params, values)]
fulldam = zip(stimIndexes, timestamps, signals, stims)
for stimIndex, timestamp, signal, stim in fulldam:
sig = AnalogSignal(signal=signal*pq.mV,
t_start=timestamp*pq.d,
file_origin=filename,
sampling_period=1.*pq.s)
segment = Segment(file_origin=filename,
index=stimIndex,
**stim)
segment.analogsignals = [sig]
block.segments.append(segment)
block.create_many_to_one_relationship()
return block
示例4: read_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read_block(self, **kargs):
if self.filename is not None:
self.axo_obj = axographio.read(self.filename)
# Build up the block
blk = Block()
blk.rec_datetime = None
if self.filename is not None:
# modified time is not ideal but less prone to
# cross-platform issues than created time (ctime)
blk.file_datetime = datetime.fromtimestamp(os.path.getmtime(self.filename))
# store the filename if it is available
blk.file_origin = self.filename
# determine the channel names and counts
_, channel_ordering = np.unique(self.axo_obj.names[1:], return_index=True)
channel_names = np.array(self.axo_obj.names[1:])[np.sort(channel_ordering)]
channel_count = len(channel_names)
# determine the time signal and sample period
sample_period = self.axo_obj.data[0].step * pq.s
start_time = self.axo_obj.data[0].start * pq.s
# Attempt to read units from the channel names
channel_unit_names = [x.split()[-1].strip('()') for x in channel_names]
channel_units = []
for unit in channel_unit_names:
try:
channel_units.append(pq.Quantity(1, unit))
except LookupError:
channel_units.append(None)
# Strip units from channel names
channel_names = [' '.join(x.split()[:-1]) for x in channel_names]
# build up segments by grouping axograph columns
for seg_idx in range(1, len(self.axo_obj.data), channel_count):
seg = Segment(index=seg_idx)
# add in the channels
for chan_idx in range(0, channel_count):
signal = pq.Quantity(
self.axo_obj.data[seg_idx + chan_idx], channel_units[chan_idx])
analog = AnalogSignal(signal,
sampling_period=sample_period, t_start=start_time,
name=channel_names[chan_idx], channel_index=chan_idx)
seg.analogsignals.append(analog)
blk.segments.append(seg)
blk.create_many_to_one_relationship()
return blk
示例5: read_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read_block(self,
lazy = False,
cascade = True,
):
"""
"""
tree = ElementTree.parse(self.filename)
root = tree.getroot()
acq = root.find('acquisitionSystem')
nbits = int(acq.find('nBits').text)
nbchannel = int(acq.find('nChannels').text)
sampling_rate = float(acq.find('samplingRate').text)*pq.Hz
voltage_range = float(acq.find('voltageRange').text)
#offset = int(acq.find('offset').text)
amplification = float(acq.find('amplification').text)
bl = Block(file_origin = os.path.basename(self.filename).replace('.xml', ''))
if cascade:
seg = Segment()
bl.segments.append(seg)
# RC and RCG
rc_list = [ ]
for i, xml_rcg in enumerate(root.find('anatomicalDescription').find('channelGroups').findall('group')):
rcg = RecordingChannelGroup(name = 'Group {0}'.format(i))
bl.recordingchannelgroups.append(rcg)
for xml_rc in xml_rcg:
rc = RecordingChannel(index = int(xml_rc.text))
rc_list.append(rc)
rcg.recordingchannels.append(rc)
rc.recordingchannelgroups.append(rcg)
rcg.channel_indexes = np.array([rc.index for rc in rcg.recordingchannels], dtype = int)
rcg.channel_names = np.array(['Channel{0}'.format(rc.index) for rc in rcg.recordingchannels], dtype = 'S')
# AnalogSignals
reader = RawBinarySignalIO(filename = self.filename.replace('.xml', '.dat'))
seg2 = reader.read_segment(cascade = True, lazy = lazy,
sampling_rate = sampling_rate,
t_start = 0.*pq.s,
unit = pq.V, nbchannel = nbchannel,
bytesoffset = 0,
dtype = np.int16 if nbits<=16 else np.int32,
rangemin = -voltage_range/2.,
rangemax = voltage_range/2.,)
for s, sig in enumerate(seg2.analogsignals):
if not lazy:
sig /= amplification
sig.segment = seg
seg.analogsignals.append(sig)
rc_list[s].analogsignals.append(sig)
bl.create_many_to_one_relationship()
return bl
示例6: proc_src
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def proc_src(filename):
'''Load an src file that has already been processed by the official matlab
file converter. That matlab data is saved to an m-file, which is then
converted to a numpy '.npz' file. This numpy file is the file actually
loaded. This function converts it to a neo block and returns the block.
This block can be compared to the block produced by BrainwareSrcIO to
make sure BrainwareSrcIO is working properly
block = proc_src(filename)
filename: The file name of the numpy file to load. It should end with
'*_src_py?.npz'. This will be converted to a neo 'file_origin' property
with the value '*.src', so the filename to compare should fit that pattern.
'py?' should be 'py2' for the python 2 version of the numpy file or 'py3'
for the python 3 version of the numpy file.
example: filename = 'file1_src_py2.npz'
src file name = 'file1.src'
'''
with np.load(filename) as srcobj:
srcfile = srcobj.items()[0][1]
filename = os.path.basename(filename[:-12]+'.src')
block = Block(file_origin=filename)
NChannels = srcfile['NChannels'][0, 0][0, 0]
side = str(srcfile['side'][0, 0][0])
ADperiod = srcfile['ADperiod'][0, 0][0, 0]
comm_seg = proc_src_comments(srcfile, filename)
block.segments.append(comm_seg)
rcg = proc_src_units(srcfile, filename)
chan_nums = np.arange(NChannels, dtype='int')
chan_names = []
for i in chan_nums:
name = 'Chan'+str(i)
chan_names.append(name)
chan = RecordingChannel(file_origin='filename',
name=name,
index=int(i))
rcg.recordingchannels.append(chan)
rcg.channel_indexes = chan_nums
rcg.channel_names = np.array(chan_names, dtype='string_')
block.recordingchannelgroups.append(rcg)
for rep in srcfile['sets'][0, 0].flatten():
proc_src_condition(rep, filename, ADperiod, side, block)
block.create_many_to_one_relationship()
return block
示例7: read_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read_block(self, lazy=False, cascade=True):
bl = Block()
tankname = os.path.basename(self.dirname)
bl.file_origin = tankname
if not cascade : return bl
for blockname in os.listdir(self.dirname):
seg = self.read_segment(blockname, lazy, cascade)
bl.segments.append(seg)
bl.create_many_to_one_relationship()
return bl
示例8: read_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read_block(self, lazy=False, cascade=True):
if self.filename is not None:
self.stfio_rec = stfio.read(self.filename)
bl = Block()
bl.description = self.stfio_rec.file_description
bl.annotate(comment=self.stfio_rec.comment)
try:
bl.rec_datetime = self.stfio_rec.datetime
except:
bl.rec_datetime = None
if not cascade:
return bl
dt = np.round(self.stfio_rec.dt * 1e-3, 9) * pq.s # ms to s
sampling_rate = 1.0/dt
t_start = 0 * pq.s
# iterate over sections first:
for j, recseg in enumerate(self.stfio_rec[0]):
seg = Segment(index=j)
length = len(recseg)
# iterate over channels:
for i, recsig in enumerate(self.stfio_rec):
name = recsig.name
unit = recsig.yunits
try:
pq.Quantity(1, unit)
except:
unit = ''
if lazy:
signal = pq.Quantity([], unit)
else:
signal = pq.Quantity(recsig[j], unit)
anaSig = AnalogSignal(signal, sampling_rate=sampling_rate,
t_start=t_start, name=str(name),
channel_index=i)
if lazy:
anaSig.lazy_shape = length
seg.analogsignals.append(anaSig)
bl.segments.append(seg)
t_start = t_start + length * dt
bl.create_many_to_one_relationship()
return bl
示例9: test__children
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def test__children(self):
blk = Block(name='block1')
blk.recordingchannelgroups = [self.rcg1]
blk.create_many_to_one_relationship()
self.assertEqual(self.rcg1._container_child_objects, ('Unit',))
self.assertEqual(self.rcg1._data_child_objects, ('AnalogSignalArray',))
self.assertEqual(self.rcg1._single_parent_objects, ('Block',))
self.assertEqual(self.rcg1._multi_child_objects, ('RecordingChannel',))
self.assertEqual(self.rcg1._multi_parent_objects, ())
self.assertEqual(self.rcg1._child_properties, ())
self.assertEqual(self.rcg1._single_child_objects,
('Unit', 'AnalogSignalArray',))
self.assertEqual(self.rcg1._container_child_containers, ('units',))
self.assertEqual(self.rcg1._data_child_containers,
('analogsignalarrays',))
self.assertEqual(self.rcg1._single_child_containers,
('units', 'analogsignalarrays'))
self.assertEqual(self.rcg1._single_parent_containers, ('block',))
self.assertEqual(self.rcg1._multi_child_containers,
('recordingchannels',))
self.assertEqual(self.rcg1._multi_parent_containers, ())
self.assertEqual(self.rcg1._child_objects,
('Unit', 'AnalogSignalArray', 'RecordingChannel'))
self.assertEqual(self.rcg1._child_containers,
('units', 'analogsignalarrays', 'recordingchannels'))
self.assertEqual(self.rcg1._parent_objects, ('Block',))
self.assertEqual(self.rcg1._parent_containers, ('block',))
self.assertEqual(len(self.rcg1.children),
(len(self.units1) +
len(self.rchan1) +
len(self.sigarr1)))
self.assertEqual(self.rcg1.children[0].name, self.unitnames1[0])
self.assertEqual(self.rcg1.children[1].name, self.unitnames1[1])
self.assertEqual(self.rcg1.children[2].name, self.sigarrnames1[0])
self.assertEqual(self.rcg1.children[3].name, self.sigarrnames1[1])
self.assertEqual(self.rcg1.children[4].name, self.rchannames1[0])
self.assertEqual(self.rcg1.children[5].name, self.rchannames1[1])
self.assertEqual(len(self.rcg1.parents), 1)
self.assertEqual(self.rcg1.parents[0].name, 'block1')
self.rcg1.create_many_to_one_relationship()
self.rcg1.create_many_to_many_relationship()
self.rcg1.create_relationship()
assert_neo_object_is_compliant(self.rcg1)
示例10: read
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read(self, lazy=False, cascade=True, **kargs):
if Block in self.readable_objects:
if hasattr(self, "read_all_blocks") and callable(getattr(self, "read_all_blocks")):
return self.read_all_blocks(lazy=lazy, cascade=cascade, **kargs)
return [self.read_block(lazy=lazy, cascade=cascade, **kargs)]
elif Segment in self.readable_objects:
bl = Block(name="One segment only")
if not cascade:
return bl
seg = self.read_segment(lazy=lazy, cascade=cascade, **kargs)
bl.segments.append(seg)
bl.create_many_to_one_relationship()
return [bl]
else:
raise NotImplementedError
示例11: read
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read(self, lazy=False, **kargs):
if lazy:
assert self.support_lazy, 'This IO do not support lazy loading'
if Block in self.readable_objects:
if (hasattr(self, 'read_all_blocks') and
callable(getattr(self, 'read_all_blocks'))):
return self.read_all_blocks(lazy=lazy, **kargs)
return [self.read_block(lazy=lazy, **kargs)]
elif Segment in self.readable_objects:
bl = Block(name='One segment only')
seg = self.read_segment(lazy=lazy, **kargs)
bl.segments.append(seg)
bl.create_many_to_one_relationship()
return [bl]
else:
raise NotImplementedError
示例12: test__construct_subsegment_by_unit
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def test__construct_subsegment_by_unit(self):
nb_seg = 3
nb_unit = 7
unit_with_sig = np.array([0, 2, 5])
signal_types = ['Vm', 'Conductances']
sig_len = 100
# channelindexes
chxs = [ChannelIndex(name='Vm',
index=unit_with_sig),
ChannelIndex(name='Conductance',
index=unit_with_sig)]
# Unit
all_unit = []
for u in range(nb_unit):
un = Unit(name='Unit #%d' % u, channel_indexes=np.array([u]))
assert_neo_object_is_compliant(un)
all_unit.append(un)
blk = Block()
blk.channel_indexes = chxs
for s in range(nb_seg):
seg = Segment(name='Simulation %s' % s)
for j in range(nb_unit):
st = SpikeTrain([1, 2], units='ms',
t_start=0., t_stop=10)
st.unit = all_unit[j]
for t in signal_types:
anasigarr = AnalogSignal(np.zeros((sig_len,
len(unit_with_sig))),
units='nA',
sampling_rate=1000.*pq.Hz,
channel_indexes=unit_with_sig)
seg.analogsignals.append(anasigarr)
blk.create_many_to_one_relationship()
for unit in all_unit:
assert_neo_object_is_compliant(unit)
for chx in chxs:
assert_neo_object_is_compliant(chx)
assert_neo_object_is_compliant(blk)
# what you want
newseg = seg.construct_subsegment_by_unit(all_unit[:4])
assert_neo_object_is_compliant(newseg)
示例13: read_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read_block(self, lazy=False, cascade=True, **kargs):
"""
Reads a block from the raw data file "fname" generated
with BrainWare
"""
# there are no keyargs implemented to so far. If someone tries to pass
# them they are expecting them to do something or making a mistake,
# neither of which should pass silently
if kargs:
raise NotImplementedError("This method does not have any " "argument implemented yet")
self._fsrc = None
block = Block(file_origin=self._filename)
# if we aren't doing cascade, don't load anything
if not cascade:
return block
# create the objects to store other objects
rcg = RecordingChannelGroup(file_origin=self._filename)
rchan = RecordingChannel(file_origin=self._filename, index=1, name="Chan1")
# load objects into their containers
rcg.recordingchannels.append(rchan)
block.recordingchannelgroups.append(rcg)
rcg.channel_indexes = np.array([1])
rcg.channel_names = np.array(["Chan1"], dtype="S")
# open the file
with open(self._path, "rb") as fobject:
# while the file is not done keep reading segments
while True:
seg = self._read_segment(fobject, lazy)
# if there are no more Segments, stop
if not seg:
break
# store the segment and signals
block.segments.append(seg)
rchan.analogsignals.append(seg.analogsignals[0])
# remove the file object
self._fsrc = None
block.create_many_to_one_relationship()
return block
示例14: read_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def read_block(self, lazy=False, cascade=True, **kargs):
'''
Reads a block from the raw data file "fname" generated
with BrainWare
'''
# there are no keyargs implemented to so far. If someone tries to pass
# them they are expecting them to do something or making a mistake,
# neither of which should pass silently
if kargs:
raise NotImplementedError('This method does not have any '
'arguments implemented yet')
self._fsrc = None
block = Block(file_origin=self._filename)
# if we aren't doing cascade, don't load anything
if not cascade:
return block
# create the objects to store other objects
chx = ChannelIndex(file_origin=self._filename,
channel_ids=np.array([1]),
index=np.array([0]),
channel_names=np.array(['Chan1'], dtype='S'))
# load objects into their containers
block.channel_indexes.append(chx)
# open the file
with open(self._path, 'rb') as fobject:
# while the file is not done keep reading segments
while True:
seg = self._read_segment(fobject, lazy)
# if there are no more Segments, stop
if not seg:
break
# store the segment and signals
seg.analogsignals[0].channel_index = chx
block.segments.append(seg)
# remove the file object
self._fsrc = None
block.create_many_to_one_relationship()
return block
示例15: generate_one_simple_block
# 需要导入模块: from neo.core import Block [as 别名]
# 或者: from neo.core.Block import create_many_to_one_relationship [as 别名]
def generate_one_simple_block(block_name='block_0', nb_segment=3, supported_objects=[], **kws):
if supported_objects and Block not in supported_objects:
raise ValueError('Block must be in supported_objects')
bl = Block() # name = block_name)
objects = supported_objects
if Segment in objects:
for s in range(nb_segment):
seg = generate_one_simple_segment(seg_name="seg" + str(s), supported_objects=objects,
**kws)
bl.segments.append(seg)
# if RecordingChannel in objects:
# populate_RecordingChannel(bl)
bl.create_many_to_one_relationship()
return bl