• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python analogsignal.AnalogSignal类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neo.core.analogsignal.AnalogSignal的典型用法代码示例。如果您正苦于以下问题:Python AnalogSignal类的具体用法?Python AnalogSignal怎么用?Python AnalogSignal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了AnalogSignal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __getitem__

 def __getitem__(self, i):
     '''
     Get the item or slice :attr:`i`.
     '''
     obj = super(BaseAnalogSignal, self).__getitem__(i)
     if isinstance(i, int):
         return obj
     elif isinstance(i, tuple):
         j, k = i
         if isinstance(k, int):
             if isinstance(j, slice):  # extract an AnalogSignal
                 obj = AnalogSignal(obj, sampling_rate=self.sampling_rate)
                 if j.start:
                     obj.t_start = (self.t_start +
                                    j.start * self.sampling_period)
             # return a Quantity (for some reason quantities does not
             # return a Quantity in this case)
             elif isinstance(j, int):
                 obj = pq.Quantity(obj, units=self.units)
             return obj
         elif isinstance(j, int):  # extract a quantity array
             # should be a better way to do this
             obj = pq.Quantity(np.array(obj), units=obj.units)
             return obj
         else:
             return obj
     elif isinstance(i, slice):
         if i.start:
             obj.t_start = self.t_start + i.start * self.sampling_period
         return obj
     else:
         raise IndexError("index should be an integer, tuple or slice")
开发者ID:bal47,项目名称:python-neo,代码行数:32,代码来源:analogsignalarray.py


示例2: test__pickle

    def test__pickle(self):
        signal1 = AnalogSignal([1, 2, 3, 4], sampling_period=1 * pq.ms, units=pq.S)
        signal1.annotations['index'] = 2
        signal1.channel_index = ChannelIndex(index=[0])
        signal1.array_annotate(**{'anno1': [23], 'anno2': ['A']})

        fobj = open('./pickle', 'wb')
        pickle.dump(signal1, fobj)
        fobj.close()

        fobj = open('./pickle', 'rb')
        try:
            signal2 = pickle.load(fobj)
        except ValueError:
            signal2 = None

        assert_array_equal(signal1, signal2)
        assert_array_equal(signal2.channel_index.index, np.array([0]))
        assert_array_equal(signal2.array_annotations['anno1'], np.array([23]))
        self.assertIsInstance(signal2.array_annotations, ArrayDict)
        # Make sure the dict can perform correct checks after unpickling
        signal2.array_annotations['anno3'] = [2]
        with self.assertRaises(ValueError):
            signal2.array_annotations['anno4'] = [2, 1]
        fobj.close()
        os.remove('./pickle')
开发者ID:INM-6,项目名称:python-neo,代码行数:26,代码来源:test_analogsignal.py


示例3: test__merge

    def test__merge(self):
        self.signal1.description = None
        self.signal1.file_origin = None
        assert_neo_object_is_compliant(self.signal1)

        data3 = np.arange(1000.0, 1066.0).reshape((11, 6)) * pq.uV
        data3scale = data3.rescale(self.data1quant.units)

        signal2 = AnalogSignal(self.data1quant,
                                    sampling_rate=1*pq.kHz,
                                    name='signal2',
                                    description='test signal',
                                    file_origin='testfile.txt')
        signal3 = AnalogSignal(data3,
                                    units="uV", sampling_rate=1*pq.kHz,
                                    name='signal3',
                                    description='test signal',
                                    file_origin='testfile.txt')
        signal4 = AnalogSignal(data3,
                                    units="uV", sampling_rate=1*pq.kHz,
                                    name='signal4',
                                    description='test signal',
                                    file_origin='testfile.txt')
        
        merged13 = self.signal1.merge(signal3)        
        merged23 = signal2.merge(signal3)
        merged24 = signal2.merge(signal4)
        mergeddata13 = np.array(merged13)
        mergeddata23 = np.array(merged23)
        mergeddata24 = np.array(merged24)

        targdata13 = np.hstack([self.data1quant, data3scale])
        targdata23 = np.hstack([self.data1quant, data3scale])
        targdata24 = np.hstack([self.data1quant, data3scale])

        assert_neo_object_is_compliant(signal2)
        assert_neo_object_is_compliant(signal3)
        assert_neo_object_is_compliant(merged13)
        assert_neo_object_is_compliant(merged23)
        assert_neo_object_is_compliant(merged24)

        self.assertEqual(merged13[0, 4], 4*pq.mV)
        self.assertEqual(merged23[0, 4], 4*pq.mV)
        self.assertEqual(merged13[0, 5], 1*pq.mV)
        self.assertEqual(merged23[0, 5], 1*pq.mV)
        self.assertEqual(merged13[10, 10], 1.065*pq.mV)
        self.assertEqual(merged23[10, 10], 1.065*pq.mV)
        self.assertEqual(merged13.t_stop, self.signal1.t_stop)
        self.assertEqual(merged23.t_stop, self.signal1.t_stop)

        self.assertEqual(merged13.name, 'merge(spam, signal3)')
        self.assertEqual(merged23.name, 'merge(signal2, signal3)')
        self.assertEqual(merged13.description, 'merge(None, test signal)')
        self.assertEqual(merged23.description, 'test signal')
        self.assertEqual(merged13.file_origin, 'merge(None, testfile.txt)')
        self.assertEqual(merged23.file_origin, 'testfile.txt')

        assert_arrays_equal(mergeddata13, targdata13)
        assert_arrays_equal(mergeddata23, targdata23)
        assert_arrays_equal(mergeddata24, targdata24)
