INM-6 / python-neo

Neo is a package for representing electrophysiology data in Python, together with support for reading a wide range of neurophysiology file formats
http://packages.python.org/neo/
BSD 3-Clause "New" or "Revised" License
3 stars 10 forks source link

seg.construct_subsegment_by_unit does not work #6

Open mdenker opened 9 years ago

mdenker commented 9 years ago

AnalogSignals are not carried over.

j=bl.segments[0]
k=bl.filter([{'unit_id': 0},{'electrode_id': 4}],objects="Unit")[0]
print k
l=j.construct_subsegment_by_unit(unit_list=[k])
# This is ok...
print l.spiketrains
# Should not be empty...
print l.analogsignals
lphan commented 9 years ago

bug (error) found. To get 'l.analogsignals', parameter channel_indexes must be given when creating instance of Unit. unit = Unit(name='Unit #%s' % ind, channel_indexes=ind)

Subsequently, there are some lines in file segment.py must be replaced by using function append, not extend. Otherwise, I got error 'int object is not iterable'

lphan commented 9 years ago

error is still there. seg0.analogsignals return correct list but seg1 = seg0.construct_subsegment_by_unit(unit_list=[k]) seg1.analogsignals still return empty list

lphan commented 9 years ago

Following code will return list of analogsignals (not empty). Some lines in segments.py must be changed.

from neo.core import (Segment, Block, Unit, SpikeTrain,
                        RecordingChannelGroup, AnalogSignal)
import quantities as pq
blk = Block()
rcg = RecordingChannelGroup(name='group0')
blk.recordingchannelgroups = [rcg]
for ind in range(5):
    unit = Unit(name='Unit #%s' % ind, channel_indexes=ind)
    rcg.units.append(unit)

for ind in range(3):
    seg = Segment(name='Simulation #%s' % ind)
    blk.segments.append(seg)
    for unit in rcg.units:
       train = SpikeTrain([1, 2, 3], units='ms', t_start=0.,
                          t_stop=10)
       train.unit = unit
       unit.spiketrains.append(train)
       seg.spiketrains.append(train)
       ana = AnalogSignal(signal=[.01, 3.3, 9.3], units='uV',
                          sampling_rate=1*pq.Hz, channel_index=1)
       seg.analogsignals.append(ana)
seg0 = blk.segments[-1]
unit_list = rcg.units[:2]

print "---------------------------------------------------"

seg1 = seg0.construct_subsegment_by_unit(unit_list)

print "Len seg0 spiketrains = ", len(seg0.spiketrains)
print "len seg0 analogsignals = ", len(seg0.analogsignals)
print "----> seg0.analogsignals = ", seg0.analogsignals
print "seg0.analogsignals[0] = ", seg0.analogsignals[0]

print

print "Len seg1 spiketrains = ", len(seg1.spiketrains)
print "Len seg1 analogsignals = ", len(seg1.analogsignals)
print "----> seg1.analogsignals = ", seg1.analogsignals
print "seg1.analogsignals[1] = ", seg1.analogsignals[1]