def setup_units(self): params = {'testarg2': 'yes', 'testarg3': True} self.unit1 = Unit(name='test', description='tester 1', file_origin='test.file', channels_indexes=[1], testarg1=1, **params) self.unit2 = Unit(name='test', description='tester 2', file_origin='test.file', channels_indexes=[2], testarg1=1, **params) self.unit1.annotate(testarg1=1.1, testarg0=[1, 2, 3]) self.unit2.annotate(testarg11=1.1, testarg10=[1, 2, 3]) self.unit1.spiketrains = self.train1 self.unit2.spiketrains = self.train2 self.unit1.spikes = self.spike1 self.unit2.spikes = self.spike2 create_many_to_one_relationship(self.unit1) create_many_to_one_relationship(self.unit2)
def setup_units(self): params = {'testarg2': 'yes', 'testarg3': True} self.unit1 = Unit(name='test', description='tester 1', file_origin='test.file', channels_indexes=[1], testarg1=1, **params) self.unit2 = Unit(name='test', description='tester 2', file_origin='test.file', channels_indexes=[2], testarg1=1, **params) self.unit1.annotate(testarg1=1.1, testarg0=[1, 2, 3]) self.unit2.annotate(testarg11=1.1, testarg10=[1, 2, 3]) self.unit1.spiketrains = self.train1 self.unit2.spiketrains = self.train2 self.unit1.spikes = self.spike1 self.unit2.spikes = self.spike2 self.unit1.create_many_to_one_relationship() self.unit2.create_many_to_one_relationship()
def setup_unit(self): unitname11 = 'unit 1 1' unitname12 = 'unit 1 2' unitname21 = 'unit 2 1' unitname22 = 'unit 2 2' self.unitnames1 = [unitname11, unitname12] self.unitnames2 = [unitname21, unitname22, unitname11] self.unitnames = [unitname11, unitname12, unitname21, unitname22] unit11 = Unit(name=unitname11, channel_indexes=np.array([1])) unit12 = Unit(name=unitname12, channel_indexes=np.array([2])) unit21 = Unit(name=unitname21, channel_indexes=np.array([1])) unit22 = Unit(name=unitname22, channel_indexes=np.array([2])) unit23 = Unit(name=unitname11, channel_indexes=np.array([1])) self.units1 = [unit11, unit12] self.units2 = [unit21, unit22, unit23] self.units = [unit11, unit12, unit21, unit22]
def setUp(self): unitname11 = 'unit 1 1' unitname12 = 'unit 1 2' unitname21 = 'unit 2 1' unitname22 = 'unit 2 2' channame11 = 'chan 1 1' channame12 = 'chan 1 2' channame21 = 'chan 2 1' channame22 = 'chan 2 2' segname11 = 'seg 1 1' segname12 = 'seg 1 2' segname21 = 'seg 2 1' segname22 = 'seg 2 2' self.rcgname1 = 'rcg 1' self.rcgname2 = 'rcg 2' self.rcgnames = [self.rcgname1, self.rcgname2] self.unitnames1 = [unitname11, unitname12] self.unitnames2 = [unitname21, unitname22, unitname11] self.unitnames = [unitname11, unitname12, unitname21, unitname22] self.channames1 = [channame11, channame12] self.channames2 = [channame21, channame22, channame11] self.channames = [channame11, channame12, channame21, channame22] self.segnames1 = [segname11, segname12] self.segnames2 = [segname21, segname22, segname11] self.segnames = [segname11, segname12, segname21, segname22] unit11 = Unit(name=unitname11) unit12 = Unit(name=unitname12) unit21 = Unit(name=unitname21) unit22 = Unit(name=unitname22) unit23 = unit11 chan11 = RecordingChannel(name=channame11) chan12 = RecordingChannel(name=channame12) chan21 = RecordingChannel(name=channame21) chan22 = RecordingChannel(name=channame22) chan23 = chan11 seg11 = Segment(name=segname11) seg12 = Segment(name=segname12) seg21 = Segment(name=segname21) seg22 = Segment(name=segname22) seg23 = seg11 self.units1 = [unit11, unit12] self.units2 = [unit21, unit22, unit23] self.units = [unit11, unit12, unit21, unit22] self.chan1 = [chan11, chan12] self.chan2 = [chan21, chan22, chan23] self.chan = [chan11, chan12, chan21, chan22] self.seg1 = [seg11, seg12] self.seg2 = [seg21, seg22, seg23] self.seg = [seg11, seg12, seg21, seg22] self.rcg1 = RecordingChannelGroup(name=self.rcgname1) self.rcg2 = RecordingChannelGroup(name=self.rcgname2) self.rcg = [self.rcg1, self.rcg2] self.rcg1.units = self.units1 self.rcg2.units = self.units2 self.rcg1.recordingchannels = self.chan1 self.rcg2.recordingchannels = self.chan2
class TestUnit(unittest.TestCase): def setUp(self): self.setup_spikes() self.setup_spiketrains() self.setup_units() def setup_units(self): params = {'testarg2': 'yes', 'testarg3': True} self.unit1 = Unit(name='test', description='tester 1', file_origin='test.file', channels_indexes=[1], testarg1=1, **params) self.unit2 = Unit(name='test', description='tester 2', file_origin='test.file', channels_indexes=[2], testarg1=1, **params) self.unit1.annotate(testarg1=1.1, testarg0=[1, 2, 3]) self.unit2.annotate(testarg11=1.1, testarg10=[1, 2, 3]) self.unit1.spiketrains = self.train1 self.unit2.spiketrains = self.train2 self.unit1.spikes = self.spike1 self.unit2.spikes = self.spike2 create_many_to_one_relationship(self.unit1) create_many_to_one_relationship(self.unit2) def setup_spikes(self): spikename11 = 'spike 1 1' spikename12 = 'spike 1 2' spikename21 = 'spike 2 1' spikename22 = 'spike 2 2' spikedata11 = 10 * pq.ms spikedata12 = 20 * pq.ms spikedata21 = 30 * pq.s spikedata22 = 40 * pq.s self.spikenames1 = [spikename11, spikename12] self.spikenames2 = [spikename21, spikename22] self.spikenames = [spikename11, spikename12, spikename21, spikename22] spike11 = Spike(spikedata11, t_stop=100 * pq.s, name=spikename11) spike12 = Spike(spikedata12, t_stop=100 * pq.s, name=spikename12) spike21 = Spike(spikedata21, t_stop=100 * pq.s, name=spikename21) spike22 = Spike(spikedata22, t_stop=100 * pq.s, name=spikename22) self.spike1 = [spike11, spike12] self.spike2 = [spike21, spike22] self.spike = [spike11, spike12, spike21, spike22] def setup_spiketrains(self): trainname11 = 'spiketrain 1 1' trainname12 = 'spiketrain 1 2' trainname21 = 'spiketrain 2 1' trainname22 = 'spiketrain 2 2' traindata11 = np.arange(0, 10) * pq.ms traindata12 = np.arange(10, 20) * pq.ms traindata21 = np.arange(20, 30) * pq.s traindata22 = np.arange(30, 40) * pq.s self.trainnames1 = [trainname11, trainname12] self.trainnames2 = [trainname21, trainname22] self.trainnames = [trainname11, trainname12, trainname21, trainname22] train11 = SpikeTrain(traindata11, t_stop=100 * pq.s, name=trainname11) train12 = SpikeTrain(traindata12, t_stop=100 * pq.s, name=trainname12) train21 = SpikeTrain(traindata21, t_stop=100 * pq.s, name=trainname21) train22 = SpikeTrain(traindata22, t_stop=100 * pq.s, name=trainname22) self.train1 = [train11, train12] self.train2 = [train21, train22] self.train = [train11, train12, train21, train22] def test_unit_creation(self): assert_neo_object_is_compliant(self.unit1) assert_neo_object_is_compliant(self.unit2) self.assertEqual(self.unit1.name, 'test') self.assertEqual(self.unit2.name, 'test') self.assertEqual(self.unit1.description, 'tester 1') self.assertEqual(self.unit2.description, 'tester 2') self.assertEqual(self.unit1.file_origin, 'test.file') self.assertEqual(self.unit2.file_origin, 'test.file') self.assertEqual(self.unit1.annotations['testarg0'], [1, 2, 3]) self.assertEqual(self.unit2.annotations['testarg10'], [1, 2, 3]) self.assertEqual(self.unit1.annotations['testarg1'], 1.1) self.assertEqual(self.unit2.annotations['testarg1'], 1) self.assertEqual(self.unit2.annotations['testarg11'], 1.1) self.assertEqual(self.unit1.annotations['testarg2'], 'yes') self.assertEqual(self.unit2.annotations['testarg2'], 'yes') self.assertTrue(self.unit1.annotations['testarg3']) self.assertTrue(self.unit2.annotations['testarg3']) self.assertTrue(hasattr(self.unit1, 'spikes')) self.assertTrue(hasattr(self.unit2, 'spikes')) self.assertEqual(len(self.unit1.spikes), 2) self.assertEqual(len(self.unit2.spikes), 2) for res, targ in zip(self.unit1.spikes, self.spike1): self.assertEqual(res, targ) self.assertEqual(res.name, targ.name) for res, targ in zip(self.unit2.spikes, self.spike2): self.assertEqual(res, targ) self.assertEqual(res.name, targ.name) self.assertTrue(hasattr(self.unit1, 'spiketrains')) self.assertTrue(hasattr(self.unit2, 'spiketrains')) self.assertEqual(len(self.unit1.spiketrains), 2) self.assertEqual(len(self.unit2.spiketrains), 2) for res, targ in zip(self.unit1.spiketrains, self.train1): assert_arrays_equal(res, targ) self.assertEqual(res.name, targ.name) for res, targ in zip(self.unit2.spiketrains, self.train2): assert_arrays_equal(res, targ) self.assertEqual(res.name, targ.name) def test_unit_merge(self): self.unit1.merge(self.unit2) spikeres1 = [sig.name for sig in self.unit1.spikes] spikeres2 = [sig.name for sig in self.unit2.spikes] trainres1 = [sig.name for sig in self.unit1.spiketrains] trainres2 = [sig.name for sig in self.unit2.spiketrains] self.assertEqual(spikeres1, self.spikenames) self.assertEqual(spikeres2, self.spikenames2) self.assertEqual(trainres1, self.trainnames) self.assertEqual(trainres2, self.trainnames2) for res, targ in zip(self.unit1.spikes, self.spike): self.assertEqual(res, targ) for res, targ in zip(self.unit2.spikes, self.spike2): self.assertEqual(res, targ) for res, targ in zip(self.unit1.spiketrains, self.train): assert_arrays_equal(res, targ) for res, targ in zip(self.unit2.spiketrains, self.train2): assert_arrays_equal(res, targ)
class TestUnit(unittest.TestCase): def setUp(self): self.setup_spikes() self.setup_spiketrains() self.setup_units() def setup_units(self): params = {'testarg2': 'yes', 'testarg3': True} self.unit1 = Unit(name='test', description='tester 1', file_origin='test.file', channels_indexes=[1], testarg1=1, **params) self.unit2 = Unit(name='test', description='tester 2', file_origin='test.file', channels_indexes=[2], testarg1=1, **params) self.unit1.annotate(testarg1=1.1, testarg0=[1, 2, 3]) self.unit2.annotate(testarg11=1.1, testarg10=[1, 2, 3]) self.unit1.spiketrains = self.train1 self.unit2.spiketrains = self.train2 self.unit1.spikes = self.spike1 self.unit2.spikes = self.spike2 self.unit1.create_many_to_one_relationship() self.unit2.create_many_to_one_relationship() def setup_spikes(self): spikename11 = 'spike 1 1' spikename12 = 'spike 1 2' spikename21 = 'spike 2 1' spikename22 = 'spike 2 2' spikedata11 = 10 * pq.ms spikedata12 = 20 * pq.ms spikedata21 = 30 * pq.s spikedata22 = 40 * pq.s self.spikenames1 = [spikename11, spikename12] self.spikenames2 = [spikename21, spikename22] self.spikenames = [spikename11, spikename12, spikename21, spikename22] spike11 = Spike(spikedata11, t_stop=100*pq.s, name=spikename11) spike12 = Spike(spikedata12, t_stop=100*pq.s, name=spikename12) spike21 = Spike(spikedata21, t_stop=100*pq.s, name=spikename21) spike22 = Spike(spikedata22, t_stop=100*pq.s, name=spikename22) self.spike1 = [spike11, spike12] self.spike2 = [spike21, spike22] self.spike = [spike11, spike12, spike21, spike22] def setup_spiketrains(self): trainname11 = 'spiketrain 1 1' trainname12 = 'spiketrain 1 2' trainname21 = 'spiketrain 2 1' trainname22 = 'spiketrain 2 2' traindata11 = np.arange(0, 10) * pq.ms traindata12 = np.arange(10, 20) * pq.ms traindata21 = np.arange(20, 30) * pq.s traindata22 = np.arange(30, 40) * pq.s self.trainnames1 = [trainname11, trainname12] self.trainnames2 = [trainname21, trainname22] self.trainnames = [trainname11, trainname12, trainname21, trainname22] train11 = SpikeTrain(traindata11, t_stop=100*pq.s, name=trainname11) train12 = SpikeTrain(traindata12, t_stop=100*pq.s, name=trainname12) train21 = SpikeTrain(traindata21, t_stop=100*pq.s, name=trainname21) train22 = SpikeTrain(traindata22, t_stop=100*pq.s, name=trainname22) self.train1 = [train11, train12] self.train2 = [train21, train22] self.train = [train11, train12, train21, train22] def test_unit_creation(self): assert_neo_object_is_compliant(self.unit1) assert_neo_object_is_compliant(self.unit2) self.assertEqual(self.unit1.name, 'test') self.assertEqual(self.unit2.name, 'test') self.assertEqual(self.unit1.description, 'tester 1') self.assertEqual(self.unit2.description, 'tester 2') self.assertEqual(self.unit1.file_origin, 'test.file') self.assertEqual(self.unit2.file_origin, 'test.file') self.assertEqual(self.unit1.annotations['testarg0'], [1, 2, 3]) self.assertEqual(self.unit2.annotations['testarg10'], [1, 2, 3]) self.assertEqual(self.unit1.annotations['testarg1'], 1.1) self.assertEqual(self.unit2.annotations['testarg1'], 1) self.assertEqual(self.unit2.annotations['testarg11'], 1.1) self.assertEqual(self.unit1.annotations['testarg2'], 'yes') self.assertEqual(self.unit2.annotations['testarg2'], 'yes') self.assertTrue(self.unit1.annotations['testarg3']) self.assertTrue(self.unit2.annotations['testarg3']) self.assertTrue(hasattr(self.unit1, 'spikes')) self.assertTrue(hasattr(self.unit2, 'spikes')) self.assertEqual(len(self.unit1.spikes), 2) self.assertEqual(len(self.unit2.spikes), 2) for res, targ in zip(self.unit1.spikes, self.spike1): self.assertEqual(res, targ) self.assertEqual(res.name, targ.name) for res, targ in zip(self.unit2.spikes, self.spike2): self.assertEqual(res, targ) self.assertEqual(res.name, targ.name) self.assertTrue(hasattr(self.unit1, 'spiketrains')) self.assertTrue(hasattr(self.unit2, 'spiketrains')) self.assertEqual(len(self.unit1.spiketrains), 2) self.assertEqual(len(self.unit2.spiketrains), 2) for res, targ in zip(self.unit1.spiketrains, self.train1): assert_arrays_equal(res, targ) self.assertEqual(res.name, targ.name) for res, targ in zip(self.unit2.spiketrains, self.train2): assert_arrays_equal(res, targ) self.assertEqual(res.name, targ.name) def test_unit_merge(self): self.unit1.merge(self.unit2) spikeres1 = [sig.name for sig in self.unit1.spikes] spikeres2 = [sig.name for sig in self.unit2.spikes] trainres1 = [sig.name for sig in self.unit1.spiketrains] trainres2 = [sig.name for sig in self.unit2.spiketrains] self.assertEqual(spikeres1, self.spikenames) self.assertEqual(spikeres2, self.spikenames2) self.assertEqual(trainres1, self.trainnames) self.assertEqual(trainres2, self.trainnames2) for res, targ in zip(self.unit1.spikes, self.spike): self.assertEqual(res, targ) for res, targ in zip(self.unit2.spikes, self.spike2): self.assertEqual(res, targ) for res, targ in zip(self.unit1.spiketrains, self.train): assert_arrays_equal(res, targ) for res, targ in zip(self.unit2.spiketrains, self.train2): assert_arrays_equal(res, targ) def test__children(self): rcg = RecordingChannelGroup(name='rcg1') rcg.units = [self.unit1] rcg.create_many_to_one_relationship() self.assertEqual(self.unit1._container_child_objects, ()) self.assertEqual(self.unit1._data_child_objects, ('Spike', 'SpikeTrain')) self.assertEqual(self.unit1._single_parent_objects, ('RecordingChannelGroup',)) self.assertEqual(self.unit1._multi_child_objects, ()) self.assertEqual(self.unit1._multi_parent_objects, ()) self.assertEqual(self.unit1._child_properties, ()) self.assertEqual(self.unit1._single_child_objects, ('Spike', 'SpikeTrain')) self.assertEqual(self.unit1._container_child_containers, ()) self.assertEqual(self.unit1._data_child_containers, ('spikes', 'spiketrains')) self.assertEqual(self.unit1._single_child_containers, ('spikes', 'spiketrains')) self.assertEqual(self.unit1._single_parent_containers, ('recordingchannelgroup',)) self.assertEqual(self.unit1._multi_child_containers, ()) self.assertEqual(self.unit1._multi_parent_containers, ()) self.assertEqual(self.unit1._child_objects, ('Spike', 'SpikeTrain')) self.assertEqual(self.unit1._child_containers, ('spikes', 'spiketrains')) self.assertEqual(self.unit1._parent_objects, ('RecordingChannelGroup',)) self.assertEqual(self.unit1._parent_containers, ('recordingchannelgroup',)) self.assertEqual(len(self.unit1.children), len(self.spike1) + len(self.train1)) self.assertEqual(self.unit1.children[0].name, self.spikenames1[0]) self.assertEqual(self.unit1.children[1].name, self.spikenames1[1]) self.assertEqual(self.unit1.children[2].name, self.trainnames1[0]) self.assertEqual(self.unit1.children[3].name, self.trainnames1[1]) self.assertEqual(len(self.unit1.parents), 1) self.assertEqual(self.unit1.parents[0].name, 'rcg1') self.unit1.create_many_to_one_relationship() assert_neo_object_is_compliant(self.unit1)