开发者ID:msenoville,项目名称:python-neo,代码行数:60,代码来源:test_analogsignalarray.py


示例4: test__slice_should_modify_linked_channelindex

 def test__slice_should_modify_linked_channelindex(self):
     n = 8  # number of channels
     signal = AnalogSignal(np.arange(n * 100.0).reshape(100, n),
                           sampling_rate=1*pq.kHz,
                           units="mV")
     self.assertEqual(signal.shape, (100, n))
     signal.channel_index = ChannelIndex(index=np.arange(n, dtype=int),
                                         channel_names=["channel{0}".format(i) for i in range(n)])
     odd_channels = signal[:, 1::2]
     self.assertEqual(odd_channels.shape, (100, n//2))
     assert_array_equal(odd_channels.channel_index.index, np.arange(n//2, dtype=int))
     assert_array_equal(odd_channels.channel_index.channel_names, ["channel{0}".format(i) for i in range(1, n, 2)])
     assert_array_equal(signal.channel_index.channel_names, ["channel{0}".format(i) for i in range(n)])
开发者ID:mpsonntag,项目名称:python-neo,代码行数:13,代码来源:test_analogsignal.py


示例5: setUp

 def setUp(self):
     self.data1 = np.arange(55.0).reshape((11, 5))
     self.data1quant = self.data1 * pq.nA
     self.arr_ann1 = {'anno1': np.arange(5), 'anno2': ['a', 'b', 'c', 'd', 'e']}
     self.signal1 = AnalogSignal(self.data1quant, sampling_rate=1 * pq.kHz, name='spam',
                                 description='eggs', file_origin='testfile.txt',
                                 array_annotations=self.arr_ann1, arg1='test')
     self.data2 = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]).T
     self.data2quant = self.data2 * pq.mV
     self.arr_ann2 = {'anno1': [10, 11], 'anno2': ['k', 'l']}
     self.signal2 = AnalogSignal(self.data2quant, sampling_rate=1.0 * pq.Hz, name='spam',
                                 description='eggs', file_origin='testfile.txt',
                                 array_annotations=self.arr_ann2, arg1='test')
开发者ID:INM-6,项目名称:python-neo,代码行数:13,代码来源:test_analogsignalarray.py


示例6: setUp

 def setUp(self):
     self.data1 = np.arange(55.0).reshape((11, 5))
     self.data1quant = self.data1 * pq.nA
     self.signal1 = AnalogSignal(self.data1quant,
                                      sampling_rate=1*pq.kHz,
                                      name='spam', description='eggs',
                                      file_origin='testfile.txt',
                                      arg1='test')
     self.data2 = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]).T
     self.data2quant = self.data2 * pq.mV
     self.signal2 = AnalogSignal(self.data2quant,
                                      sampling_rate=1.0*pq.Hz,
                                      name='spam', description='eggs',
                                      file_origin='testfile.txt',
                                      arg1='test')
开发者ID:msenoville,项目名称:python-neo,代码行数:15,代码来源:test_analogsignalarray.py


