本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)