本文整理汇总了Python中neo.core.epoch.Epoch类的典型用法代码示例。如果您正苦于以下问题:Python Epoch类的具体用法?Python Epoch怎么用?Python Epoch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Epoch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_as_array
def test_as_array(self):
times = [2, 3, 4, 5]
durations = [0.1, 0.2, 0.3, 0.4]
epc = Epoch(times * pq.ms, durations=durations * pq.ms)
epc_as_arr = epc.as_array(units='ms')
self.assertIsInstance(epc_as_arr, np.ndarray)
assert_array_equal(times, epc_as_arr)
示例2: test__children
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)
示例3: test_as_quantity
def test_as_quantity(self):
times = [2, 3, 4, 5]
durations = [0.1, 0.2, 0.3, 0.4]
epc = Epoch(times * pq.ms, durations=durations * pq.ms)
epc_as_q = epc.as_quantity()
self.assertIsInstance(epc_as_q, pq.Quantity)
assert_array_equal(times * pq.ms, epc_as_q)
示例4: test__time_slice
def test__time_slice(self):
epc = Epoch(times=[10, 20, 30] * pq.s, durations=[10, 5, 7] * pq.ms,
labels=np.array(['btn0', 'btn1', 'btn2'], dtype='S'),
foo='bar')
epc2 = epc.time_slice(10 * pq.s, 20 * pq.s)
assert_arrays_equal(epc2.times, [10, 20] * pq.s)
assert_arrays_equal(epc2.durations, [10, 5] * pq.ms)
assert_arrays_equal(epc2.labels, np.array(['btn0','btn1'], dtype='S'))
self.assertEqual(epc.annotations, epc2.annotations)
示例5: test__pretty
def test__pretty(self):
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')
epc.annotate(test1=1.1, test0=[1, 2])
assert_neo_object_is_compliant(epc)
prepr = pretty(epc)
targ = ("Epoch\nname: '%s'\ndescription: '%s'\nannotations: %s"
"" % (epc.name, epc.description, pretty(epc.annotations)))
self.assertEqual(prepr, targ)
示例6: test__pretty
def test__pretty(self):
epc = Epoch(1.5*pq.ms, duration=20*pq.ns,
label='test epoch', name='test', description='tester',
file_origin='test.file')
epc.annotate(targ1=1.1, targ0=[1])
assert_neo_object_is_compliant(epc)
prepr = pretty(epc)
targ = ("Epoch\nname: '%s'\ndescription: '%s'\nannotations: %s" %
(epc.name, epc.description, pretty(epc.annotations)))
self.assertEqual(prepr, targ)
示例7: test__time_slice
def test__time_slice(self):
arr_ann = {'index': np.arange(3), 'test': ['a', 'b', 'c']}
epc = Epoch(times=[10, 20, 30] * pq.s, durations=[10, 5, 7] * pq.ms,
labels=np.array(['btn0', 'btn1', 'btn2'], dtype='S'), foo='bar',
array_annotations=arr_ann)
epc2 = epc.time_slice(10 * pq.s, 20 * pq.s)
assert_arrays_equal(epc2.times, [10, 20] * pq.s)
assert_arrays_equal(epc2.durations, [10, 5] * pq.ms)
assert_arrays_equal(epc2.labels, np.array(['btn0', 'btn1'], dtype='S'))
self.assertEqual(epc.annotations, epc2.annotations)
assert_arrays_equal(epc2.array_annotations['index'], np.arange(2))
assert_arrays_equal(epc2.array_annotations['test'], np.array(['a', 'b']))
self.assertIsInstance(epc2.array_annotations, ArrayDict)
示例8: test_Epoch_repr
def test_Epoch_repr(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)
targ = ('<Epoch: test epoch [email protected] ms for 20.0 ns, '
+ 'test epoch [email protected] ms for 40.0 ns, '
+ 'test epoch [email protected] ms for 60.0 ns>')
res = repr(epc)
self.assertEqual(targ, res)
示例9: test_time_slice_differnt_units
def test_time_slice_differnt_units(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)
targ = Epoch([1.5]*pq.ms, durations=[40]*pq.ns,
labels=np.array(['test epoch 2'], dtype='S'),
name='test', description='tester',
file_origin='test.file',
test1=1, **params)
targ.annotate(test1=1.1, test0=[1, 2])
assert_neo_object_is_compliant(targ)
t_start = 0.0012 * pq.s
t_stop = 0.0016 * pq.s
result = epc.time_slice(t_start, t_stop)
assert_arrays_equal(result.times, targ.times)
assert_arrays_equal(result.durations, targ.durations)
assert_arrays_equal(result.labels, targ.labels)
self.assertEqual(result.name, targ.name)
self.assertEqual(result.description, targ.description)
self.assertEqual(result.file_origin, targ.file_origin)
self.assertEqual(result.annotations['test0'], targ.annotations['test0'])
self.assertEqual(result.annotations['test1'], targ.annotations['test1'])
self.assertEqual(result.annotations['test2'], targ.annotations['test2'])
示例10: test_time_slice_empty
def test_time_slice_empty(self):
params = {'test2': 'y1', 'test3': True}
epc = Epoch([]*pq.ms, durations=[]*pq.ns,
labels=np.array([], 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)
targ = Epoch([]*pq.ms, durations=[]*pq.ns,
labels=np.array([], dtype='S'),
name='test', description='tester',
file_origin='test.file',
test1=1, **params)
targ.annotate(test1=1.1, test0=[1, 2])
assert_neo_object_is_compliant(targ)
t_start = 1.2
t_stop = 1.6
result = epc.time_slice(t_start, t_stop)
assert_arrays_equal(result.times, targ.times)
assert_arrays_equal(result.durations, targ.durations)
assert_arrays_equal(result.labels, targ.labels)
self.assertEqual(result.name, targ.name)
self.assertEqual(result.description, targ.description)
self.assertEqual(result.file_origin, targ.file_origin)
self.assertEqual(result.annotations['test0'], targ.annotations['test0'])
self.assertEqual(result.annotations['test1'], targ.annotations['test1'])
self.assertEqual(result.annotations['test2'], targ.annotations['test2'])
示例11: test_time_slice_none_both
def test_time_slice_none_both(self):
params = {'test2': 'y1', 'test3': True}
arr_ann = {'index': np.arange(3), 'test': ['a', 'b', 'c']}
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,
array_annotations=arr_ann, **params)
epc.annotate(test1=1.1, test0=[1, 2])
assert_neo_object_is_compliant(epc)
targ = 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,
array_annotations=arr_ann, **params)
targ.annotate(test1=1.1, test0=[1, 2])
assert_neo_object_is_compliant(targ)
t_start = None
t_stop = None
result = epc.time_slice(t_start, t_stop)
assert_arrays_equal(result.times, targ.times)
assert_arrays_equal(result.durations, targ.durations)
assert_arrays_equal(result.labels, targ.labels)
self.assertEqual(result.name, targ.name)
self.assertEqual(result.description, targ.description)
self.assertEqual(result.file_origin, targ.file_origin)
self.assertEqual(result.annotations['test0'], targ.annotations['test0'])
self.assertEqual(result.annotations['test1'], targ.annotations['test1'])
self.assertEqual(result.annotations['test2'], targ.annotations['test2'])
assert_arrays_equal(result.array_annotations['index'], np.array([0, 1, 2]))
assert_arrays_equal(result.array_annotations['test'], np.array(['a', 'b', 'c']))
self.assertIsInstance(result.array_annotations, ArrayDict)
示例12: test_Epoch_merge
def test_Epoch_merge(self):
params1 = {'test2': 'y1', 'test3': True}
params2 = {'test2': 'no', 'test4': False}
paramstarg = {'test2': 'yes;no', 'test3': True, 'test4': False}
arr_ann1 = {'index': np.arange(10, 13)}
arr_ann2 = {'index': np.arange(3), 'test': ['a', 'b', 'c']}
epc1 = Epoch([1.1, 1.5, 1.7] * pq.ms, durations=[20, 40, 60] * pq.us,
labels=np.array(['test epoch 1 1', 'test epoch 1 2', 'test epoch 1 3'],
dtype='S'), name='test', description='tester 1',
file_origin='test.file', test1=1, array_annotations=arr_ann1, **params1)
epc2 = Epoch([2.1, 2.5, 2.7] * pq.us, durations=[3, 5, 7] * pq.ms,
labels=np.array(['test epoch 2 1', 'test epoch 2 2', 'test epoch 2 3'],
dtype='S'), name='test', description='tester 2',
file_origin='test.file', test1=1, array_annotations=arr_ann2, **params2)
epctarg = Epoch([1.1, 1.5, 1.7, .0021, .0025, .0027] * pq.ms,
durations=[20, 40, 60, 3000, 5000, 7000] * pq.us,
labels=np.array(['test epoch 1 1', 'test epoch 1 2', 'test epoch 1 3',
'test epoch 2 1', 'test epoch 2 2', 'test epoch 2 3'],
dtype='S'),
name='test',
description='merge(tester 1, tester 2)', file_origin='test.file',
array_annotations={'index': [10, 11, 12, 0, 1, 2]}, test1=1, **paramstarg)
assert_neo_object_is_compliant(epc1)
assert_neo_object_is_compliant(epc2)
assert_neo_object_is_compliant(epctarg)
with warnings.catch_warnings(record=True) as w:
epcres = epc1.merge(epc2)
self.assertTrue(len(w), 1)
self.assertEqual(w[0].category, UserWarning)
self.assertSequenceEqual(str(w[0].message), "The following array annotations were "
"omitted, because they were only present"
" in one of the merged objects: "
"[] from the one that was merged "
"into and ['test'] from the one that "
"was merged into the other")
assert_neo_object_is_compliant(epcres)
assert_same_sub_schema(epctarg, epcres)
# Remove this, when array_annotations are added to assert_same_sub_schema
assert_arrays_equal(epcres.array_annotations['index'], np.array([10, 11, 12, 0, 1, 2]))
self.assertTrue('test' not in epcres.array_annotations)
self.assertIsInstance(epcres.array_annotations, ArrayDict)
示例13: test_epoch_creation
def test_epoch_creation(self):
params = {'test2': 'y1', 'test3': True}
epc = Epoch(1.5*pq.ms, duration=20*pq.ns,
label='test epoch', 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)
self.assertEqual(epc.time, 1.5*pq.ms)
self.assertEqual(epc.duration, 20*pq.ns)
self.assertEqual(epc.label, 'test epoch')
self.assertEqual(epc.name, 'test')
self.assertEqual(epc.description, 'tester')
self.assertEqual(epc.file_origin, 'test.file')
self.assertEqual(epc.annotations['test0'], [1, 2])
self.assertEqual(epc.annotations['test1'], 1.1)
self.assertEqual(epc.annotations['test2'], 'y1')
self.assertTrue(epc.annotations['test3'])
示例14: test_Epoch_merge
def test_Epoch_merge(self):
params1 = {'test2': 'y1', 'test3': True}
params2 = {'test2': 'no', 'test4': False}
paramstarg = {'test2': 'yes;no',
'test3': True,
'test4': False}
epc1 = Epoch([1.1, 1.5, 1.7]*pq.ms,
durations=[20, 40, 60]*pq.us,
labels=np.array(['test epoch 1 1',
'test epoch 1 2',
'test epoch 1 3'], dtype='S'),
name='test', description='tester 1',
file_origin='test.file',
test1=1, **params1)
epc2 = Epoch([2.1, 2.5, 2.7]*pq.us,
durations=[3, 5, 7]*pq.ms,
labels=np.array(['test epoch 2 1',
'test epoch 2 2',
'test epoch 2 3'], dtype='S'),
name='test', description='tester 2',
file_origin='test.file',
test1=1, **params2)
epctarg = Epoch([1.1, 1.5, 1.7, .0021, .0025, .0027]*pq.ms,
durations=[20, 40, 60, 3000, 5000, 7000]*pq.ns,
labels=np.array(['test epoch 1 1',
'test epoch 1 2',
'test epoch 1 3',
'test epoch 2 1',
'test epoch 2 2',
'test epoch 2 3'], dtype='S'),
name='test',
description='merge(tester 1, tester 2)',
file_origin='test.file',
test1=1, **paramstarg)
assert_neo_object_is_compliant(epc1)
assert_neo_object_is_compliant(epc2)
assert_neo_object_is_compliant(epctarg)
epcres = epc1.merge(epc2)
assert_neo_object_is_compliant(epcres)
assert_same_sub_schema(epctarg, epcres)
示例15: test__children
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)