本文整理汇总了Python中neo.core.analogsignal.AnalogSignal.annotate方法的典型用法代码示例。如果您正苦于以下问题:Python AnalogSignal.annotate方法的具体用法?Python AnalogSignal.annotate怎么用?Python AnalogSignal.annotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neo.core.analogsignal.AnalogSignal
的用法示例。
在下文中一共展示了AnalogSignal.annotate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestArrayMethods
# 需要导入模块: from neo.core.analogsignal import AnalogSignal [as 别名]
# 或者: from neo.core.analogsignal.AnalogSignal import annotate [as 别名]
class TestArrayMethods(unittest.TestCase):
def setUp(self):
self.signal = AnalogSignal(numpy.arange(10.0), units="nA", sampling_rate=1*kHz)
def test__slice_should_return_AnalogSignal(self):
sub = self.signal[3:8]
self.assertIsInstance(sub, AnalogSignal)
self.assertEqual(sub.size, 5)
self.assertEqual(sub.sampling_period, self.signal.sampling_period)
self.assertEqual(sub.sampling_rate, self.signal.sampling_rate)
self.assertEqual(sub.t_start,
self.signal.t_start+3*sub.sampling_period)
self.assertEqual(sub.t_stop,
sub.t_start + 5*sub.sampling_period)
# Test other attributes were copied over (in this case, defaults)
self.assertEqual(sub.file_origin, self.signal.file_origin)
self.assertEqual(sub.name, self.signal.name)
self.assertEqual(sub.description, self.signal.description)
self.assertEqual(sub.annotations, self.signal.annotations)
sub = self.signal[3:8]
self.assertEqual(sub.file_origin, self.signal.file_origin)
self.assertEqual(sub.name, self.signal.name)
self.assertEqual(sub.description, self.signal.description)
self.assertEqual(sub.annotations, self.signal.annotations)
def test__slice_with_attributes(self):
# Set attributes, slice, test that they are copied
self.signal.file_origin = 'crack.txt'
self.signal.name = 'sig'
self.signal.description = 'a signal'
self.signal.annotate(ratname='Georges')
# slice
sub = self.signal[3:8]
# tests from other slice test
self.assertIsInstance(sub, AnalogSignal)
self.assertEqual(sub.size, 5)
self.assertEqual(sub.sampling_period, self.signal.sampling_period)
self.assertEqual(sub.sampling_rate, self.signal.sampling_rate)
self.assertEqual(sub.t_start,
self.signal.t_start+3*sub.sampling_period)
self.assertEqual(sub.t_stop,
sub.t_start + 5*sub.sampling_period)
# Test other attributes were copied over (in this case, set by user)
self.assertEqual(sub.file_origin, self.signal.file_origin)
self.assertEqual(sub.name, self.signal.name)
self.assertEqual(sub.description, self.signal.description)
self.assertEqual(sub.annotations, self.signal.annotations)
self.assertEqual(sub.annotations, {'ratname': 'Georges'})
def test__slice_should_change_sampling_period(self):
sub = self.signal[:2]
self.assertEqual(sub.sampling_period, self.signal.sampling_period)
sub = self.signal[::2]
self.assertEqual(sub.sampling_period, self.signal.sampling_period * 2)
sub = self.signal[1:7:2]
self.assertEqual(sub.sampling_period, self.signal.sampling_period * 2)
def test__getitem_should_return_single_quantity(self):
self.assertEqual(self.signal[0], 0*nA)
self.assertEqual(self.signal[9], 9*nA)
self.assertRaises(IndexError, self.signal.__getitem__, 10)
def test_comparison_operators(self):
assert_arrays_equal(self.signal >= 5*nA,
numpy.array([False, False, False, False, False, True, True, True, True, True]))
assert_arrays_equal(self.signal >= 5*pA,
numpy.array([False, True, True, True, True, True, True, True, True, True]))
def test__comparison_with_inconsistent_units_should_raise_Exception(self):
self.assertRaises(ValueError, self.signal.__gt__, 5*mV)
def test_simple_statistics(self):
self.assertEqual(self.signal.max(), 9*nA)
self.assertEqual(self.signal.min(), 0*nA)
self.assertEqual(self.signal.mean(), 4.5*nA)