Skip to content

Commit 2001f0c

Browse files
committed
Implementation of the conn_fcd_corr + test + doc
1 parent e47559c commit 2001f0c

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

docs/source/api/api_connectivity.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,30 @@ Connectivity metrics
2222
Utility functions
2323
+++++++++++++++++
2424

25+
Reshaping connectivity outputs
26+
==============================
27+
2528
.. autosummary::
2629
:toctree: generated/
2730

2831
conn_reshape_undirected
2932
conn_reshape_directed
3033
conn_ravel_directed
3134
conn_get_pairs
35+
36+
Metrics to apply on FC
37+
======================
38+
39+
.. autosummary::
40+
:toctree: generated/
41+
42+
conn_fcd_corr
43+
44+
Define sliding windows
45+
======================
46+
47+
.. autosummary::
48+
:toctree: generated/
49+
3250
define_windows
3351
plot_windows

frites/conn/conn_fcd_corr.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def conn_fcd_corr(conn, roi='roi', times='times', tskip=1, estimator=None,
5555
conn = conn.loc[:, ::tskip, :]
5656

5757
# get coordinates
58-
supp_c, roi_c = conn[supp_dim].data, conn[roi].data
59-
times_c = conn[times].data
58+
supp_c, times_c = conn[supp_dim].data, conn[times].data
6059

6160
# _______________________________ ESTIMATOR _______________________________
6261
if estimator is None:

frites/conn/tests/test_fcd_corr.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)