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

Python tools.assert_arrays_almost_equal函数代码示例

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

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



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

示例1: test__time_slice__different_units

    def test__time_slice__different_units(self):
        self.signal2.t_start = 10.0 * pq.ms
        assert_neo_object_is_compliant(self.signal2)

        t_start = 2 * pq.s + 10.0 * pq.ms
        t_stop = 4 * pq.s + 10.0 * pq.ms

        result = self.signal2.time_slice(t_start, t_stop)
        self.assertIsInstance(result, AnalogSignalArray)
        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'})

        targ = AnalogSignalArray(np.array([[2, 3], [2, 3]]).T,
                                 t_start=t_start.rescale(pq.ms),
                                 sampling_rate=1.0*pq.Hz, units='mV',
                                 name='spam', description='eggs',
                                 file_origin='testfile.txt', arg1='test')
        assert_neo_object_is_compliant(result)

        assert_neo_object_is_compliant(self.signal2)
        self.assertEqual(self.signal2.t_start, 10.0 * pq.ms)
        self.assertAlmostEqual(result.t_stop, t_stop, delta=1e-12*pq.ms)
        self.assertAlmostEqual(result.t_start, t_start, delta=1e-12*pq.ms)
        assert_arrays_almost_equal(result.times, targ.times, 1e-12*pq.ms)
        self.assertEqual(result.sampling_rate, targ.sampling_rate)
        assert_arrays_equal(result, targ)
        assert_same_sub_schema(result, targ)
开发者ID:NeuroArchive,项目名称:python-neo,代码行数:30,代码来源:test_analogsignalarray.py


示例2: test_duplicate_with_new_data

 def test_duplicate_with_new_data(self):
     signal1 = self.epoch
     new_data = np.sort(np.random.uniform(0, 100, (self.epoch))) * pq.ms
     signal1b = signal1.duplicate_with_new_data(new_data)
     assert_arrays_almost_equal(np.asarray(signal1b),
                                np.asarray(new_data), 1e-12)
     assert_arrays_almost_equal(np.asarray(signal1b.durations),
                                np.asarray(signal1.durations), 1e-12)
开发者ID:CINPLA,项目名称:python-neo,代码行数:8,代码来源:test_epoch.py


示例3: test__duplicate_with_new_array

 def test__duplicate_with_new_array(self):
     signal1 = self.signals[1]
     signal2 = self.signals[2]
     data2 = self.data[2]
     signal1b = signal1.duplicate_with_new_array(data2)
     assert_arrays_almost_equal(np.asarray(signal1b), np.asarray(signal2 / 1000.0), 1e-12)
     self.assertEqual(signal1b.t_start, signal1.t_start)
     self.assertEqual(signal1b.sampling_rate, signal1.sampling_rate)
开发者ID:NeuroArchive,项目名称:python-neo,代码行数:8,代码来源:test_analogsignal.py


示例4: test_AnalogSignalProxy

    def test_AnalogSignalProxy(self):
        proxy_anasig = AnalogSignalProxy(rawio=self.reader, global_channel_indexes=None,
                        block_index=0, seg_index=0,)

        assert proxy_anasig.sampling_rate == 10 * pq.kHz
        assert proxy_anasig.t_start == 0 * pq.s
        assert proxy_anasig.t_stop == 10 * pq.s
        assert proxy_anasig.duration == 10 * pq.s
        assert proxy_anasig.file_origin == 'my_filename.fake'

        # full load
        full_anasig = proxy_anasig.load(time_slice=None)
        assert isinstance(full_anasig, AnalogSignal)
        assert_same_attributes(proxy_anasig, full_anasig)

        # slice time
        anasig = proxy_anasig.load(time_slice=(2. * pq.s, 5 * pq.s))
        assert anasig.t_start == 2. * pq.s
        assert anasig.duration == 3. * pq.s
        assert anasig.shape == (30000, 16)

        # ceil next sample when slicing
        anasig = proxy_anasig.load(time_slice=(1.99999 * pq.s, 5.000001 * pq.s))
        assert anasig.t_start == 2. * pq.s
        assert anasig.duration == 3. * pq.s
        assert anasig.shape == (30000, 16)

        # buggy time slice
        with self.assertRaises(AssertionError):
            anasig = proxy_anasig.load(time_slice=(2. * pq.s, 15 * pq.s))
        anasig = proxy_anasig.load(time_slice=(2. * pq.s, 15 * pq.s), strict_slicing=False)
        assert proxy_anasig.t_stop == 10 * pq.s

        # select channels
        anasig = proxy_anasig.load(channel_indexes=[3, 4, 9])
        assert anasig.shape[1] == 3

        # select channels and slice times
        anasig = proxy_anasig.load(time_slice=(2. * pq.s, 5 * pq.s), channel_indexes=[3, 4, 9])
        assert anasig.shape == (30000, 3)

        # magnitude mode rescaled
        anasig_float = proxy_anasig.load(magnitude_mode='rescaled')
        assert anasig_float.dtype == 'float32'
        assert anasig_float.units == pq.uV
        assert anasig_float.units == proxy_anasig.units

        # magnitude mode raw
        anasig_int = proxy_anasig.load(magnitude_mode='raw')
        assert anasig_int.dtype == 'int16'
        assert anasig_int.units == pq.CompoundUnit('0.0152587890625*uV')

        assert_arrays_almost_equal(anasig_float, anasig_int.rescale('uV'), 1e-9)
