def setUp(self): params = {'test2': 'y1', 'test3': True} self.sampling_rate1 = .1*pq.Hz self.left_sweep1 = 2.*pq.s self.spike1 = Spike(1.5*pq.ms, waveform=[[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]]*pq.mV, sampling_rate=self.sampling_rate1, left_sweep=self.left_sweep1, name='test', description='tester', file_origin='test.file', test1=1, **params) self.spike1.annotate(test1=1.1, test0=[1, 2])
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(self): params = {"testarg2": "yes", "testarg3": True} self.sampling_rate1 = 0.1 * pq.Hz self.left_sweep1 = 2.0 * pq.s self.spike1 = Spike( 1.5 * pq.ms, waveform=[[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]] * pq.mV, sampling_rate=self.sampling_rate1, left_sweep=self.left_sweep1, name="test", description="tester", file_origin="test.file", testarg1=1, **params ) self.spike1.annotate(testarg1=1.1, testarg0=[1, 2, 3])
class TestSpike(unittest.TestCase): def setUp(self): params = {"testarg2": "yes", "testarg3": True} self.sampling_rate1 = 0.1 * pq.Hz self.left_sweep1 = 2.0 * pq.s self.spike1 = Spike( 1.5 * pq.ms, waveform=[[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]] * pq.mV, sampling_rate=self.sampling_rate1, left_sweep=self.left_sweep1, name="test", description="tester", file_origin="test.file", testarg1=1, **params ) self.spike1.annotate(testarg1=1.1, testarg0=[1, 2, 3]) def test_spike_creation(self): assert_neo_object_is_compliant(self.spike1) self.assertEqual(self.spike1.time, 1.5 * pq.ms) assert_arrays_equal(self.spike1.waveform, [[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]] * pq.mV) self.assertEqual(self.spike1.sampling_rate, 0.1 * pq.Hz) self.assertEqual(self.spike1.left_sweep, 2.0 * pq.s) self.assertEqual(self.spike1.description, "tester") self.assertEqual(self.spike1.file_origin, "test.file") self.assertEqual(self.spike1.annotations["testarg0"], [1, 2, 3]) self.assertEqual(self.spike1.annotations["testarg1"], 1.1) self.assertEqual(self.spike1.annotations["testarg2"], "yes") self.assertTrue(self.spike1.annotations["testarg3"]) def test__duration(self): result1 = self.spike1.duration self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.duration self.spike1.sampling_rate = self.sampling_rate1 self.spike1.waveform = None assert_neo_object_is_compliant(self.spike1) result3 = self.spike1.duration self.assertEqual(result1, 30.0 / pq.Hz) self.assertEqual(result1.units, 1.0 / pq.Hz) self.assertEqual(result2, None) self.assertEqual(result3, None) def test__sampling_period(self): result1 = self.spike1.sampling_period self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.sampling_period self.spike1.sampling_rate = self.sampling_rate1 self.spike1.sampling_period = 10.0 * pq.ms assert_neo_object_is_compliant(self.spike1) result3a = self.spike1.sampling_period result3b = self.spike1.sampling_rate self.spike1.sampling_period = None result4a = self.spike1.sampling_period result4b = self.spike1.sampling_rate self.assertEqual(result1, 10.0 / pq.Hz) self.assertEqual(result1.units, 1.0 / pq.Hz) self.assertEqual(result2, None) self.assertEqual(result3a, 10.0 * pq.ms) self.assertEqual(result3a.units, 1.0 * pq.ms) self.assertEqual(result3b, 0.1 / pq.ms) self.assertEqual(result3b.units, 1.0 / pq.ms) self.assertEqual(result4a, None) self.assertEqual(result4b, None) def test__right_sweep(self): result1 = self.spike1.right_sweep self.spike1.left_sweep = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.right_sweep self.spike1.left_sweep = self.left_sweep1 self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result3 = self.spike1.right_sweep self.spike1.sampling_rate = self.sampling_rate1 self.spike1.waveform = None assert_neo_object_is_compliant(self.spike1) result4 = self.spike1.right_sweep self.assertEqual(result1, 32.0 * pq.s) self.assertEqual(result1.units, 1.0 * pq.s) self.assertEqual(result2, None) self.assertEqual(result3, None) self.assertEqual(result4, None) 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)
class TestSpike(unittest.TestCase): def setUp(self): params = {'test2': 'y1', 'test3': True} self.sampling_rate1 = .1*pq.Hz self.left_sweep1 = 2.*pq.s self.spike1 = Spike(1.5*pq.ms, waveform=[[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]]*pq.mV, sampling_rate=self.sampling_rate1, left_sweep=self.left_sweep1, name='test', description='tester', file_origin='test.file', test1=1, **params) self.spike1.annotate(test1=1.1, test0=[1, 2]) def test_spike_creation(self): assert_neo_object_is_compliant(self.spike1) self.assertEqual(self.spike1.time, 1.5*pq.ms) assert_arrays_equal(self.spike1.waveform, [[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]]*pq.mV) self.assertEqual(self.spike1.sampling_rate, .1*pq.Hz) self.assertEqual(self.spike1.left_sweep, 2.*pq.s) self.assertEqual(self.spike1.description, 'tester') self.assertEqual(self.spike1.file_origin, 'test.file') self.assertEqual(self.spike1.annotations['test0'], [1, 2]) self.assertEqual(self.spike1.annotations['test1'], 1.1) self.assertEqual(self.spike1.annotations['test2'], 'y1') self.assertTrue(self.spike1.annotations['test3']) def test__duration(self): result1 = self.spike1.duration self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.duration self.spike1.sampling_rate = self.sampling_rate1 self.spike1.waveform = None assert_neo_object_is_compliant(self.spike1) result3 = self.spike1.duration self.assertEqual(result1, 30./pq.Hz) self.assertEqual(result1.units, 1./pq.Hz) self.assertEqual(result2, None) self.assertEqual(result3, None) def test__sampling_period(self): result1 = self.spike1.sampling_period self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.sampling_period self.spike1.sampling_rate = self.sampling_rate1 self.spike1.sampling_period = 10.*pq.ms assert_neo_object_is_compliant(self.spike1) result3a = self.spike1.sampling_period result3b = self.spike1.sampling_rate self.spike1.sampling_period = None result4a = self.spike1.sampling_period result4b = self.spike1.sampling_rate self.assertEqual(result1, 10./pq.Hz) self.assertEqual(result1.units, 1./pq.Hz) self.assertEqual(result2, None) self.assertEqual(result3a, 10.*pq.ms) self.assertEqual(result3a.units, 1.*pq.ms) self.assertEqual(result3b, .1/pq.ms) self.assertEqual(result3b.units, 1./pq.ms) self.assertEqual(result4a, None) self.assertEqual(result4b, None) def test__right_sweep(self): result1 = self.spike1.right_sweep self.spike1.left_sweep = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.right_sweep self.spike1.left_sweep = self.left_sweep1 self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result3 = self.spike1.right_sweep self.spike1.sampling_rate = self.sampling_rate1 self.spike1.waveform = None assert_neo_object_is_compliant(self.spike1) result4 = self.spike1.right_sweep self.assertEqual(result1, 32.*pq.s) self.assertEqual(result1.units, 1.*pq.s) self.assertEqual(result2, None) self.assertEqual(result3, None) self.assertEqual(result4, None) 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) @unittest.skipUnless(HAVE_IPYTHON, "requires IPython") def test__pretty(self): ann = {'targ0': self.spike1.annotations['test0']} self.spike1.annotations = ann res = pretty(self.spike1) targ = ("Spike " + "name: '%s' description: '%s' annotations: %s" % (self.spike1.name, self.spike1.description, ann)) self.assertEqual(res, targ)
class TestSpike(unittest.TestCase): def setUp(self): params = {'testarg2': 'yes', 'testarg3': True} self.sampling_rate1 = .1 * pq.Hz self.left_sweep1 = 2. * pq.s self.spike1 = Spike(1.5 * pq.ms, waveform=[[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]] * pq.mV, sampling_rate=self.sampling_rate1, left_sweep=self.left_sweep1, name='test', description='tester', file_origin='test.file', testarg1=1, **params) self.spike1.annotate(testarg1=1.1, testarg0=[1, 2, 3]) def test_spike_creation(self): assert_neo_object_is_compliant(self.spike1) self.assertEqual(self.spike1.time, 1.5 * pq.ms) assert_arrays_equal(self.spike1.waveform, [[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]] * pq.mV) self.assertEqual(self.spike1.sampling_rate, .1 * pq.Hz) self.assertEqual(self.spike1.left_sweep, 2. * pq.s) self.assertEqual(self.spike1.description, 'tester') self.assertEqual(self.spike1.file_origin, 'test.file') self.assertEqual(self.spike1.annotations['testarg0'], [1, 2, 3]) self.assertEqual(self.spike1.annotations['testarg1'], 1.1) self.assertEqual(self.spike1.annotations['testarg2'], 'yes') self.assertTrue(self.spike1.annotations['testarg3']) def test__duration(self): result1 = self.spike1.duration self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.duration self.spike1.sampling_rate = self.sampling_rate1 self.spike1.waveform = None assert_neo_object_is_compliant(self.spike1) result3 = self.spike1.duration self.assertEqual(result1, 30. / pq.Hz) self.assertEqual(result1.units, 1. / pq.Hz) self.assertEqual(result2, None) self.assertEqual(result3, None) def test__sampling_period(self): result1 = self.spike1.sampling_period self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.sampling_period self.spike1.sampling_rate = self.sampling_rate1 self.spike1.sampling_period = 10. * pq.ms assert_neo_object_is_compliant(self.spike1) result3a = self.spike1.sampling_period result3b = self.spike1.sampling_rate self.spike1.sampling_period = None result4a = self.spike1.sampling_period result4b = self.spike1.sampling_rate self.assertEqual(result1, 10. / pq.Hz) self.assertEqual(result1.units, 1. / pq.Hz) self.assertEqual(result2, None) self.assertEqual(result3a, 10. * pq.ms) self.assertEqual(result3a.units, 1. * pq.ms) self.assertEqual(result3b, .1 / pq.ms) self.assertEqual(result3b.units, 1. / pq.ms) self.assertEqual(result4a, None) self.assertEqual(result4b, None) def test__right_sweep(self): result1 = self.spike1.right_sweep self.spike1.left_sweep = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.right_sweep self.spike1.left_sweep = self.left_sweep1 self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result3 = self.spike1.right_sweep self.spike1.sampling_rate = self.sampling_rate1 self.spike1.waveform = None assert_neo_object_is_compliant(self.spike1) result4 = self.spike1.right_sweep self.assertEqual(result1, 32. * pq.s) self.assertEqual(result1.units, 1. * pq.s) self.assertEqual(result2, None) self.assertEqual(result3, None) self.assertEqual(result4, None)
class TestSpike(unittest.TestCase): def setUp(self): params = {'testarg2': 'yes', 'testarg3': True} self.sampling_rate1 = .1*pq.Hz self.left_sweep1 = 2.*pq.s self.spike1 = Spike(1.5*pq.ms, waveform=[[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]]*pq.mV, sampling_rate=self.sampling_rate1, left_sweep=self.left_sweep1, name='test', description='tester', file_origin='test.file', testarg1=1, **params) self.spike1.annotate(testarg1=1.1, testarg0=[1, 2, 3]) def test_spike_creation(self): assert_neo_object_is_compliant(self.spike1) self.assertEqual(self.spike1.time, 1.5*pq.ms) assert_arrays_equal(self.spike1.waveform, [[1.1, 1.5, 1.7], [2.2, 2.6, 2.8]]*pq.mV) self.assertEqual(self.spike1.sampling_rate, .1*pq.Hz) self.assertEqual(self.spike1.left_sweep, 2.*pq.s) self.assertEqual(self.spike1.description, 'tester') self.assertEqual(self.spike1.file_origin, 'test.file') self.assertEqual(self.spike1.annotations['testarg0'], [1, 2, 3]) self.assertEqual(self.spike1.annotations['testarg1'], 1.1) self.assertEqual(self.spike1.annotations['testarg2'], 'yes') self.assertTrue(self.spike1.annotations['testarg3']) def test__duration(self): result1 = self.spike1.duration self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.duration self.spike1.sampling_rate = self.sampling_rate1 self.spike1.waveform = None assert_neo_object_is_compliant(self.spike1) result3 = self.spike1.duration self.assertEqual(result1, 30./pq.Hz) self.assertEqual(result1.units, 1./pq.Hz) self.assertEqual(result2, None) self.assertEqual(result3, None) def test__sampling_period(self): result1 = self.spike1.sampling_period self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.sampling_period self.spike1.sampling_rate = self.sampling_rate1 self.spike1.sampling_period = 10.*pq.ms assert_neo_object_is_compliant(self.spike1) result3a = self.spike1.sampling_period result3b = self.spike1.sampling_rate self.spike1.sampling_period = None result4a = self.spike1.sampling_period result4b = self.spike1.sampling_rate self.assertEqual(result1, 10./pq.Hz) self.assertEqual(result1.units, 1./pq.Hz) self.assertEqual(result2, None) self.assertEqual(result3a, 10.*pq.ms) self.assertEqual(result3a.units, 1.*pq.ms) self.assertEqual(result3b, .1/pq.ms) self.assertEqual(result3b.units, 1./pq.ms) self.assertEqual(result4a, None) self.assertEqual(result4b, None) def test__right_sweep(self): result1 = self.spike1.right_sweep self.spike1.left_sweep = None assert_neo_object_is_compliant(self.spike1) result2 = self.spike1.right_sweep self.spike1.left_sweep = self.left_sweep1 self.spike1.sampling_rate = None assert_neo_object_is_compliant(self.spike1) result3 = self.spike1.right_sweep self.spike1.sampling_rate = self.sampling_rate1 self.spike1.waveform = None assert_neo_object_is_compliant(self.spike1) result4 = self.spike1.right_sweep self.assertEqual(result1, 32.*pq.s) self.assertEqual(result1.units, 1.*pq.s) self.assertEqual(result2, None) self.assertEqual(result3, None) self.assertEqual(result4, None) 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)