|
| 1 | +"""Test conn_fcd_corr""" |
| 2 | +import numpy as np |
| 3 | +import xarray as xr |
| 4 | + |
| 5 | +from frites.estimator import DcorrEstimator |
| 6 | +from frites.conn import conn_dfc, conn_fcd_corr, define_windows |
| 7 | + |
| 8 | +# sample data |
| 9 | +x = np.random.rand(10, 3, 1000) |
| 10 | +trials = np.arange(10) |
| 11 | +roi = ['roi_1', 'roi_0', 'roi_0'] |
| 12 | +times = (np.arange(1000) - 10) / 64. |
| 13 | +x = xr.DataArray(x, dims=('trials', 'roi', 'times'), |
| 14 | + coords=(trials, roi, times)) |
| 15 | +win, _ = define_windows(times, slwin_len=.5, slwin_step=.1) |
| 16 | +dfc = conn_dfc(x, times='times', roi='roi', win_sample=win, verbose=False) |
| 17 | + |
| 18 | + |
| 19 | +class TestFCDCorr(object): |
| 20 | + |
| 21 | + def test_smoke(self): |
| 22 | + """Test that it's working (overall).""" |
| 23 | + # test on full network |
| 24 | + corr = conn_fcd_corr(dfc, roi='roi', times='times', verbose=False) |
| 25 | + assert corr.shape[0] == len(trials) |
| 26 | + assert corr.shape[1] == corr.shape[2] == len(win) |
| 27 | + |
| 28 | + # test on single time-point |
| 29 | + corr = conn_fcd_corr(dfc.isel(times=[0]), roi='roi', times='times', |
| 30 | + verbose=False) |
| 31 | + assert corr.shape[0] == len(trials) |
| 32 | + assert corr.shape[1] == corr.shape[2] == 1 |
| 33 | + |
| 34 | + # test internal reshaping |
| 35 | + corr = conn_fcd_corr(dfc.transpose('times', 'trials', 'roi'), |
| 36 | + roi='roi', times='times', verbose=False) |
| 37 | + assert corr.shape[0] == len(trials) |
| 38 | + assert corr.shape[1] == corr.shape[2] == len(win) |
| 39 | + |
| 40 | + def test_kwargs(self): |
| 41 | + """Test with a custom estimator.""" |
| 42 | + # testing estimator and tskip |
| 43 | + est = DcorrEstimator() |
| 44 | + corr = conn_fcd_corr(dfc, roi='roi', times='times', verbose=False, |
| 45 | + estimator=est, tskip=10) |
| 46 | + assert np.nanmin(corr.data) > 0 |
| 47 | + assert corr.shape[0] == len(trials) |
| 48 | + assert corr.shape[1] == corr.shape[2] == len(win[::10]) |
| 49 | + |
| 50 | + # testing diagonal filling |
| 51 | + corr = conn_fcd_corr(dfc, roi='roi', times='times', fill_diagonal=-1, |
| 52 | + verbose=False) |
| 53 | + cm = corr.mean('trials') |
| 54 | + np.testing.assert_array_equal(np.diag(cm), np.full((len(win),), -1)) |
0 commit comments