本文整理匯總了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)