示例7: test_splice_2channels_inplace

 def test_splice_2channels_inplace(self):
     arr_ann1 = {'index': np.arange(10, 12)}
     arr_ann2 = {'index': np.arange(2), 'test': ['a', 'b']}
     signal = AnalogSignal(np.arange(20.0).reshape((10, 2)), sampling_rate=1 * pq.kHz,
                           units="mV", array_annotations=arr_ann1)
     signal_for_splicing = AnalogSignal(np.array([[0.1, 0.0], [0.2, 0.0], [0.3, 0.0]]),
                                        t_start=3 * pq.ms, array_annotations=arr_ann2,
                                        sampling_rate=self.signal1.sampling_rate, units=pq.V)
     result = signal.splice(signal_for_splicing, copy=False)
     assert_array_equal(result.magnitude, np.array(
         [[0.0, 1.0], [2.0, 3.0], [4.0, 5.0], [100.0, 0.0], [200.0, 0.0], [300.0, 0.0],
          [12.0, 13.0], [14.0, 15.0], [16.0, 17.0], [18.0, 19.0]]))
     assert_array_equal(signal, result)  # in-place
     # Array annotations are taken from the main signal
     assert_array_equal(result.array_annotations['index'], np.arange(10, 12))
     self.assertIsInstance(result.array_annotations, ArrayDict)
     self.assertNotIn('test', result.array_annotations)
开发者ID:INM-6,项目名称:python-neo,代码行数:17,代码来源:test_analogsignal.py


示例8: test__pickle

    def test__pickle(self):
        a = AnalogSignal([1,2,3,4],sampling_period=1*pq.ms,units=pq.S)
        a.annotations['index'] = 2

        f = open('./pickle','wb')
        pickle.dump(a,f)
        f.close()

        f = open('./pickle','rb')
        try:
            b = pickle.load(f)
        except ValueError:
            b = None

        assert_arrays_equal(a, b)
        f.close()
        os.remove('./pickle')
开发者ID:michaelfsp,项目名称:python-neo,代码行数:17,代码来源:test_analogsignal.py


示例9: setUp

 def setUp(self):
     self.data1 = np.arange(10.0)
     self.data1quant = self.data1 * pq.nA
     self.signal1 = AnalogSignal(self.data1quant, sampling_rate=1*pq.kHz,
                                      name='spam', description='eggs',
                                      file_origin='testfile.txt', arg1='test')
     self.signal1.segment = Segment()
     self.signal1.channel_index = ChannelIndex(index=[0])
开发者ID:msenoville,项目名称:python-neo,代码行数:8,代码来源:test_analogsignal.py


示例10: test__pickle

    def test__pickle(self):
        signal1 = AnalogSignal([1, 2, 3, 4], sampling_period=1*pq.ms,
                                    units=pq.S)
        signal1.annotations['index'] = 2

        fobj = open('./pickle', 'wb')
        pickle.dump(signal1, fobj)
        fobj.close()

        fobj = open('./pickle', 'rb')
        try:
            signal2 = pickle.load(fobj)
        except ValueError:
            signal2 = None

        assert_array_equal(signal1, signal2)
        fobj.close()
        os.remove('./pickle')
开发者ID:CINPLA,项目名称:python-neo,代码行数:18,代码来源:test_analogsignal.py


示例11: test__pickle

    def test__pickle(self):
        signal1 = AnalogSignal([1, 2, 3, 4], sampling_period=1 * pq.ms, units=pq.S, channel_index=42)
        signal1.annotations["index"] = 2

        fobj = open("./pickle", "wb")
        pickle.dump(signal1, fobj)
        fobj.close()

        fobj = open("./pickle", "rb")
        try:
            signal2 = pickle.load(fobj)
        except ValueError:
            signal2 = None

        assert_arrays_equal(signal1, signal2)
        self.assertEqual(signal1.channel_index, signal2.channel_index, 42)
        fobj.close()
        os.remove("./pickle")
开发者ID:NeuroArchive,项目名称:python-neo,代码行数:18,代码来源:test_analogsignal.py


示例12: setUp

 def setUp(self):
     self.data1 = np.arange(10.0)
     self.data1quant = self.data1 * pq.nA
     self.signal1 = AnalogSignal(
         self.data1quant,
         sampling_rate=1 * pq.kHz,
         name="spam",
         description="eggs",
         file_origin="testfile.txt",
         arg1="test",
     )
开发者ID:NeuroArchive,项目名称:python-neo,代码行数:11,代码来源:test_analogsignal.py