开发者ID:INM-6,项目名称:python-neo,代码行数:53,代码来源:test_proxyobjects.py


示例5: test_duplicate_with_new_data

 def test_duplicate_with_new_data(self):
     signal1 = self.event
     new_data = np.sort(np.random.uniform(0, 100, (self.event.size))) * pq.ms
     signal1b = signal1.duplicate_with_new_data(new_data)
     assert_arrays_almost_equal(np.asarray(signal1b), np.asarray(new_data), 1e-12)
     # Note: Labels and Durations are NOT copied any more!!!
     # After duplicating, array annotations should always be empty,
     # because different length of data would cause inconsistencies
     # Only labels and durations should be available
     assert_arrays_equal(signal1b.labels, np.ndarray((0,), dtype='S'))
     self.assertTrue('index' not in signal1b.array_annotations)
     self.assertTrue('test' not in signal1b.array_annotations)
     self.assertIsInstance(signal1b.array_annotations, ArrayDict)
开发者ID:INM-6,项目名称:python-neo,代码行数:13,代码来源:test_event.py


示例6: test__duplicate_with_new_data

 def test__duplicate_with_new_data(self):
     signal1 = self.signals[1]
     signal2 = self.signals[2]
     data2 = self.data[2]
     signal1.array_annotate(ann=np.arange(signal1.shape[-1]))
     signal1b = signal1.duplicate_with_new_data(data2)
     assert_arrays_almost_equal(np.asarray(signal1b), np.asarray(signal2 / 1000.), 1e-12)
     self.assertEqual(signal1b.t_start, signal1.t_start)
     self.assertEqual(signal1b.sampling_rate, signal1.sampling_rate)
     # After duplicating, array annotations should always be empty,
     # because different length of data would cause inconsistencies
     self.assertEqual(signal1b.array_annotations, {})
     self.assertIsInstance(signal1b.array_annotations, ArrayDict)
开发者ID:INM-6,项目名称:python-neo,代码行数:13,代码来源:test_analogsignal.py


示例7: test__rescale_new

    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*1000., 1e-10)
开发者ID:ChrisNolan1992,项目名称:python-neo,代码行数:13,代码来源:test_analogsignal.py


示例8: test_time_slice_different_units

    def test_time_slice_different_units(self):
        #import numpy
        av = AnalogSignalArray(numpy.array([[0,1,2,3,4,5],[0,1,2,3,4,5]]).T, t_start = 10.0 * pq.ms,sampling_rate=1.0*pq.Hz, units='mV')

        t_start = 2 * pq.s + 10.0 * pq.ms
        t_stop = 4 * pq.s + 10.0 * pq.ms
        av2 = av.time_slice(t_start,t_stop)
        correct = AnalogSignalArray(numpy.array([[2,3],[2,3]]).T, t_start = t_start,sampling_rate=1.0*pq.Hz, units='mV')

        self.assertIsInstance(av2, AnalogSignalArray)
        self.assertAlmostEqual(av2.t_stop,t_stop,delta=1e-12*ms)
        self.assertAlmostEqual(av2.t_start,t_start,delta=1e-12*ms)
        assert_arrays_almost_equal(av2.times,correct.times,1e-12*ms)
        self.assertEqual(av2.sampling_rate, correct.sampling_rate)
开发者ID:dengemann,项目名称:python-neo,代码行数:14,代码来源:test_analogsignalarray.py


