本文整理汇总了Python中neo.core.event.Event.segment方法的典型用法代码示例。如果您正苦于以下问题:Python Event.segment方法的具体用法?Python Event.segment怎么用?Python Event.segment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neo.core.event.Event
的用法示例。
在下文中一共展示了Event.segment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_epoch
# 需要导入模块: from neo.core.event import Event [as 别名]
# 或者: from neo.core.event.Event import segment [as 别名]
def test_to_epoch(self):
seg = Segment(name="test")
event = Event(times=np.array([5.0, 12.0, 23.0, 45.0]), units="ms",
labels=np.array(["A", "B", "C", "D"]))
event.segment = seg
# Mode 1
epoch = event.to_epoch()
self.assertIsInstance(epoch, Epoch)
assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0]))
assert_array_equal(epoch.durations.magnitude, np.array([7.0, 11.0, 22.0]))
assert_array_equal(epoch.labels, np.array(['A-B', 'B-C', 'C-D']))
# Mode 2
epoch = event.to_epoch(pairwise=True)
assert_array_equal(epoch.times.magnitude, np.array([5.0, 23.0]))
assert_array_equal(epoch.durations.magnitude, np.array([7.0, 22.0]))
assert_array_equal(epoch.labels, np.array(['A-B', 'C-D']))
# Mode 3 (scalar)
epoch = event.to_epoch(durations=2.0 * pq.ms)
assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0, 45.0]))
assert_array_equal(epoch.durations.magnitude, np.array([2.0, 2.0, 2.0, 2.0]))
self.assertEqual(epoch.durations.size, 4)
assert_array_equal(epoch.labels, np.array(['A', 'B', 'C', 'D']))
# Mode 3 (array)
epoch = event.to_epoch(durations=np.array([2.0, 3.0, 4.0, 5.0]) * pq.ms)
assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0, 45.0]))
assert_array_equal(epoch.durations.magnitude, np.array([2.0, 3.0, 4.0, 5.0]))
assert_array_equal(epoch.labels, np.array(['A', 'B', 'C', 'D']))
# Error conditions
self.assertRaises(ValueError, event.to_epoch, pairwise=True, durations=2.0 * pq.ms)
odd_event = Event(times=np.array([5.0, 12.0, 23.0]), units="ms",
labels=np.array(["A", "B", "C"]))
self.assertRaises(ValueError, odd_event.to_epoch, pairwise=True)