Ejemplo n.º 1
0
 def test__signals_with_different_data_complement_should_be_non_equal(self):
     signal1 = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                                 units="mV",
                                 sampling_rate=1 * kHz)
     signal2 = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                                 units="mV",
                                 sampling_rate=2 * kHz)
     self.assertNotEqual(signal1, signal2)
Ejemplo n.º 2
0
 def test__adding_signals_with_inconsistent_data_complement_should_raise_Exception(
         self):
     signal1 = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                                 units="mV",
                                 sampling_rate=1 * kHz)
     signal2 = AnalogSignalArray(numpy.arange(100.0, 155.0).reshape(
         (11, 5)),
                                 units="mV",
                                 sampling_rate=0.5 * kHz)
     self.assertRaises(Exception, signal1.__add__, signal2)
Ejemplo n.º 3
0
 def test__adding_two_consistent_signals_should_preserve_data_complement(
         self):
     signal1 = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                                 units="mV",
                                 sampling_rate=1 * kHz)
     signal2 = AnalogSignalArray(numpy.arange(100.0, 155.0).reshape(
         (11, 5)),
                                 units="mV",
                                 sampling_rate=1 * kHz)
     sum = signal1 + signal2
     assert_arrays_equal(
         sum,
         AnalogSignalArray(numpy.arange(100.0, 210.0, 2.0).reshape((11, 5)),
                           units="mV",
                           sampling_rate=1 * kHz))
Ejemplo n.º 4
0
 def test__create_from_quantities_array(self):
     data = numpy.arange(20.0).reshape((10, 2)) * mV
     rate = 5000 * Hz
     a = AnalogSignalArray(data, sampling_rate=rate)
     self.assertEqual(a.t_start, 0 * ms)
     self.assertEqual(a.t_stop, data.shape[0] / rate)
     self.assertEqual(a[9, 0], 18000 * uV)
Ejemplo n.º 5
0
 def test__merge(self):
     signal1 = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                                 units="mV",
                                 sampling_rate=1 * kHz,
                                 channel_index=range(5))
     signal2 = AnalogSignalArray(numpy.arange(1000.0, 1066.0).reshape(
         (11, 6)),
                                 units="uV",
                                 sampling_rate=1 * kHz,
                                 channel_index=range(5, 11))
     merged = signal1.merge(signal2)
     self.assertEqual(merged[0, 4], 4 * mV)
     self.assertEqual(merged[0, 5], 1 * mV)
     self.assertEqual(merged[10, 10], 1.065 * mV)
     self.assertEqual(merged.t_stop, signal1.t_stop)
     assert_arrays_equal(merged.channel_indexes, numpy.arange(11))
Ejemplo n.º 6
0
 def test__create_from_numpy_array(self):
     data = numpy.arange(20.0).reshape((10, 2))
     rate = 1 * kHz
     a = AnalogSignalArray(data, sampling_rate=rate, units="uV")
     self.assertEqual(a.t_start, 0 * ms)
     self.assertEqual(a.t_stop, data.shape[0] / rate)
     self.assertEqual(a[9, 0], 0.018 * mV)
     self.assertEqual(a[9, 1], 19 * uV)
Ejemplo n.º 7
0
 def test__create_from_list(self):
     data = [(i, i, i) for i in range(10)]  # 3 signals each with 10 samples
     rate = 1000 * Hz
     a = AnalogSignalArray(data, sampling_rate=rate, units="mV")
     self.assertEqual(a.shape, (10, 3))
     self.assertEqual(a.t_start, 0 * ms)
     self.assertEqual(a.t_stop, len(data) / rate)
     self.assertEqual(a[9, 0], 9000 * uV)
Ejemplo n.º 8
0
 def test__slice_both_dimensions_should_return_analogsignalarray(self):
     values = self.signal[0:3, 0:3]
     assert_arrays_equal(
         values,
         AnalogSignalArray([[0, 1, 2], [5, 6, 7], [10, 11, 12]],
                           dtype=float,
                           units="nA",
                           sampling_rate=1 * kHz))
Ejemplo n.º 9
0
 def test_time_slice(self):
     #import numpy
     av = AnalogSignalArray(numpy.array([[0, 1, 2, 3, 4, 5],
                                         [0, 1, 2, 3, 4, 5]]).T,
                            sampling_rate=1.0 * pq.Hz,
                            units='mV')
     t_start = 2 * pq.s
     t_stop = 4 * pq.s
     av2 = av.time_slice(t_start, t_stop)
     correct = AnalogSignalArray(numpy.array([[2, 3], [2, 3]]).T,
                                 sampling_rate=1.0 * pq.Hz,
                                 units='mV')
     ar = numpy.array(
         [a == b for (a, b) in zip(av2.flatten(), correct.flatten())])
     self.assertEqual(ar.all(), True)
     self.assertIsInstance(av2, AnalogSignalArray)
     self.assertEqual(av2.t_stop, t_stop)
     self.assertEqual(av2.t_start, t_start)
     self.assertEqual(av2.sampling_rate, correct.sampling_rate)
