class TestAnalogSignalArrayArrayMethods(unittest.TestCase):
    def setUp(self):
        self.data1 = np.arange(55.0).reshape((11, 5))
        self.data1quant = self.data1 * pq.nA
        self.signal1 = AnalogSignalArray(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 = AnalogSignalArray(self.data2quant,
                                         sampling_rate=1.0*pq.Hz,
                                         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__index_dim1_should_return_analogsignal(self):
        result = self.signal1[:, 0]
        self.assertIsInstance(result, AnalogSignal)
        assert_neo_object_is_compliant(result)
        self.assertEqual(result.name, None)
        self.assertEqual(result.description, None)
        self.assertEqual(result.file_origin, None)
        self.assertEqual(result.annotations, {})

        self.assertEqual(result.t_stop, self.signal1.t_stop)
        self.assertEqual(result.t_start, self.signal1.t_start)
        self.assertEqual(result.sampling_rate,
                         self.signal1.sampling_rate)
        assert_arrays_equal(result, self.data1[:, 0])

    def test__index_dim1_and_slice_dim0_should_return_analogsignal(self):
        result = self.signal1[2:7, 0]
        self.assertIsInstance(result, AnalogSignal)
        assert_neo_object_is_compliant(result)
        self.assertEqual(result.name, None)
        self.assertEqual(result.description, None)
        self.assertEqual(result.file_origin, None)
        self.assertEqual(result.annotations, {})

        self.assertEqual(result.t_start,
                         self.signal1.t_start+2*self.signal1.sampling_period)
        self.assertEqual(result.t_stop,
                         self.signal1.t_start+7*self.signal1.sampling_period)
        self.assertEqual(result.sampling_rate,
                         self.signal1.sampling_rate)
        assert_arrays_equal(result, self.data1[2:7, 0])

    def test__index_dim0_should_return_quantity_array(self):
        # i.e. values from all signals for a single point in time
        result = self.signal1[3, :]
        self.assertIsInstance(result, pq.Quantity)
        self.assertFalse(hasattr(result, 'name'))
        self.assertFalse(hasattr(result, 'description'))
        self.assertFalse(hasattr(result, 'file_origin'))
        self.assertFalse(hasattr(result, 'annotations'))

        self.assertEqual(result.shape, (5,))
        self.assertFalse(hasattr(result, "t_start"))
        self.assertEqual(result.units, pq.nA)
        assert_arrays_equal(result, self.data1[3, :])

    def test__index_dim0_and_slice_dim1_should_return_quantity_array(self):
        # i.e. values from a subset of signals for a single point in time
        result = self.signal1[3, 2:5]
        self.assertIsInstance(result, pq.Quantity)
        self.assertFalse(hasattr(result, 'name'))
        self.assertFalse(hasattr(result, 'description'))
        self.assertFalse(hasattr(result, 'file_origin'))
        self.assertFalse(hasattr(result, 'annotations'))

        self.assertEqual(result.shape, (3,))
        self.assertFalse(hasattr(result, "t_start"))
        self.assertEqual(result.units, pq.nA)
        assert_arrays_equal(result, self.data1[3, 2:5])

    def test__index_as_string_IndexError(self):
        self.assertRaises(IndexError, self.signal1.__getitem__, 5.)

    def test__slice_both_dimensions_should_return_analogsignalarray(self):
        result = self.signal1[0:3, 0:3]
        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([[0, 1, 2], [5, 6, 7], [10, 11, 12]],
                                 dtype=float, units="nA",
                                 sampling_rate=1*pq.kHz,
                                 name='spam', description='eggs',
                                 file_origin='testfile.txt', arg1='test')
        assert_neo_object_is_compliant(targ)

        self.assertEqual(result.t_stop, targ.t_stop)
        self.assertEqual(result.t_start, targ.t_start)
        self.assertEqual(result.sampling_rate, targ.sampling_rate)
        self.assertEqual(result.shape, targ.shape)
        assert_same_sub_schema(result, targ)
        assert_arrays_equal(result, self.data1[0:3, 0:3])

    def test__slice_only_first_dimension_should_return_analogsignalarray(self):
        result = self.signal1[2:7]
        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'})

        self.assertEqual(result.shape, (5, 5))
        self.assertEqual(result.t_start,
                         self.signal1.t_start+2*self.signal1.sampling_period)
        self.assertEqual(result.t_stop,
                         self.signal1.t_start+7*self.signal1.sampling_period)
        self.assertEqual(result.sampling_rate, self.signal1.sampling_rate)
        assert_arrays_equal(result, self.data1[2:7])

    def test__getitem_should_return_single_quantity(self):
        # quantities drops the units in this case
        self.assertEqual(self.signal1[9, 3], 48000*pq.pA)
        self.assertEqual(self.signal1[9][3], self.signal1[9, 3])
        self.assertTrue(hasattr(self.signal1[9, 3], 'units'))
        self.assertRaises(IndexError, self.signal1.__getitem__, (99, 73))

    def test_comparison_operators(self):
        assert_arrays_equal(self.signal1[0:3, 0:3] >= 5*pq.nA,
                            np.array([[False, False, False],
                                      [True, True, True],
                                      [True, True, True]]))
        assert_arrays_equal(self.signal1[0:3, 0:3] >= 5*pq.pA,
                            np.array([[False, True, True],
                                      [True, True, True],
                                      [True, True, True]]))

    def test__comparison_with_inconsistent_units_should_raise_Exception(self):
        self.assertRaises(ValueError, self.signal1.__gt__, 5*pq.mV)

    def test__simple_statistics(self):
        self.assertEqual(self.signal1.max(), 54000*pq.pA)
        self.assertEqual(self.signal1.min(), 0*pq.nA)
        self.assertEqual(self.signal1.mean(), 27*pq.nA)

    def test__rescale_same(self):
        result = self.signal1.copy()
        result = result.rescale(pq.nA)

        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'})

        self.assertEqual(result.units, 1*pq.nA)
        assert_arrays_equal(result, self.data1)
        assert_same_sub_schema(result, self.signal1)

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

        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'})

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

    def test__time_slice(self):
        t_start = 2 * pq.s
        t_stop = 4 * pq.s

        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,
                                 sampling_rate=1.0*pq.Hz, units='mV',
                                 t_start=t_start,
                                 name='spam', description='eggs',
                                 file_origin='testfile.txt', arg1='test')
        assert_neo_object_is_compliant(result)

        self.assertEqual(result.t_stop, t_stop)
        self.assertEqual(result.t_start, t_start)
        self.assertEqual(result.sampling_rate, targ.sampling_rate)
        assert_arrays_equal(result, targ)
        assert_same_sub_schema(result, targ)

    def test__time_slice__out_of_bounds_ValueError(self):
        t_start_good = 2 * pq.s
        t_stop_good = 4 * pq.s
        t_start_bad = -2 * pq.s
        t_stop_bad = 40 * pq.s

        self.assertRaises(ValueError, self.signal2.time_slice,
                          t_start_good, t_stop_bad)
        self.assertRaises(ValueError, self.signal2.time_slice,
                          t_start_bad, t_stop_good)
        self.assertRaises(ValueError, self.signal2.time_slice,
                          t_start_bad, t_stop_bad)

    def test__time_equal(self):
        t_start = 0 * pq.s
        t_stop = 6 * pq.s

        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'})

        self.assertEqual(result.t_stop, t_stop)
        self.assertEqual(result.t_start, t_start)
        assert_arrays_equal(result, self.signal2)
        assert_same_sub_schema(result, self.signal2)

    def test__time_slice__offset(self):
        self.signal2.t_start = 10.0 * pq.s
        assert_neo_object_is_compliant(self.signal2)

        t_start = 12 * pq.s
        t_stop = 14 * pq.s

        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=12.0*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)

        self.assertEqual(self.signal2.t_start, 10.0 * pq.s)
        self.assertEqual(result.t_stop, t_stop)
        self.assertEqual(result.t_start, t_start)
        self.assertEqual(result.sampling_rate, targ.sampling_rate)
        assert_arrays_equal(result, targ)
        assert_same_sub_schema(result, targ)

    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)
