Skip to content

Commit

Permalink
Implementation of the conn_fcd_corr + test + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneCmb committed Oct 11, 2021
1 parent e47559c commit 2001f0c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/source/api/api_connectivity.rst
Expand Up @@ -22,12 +22,30 @@ Connectivity metrics
Utility functions
+++++++++++++++++

Reshaping connectivity outputs
==============================

.. autosummary::
:toctree: generated/

conn_reshape_undirected
conn_reshape_directed
conn_ravel_directed
conn_get_pairs

Metrics to apply on FC
======================

.. autosummary::
:toctree: generated/

conn_fcd_corr

Define sliding windows
======================

.. autosummary::
:toctree: generated/

define_windows
plot_windows
3 changes: 1 addition & 2 deletions frites/conn/conn_fcd_corr.py
Expand Up @@ -55,8 +55,7 @@ def conn_fcd_corr(conn, roi='roi', times='times', tskip=1, estimator=None,
conn = conn.loc[:, ::tskip, :]

# get coordinates
supp_c, roi_c = conn[supp_dim].data, conn[roi].data
times_c = conn[times].data
supp_c, times_c = conn[supp_dim].data, conn[times].data

# _______________________________ ESTIMATOR _______________________________
if estimator is None:
Expand Down
54 changes: 54 additions & 0 deletions frites/conn/tests/test_fcd_corr.py
@@ -0,0 +1,54 @@
"""Test conn_fcd_corr"""
import numpy as np
import xarray as xr

from frites.estimator import DcorrEstimator
from frites.conn import conn_dfc, conn_fcd_corr, define_windows

# sample data
x = np.random.rand(10, 3, 1000)
trials = np.arange(10)
roi = ['roi_1', 'roi_0', 'roi_0']
times = (np.arange(1000) - 10) / 64.
x = xr.DataArray(x, dims=('trials', 'roi', 'times'),
coords=(trials, roi, times))
win, _ = define_windows(times, slwin_len=.5, slwin_step=.1)
dfc = conn_dfc(x, times='times', roi='roi', win_sample=win, verbose=False)


class TestFCDCorr(object):

def test_smoke(self):
"""Test that it's working (overall)."""
# test on full network
corr = conn_fcd_corr(dfc, roi='roi', times='times', verbose=False)
assert corr.shape[0] == len(trials)
assert corr.shape[1] == corr.shape[2] == len(win)

# test on single time-point
corr = conn_fcd_corr(dfc.isel(times=[0]), roi='roi', times='times',
verbose=False)
assert corr.shape[0] == len(trials)
assert corr.shape[1] == corr.shape[2] == 1

# test internal reshaping
corr = conn_fcd_corr(dfc.transpose('times', 'trials', 'roi'),
roi='roi', times='times', verbose=False)
assert corr.shape[0] == len(trials)
assert corr.shape[1] == corr.shape[2] == len(win)

def test_kwargs(self):
"""Test with a custom estimator."""
# testing estimator and tskip
est = DcorrEstimator()
corr = conn_fcd_corr(dfc, roi='roi', times='times', verbose=False,
estimator=est, tskip=10)
assert np.nanmin(corr.data) > 0
assert corr.shape[0] == len(trials)
assert corr.shape[1] == corr.shape[2] == len(win[::10])

# testing diagonal filling
corr = conn_fcd_corr(dfc, roi='roi', times='times', fill_diagonal=-1,
verbose=False)
cm = corr.mean('trials')
np.testing.assert_array_equal(np.diag(cm), np.full((len(win),), -1))

0 comments on commit 2001f0c

Please sign in to comment.