示例13: test_splice_2channels_inplace

 def test_splice_2channels_inplace(self):
     signal = AnalogSignal(np.arange(20.0).reshape((10, 2)),
                           sampling_rate=1 * pq.kHz,
                           units="mV")
     signal_for_splicing = AnalogSignal(np.array([[0.1, 0.0], [0.2, 0.0], [0.3, 0.0]]),
                                        t_start=3*pq.ms,
                                        sampling_rate=self.signal1.sampling_rate,
                                        units=pq.V)
     result = signal.splice(signal_for_splicing, copy=False)
     assert_array_equal(result.magnitude,
                        np.array([[0.0, 1.0],
                                  [2.0, 3.0],
                                  [4.0, 5.0],
                                  [100.0, 0.0],
                                  [200.0, 0.0],
                                  [300.0, 0.0],
                                  [12.0, 13.0],
                                  [14.0, 15.0],
                                  [16.0, 17.0],
                                  [18.0, 19.0]]))
     assert_array_equal(signal, result)  # in-place
开发者ID:msenoville,项目名称:python-neo,代码行数:21,代码来源:test_analogsignal.py


示例14: TestAnalogSignalArrayMethods

class TestAnalogSignalArrayMethods(unittest.TestCase):
    def setUp(self):
        self.data1 = np.arange(10.0)
        self.data1quant = self.data1 * pq.nA
        self.signal1 = AnalogSignal(self.data1quant, sampling_rate=1*pq.kHz,
                                         name='spam', description='eggs',
                                         file_origin='testfile.txt', arg1='test')
        self.signal1.segment = Segment()
        self.signal1.channel_index = ChannelIndex(index=[0])

    def test__compliant(self):
        assert_neo_object_is_compliant(self.signal1)

    def test__slice_should_return_AnalogSignalArray(self):
        # slice
        for index in (0, np.int64(0)):
            result = self.signal1[3:8, index]
            self.assertIsInstance(result, AnalogSignal)
            assert_neo_object_is_compliant(result)
            self.assertEqual(result.name, 'spam')         # should slicing really preserve name and description?
            self.assertEqual(result.description, 'eggs')  # perhaps these should be modified to indicate the slice?
            self.assertEqual(result.file_origin, 'testfile.txt')
            self.assertEqual(result.annotations, {'arg1': 'test'})

            self.assertEqual(result.size, 5)
            self.assertEqual(result.sampling_period, self.signal1.sampling_period)
            self.assertEqual(result.sampling_rate, self.signal1.sampling_rate)
            self.assertEqual(result.t_start,
                             self.signal1.t_start+3*result.sampling_period)
            self.assertEqual(result.t_stop,
                             result.t_start + 5*result.sampling_period)
            assert_array_equal(result.magnitude, self.data1[3:8].reshape(-1, 1))

            # Test other attributes were copied over (in this case, defaults)
            self.assertEqual(result.file_origin, self.signal1.file_origin)
            self.assertEqual(result.name, self.signal1.name)
            self.assertEqual(result.description, self.signal1.description)
            self.assertEqual(result.annotations, self.signal1.annotations)

    def test__slice_should_let_access_to_parents_objects(self):
        result =  self.signal1.time_slice(1*pq.ms,3*pq.ms)
        self.assertEqual(result.segment, self.signal1.segment)
        self.assertEqual(result.channel_index, self.signal1.channel_index)

    def test__slice_should_change_sampling_period(self):
        result1 = self.signal1[:2, 0]
        result2 = self.signal1[::2, 0]
        result3 = self.signal1[1:7:2, 0]

        self.assertIsInstance(result1, AnalogSignal)
        assert_neo_object_is_compliant(result1)
        self.assertEqual(result1.name, 'spam')
        self.assertEqual(result1.description, 'eggs')
        self.assertEqual(result1.file_origin, 'testfile.txt')
        self.assertEqual(result1.annotations, {'arg1': 'test'})

        self.assertIsInstance(result2, AnalogSignal)
        assert_neo_object_is_compliant(result2)
        self.assertEqual(result2.name, 'spam')
        self.assertEqual(result2.description, 'eggs')
        self.assertEqual(result2.file_origin, 'testfile.txt')
        self.assertEqual(result2.annotations, {'arg1': 'test'})

        self.assertIsInstance(result3, AnalogSignal)
        assert_neo_object_is_compliant(result3)
        self.assertEqual(result3.name, 'spam')
        self.assertEqual(result3.description, 'eggs')
        self.assertEqual(result3.file_origin, 'testfile.txt')
        self.assertEqual(result3.annotations, {'arg1': 'test'})

        self.assertEqual(result1.sampling_period, self.signal1.sampling_period)
        self.assertEqual(result2.sampling_period,
                         self.signal1.sampling_period * 2)
        self.assertEqual(result3.sampling_period,
                         self.signal1.sampling_period * 2)

        assert_array_equal(result1.magnitude, self.data1[:2].reshape(-1, 1))
        assert_array_equal(result2.magnitude, self.data1[::2].reshape(-1, 1))
        assert_array_equal(result3.magnitude, self.data1[1:7:2].reshape(-1, 1))

    def test__slice_should_modify_linked_channelindex(self):
        n = 8  # number of channels
        signal = AnalogSignal(np.arange(n * 100.0).reshape(100, n),
                              sampling_rate=1*pq.kHz,
                              units="mV",
                              name="test")
        self.assertEqual(signal.shape, (100, n))
        signal.channel_index = ChannelIndex(index=np.arange(n, dtype=int),
                                            channel_names=["channel{0}".format(i) for i in range(n)])
        signal.channel_index.analogsignals.append(signal)
        odd_channels = signal[:, 1::2]
        self.assertEqual(odd_channels.shape, (100, n//2))
        assert_array_equal(odd_channels.channel_index.index, np.arange(n//2, dtype=int))
        assert_array_equal(odd_channels.channel_index.channel_names, ["channel{0}".format(i) for i in range(1, n, 2)])
        assert_array_equal(signal.channel_index.channel_names, ["channel{0}".format(i) for i in range(n)])
        self.assertEqual(odd_channels.channel_index.analogsignals[0].name, signal.name)

    def test__copy_should_let_access_to_parents_objects(self):
        result =  self.signal1.copy()
        self.assertIs(result.segment, self.signal1.segment)
#.........这里部分代码省略.........
开发者ID:msenoville,项目名称:python-neo,代码行数:101,代码来源:test_analogsignal.py


示例15: TestAnalogSignalArrayCombination

class TestAnalogSignalArrayCombination(unittest.TestCase):
    def setUp(self):
        self.data1 = np.arange(55.0).reshape((11, 5))
        self.data1quant = self.data1 * pq.mV
        self.signal1 = AnalogSignal(self.data1quant,
                                         sampling_rate=1*pq.kHz,
                                         name='spam', description='eggs',
                                         file_origin='testfile.txt',
                                         arg1='test')
        self.data2 = np.arange(100.0, 155.0).reshape((11, 5))
        self.data2quant = self.data2 * pq.mV
        self.signal2 = AnalogSignal(self.data2quant,
                                         sampling_rate=1*pq.kHz,
                                         name='spam', description='eggs',
                                         file_origin='testfile.txt',
                                         arg1='test')

    def test__compliant(self):
        assert_neo_object_is_compliant(self.signal1)
        self.assertEqual(self.signal1.name, 'spam')
        self.assertEqual(self.signal1.description, 'eggs')
        self.assertEqual(self.signal1.file_origin, 'testfile.txt')
        self.assertEqual(self.signal1.annotations, {'arg1': 'test'})

        assert_neo_object_is_compliant(self.signal2)
        self.assertEqual(self.signal2.name, 'spam')
        self.assertEqual(self.signal2.description, 'eggs')
        self.assertEqual(self.signal2.file_origin, 'testfile.txt')
        self.assertEqual(self.signal2.annotations, {'arg1': 'test'})

    def test__add_const_quantity_should_preserve_data_complement(self):
        result = self.signal1 + 0.065*pq.V
        self.assertIsInstance(result, AnalogSignal)
        assert_neo_object_is_compliant(result)
        self.assertEqual(result.name, 'spam')
        self.assertEqual(result.description, 'eggs')
        self.assertEqual(result.file_origin, 'testfile.txt')
        self.assertEqual(result.annotations, {'arg1': 'test'})

        # time zero, signal index 4
        assert_arrays_equal(result, self.data1 + 65)
        self.assertEqual(self.signal1[0, 4], 4*pq.mV)
        self.assertEqual(result[0, 4], 69000*pq.uV)
        self.assertEqual(self.signal1.t_start, result.t_start)
        self.assertEqual(self.signal1.sampling_rate, result.sampling_rate)

    def test__add_two_consistent_signals_should_preserve_data_complement(self):
        result = self.signal1 + self.signal2
        self.assertIsInstance(result, AnalogSignal)
        assert_neo_object_is_compliant(result)
        self.assertEqual(result.name, 'spam')
        self.assertEqual(result.description, 'eggs')
        self.assertEqual(result.file_origin, 'testfile.txt')
        self.assertEqual(result.annotations, {'arg1': 'test'})

        targdata = np.arange(100.0, 210.0, 2.0).reshape((11, 5))
        targ = AnalogSignal(targdata, units="mV",
                                 sampling_rate=1*pq.kHz,
                                 name='spam', description='eggs',
                                 file_origin='testfile.txt', arg1='test')
        assert_neo_object_is_compliant(targ)

        assert_arrays_equal(result, targdata)
        assert_same_sub_schema(result, targ)

    def test__add_signals_with_inconsistent_data_complement_ValueError(self):
        self.signal2.sampling_rate = 0.5*pq.kHz
        assert_neo_object_is_compliant(self.signal2)

        self.assertRaises(ValueError, self.signal1.__add__, self.signal2)

    def test__subtract_const_should_preserve_data_complement(self):
        result = self.signal1 - 65*pq.mV
        self.assertIsInstance(result, AnalogSignal)
        assert_neo_object_is_compliant(result)
        self.assertEqual(result.name, 'spam')
        self.assertEqual(result.description, 'eggs')
        self.assertEqual(result.file_origin, 'testfile.txt')
        self.assertEqual(result.annotations, {'arg1': 'test'})

        self.assertEqual(np.array(self.signal1[1, 4]), 9)
        self.assertEqual(np.array(result[1, 4]), -56)
        assert_arrays_equal(result, self.data1 - 65)
        self.assertEqual(self.signal1.sampling_rate, result.sampling_rate)

    def test__subtract_from_const_should_return_signal(self):
        result = 10*pq.mV - self.signal1
        self.assertIsInstance(result, AnalogSignal)
        assert_neo_object_is_compliant(result)
        self.assertEqual(result.name, 'spam')
        self.assertEqual(result.description, 'eggs')
        self.assertEqual(result.file_origin, 'testfile.txt')
        self.assertEqual(result.annotations, {'arg1': 'test'})

        self.assertEqual(np.array(self.signal1[1, 4]), 9)
        self.assertEqual(np.array(result[1, 4]), 1)
        assert_arrays_equal(result, 10 - self.data1)
        self.assertEqual(self.signal1.sampling_rate, result.sampling_rate)

    def test__mult_by_const_float_should_preserve_data_complement(self):
#.........这里部分代码省略.........
开发者ID:msenoville,项目名称:python-neo,代码行数:101,代码来源:test_analogsignalarray.py


示例16: TestAnalogSignalArrayMethods

class TestAnalogSignalArrayMethods(unittest.TestCase):
    def setUp(self):
        self.data1 = np.arange(10.0)
        self.data1quant = self.data1 * pq.nA
        self.signal1 = AnalogSignal(self.data1quant, sampling_rate=1*pq.kHz,
                                    name='spam', description='eggs',
                                    file_origin='testfile.txt', arg1='test')

    def test__compliant(self):
        assert_neo_object_is_compliant(self.signal1)

    def test__slice_should_return_AnalogSignal(self):
        # slice
        result = self.signal1[3:8]
        self.assertIsInstance(result, AnalogSignal)
        assert_neo_object_is_compliant(result)
        self.assertEqual(result.name, 'spam')
        self.assertEqual(result.description, 'eggs')
        self.assertEqual(result.file_origin, 'testfile.txt')
        self.assertEqual(result.annotations, {'arg1': 'test'})

        self.assertEqual(result.size, 5)
        self.assertEqual(result.sampling_period, self.signal1.sampling_period)
        self.assertEqual(result.sampling_rate, self.signal1.sampling_rate)
        self.assertEqual(result.t_start,
                         self.signal1.t_start+3*result.sampling_period)
        self.assertEqual(result.t_stop,
                         result.t_start + 5*result.sampling_period)
        assert_arrays_equal(result, self.data1[3:8])

        # Test other attributes were copied over (in this case, defaults)
        self.assertEqual(result.file_origin, self.signal1.file_origin)
        self.assertEqual(result.name, self.signal1.name)
        self.assertEqual(result.description, self.signal1.description)
        self.assertEqual(result.annotations, self.signal1.annotations)

    def test__slice_should_change_sampling_period(self):
        result1 = self.signal1[:2]
        result2 = self.signal1[::2]
        result3 = self.signal1[1:7:2]

        self.assertIsInstance(result1, AnalogSignal)
        assert_neo_object_is_compliant(result1)
        self.assertEqual(result1.name, 'spam')
        self.assertEqual(result1.description, 'eggs')
        self.assertEqual(result1.file_origin, 'testfile.txt')
        self.assertEqual(result1.annotations, {'arg1': 'test'})

        self.assertIsInstance(result2, AnalogSignal)
        assert_neo_object_is_compliant(result2)
        self.assertEqual(result2.name, 'spam')
        self.assertEqual(result2.description, 'eggs')
        self.assertEqual(result2.file_origin, 'testfile.txt')
        self.assertEqual(result2.annotations, {'arg1': 'test'})

        self.assertIsInstance(result3, AnalogSignal)
        assert_neo_object_is_compliant(result3)
        self.assertEqual(result3.name, 'spam')
        self.assertEqual(result3.description, 'eggs')
        self.assertEqual(result3.file_origin, 'testfile.txt')
        self.assertEqual(result3.annotations, {'arg1': 'test'})

        self.assertEqual(result1.sampling_period, self.signal1.sampling_period)
        self.assertEqual(result2.sampling_period,
                         self.signal1.sampling_period * 2)
        self.assertEqual(result3.sampling_period,
                         self.signal1.sampling_period * 2)

        assert_arrays_equal(result1, self.data1[:2])
        assert_arrays_equal(result2, self.data1[::2])
        assert_arrays_equal(result3, self.data1[1:7:2])

    def test__getitem_should_return_single_quantity(self):
        result1 = self.signal1[0]
        result2 = self.signal1[9]

        self.assertIsInstance(result1, pq.Quantity)
        self.assertFalse(hasattr(result1, 'name'))
        self.assertFalse(hasattr(result1, 'description'))
        self.assertFalse(hasattr(result1, 'file_origin'))
        self.assertFalse(hasattr(result1, 'annotations'))

        self.assertIsInstance(result2, pq.Quantity)
        self.assertFalse(hasattr(result2, 'name'))
        self.assertFalse(hasattr(result2, 'description'))
        self.assertFalse(hasattr(result2, 'file_origin'))
        self.assertFalse(hasattr(result2, 'annotations'))

        self.assertEqual(result1, 0*pq.nA)
        self.assertEqual(result2, 9*pq.nA)

    def test__getitem_out_of_bounds_IndexError(self):
        self.assertRaises(IndexError, self.signal1.__getitem__, 10)

    def test_comparison_operators(self):
        assert_arrays_equal(self.signal1 >= 5*pq.nA,
                            np.array([False, False, False, False, False,
                                      True, True, True, True, True]))
        assert_arrays_equal(self.signal1 >= 5*pq.pA,
                            np.array([False, True, True, True, True,
#.........这里部分代码省略.........
开发者ID:ChrisNolan1992,项目名称:python-neo,代码行数:101,代码来源:test_analogsignal.py


示例17: setUp

 def setUp(self):
     self.data1 = np.arange(10.0)
     self.data1quant = self.data1 * pq.nA
     self.signal1 = AnalogSignal(self.data1quant, sampling_rate=1*pq.kHz,
                                 name='spam', description='eggs',
                                 file_origin='testfile.txt', arg1='test')
开发者ID:ChrisNolan1992,项目名称:python-neo,代码行数:6,代码来源:test_analogsignal.py


示例18: setUp

 def setUp(self):
     self.signal = AnalogSignal(numpy.arange(10.0), units="nA", sampling_rate=1*kHz)
开发者ID:gentnerlab-user,项目名称:python-neo,代码行数:2,代码来源:test_analogsignal.py


示例19: TestArrayMethods

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)
开发者ID:gentnerlab-user,项目名称:python-neo,代码行数:84,代码来源:test_analogsignal.py


示例20: TestAnalogSignalArrayMethods

class TestAnalogSignalArrayMethods(unittest.TestCase):
    def setUp(self):
        self.data1 = np.arange(10.0)
        self.data1quant = self.data1 * pq.nA
        self.signal1 = AnalogSignal(self.data1quant, sampling_rate=1*pq.kHz,
                                         name='spam', description='eggs',
                                         file_origin='testfile.txt', arg1='test')
        self.signal1.segment = 1
        self.signal1.channel_index = ChannelIndex(index=[0])

    def test__compliant(self):
        assert_neo_object_is_compliant(self.signal1)

    def test__slice_should_return_AnalogSignalArray(self):
        # slice
        result = self.signal1[3:8, 0]
        self.assertIsInstance(result, AnalogSignal)
        assert_neo_object_is_compliant(result)
        self.assertEqual(result.name, 'spam')         # should slicing really preserve name and description?
        self.assertEqual(result.description, 'eggs')  # perhaps these should be modified to indicate the slice?
        self.assertEqual(result.file_origin, 'testfile.txt')
        self.assertEqual(result.annotations, {'arg1': 'test'})

        self.assertEqual(result.size, 5)
        self.assertEqual(result.sampling_period, self.signal1.sampling_period)
        self.assertEqual(result.sampling_rate, self.signal1.sampling_rate)
        self.assertEqual(result.t_start,
                         self.signal1.t_start+3*result.sampling_period)
        self.assertEqual(result.t_stop,
                         result.t_start + 5*result.sampling_period)
        assert_array_equal(result.magnitude, self.data1[3:8].reshape(-1, 1))

        # Test other attributes were copied over (in this case, defaults)
        self.assertEqual(result.file_origin, self.signal1.file_origin)
        self.assertEqual(result.name, self.signal1.name)
        self.assertEqual(result.description, self.signal1.description)
        self.assertEqual(result.annotations, self.signal1.annotations)

    def test__slice_should_let_access_to_parents_objects(self):
        result =  self.signal1.time_slice(1*pq.ms,3*pq.ms)
        self.assertEqual(result.segment, self.signal1.segment)
        self.assertEqual(result.channel_index, self.signal1.channel_index)

    def test__slice_should_change_sampling_period(self):
        result1 = self.signal1[:2, 0]
        result2 = self.signal1[::2, 0]
        result3 = self.signal1[1:7:2, 0]

        self.assertIsInstance(result1, AnalogSignal)
        assert_neo_object_is_compliant(result1)
        self.assertEqual(result1.name, 'spam')
        self.assertEqual(result1.description, 'eggs')
        self.assertEqual(result1.file_origin, 'testfile.txt')
        self.assertEqual(result1.annotations, {'arg1': 'test'})

        self.assertIsInstance(result2, AnalogSignal)
        assert_neo_object_is_compliant(result2)
        self.assertEqual(result2.name, 'spam')
        self.assertEqual(result2.description, 'eggs')
        self.assertEqual(result2.file_origin, 'testfile.txt')
        self.assertEqual(result2.annotations, {'arg1': 'test'})

        self.assertIsInstance(result3, AnalogSignal)
        assert_neo_object_is_compliant(result3)
        self.assertEqual(result3.name, 'spam')
        self.assertEqual(result3.description, 'eggs')
        self.assertEqual(result3.file_origin, 'testfile.txt')
        self.assertEqual(result3.annotations, {'arg1': 'test'})

        self.assertEqual(result1.sampling_period, self.signal1.sampling_period)
        self.assertEqual(result2.sampling_period,
                         self.signal1.sampling_period * 2)
        self.assertEqual(result3.sampling_period,
                         self.signal1.sampling_period * 2)

        assert_array_equal(result1.magnitude, self.data1[:2].reshape(-1, 1))
        assert_array_equal(result2.magnitude, self.data1[::2].reshape(-1, 1))
        assert_array_equal(result3.magnitude, self.data1[1:7:2].reshape(-1, 1))

    def test__slice_should_modify_linked_channelindex(self):
        n = 8  # number of channels
        signal = AnalogSignal(np.arange(n * 100.0).reshape(100, n),
                              sampling_rate=1*pq.kHz,
                              units="mV")
        self.assertEqual(signal.shape, (100, n))
        signal.channel_index = ChannelIndex(index=np.arange(n, dtype=int),
                                            channel_names=["channel{0}".format(i) for i in range(n)])
        odd_channels = signal[:, 1::2]
        self.assertEqual(odd_channels.shape, (100, n//2))
        assert_array_equal(odd_channels.channel_index.index, np.arange(n//2, dtype=int))
        assert_array_equal(odd_channels.channel_index.channel_names, ["channel{0}".format(i) for i in range(1, n, 2)])
        assert_array_equal(signal.channel_index.channel_names, ["channel{0}".format(i) for i in range(n)])

    def test__copy_should_let_access_to_parents_o 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python baseneo.BaseNeo类代码示例发布时间:2022-05-27
下一篇:
Python core.SpikeTrain类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap