当前位置: 首页>>代码示例>>Python>>正文


Python AnalogSignal.splice方法代码示例

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


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

示例1: test_splice_2channels_inplace

# 需要导入模块: from neo.core.analogsignal import AnalogSignal [as 别名]
# 或者: from neo.core.analogsignal.AnalogSignal import splice [as 别名]
 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,代码行数:19,代码来源:test_analogsignal.py

示例2: test_splice_2channels_inplace

# 需要导入模块: from neo.core.analogsignal import AnalogSignal [as 别名]
# 或者: from neo.core.analogsignal.AnalogSignal import splice [as 别名]
 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,代码行数:23,代码来源:test_analogsignal.py

示例3: TestAnalogSignalArrayMethods

# 需要导入模块: from neo.core.analogsignal import AnalogSignal [as 别名]
# 或者: from neo.core.analogsignal.AnalogSignal import splice [as 别名]

#.........这里部分代码省略.........

    def test__rescale_new(self):
        result = self.signal1.copy()
        result = result.rescale(pq.pA)

        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.units, 1*pq.pA)
        assert_arrays_almost_equal(np.array(result), self.data1.reshape(-1, 1)*1000., 1e-10)

        self.assertIsInstance(result.channel_index, ChannelIndex)
        self.assertIsInstance(result.segment, Segment)
        self.assertIs(result.channel_index, self.signal1.channel_index)
        self.assertIs(result.segment, self.signal1.segment)

    def test__rescale_new_incompatible_ValueError(self):
        self.assertRaises(ValueError, self.signal1.rescale, pq.mV)

    def test_as_array(self):
        sig_as_arr = self.signal1.as_array()
        self.assertIsInstance(sig_as_arr, np.ndarray)
        assert_array_equal(self.data1, sig_as_arr.flat)

    def test_as_quantity(self):
        sig_as_q = self.signal1.as_quantity()
        self.assertIsInstance(sig_as_q, pq.Quantity)
        assert_array_equal(self.data1, sig_as_q.magnitude.flat)

    def test_splice_1channel_inplace(self):
        signal_for_splicing = AnalogSignal([0.1, 0.1, 0.1],
                                           t_start=3*pq.ms,
                                           sampling_rate=self.signal1.sampling_rate,
                                           units=pq.uA)
        result = self.signal1.splice(signal_for_splicing, copy=False)
        assert_array_equal(result.magnitude.flatten(),
                           np.array([0.0, 1.0, 2.0, 100.0, 100.0, 100.0, 6.0, 7.0, 8.0, 9.0]))
        assert_array_equal(self.signal1, result)  # in-place
        self.assertEqual(result.segment, self.signal1.segment)
        self.assertEqual(result.channel_index, self.signal1.channel_index)

    def test_splice_1channel_with_copy(self):
        signal_for_splicing = AnalogSignal([0.1, 0.1, 0.1],
                                           t_start=3*pq.ms,
                                           sampling_rate=self.signal1.sampling_rate,
                                           units=pq.uA)
        result = self.signal1.splice(signal_for_splicing, copy=True)
        assert_array_equal(result.magnitude.flatten(),
                           np.array([0.0, 1.0, 2.0, 100.0, 100.0, 100.0, 6.0, 7.0, 8.0, 9.0]))
        assert_array_equal(self.signal1.magnitude.flatten(),
                           np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]))
        self.assertIs(result.segment, None)
        self.assertIs(result.channel_index, None)

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

示例4: TestAnalogSignalArrayMethods

# 需要导入模块: from neo.core.analogsignal import AnalogSignal [as 别名]
# 或者: from neo.core.analogsignal.AnalogSignal import splice [as 别名]

#.........这里部分代码省略.........
        result = self.signal1.copy()
        result = result.rescale(pq.pA)

        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.array_annotations, {'anno1': [23], 'anno2': ['A']})
        self.assertIsInstance(result.array_annotations, ArrayDict)

        self.assertEqual(result.units, 1 * pq.pA)
        assert_arrays_almost_equal(np.array(result), self.data1.reshape(-1, 1) * 1000., 1e-10)

        self.assertIsInstance(result.channel_index, ChannelIndex)
        self.assertIsInstance(result.segment, Segment)
        self.assertIs(result.channel_index, self.signal1.channel_index)
        self.assertIs(result.segment, self.signal1.segment)

    def test__rescale_new_incompatible_ValueError(self):
        self.assertRaises(ValueError, self.signal1.rescale, pq.mV)

    def test_as_array(self):
        sig_as_arr = self.signal1.as_array()
        self.assertIsInstance(sig_as_arr, np.ndarray)
        assert_array_equal(self.data1, sig_as_arr.flat)

    def test_as_quantity(self):
        sig_as_q = self.signal1.as_quantity()
        self.assertIsInstance(sig_as_q, pq.Quantity)
        assert_array_equal(self.data1, sig_as_q.magnitude.flat)

    def test_splice_1channel_inplace(self):
        signal_for_splicing = AnalogSignal([0.1, 0.1, 0.1], t_start=3 * pq.ms,
                                           sampling_rate=self.signal1.sampling_rate, units=pq.uA,
                                           array_annotations={'anno1': [0], 'anno2': ['C']})
        result = self.signal1.splice(signal_for_splicing, copy=False)
        assert_array_equal(result.magnitude.flatten(),
                           np.array([0.0, 1.0, 2.0, 100.0, 100.0, 100.0, 6.0, 7.0, 8.0, 9.0]))
        assert_array_equal(self.signal1, result)  # in-place
        self.assertEqual(result.segment, self.signal1.segment)
        self.assertEqual(result.channel_index, self.signal1.channel_index)
        assert_array_equal(result.array_annotations['anno1'], np.array([23]))
        assert_array_equal(result.array_annotations['anno2'], np.array(['A']))
        self.assertIsInstance(result.array_annotations, ArrayDict)

    def test_splice_1channel_with_copy(self):
        signal_for_splicing = AnalogSignal([0.1, 0.1, 0.1], t_start=3 * pq.ms,
                                           sampling_rate=self.signal1.sampling_rate, units=pq.uA,
                                           array_annotations={'anno1': [0], 'anno2': ['C']})
        result = self.signal1.splice(signal_for_splicing, copy=True)
        assert_array_equal(result.magnitude.flatten(),
                           np.array([0.0, 1.0, 2.0, 100.0, 100.0, 100.0, 6.0, 7.0, 8.0, 9.0]))
        assert_array_equal(self.signal1.magnitude.flatten(),
                           np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]))
        self.assertIs(result.segment, None)
        self.assertIs(result.channel_index, None)
        assert_array_equal(result.array_annotations['anno1'], np.array([23]))
        assert_array_equal(result.array_annotations['anno2'], np.array(['A']))
        self.assertIsInstance(result.array_annotations, ArrayDict)

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


注:本文中的neo.core.analogsignal.AnalogSignal.splice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。