def test_maxcorr(): t1 = TimeSeries([1, 2, 3, 4], [40, 50, 60, 70]) t2 = TimeSeries([1, 2, 3, 4], [50, 60, 70, 40]) standts1 = _corr.stand(t1, t1.mean(), t1.std()) standts2 = _corr.stand(t2, t2.mean(), t2.std()) idx, mcorr = _corr.max_corr_at_phase(standts1, standts2) #idx should be equal to one since the second ts is shifted by 1 assert(idx == 1) assert(np.real(mcorr) == 4)
def test_maxcorr(): t1 = TimeSeries([1, 2, 3, 4], [40, 50, 60, 70]) t2 = TimeSeries([1, 2, 3, 4], [50, 60, 70, 40]) standts1 = _corr.stand(t1, t1.mean(), t1.std()) standts2 = _corr.stand(t2, t2.mean(), t2.std()) idx, mcorr = _corr.max_corr_at_phase(standts1, standts2) #idx should be equal to one since the second ts is shifted by 1 assert (idx == 1) assert (np.real(mcorr) == 4)
def test_corr(): """ Test cross-correlation functions. """ arr_1 = np.linspace(1, 0, 50, dtype=complex) arr_2 = np.arange(0, 50, dtype=complex) ts_1 = TimeSeries(arr_2, arr_1) ts_2 = TimeSeries(arr_2, arr_2) out_arr = _corr.ccor(ts_1, ts_2) # Ensure result is consistent with numpy.fft. test_arr = np.fft.ifft(np.fft.fft(ts_1) * np.conj(np.fft.fft(ts_2))) assert np.allclose(out_arr, test_arr) # Test max_corr_at_phase using actual precomputed value of maxcorr. idx, maxcorr = _corr.max_corr_at_phase(ts_1, ts_2) assert idx == 25 assert np.isclose(maxcorr, 718.87755102040819)