本文整理汇总了Python中neo.core.Segment.create_many_to_one_relationship方法的典型用法代码示例。如果您正苦于以下问题:Python Segment.create_many_to_one_relationship方法的具体用法?Python Segment.create_many_to_one_relationship怎么用?Python Segment.create_many_to_one_relationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neo.core.Segment
的用法示例。
在下文中一共展示了Segment.create_many_to_one_relationship方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
signal = self.signals[0]
segment = Segment(name='seg1')
segment.analogsignals = [signal]
segment.create_many_to_one_relationship()
chx = ChannelIndex(name='chx1', index=np.arange(signal.shape[1]))
chx.analogsignals = [signal]
chx.create_many_to_one_relationship()
self.assertEqual(signal._single_parent_objects, ('Segment', 'ChannelIndex'))
self.assertEqual(signal._multi_parent_objects, ())
self.assertEqual(signal._single_parent_containers, ('segment', 'channel_index'))
self.assertEqual(signal._multi_parent_containers, ())
self.assertEqual(signal._parent_objects, ('Segment', 'ChannelIndex'))
self.assertEqual(signal._parent_containers, ('segment', 'channel_index'))
self.assertEqual(len(signal.parents), 2)
self.assertEqual(signal.parents[0].name, 'seg1')
self.assertEqual(signal.parents[1].name, 'chx1')
assert_neo_object_is_compliant(signal)
示例2: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
segment = Segment(name='seg1')
segment.spikes = [self.spike1]
segment.create_many_to_one_relationship()
unit = Unit(name='unit1')
unit.spikes = [self.spike1]
unit.create_many_to_one_relationship()
self.assertEqual(self.spike1._single_parent_objects,
('Segment', 'Unit'))
self.assertEqual(self.spike1._multi_parent_objects, ())
self.assertEqual(self.spike1._single_parent_containers,
('segment', 'unit'))
self.assertEqual(self.spike1._multi_parent_containers, ())
self.assertEqual(self.spike1._parent_objects,
('Segment', 'Unit'))
self.assertEqual(self.spike1._parent_containers,
('segment', 'unit'))
self.assertEqual(len(self.spike1.parents), 2)
self.assertEqual(self.spike1.parents[0].name, 'seg1')
self.assertEqual(self.spike1.parents[1].name, 'unit1')
assert_neo_object_is_compliant(self.spike1)
示例3: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
signal = self.signals[0]
segment = Segment(name='seg1')
segment.analogsignals = [signal]
segment.create_many_to_one_relationship()
rchan = RecordingChannel(name='rchan1')
rchan.analogsignals = [signal]
rchan.create_many_to_one_relationship()
self.assertEqual(signal._single_parent_objects,
('Segment', 'RecordingChannel'))
self.assertEqual(signal._multi_parent_objects, ())
self.assertEqual(signal._single_parent_containers,
('segment', 'recordingchannel'))
self.assertEqual(signal._multi_parent_containers, ())
self.assertEqual(signal._parent_objects,
('Segment', 'RecordingChannel'))
self.assertEqual(signal._parent_containers,
('segment', 'recordingchannel'))
self.assertEqual(len(signal.parents), 2)
self.assertEqual(signal.parents[0].name, 'seg1')
self.assertEqual(signal.parents[1].name, 'rchan1')
assert_neo_object_is_compliant(signal)
示例4: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
params = {'test2': 'y1', 'test3': True}
epc = Epoch([1.1, 1.5, 1.7]*pq.ms, durations=[20, 40, 60]*pq.ns,
labels=np.array(['test epoch 1',
'test epoch 2',
'test epoch 3'], dtype='S'),
name='test', description='tester',
file_origin='test.file',
test1=1, **params)
epc.annotate(test1=1.1, test0=[1, 2])
assert_neo_object_is_compliant(epc)
segment = Segment(name='seg1')
segment.epochs = [epc]
segment.create_many_to_one_relationship()
self.assertEqual(epc._single_parent_objects, ('Segment',))
self.assertEqual(epc._multi_parent_objects, ())
self.assertEqual(epc._single_parent_containers, ('segment',))
self.assertEqual(epc._multi_parent_containers, ())
self.assertEqual(epc._parent_objects, ('Segment',))
self.assertEqual(epc._parent_containers, ('segment',))
self.assertEqual(len(epc.parents), 1)
self.assertEqual(epc.parents[0].name, 'seg1')
assert_neo_object_is_compliant(epc)
示例5: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
params = {"test2": "y1", "test3": True}
evt = Event(
1.5 * pq.ms,
label="test epoch",
name="test",
description="tester",
file_origin="test.file",
test1=1,
**params
)
evt.annotate(test1=1.1, test0=[1, 2])
assert_neo_object_is_compliant(evt)
segment = Segment(name="seg1")
segment.events = [evt]
segment.create_many_to_one_relationship()
self.assertEqual(evt._single_parent_objects, ("Segment",))
self.assertEqual(evt._multi_parent_objects, ())
self.assertEqual(evt._single_parent_containers, ("segment",))
self.assertEqual(evt._multi_parent_containers, ())
self.assertEqual(evt._parent_objects, ("Segment",))
self.assertEqual(evt._parent_containers, ("segment",))
self.assertEqual(len(evt.parents), 1)
self.assertEqual(evt.parents[0].name, "seg1")
assert_neo_object_is_compliant(evt)
示例6: read_segment
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def read_segment(self, lazy=False, cascade=True):
data, metadata = self._read_file_contents()
annotations = dict((k, metadata.get(k, 'unknown')) for k in ("label", "variable", "first_id", "last_id"))
seg = Segment(**annotations)
if cascade:
if metadata['variable'] == 'spikes':
for i in range(metadata['first_index'], metadata['last_index'] + 1):
spiketrain = self._extract_spikes(data, metadata, i, lazy)
if spiketrain is not None:
seg.spiketrains.append(spiketrain)
seg.annotate(dt=metadata['dt']) # store dt for SpikeTrains only, as can be retrieved from sampling_period for AnalogSignal
else:
signal = self._extract_signals(data, metadata, lazy)
if signal is not None:
seg.analogsignals.append(signal)
seg.create_many_to_one_relationship()
return seg
示例7: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
params = {'testarg2': 'yes', 'testarg3': True}
evta = EventArray([1.1, 1.5, 1.7]*pq.ms,
labels=np.array(['test event 1',
'test event 2',
'test event 3'], dtype='S'),
name='test', description='tester',
file_origin='test.file',
testarg1=1, **params)
evta.annotate(testarg1=1.1, testarg0=[1, 2, 3])
assert_neo_object_is_compliant(evta)
segment = Segment(name='seg1')
segment.eventarrays = [evta]
segment.create_many_to_one_relationship()
self.assertEqual(evta._container_child_objects, ())
self.assertEqual(evta._data_child_objects, ())
self.assertEqual(evta._single_parent_objects, ('Segment',))
self.assertEqual(evta._multi_child_objects, ())
self.assertEqual(evta._multi_parent_objects, ())
self.assertEqual(evta._child_properties, ())
self.assertEqual(evta._single_child_objects, ())
self.assertEqual(evta._container_child_containers, ())
self.assertEqual(evta._data_child_containers, ())
self.assertEqual(evta._single_child_containers, ())
self.assertEqual(evta._single_parent_containers, ('segment',))
self.assertEqual(evta._multi_child_containers, ())
self.assertEqual(evta._multi_parent_containers, ())
self.assertEqual(evta._child_objects, ())
self.assertEqual(evta._child_containers, ())
self.assertEqual(evta._parent_objects, ('Segment',))
self.assertEqual(evta._parent_containers, ('segment',))
self.assertEqual(evta.children, ())
self.assertEqual(len(evta.parents), 1)
self.assertEqual(evta.parents[0].name, 'seg1')
evta.create_many_to_one_relationship()
evta.create_many_to_many_relationship()
evta.create_relationship()
assert_neo_object_is_compliant(evta)
示例8: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
signal = self.signals[0]
segment = Segment(name='seg1')
segment.analogsignalarrays = [signal]
segment.create_many_to_one_relationship()
rcg = RecordingChannelGroup(name='rcg1')
rcg.analogsignalarrays = [signal]
rcg.create_many_to_one_relationship()
self.assertEqual(signal._container_child_objects, ())
self.assertEqual(signal._data_child_objects, ())
self.assertEqual(signal._single_parent_objects,
('Segment', 'RecordingChannelGroup'))
self.assertEqual(signal._multi_child_objects, ())
self.assertEqual(signal._multi_parent_objects, ())
self.assertEqual(signal._child_properties, ())
self.assertEqual(signal._single_child_objects, ())
self.assertEqual(signal._container_child_containers, ())
self.assertEqual(signal._data_child_containers, ())
self.assertEqual(signal._single_child_containers, ())
self.assertEqual(signal._single_parent_containers,
('segment', 'recordingchannelgroup'))
self.assertEqual(signal._multi_child_containers, ())
self.assertEqual(signal._multi_parent_containers, ())
self.assertEqual(signal._child_objects, ())
self.assertEqual(signal._child_containers, ())
self.assertEqual(signal._parent_objects,
('Segment', 'RecordingChannelGroup'))
self.assertEqual(signal._parent_containers,
('segment', 'recordingchannelgroup'))
self.assertEqual(signal.children, ())
self.assertEqual(len(signal.parents), 2)
self.assertEqual(signal.parents[0].name, 'seg1')
self.assertEqual(signal.parents[1].name, 'rcg1')
signal.create_many_to_one_relationship()
signal.create_many_to_many_relationship()
signal.create_relationship()
assert_neo_object_is_compliant(signal)
示例9: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
params = {'testarg2': 'yes', 'testarg3': True}
epc = Epoch(1.5*pq.ms, duration=20*pq.ns,
label='test epoch', name='test', description='tester',
file_origin='test.file',
testarg1=1, **params)
epc.annotate(testarg1=1.1, testarg0=[1, 2, 3])
assert_neo_object_is_compliant(epc)
segment = Segment(name='seg1')
segment.epochs = [epc]
segment.create_many_to_one_relationship()
self.assertEqual(epc._container_child_objects, ())
self.assertEqual(epc._data_child_objects, ())
self.assertEqual(epc._single_parent_objects, ('Segment',))
self.assertEqual(epc._multi_child_objects, ())
self.assertEqual(epc._multi_parent_objects, ())
self.assertEqual(epc._child_properties, ())
self.assertEqual(epc._single_child_objects, ())
self.assertEqual(epc._container_child_containers, ())
self.assertEqual(epc._data_child_containers, ())
self.assertEqual(epc._single_child_containers, ())
self.assertEqual(epc._single_parent_containers, ('segment',))
self.assertEqual(epc._multi_child_containers, ())
self.assertEqual(epc._multi_parent_containers, ())
self.assertEqual(epc._child_objects, ())
self.assertEqual(epc._child_containers, ())
self.assertEqual(epc._parent_objects, ('Segment',))
self.assertEqual(epc._parent_containers, ('segment',))
self.assertEqual(epc.children, ())
self.assertEqual(len(epc.parents), 1)
self.assertEqual(epc.parents[0].name, 'seg1')
epc.create_many_to_one_relationship()
epc.create_many_to_many_relationship()
epc.create_relationship()
assert_neo_object_is_compliant(epc)
示例10: read_segment
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def read_segment(self,
lazy = False,
cascade = True,
delimiter = '\t',
t_start = 0.*pq.s,
unit = pq.s,
):
"""
Arguments:
delimiter : columns delimiter in file '\t' or one space or two space or ',' or ';'
t_start : time start of all spiketrain 0 by default
unit : unit of spike times, can be a str or directly a Quantities
"""
unit = pq.Quantity(1, unit)
seg = Segment(file_origin = os.path.basename(self.filename))
if not cascade:
return seg
f = open(self.filename, 'Ur')
for i,line in enumerate(f) :
alldata = line[:-1].split(delimiter)
if alldata[-1] == '': alldata = alldata[:-1]
if alldata[0] == '': alldata = alldata[1:]
if lazy:
spike_times = [ ]
t_stop = t_start
else:
spike_times = np.array(alldata).astype('f')
t_stop = spike_times.max()*unit
sptr = SpikeTrain(spike_times*unit, t_start=t_start, t_stop=t_stop)
if lazy:
sptr.lazy_shape = len(alldata)
sptr.annotate(channel_index = i)
seg.spiketrains.append(sptr)
f.close()
seg.create_many_to_one_relationship()
return seg
示例11: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
signal = self.signals[0]
segment = Segment(name="seg1")
segment.analogsignals = [signal]
segment.create_many_to_one_relationship()
rchan = RecordingChannel(name="rchan1")
rchan.analogsignals = [signal]
rchan.create_many_to_one_relationship()
self.assertEqual(signal._container_child_objects, ())
self.assertEqual(signal._data_child_objects, ())
self.assertEqual(signal._single_parent_objects, ("Segment", "RecordingChannel"))
self.assertEqual(signal._multi_child_objects, ())
self.assertEqual(signal._multi_parent_objects, ())
self.assertEqual(signal._child_properties, ())
self.assertEqual(signal._single_child_objects, ())
self.assertEqual(signal._container_child_containers, ())
self.assertEqual(signal._data_child_containers, ())
self.assertEqual(signal._single_child_containers, ())
self.assertEqual(signal._single_parent_containers, ("segment", "recordingchannel"))
self.assertEqual(signal._multi_child_containers, ())
self.assertEqual(signal._multi_parent_containers, ())
self.assertEqual(signal._child_objects, ())
self.assertEqual(signal._child_containers, ())
self.assertEqual(signal._parent_objects, ("Segment", "RecordingChannel"))
self.assertEqual(signal._parent_containers, ("segment", "recordingchannel"))
self.assertEqual(signal.children, ())
self.assertEqual(len(signal.parents), 2)
self.assertEqual(signal.parents[0].name, "seg1")
self.assertEqual(signal.parents[1].name, "rchan1")
signal.create_many_to_one_relationship()
signal.create_many_to_many_relationship()
signal.create_relationship()
assert_neo_object_is_compliant(signal)
示例12: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def test__children(self):
segment = Segment(name="seg1")
segment.spikes = [self.spike1]
segment.create_many_to_one_relationship()
unit = Unit(name="unit1")
unit.spikes = [self.spike1]
unit.create_many_to_one_relationship()
self.assertEqual(self.spike1._container_child_objects, ())
self.assertEqual(self.spike1._data_child_objects, ())
self.assertEqual(self.spike1._single_parent_objects, ("Segment", "Unit"))
self.assertEqual(self.spike1._multi_child_objects, ())
self.assertEqual(self.spike1._multi_parent_objects, ())
self.assertEqual(self.spike1._child_properties, ())
self.assertEqual(self.spike1._single_child_objects, ())
self.assertEqual(self.spike1._container_child_containers, ())
self.assertEqual(self.spike1._data_child_containers, ())
self.assertEqual(self.spike1._single_child_containers, ())
self.assertEqual(self.spike1._single_parent_containers, ("segment", "unit"))
self.assertEqual(self.spike1._multi_child_containers, ())
self.assertEqual(self.spike1._multi_parent_containers, ())
self.assertEqual(self.spike1._child_objects, ())
self.assertEqual(self.spike1._child_containers, ())
self.assertEqual(self.spike1._parent_objects, ("Segment", "Unit"))
self.assertEqual(self.spike1._parent_containers, ("segment", "unit"))
self.assertEqual(self.spike1.children, ())
self.assertEqual(len(self.spike1.parents), 2)
self.assertEqual(self.spike1.parents[0].name, "seg1")
self.assertEqual(self.spike1.parents[1].name, "unit1")
self.spike1.create_many_to_one_relationship()
self.spike1.create_many_to_many_relationship()
self.spike1.create_relationship()
assert_neo_object_is_compliant(self.spike1)
示例13: read_segment
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
#.........这里部分代码省略.........
unit = dataBlockHeader['Unit']
pos = pos_spikes[chan,unit]
stimearrays[chan, unit][pos] = time
if load_spike_waveform and n1*n2 != 0 :
swfarrays[chan,unit][pos,:,:] = np.fromstring( fid.read(n1*n2*2) , dtype = 'i2').reshape(n1,n2).astype('f4')
else:
fid.seek(n1*n2*2,1)
pos_spikes[chan,unit] +=1
elif dataBlockHeader['Type'] == 4:
# event
pos = eventpositions[chan]
evarrays[chan]['times'][pos] = time
evarrays[chan]['labels'][pos] = dataBlockHeader['Unit']
eventpositions[chan]+= 1
elif dataBlockHeader['Type'] == 5:
#signal
data = np.fromstring( fid.read(n2*2) , dtype = 'i2').astype('f4')
sigarrays[chan][sample_positions[chan] : sample_positions[chan]+data.size] = data
sample_positions[chan] += data.size
## Step 4: create neo object
for chan, h in iteritems(eventHeaders):
if lazy:
times = []
labels = None
else:
times = evarrays[chan]['times']
labels = evarrays[chan]['labels']
ea = EventArray(
times*pq.s,
labels=labels,
channel_name=eventHeaders[chan]['Name'],
channel_index=chan
)
if lazy:
ea.lazy_shape = nb_events[chan]
seg.eventarrays.append(ea)
for chan, h in iteritems(slowChannelHeaders):
if lazy:
signal = [ ]
else:
if globalHeader['Version'] ==100 or globalHeader['Version'] ==101 :
gain = 5000./(2048*slowChannelHeaders[chan]['Gain']*1000.)
elif globalHeader['Version'] ==102 :
gain = 5000./(2048*slowChannelHeaders[chan]['Gain']*slowChannelHeaders[chan]['PreampGain'])
elif globalHeader['Version'] >= 103:
gain = globalHeader['SlowMaxMagnitudeMV']/(.5*(2**globalHeader['BitsPerSpikeSample'])*\
slowChannelHeaders[chan]['Gain']*slowChannelHeaders[chan]['PreampGain'])
signal = sigarrays[chan]*gain
anasig = AnalogSignal(signal*pq.V,
sampling_rate = float(slowChannelHeaders[chan]['ADFreq'])*pq.Hz,
t_start = t_starts[chan]*pq.s,
channel_index = slowChannelHeaders[chan]['Channel'],
channel_name = slowChannelHeaders[chan]['Name'],
)
if lazy:
anasig.lazy_shape = nb_samples[chan]
seg.analogsignals.append(anasig)
for (chan, unit), value in np.ndenumerate(nb_spikes):
if nb_spikes[chan, unit] == 0: continue
if lazy:
times = [ ]
waveforms = None
t_stop = 0
else:
times = stimearrays[chan,unit]
t_stop = times.max()
if load_spike_waveform:
if globalHeader['Version'] <103:
gain = 3000./(2048*dspChannelHeaders[chan]['Gain']*1000.)
elif globalHeader['Version'] >=103 and globalHeader['Version'] <105:
gain = globalHeader['SpikeMaxMagnitudeMV']/(.5*2.**(globalHeader['BitsPerSpikeSample'])*1000.)
elif globalHeader['Version'] >105:
gain = globalHeader['SpikeMaxMagnitudeMV']/(.5*2.**(globalHeader['BitsPerSpikeSample'])*globalHeader['SpikePreAmpGain'])
waveforms = swfarrays[chan, unit] * gain * pq.V
else:
waveforms = None
sptr = SpikeTrain(
times,
units='s',
t_stop=t_stop*pq.s,
waveforms=waveforms
)
sptr.annotate(unit_name = dspChannelHeaders[chan]['Name'])
sptr.annotate(channel_index = chan)
for key, val in dspChannelHeaders[chan].iteritems():
sptr.annotate(**{key: val})
if lazy:
sptr.lazy_shape = nb_spikes[chan,unit]
seg.spiketrains.append(sptr)
seg.create_many_to_one_relationship()
return seg
示例14: read_segment
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def read_segment(self,
# the 2 first keyword arguments are imposed by neo.io API
lazy = False,
cascade = True,
# all following arguments are decided by this IO and are free
t_start = 0.,
segment_duration = 0.,
):
"""
Return a Segment containing all analog and spike channels, as well as
all trigger events.
Parameters:
segment_duration :is the size in secend of the segment.
num_analogsignal : number of AnalogSignal in this segment
num_spiketrain : number of SpikeTrain in this segment
"""
#if no segment duration is given, use the complete file
if segment_duration == 0. :
segment_duration=float(self.metadata["TimeSpan"])
#if the segment duration is bigger than file, use the complete file
if segment_duration >=float(self.metadata["TimeSpan"]):
segment_duration=float(self.metadata["TimeSpan"])
#if the time sum of start point and segment duration is bigger than
#the file time span, cap it at the end
if segment_duration+t_start>float(self.metadata["TimeSpan"]):
segment_duration = float(self.metadata["TimeSpan"])-t_start
# create an empty segment
seg = Segment( name = "segment from the NeuroshareapiIO")
if cascade:
# read nested analosignal
if self.metadata["num_analogs"] == 0:
print ("no analog signals in this file!")
else:
#run through the number of analog channels found at the __init__ function
for i in range(self.metadata["num_analogs"]):
#create an analog signal object for each channel found
ana = self.read_analogsignal( lazy = lazy , cascade = cascade ,
channel_index = self.metadata["elecChanId"][i],
segment_duration = segment_duration, t_start=t_start)
#add analog signal read to segment object
seg.analogsignals += [ ana ]
# read triggers (in this case without any duration)
for i in range(self.metadata["num_trigs"]):
#create event object for each trigger/bit found
eva = self.read_eventarray(lazy = lazy ,
cascade = cascade,
channel_index = self.metadata["triggersId"][i],
segment_duration = segment_duration,
t_start = t_start,)
#add event object to segment
seg.eventarrays += [eva]
#read epochs (digital events with duration)
for i in range(self.metadata["num_digiEpochs"]):
#create event object for each trigger/bit found
epa = self.read_epocharray(lazy = lazy,
cascade = cascade,
channel_index = self.metadata["digiEpochId"][i],
segment_duration = segment_duration,
t_start = t_start,)
#add event object to segment
seg.epocharrays += [epa]
# read nested spiketrain
#run through all spike channels found
for i in range(self.metadata["num_spkChans"]):
#create spike object
sptr = self.read_spiketrain(lazy = lazy, cascade = cascade,
channel_index = self.metadata["spkChanId"][i],
segment_duration = segment_duration,
t_start = t_start)
#add the spike object to segment
seg.spiketrains += [sptr]
seg.create_many_to_one_relationship()
return seg
示例15: read_segment
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import create_many_to_one_relationship [as 别名]
def read_segment(self, take_ideal_sampling_rate=False,
lazy=False, cascade=True):
"""
Arguments:
"""
header = self.read_header(filename=self.filename)
# ~ print header
fid = open(self.filename, 'rb')
seg = Segment(
file_origin=os.path.basename(self.filename),
ced_version=str(header.system_id),
)
if not cascade:
fid.close()
return seg
def addannotations(ob, channelHeader):
ob.annotate(title=channelHeader.title)
ob.annotate(physical_channel_index=channelHeader.phy_chan)
ob.annotate(comment=channelHeader.comment)
for i in range(header.channels):
channelHeader = header.channelHeaders[i]
#~ print 'channel' , i , 'kind' , channelHeader.kind
if channelHeader.kind != 0:
#~ print '####'
#~ print 'channel' , i, 'kind' , channelHeader.kind , \
#~ channelHeader.type , channelHeader.phy_chan
#~ print channelHeader
pass
if channelHeader.kind in [1, 9]:
#~ print 'analogChanel'
ana_sigs = self.read_one_channel_continuous(
fid, i, header, take_ideal_sampling_rate, lazy=lazy)
#~ print 'nb sigs', len(anaSigs) , ' sizes : ',
for anaSig in ana_sigs:
addannotations(anaSig, channelHeader)
anaSig.name = str(anaSig.annotations['title'])
seg.analogsignals.append(anaSig)
#~ print sig.signal.size,
#~ print ''
elif channelHeader.kind in [2, 3, 4, 5, 8]:
ea = self.read_one_channel_event_or_spike(
fid, i, header, lazy=lazy)
if ea is not None:
addannotations(ea, channelHeader)
seg.events.append(ea)
elif channelHeader.kind in [6, 7]:
sptrs = self.read_one_channel_event_or_spike(
fid, i, header, lazy=lazy)
if sptrs is not None:
for sptr in sptrs:
addannotations(sptr, channelHeader)
seg.spiketrains.append(sptr)
fid.close()
seg.create_many_to_one_relationship()
return seg