def test_TimeSeries():
    """Testing the initialization of the uniform time series object """

    #Test initialization with duration:
    tseries1 = ts.TimeSeries([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], duration=10)
    tseries2 = ts.TimeSeries([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], sampling_interval=1)
    npt.assert_equal(tseries1.time, tseries2.time)

    #downsampling:
    t1 = ts.UniformTime(length=8, sampling_rate=2)
    #duration is the same, but we're downsampling to 1Hz
    tseries1 = ts.TimeSeries(data=[1, 2, 3, 4], time=t1, sampling_rate=1)
    #If you didn't explicitely provide the rate you want to downsample to, that
    #is an error:
    npt.assert_raises(ValueError, ts.TimeSeries, dict(data=[1, 2, 3, 4],
                                                           time=t1))

    tseries2 = ts.TimeSeries(data=[1, 2, 3, 4], sampling_rate=1)
    tseries3 = ts.TimeSeries(data=[1, 2, 3, 4], sampling_rate=1000,
                                    time_unit='ms')
    #you can specify the sampling_rate or the sampling_interval, to the same
    #effect, where specificying the sampling_interval is in the units of that
    #time-series:
    tseries4 = ts.TimeSeries(data=[1, 2, 3, 4], sampling_interval=1,
                                        time_unit='ms')
    npt.assert_equal(tseries4.time, tseries3.time)

    #The units you use shouldn't matter - time is time:
    tseries6 = ts.TimeSeries(data=[1, 2, 3, 4],
                                    sampling_interval=0.001,
                                    time_unit='s')
    npt.assert_equal(tseries6.time, tseries3.time)

    #And this too - perverse, but should be possible:
    tseries5 = ts.TimeSeries(data=[1, 2, 3, 4],
                                    sampling_interval=ts.TimeArray(0.001,
                                                         time_unit='s'),
                                    time_unit='ms')

    npt.assert_equal(tseries5.time, tseries3.time)

    #initializing with a UniformTime object:
    t = ts.UniformTime(length=3, sampling_rate=3)

    data = [1, 2, 3]

    tseries7 = ts.TimeSeries(data=data, time=t)

    npt.assert_equal(tseries7.data, data)

    data = [1, 2, 3, 4]
    #If the data is not the right length, that should throw an error:
    npt.assert_raises(ValueError,
                          ts.TimeSeries, dict(data=data, time=t))

    # test basic arithmetics wiht TimeSeries
    tseries1 = ts.TimeSeries([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], sampling_rate=1)
    tseries2 = tseries1 + 1
    npt.assert_equal(tseries1.data + 1, tseries2.data)
    npt.assert_equal(tseries1.time, tseries2.time)
    tseries2 -= 1
    npt.assert_equal(tseries1.data, tseries2.data)
    npt.assert_equal(tseries1.time, tseries2.time)
    tseries2 = tseries1 * 2
    npt.assert_equal(tseries1.data * 2, tseries2.data)
    npt.assert_equal(tseries1.time, tseries2.time)
    tseries2 = tseries2 / 2
    npt.assert_equal(tseries1.data, tseries2.data)
    npt.assert_equal(tseries1.time, tseries2.time)

    tseries_nd1 = ts.TimeSeries(np.random.randn(3, 100), sampling_rate=1)
    tseries_nd2 = ts.TimeSeries(np.random.randn(3, 100), sampling_rate=1)
    npt.assert_equal((tseries_nd1 + tseries_nd2).data,
                     tseries_nd1.data + tseries_nd2.data)

    npt.assert_equal((tseries_nd1 - tseries_nd2).data,
                     tseries_nd1.data - tseries_nd2.data)

    npt.assert_equal((tseries_nd1 * tseries_nd2).data,
                     tseries_nd1.data * tseries_nd2.data)

    npt.assert_equal((tseries_nd1 / tseries_nd2).data,
                     tseries_nd1.data / tseries_nd2.data)
dataset/ETHPy150Open nipy/nitime/nitime/tests/test_timeseries.py/test_TimeSeries/original