|
11 | 11 |
|
12 | 12 |
|
13 | 13 | def conn_dfc(data, win_sample=None, times=None, roi=None, n_jobs=1, gcrn=True,
|
14 |
| - verbose=None): |
| 14 | + agg_ch=False, verbose=None): |
15 | 15 | """Single trial Dynamic Functional Connectivity.
|
16 | 16 |
|
17 | 17 | This function computes the Dynamic Functional Connectivity (DFC) using the
|
@@ -46,6 +46,13 @@ def conn_dfc(data, win_sample=None, times=None, roi=None, n_jobs=1, gcrn=True,
|
46 | 46 | Specify if the Gaussian Copula Rank Normalization should be applied.
|
47 | 47 | If the data are normalized (e.g z-score) this parameter can be set to
|
48 | 48 | False because the data can be considered as gaussian over time.
|
| 49 | + agg_ch : bool | False |
| 50 | + In case there are multiple electrodes, channels, contacts or sources |
| 51 | + inside a brain region, specify how the data has to be aggregated. Use |
| 52 | + either : |
| 53 | +
|
| 54 | + * agg_ch=False : compute the pairwise DFC aross all possible pairs |
| 55 | + * agg_ch=True : compute the multivariate MI |
49 | 56 |
|
50 | 57 | Returns
|
51 | 58 | -------
|
@@ -78,13 +85,20 @@ def conn_dfc(data, win_sample=None, times=None, roi=None, n_jobs=1, gcrn=True,
|
78 | 85 |
|
79 | 86 | # -------------------------------------------------------------------------
|
80 | 87 | # find group of brain regions
|
81 |
| - gp = pd.DataFrame({'roi': roi}).groupby('roi').groups |
82 |
| - roi_gp, roi_idx = list(gp.keys()), list(gp.values()) |
| 88 | + if agg_ch: |
| 89 | + logger.info(' Grouping pairs of brain regions') |
| 90 | + gp = pd.DataFrame({'roi': roi}).groupby('roi').groups |
| 91 | + roi_gp = np.array(list(gp.keys())) |
| 92 | + roi_idx = np.array(list(gp.values())) |
| 93 | + else: |
| 94 | + roi_gp, roi_idx = roi, np.arange(len(roi)).reshape(-1, 1) |
83 | 95 | n_roi = len(roi_gp)
|
84 | 96 | x_s, x_t = np.triu_indices(n_roi, k=1)
|
85 | 97 | n_pairs = len(x_s)
|
86 |
| - pairs = np.c_[x_s, x_t] |
87 |
| - roi_p = [f"{roi_gp[s]}-{roi_gp[t]}" for s, t in zip(x_s, x_t)] |
| 98 | + # build names of pairs of brain regions |
| 99 | + roi_s, roi_t = roi_gp[x_s], roi_gp[x_t] |
| 100 | + roi_s, roi_t = np.sort(np.c_[roi_s, roi_t], axis=1).T |
| 101 | + roi_p = [f"{s}-{t}" for s, t in zip(roi_s, roi_t)] |
88 | 102 |
|
89 | 103 | # -------------------------------------------------------------------------
|
90 | 104 | # prepare outputs and elements
|
|
0 commit comments