class TestArrayMethods(unittest.TestCase):

    def setUp(self):
        self.signal = AnalogSignalArray(numpy.arange(55.0).reshape((11,5)), units="nA", sampling_rate=1*kHz)

    def test__index_dim1_should_return_analogsignal(self):
        single_signal = self.signal[:, 0]
        self.assertIsInstance(single_signal, AnalogSignal)
        self.assertEqual(single_signal.t_stop, self.signal.t_stop)
        self.assertEqual(single_signal.t_start, self.signal.t_start)
        self.assertEqual(single_signal.sampling_rate, self.signal.sampling_rate)

    def test__index_dim1_and_slice_dim0_should_return_analogsignal(self):
        single_signal = self.signal[2:7,0]
        self.assertIsInstance(single_signal, AnalogSignal)
        self.assertEqual(single_signal.t_start, self.signal.t_start+2*self.signal.sampling_period)
        self.assertEqual(single_signal.t_stop, self.signal.t_start+7*self.signal.sampling_period)
        self.assertEqual(single_signal.sampling_rate, self.signal.sampling_rate)

    def test__index_dim0_should_return_quantity_array(self):
        # i.e. values from all signals for a single point in time
        values = self.signal[3, :]
        self.assertNotIsInstance(values, AnalogSignalArray)
        self.assertEqual(values.shape, (5,))
        assert not hasattr(values, "t_start")
        self.assertEqual(values.units, pq.nA)

    def test__index_dim0_and_slice_dim1_should_return_quantity_array(self):
        # i.e. values from a subset of signals for a single point in time
        values = self.signal[3, 2:5]
        self.assertNotIsInstance(values, AnalogSignalArray)
        self.assertEqual(values.shape, (3,))
        assert not hasattr(values, "t_start")
        self.assertEqual(values.units, pq.nA)

    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))

    def test__slice_only_first_dimension_should_return_analogsignalarray(self):
        signal2 = self.signal[2:7]
        self.assertIsInstance(signal2, AnalogSignalArray)
        self.assertEqual(signal2.shape, (5,5))
        self.assertEqual(signal2.t_start, self.signal.t_start+2*self.signal.sampling_period)
        self.assertEqual(signal2.t_stop, self.signal.t_start+7*self.signal.sampling_period)
        self.assertEqual(signal2.sampling_rate, self.signal.sampling_rate)

    def test__getitem_should_return_single_quantity(self):
        self.assertEqual(self.signal[9, 3], 48000*pA) # quantities drops the units in this case
        self.assertEqual(self.signal[9][3], self.signal[9, 3])
        assert hasattr(self.signal[9, 3], 'units')
        self.assertRaises(IndexError, self.signal.__getitem__, (99,73))

    def test_comparison_operators(self):
        assert_arrays_equal(self.signal[0:3, 0:3] >= 5*nA,
                            numpy.array([[False, False, False], [True, True, True], [True, True, True]]))
        assert_arrays_equal(self.signal[0:3, 0:3] >= 5*pA,
                            numpy.array([[False, 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(), 54000*pA)
        self.assertEqual(self.signal.min(), 0*nA)
        self.assertEqual(self.signal.mean(), 27*nA)

    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)

    def test_time_equal(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 = 0 * pq.s
        t_stop = 6 * pq.s
        av2 = av.time_slice(t_start,t_stop)
        ar = numpy.array([a == b for (a,b) in zip(av2.flatten(),av.flatten())])
        self.assertEqual(ar.all(),True)
        self.assertIsInstance(av2, AnalogSignalArray)
        self.assertEqual(av2.t_stop,t_stop)
        self.assertEqual(av2.t_start,t_start)


    def test_time_slice_offset(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.s,sampling_rate=1.0*pq.Hz, units='mV')
        t_start = 12 * pq.s
        t_stop = 14 * pq.s
        av2 = av.time_slice(t_start,t_stop)
        correct = AnalogSignalArray(numpy.array([[2,3],[2,3]]).T, t_start = 12.0*pq.ms,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)

    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)
Exemple #3
0
class TestArrayMethods(unittest.TestCase):
    def setUp(self):
        self.signal = AnalogSignalArray(numpy.arange(55.0).reshape((11, 5)),
                                        units="nA",
                                        sampling_rate=1 * kHz)

    def test__index_dim1_should_return_analogsignal(self):
        single_signal = self.signal[:, 0]
        self.assertIsInstance(single_signal, AnalogSignal)
        self.assertEqual(single_signal.t_stop, self.signal.t_stop)
        self.assertEqual(single_signal.t_start, self.signal.t_start)
        self.assertEqual(single_signal.sampling_rate,
                         self.signal.sampling_rate)

    def test__index_dim1_and_slice_dim0_should_return_analogsignal(self):
        single_signal = self.signal[2:7, 0]
        self.assertIsInstance(single_signal, AnalogSignal)
        self.assertEqual(single_signal.t_start,
                         self.signal.t_start + 2 * self.signal.sampling_period)
        self.assertEqual(single_signal.t_stop,
                         self.signal.t_start + 7 * self.signal.sampling_period)
        self.assertEqual(single_signal.sampling_rate,
                         self.signal.sampling_rate)

    def test__index_dim0_should_return_quantity_array(self):
        # i.e. values from all signals for a single point in time
        values = self.signal[3, :]
        self.assertNotIsInstance(values, AnalogSignalArray)
        self.assertEqual(values.shape, (5, ))
        assert not hasattr(values, "t_start")
        self.assertEqual(values.units, pq.nA)

    def test__index_dim0_and_slice_dim1_should_return_quantity_array(self):
        # i.e. values from a subset of signals for a single point in time
        values = self.signal[3, 2:5]
        self.assertNotIsInstance(values, AnalogSignalArray)
        self.assertEqual(values.shape, (3, ))
        assert not hasattr(values, "t_start")
        self.assertEqual(values.units, pq.nA)

    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))

    def test__slice_only_first_dimension_should_return_analogsignalarray(self):
        signal2 = self.signal[2:7]
        self.assertIsInstance(signal2, AnalogSignalArray)
        self.assertEqual(signal2.shape, (5, 5))
        self.assertEqual(signal2.t_start,
                         self.signal.t_start + 2 * self.signal.sampling_period)
        self.assertEqual(signal2.t_stop,
                         self.signal.t_start + 7 * self.signal.sampling_period)
        self.assertEqual(signal2.sampling_rate, self.signal.sampling_rate)

    def test__getitem_should_return_single_quantity(self):
        self.assertEqual(self.signal[9, 3],
                         48000 * pA)  # quantities drops the units in this case
        self.assertEqual(self.signal[9][3], self.signal[9, 3])
        assert hasattr(self.signal[9, 3], 'units')
        self.assertRaises(IndexError, self.signal.__getitem__, (99, 73))

    def test_comparison_operators(self):
        assert_arrays_equal(
            self.signal[0:3, 0:3] >= 5 * nA,
            numpy.array([[False, False, False], [True, True, True],
                         [True, True, True]]))
        assert_arrays_equal(
            self.signal[0:3, 0:3] >= 5 * pA,
            numpy.array([[False, 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(), 54000 * pA)
        self.assertEqual(self.signal.min(), 0 * nA)
        self.assertEqual(self.signal.mean(), 27 * nA)

    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)

    def test_time_equal(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 = 0 * pq.s
        t_stop = 6 * pq.s
        av2 = av.time_slice(t_start, t_stop)
        ar = numpy.array(
            [a == b for (a, b) in zip(av2.flatten(), av.flatten())])
        self.assertEqual(ar.all(), True)
        self.assertIsInstance(av2, AnalogSignalArray)
        self.assertEqual(av2.t_stop, t_stop)
        self.assertEqual(av2.t_start, t_start)

    def test_time_slice_offset(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.s,
                               sampling_rate=1.0 * pq.Hz,
                               units='mV')
        t_start = 12 * pq.s
        t_stop = 14 * pq.s
        av2 = av.time_slice(t_start, t_stop)
        correct = AnalogSignalArray(numpy.array([[2, 3], [2, 3]]).T,
                                    t_start=12.0 * pq.ms,
                                    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)

    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)