示例9: test__rescale_new

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

        self.assertIsInstance(result, IrregularlySampledSignal)
        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.uV)
        assert_arrays_almost_equal(np.array(result), self.data1.reshape(-1, 1)*1000., 1e-10)
        assert_array_equal(result.times, self.time1quant)
开发者ID:CINPLA,项目名称:python-neo,代码行数:14,代码来源:test_irregularysampledsignal.py


示例10: test2

    def test2(self):
        """Read data into two segments instead of just one"""
        full_range = 8192 * pq.mV
        bio = neo.io.BlackrockIO(filename=self.fn, full_range=full_range)
        block = bio.read_block(n_starts=[0, 3], n_stops=[2, 6])
        self.assertEqual(bio.header.Channel_Count, 2)
        self.assertEqual(bio.header.n_samples, 6)

        # Everything in two segments
        self.assertEqual(len(block.segments), 2)

        # Test first seg
        seg = block.segments[0]
        self.assertEqual(len(seg.analogsignals), 2)
        assert_arrays_almost_equal(seg.analogsignals[0],
                                   [3., 4.] * pq.mV, .0001)
        assert_arrays_almost_equal(seg.analogsignals[1],
                                   [6., -4.] * pq.mV, .0001)

        # Test second seg
        seg = block.segments[1]
        self.assertEqual(len(seg.analogsignals), 2)
        assert_arrays_almost_equal(seg.analogsignals[0],
                                   [-3., -4., -5.] * pq.mV, .0001)
        assert_arrays_almost_equal(seg.analogsignals[1],
                                   [-6., 4., 5.] * pq.mV, .0001)
开发者ID:ChrisNolan1992,项目名称:python-neo,代码行数:26,代码来源:test_blackrockio.py


示例11: test1

    def test1(self):
        """Read data into one big segment (default)"""
        full_range = 8192 * pq.mV
        bio = neo.io.BlackrockIO(filename=self.fn, full_range=full_range)
        block = bio.read_block(n_starts=[0], n_stops=[6])
        self.assertEqual(bio.header.Channel_Count, 2)
        self.assertEqual(bio.header.n_samples, 6)

        # Everything put in one segment
        self.assertEqual(len(block.segments), 1)
        seg = block.segments[0]
        self.assertEqual(len(seg.analogsignals), 2)

        assert_arrays_almost_equal(seg.analogsignals[0],
                                   [3., 4., 5., -3., -4., -5.] * pq.mV, .0001)
        assert_arrays_almost_equal(seg.analogsignals[1],
                                   [6., -4., -5., -6., 4., 5.] * pq.mV, .0001)
开发者ID:ChrisNolan1992,项目名称:python-neo,代码行数:17,代码来源:test_blackrockio.py


示例12: test__rescale_new

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


示例13: test__time_slice__no_explicit_time

    def test__time_slice__no_explicit_time(self):
        self.signal2.t_start = 10.0 * pq.ms
        assert_neo_object_is_compliant(self.signal2)

        t1 = 2 * pq.s + 10.0 * pq.ms
        t2 = 4 * pq.s + 10.0 * pq.ms

        for t_start,t_stop in [(t1,None),(None,None),(None,t2)]:

            t_start_targ = t1 if t_start!=None else self.signal2.t_start
            t_stop_targ = t2 if t_stop!=None else self.signal2.t_stop

            result = self.signal2.time_slice(t_start, t_stop)
            self.assertIsInstance(result, AnalogSignalArray)
            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'})

            targ_ind = np.where((self.signal2.times >= t_start_targ) &
                                (self.signal2.times < t_stop_targ))
            targ_array = self.signal2.magnitude[targ_ind]

            targ = AnalogSignalArray(targ_array,
                                     t_start=t_start_targ.rescale(pq.ms),
                                     sampling_rate=1.0*pq.Hz, units='mV',
                                     name='spam', description='eggs',
                                     file_origin='testfile.txt', arg1='test')
            assert_neo_object_is_compliant(result)

            assert_neo_object_is_compliant(self.signal2)
            self.assertEqual(self.signal2.t_start, 10.0 * pq.ms)
            self.assertAlmostEqual(result.t_stop, t_stop_targ, delta=1e-12*pq.ms)
            self.assertAlmostEqual(result.t_start, t_start_targ, delta=1e-12*pq.ms)
            assert_arrays_almost_equal(result.times, targ.times, 1e-12*pq.ms)
            self.assertEqual(result.sampling_rate, targ.sampling_rate)
            assert_arrays_equal(result, targ)
            assert_same_sub_schema(result, targ)