Ejemplo n.º 10
0
 def test__adding_a_constant_to_a_signal_should_preserve_data_complement(
         self):
     signal = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                                units="mV",
                                sampling_rate=1 * kHz)
     signal_with_offset = signal + 0.065 * V
     self.assertEqual(signal[0, 4], 4 * mV)  # time zero, signal index 4
     self.assertEqual(signal_with_offset[0, 4], 69000 * uV)
     for attr in "t_start", "sampling_rate":
         self.assertEqual(getattr(signal, attr),
                          getattr(signal_with_offset, attr))
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    def test__pickle(self):
        a = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                              units="mV",
                              sampling_rate=1 * kHz,
                              channel_index=range(5))

        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)
        self.assertEqual(list(a.channel_indexes), [0, 1, 2, 3, 4])
        self.assertEqual(list(a.channel_indexes), list(b.channel_indexes))
        f.close()
        os.remove('./pickle')
Ejemplo n.º 13
0
    def setup_analogsignalarrays(self):
        sigarrname11 = 'analogsignalarray 1 1'
        sigarrname12 = 'analogsignalarray 1 2'
        sigarrname21 = 'analogsignalarray 2 1'
        sigarrname22 = 'analogsignalarray 2 2'

        sigarrdata11 = np.arange(0, 10).reshape(5, 2) * pq.mV
        sigarrdata12 = np.arange(10, 20).reshape(5, 2) * pq.mV
        sigarrdata21 = np.arange(20, 30).reshape(5, 2) * pq.V
        sigarrdata22 = np.arange(30, 40).reshape(5, 2) * pq.V
        sigarrdata112 = np.hstack([sigarrdata11, sigarrdata11]) * pq.mV

        self.sigarrnames1 = [sigarrname11, sigarrname12]
        self.sigarrnames2 = [sigarrname21, sigarrname22, sigarrname11]
        self.sigarrnames = [
            sigarrname11, sigarrname12, sigarrname21, sigarrname22
        ]

        sigarr11 = AnalogSignalArray(sigarrdata11,
                                     name=sigarrname11,
                                     sampling_rate=1 * pq.Hz,
                                     channel_index=np.array([1]))
        sigarr12 = AnalogSignalArray(sigarrdata12,
                                     name=sigarrname12,
                                     sampling_rate=1 * pq.Hz,
                                     channel_index=np.array([2]))
        sigarr21 = AnalogSignalArray(sigarrdata21,
                                     name=sigarrname21,
                                     sampling_rate=1 * pq.Hz,
                                     channel_index=np.array([1]))
        sigarr22 = AnalogSignalArray(sigarrdata22,
                                     name=sigarrname22,
                                     sampling_rate=1 * pq.Hz,
                                     channel_index=np.array([2]))
        sigarr23 = AnalogSignalArray(sigarrdata11,
                                     name=sigarrname11,
                                     sampling_rate=1 * pq.Hz,
                                     channel_index=np.array([1]))
        sigarr112 = AnalogSignalArray(sigarrdata112,
                                      name=sigarrname11,
                                      sampling_rate=1 * pq.Hz,
                                      channel_index=np.array([1]))

        self.sigarr1 = [sigarr11, sigarr12]
        self.sigarr2 = [sigarr21, sigarr22, sigarr23]
        self.sigarr = [sigarr112, sigarr12, sigarr21, sigarr22]
Ejemplo n.º 14
0
 def test__create_with_copy_false_should_return_view(self):
     data = numpy.arange(20.0).reshape((10, 2)) * mV
     rate = 5000 * Hz
     a = AnalogSignalArray(data, copy=False, sampling_rate=rate)
     data[3, 0] = 99 * mV
     self.assertEqual(a[3, 0], 99000 * uV)
Ejemplo n.º 15
0
 def test__create_with_copy_true_should_return_copy(self):
     data = numpy.arange(20.0).reshape((10, 2)) * mV
     rate = 5000 * Hz
     a = AnalogSignalArray(data, copy=True, sampling_rate=rate)
     data[3, 0] = 0.099 * V
     self.assertNotEqual(a[3, 0], 99 * mV)
Ejemplo n.º 16
0
 def setUp(self):
     self.signal = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                                     units="nA",
                                     sampling_rate=1 * kHz)