开发者ID:bal47,项目名称:python-neo,代码行数:39,代码来源:test_analogsignalarray.py


示例14: test__sampling_intervals_getter

 def test__sampling_intervals_getter(self):
     for signal, times in zip(self.signals, self.times):
         assert_arrays_almost_equal(signal.sampling_intervals,
                                    np.diff(times),
                                    threshold=1e-15)
开发者ID:msenoville,项目名称:python-neo,代码行数:5,代码来源:test_irregularysampledsignal.py


示例15: test__times_getter

 def test__times_getter(self):
     for i, signal in enumerate(self.signals):
         targ = np.arange(self.data[i].size)
         targ = targ/self.rates[i] + self.t_start[i]
         assert_neo_object_is_compliant(signal)
         assert_arrays_almost_equal(signal.times, targ, 1e-12*pq.ms)
开发者ID:msenoville,项目名称:python-neo,代码行数:6,代码来源:test_analogsignal.py


示例16: test1

    def test1(self):
        """Create clu and fet files based on spiketrains in a block.

        Checks that
            Files are created
            Converted to samples correctly
            Missing sampling rate are taken from IO reader default
            Spiketrains without cluster info are assigned to cluster 0
            Spiketrains across segments are concatenated
        """
        block = neo.Block()
        segment = neo.Segment()
        segment2 = neo.Segment()
        block.segments.append(segment)
        block.segments.append(segment2)

        # Fake spiketrain 1
        st1 = neo.SpikeTrain(times=[.002, .004, .006], units='s', t_stop=1.)
        st1.annotations['cluster'] = 0
        st1.annotations['group'] = 0
        wff = np.array([
            [11.3, 0.2],
            [-0.3, 12.3],
            [3.0, -2.5]])
        st1.annotations['waveform_features'] = wff
        segment.spiketrains.append(st1)

        # Create empty directory for writing
        if not os.path.exists(self.dirname):
            os.mkdir(self.dirname)
        delete_test_session(self.dirname)

        # Create writer
        kio = KlustaKwikIO(filename=os.path.join(self.dirname, 'base2'),
                           sampling_rate=1000.)
        kio.write_block(block)

        # Check files were created
        for fn in ['.fet.0', '.clu.0']:
            self.assertTrue(os.path.exists(os.path.join(self.dirname,
                                                        'base2' + fn)))

        # Check files contain correct content
        fi = file(os.path.join(self.dirname, 'base2.fet.0'))

        # first line is nbFeatures
        self.assertEqual(fi.readline(), '2\n')

        # Now check waveforms and times are same
        data = fi.readlines()
        new_wff = []
        new_times = []
        for line in data:
            line_split = line.split()
            new_wff.append([float(val) for val in line_split[:-1]])
            new_times.append(int(line_split[-1]))
        self.assertEqual(new_times, [2, 4, 6])
        assert_arrays_almost_equal(wff, np.array(new_wff), .00001)

        # Clusters on group 0
        data = file(os.path.join(self.dirname, 'base2.clu.0')).readlines()
        data = [int(d) for d in data]
        self.assertEqual(data, [1, 0, 0, 0])

        # Now read the features and test same
        block = kio.read_block()
        train = block.segments[0].spiketrains[0]
        assert_arrays_almost_equal(wff, train.annotations['waveform_features'],
                                   .00001)

        # Empty out test session again
        delete_test_session(self.dirname)
开发者ID:MartinHeroux,项目名称:ScientificallySound_files,代码行数:72,代码来源:test_klustakwikio.py


示例17: test__times

 def test__times(self):
     for i, signal in enumerate(self.signals):
         targ = np.arange(self.data[i].shape[0])
         targ = targ/self.rates[i] + self.t_start[i]
         assert_arrays_almost_equal(signal.times, targ, 1e-12*pq.ms)
开发者ID:NeuroArchive,项目名称:python-neo,代码行数:5,代码来源:test_analogsignalarray.py


示例18: test__times

 def test__times(self):
     for i in range(3):
         assert_arrays_almost_equal(self.signals[i].times,
                                    numpy.arange(self.data[i].shape[0])/self.rates[i] + self.t_start[i],
                                    1e-12*ms)
开发者ID:dengemann,项目名称:python-neo,代码行数:5,代码来源:test_analogsignalarray.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python tools.assert_arrays_equal函数代码示例发布时间:2022-05-27
下一篇:
Python tools.get_test_file_full_path函数代码示例发布时间: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