@@ -53,14 +53,14 @@ def spectral_connectivity_time(data, names=None, method='coh', indices=None,
53
53
Extract frequencies of interest. This parameters should be an array of
54
54
shapes (n_foi, 2) defining where each band of interest start and
55
55
finish.
56
- sm_times : float | .5
57
- Number of points to consider for the temporal smoothing in seconds. By
58
- default, a 500ms smoothing is used.
59
- sm_freqs : int | 1
56
+ sm_times : float
57
+ Amount of time to consider for the temporal smoothing in seconds. By
58
+ default, 0.5 sec smoothing is used.
59
+ sm_freqs : int
60
60
Number of points for frequency smoothing. By default, 1 is used which
61
- is equivalent to no smoothing
62
- kernel : {'square', 'hanning'}
63
- Kernel type to use. Choose either 'square' or 'hanning'
61
+ is equivalent to no smoothing.
62
+ sm_kernel : {'square', 'hanning'}
63
+ Kernel type to use. Choose either 'square' or 'hanning' (default).
64
64
mode : str, optional
65
65
Spectrum estimation mode can be either: 'multitaper', or
66
66
'cwt_morlet'.
@@ -239,6 +239,7 @@ def _spectral_connectivity(data, method, kernel, foi_idx,
239
239
n_pairs = len (source_idx )
240
240
241
241
# first compute time-frequency decomposition
242
+ collapse = None
242
243
if mode == 'cwt_morlet' :
243
244
out = tfr_array_morlet (
244
245
data , sfreq , freqs , n_cycles = n_cycles , output = 'complex' ,
@@ -261,13 +262,24 @@ def _spectral_connectivity(data, method, kernel, foi_idx,
261
262
data , sfreq , freqs , n_cycles = n_cycles ,
262
263
time_bandwidth = mt_bandwidth , output = 'complex' , decim = decim ,
263
264
n_jobs = n_jobs , ** kw_mt )
265
+ collapse = True
266
+ if out .ndim == 5 : # newest MNE-Python
267
+ collapse = - 3
264
268
265
269
# get the supported connectivity function
266
270
conn_func = {'coh' : _coh , 'plv' : _plv , 'sxy' : _cs }[method ]
267
271
268
272
# computes conn across trials
273
+ # TODO: This is wrong -- it averages in the complex domain (over tapers).
274
+ # What it *should* do is compute the conn for each taper, then average
275
+ # (see below).
276
+ if collapse is not None :
277
+ out = np .mean (out , axis = collapse )
269
278
this_conn = conn_func (out , kernel , foi_idx , source_idx , target_idx ,
270
279
n_jobs = n_jobs , verbose = verbose , total = n_pairs )
280
+ # This is where it should go, but the regression test fails...
281
+ # if collapse is not None:
282
+ # this_conn = [c.mean(axis=collapse) for c in this_conn]
271
283
return this_conn
272
284
273
285
@@ -288,10 +300,10 @@ def _coh(w, kernel, foi_idx, source_idx, target_idx, n_jobs, verbose, total):
288
300
# define the pairwise coherence
289
301
def pairwise_coh (w_x , w_y ):
290
302
# computes the coherence
291
- s_xy = w [:, w_y , :, : ] * np .conj (w [:, w_x , :, : ])
303
+ s_xy = w [:, w_y ] * np .conj (w [:, w_x ])
292
304
s_xy = _smooth_spectra (s_xy , kernel )
293
- s_xx = s_auto [:, w_x , :, : ]
294
- s_yy = s_auto [:, w_y , :, : ]
305
+ s_xx = s_auto [:, w_x ]
306
+ s_yy = s_auto [:, w_y ]
295
307
out = np .abs (s_xy ) ** 2 / (s_xx * s_yy )
296
308
# mean inside frequency sliding window (if needed)
297
309
if isinstance (foi_idx , np .ndarray ):
@@ -312,7 +324,7 @@ def _plv(w, kernel, foi_idx, source_idx, target_idx, n_jobs, verbose, total):
312
324
# define the pairwise plv
313
325
def pairwise_plv (w_x , w_y ):
314
326
# computes the plv
315
- s_xy = w [:, w_y , :, : ] * np .conj (w [:, w_x , :, : ])
327
+ s_xy = w [:, w_y ] * np .conj (w [:, w_x ])
316
328
# complex exponential of phase differences
317
329
exp_dphi = s_xy / np .abs (s_xy )
318
330
# smooth e^(-i*\delta\phi)
@@ -338,7 +350,7 @@ def _cs(w, kernel, foi_idx, source_idx, target_idx, n_jobs, verbose, total):
338
350
# define the pairwise cross-spectra
339
351
def pairwise_cs (w_x , w_y ):
340
352
# computes the cross-spectra
341
- out = w [:, w_x , :, : ] * np .conj (w [:, w_y , :, : ])
353
+ out = w [:, w_x ] * np .conj (w [:, w_y ])
342
354
out = _smooth_spectra (out , kernel )
343
355
if foi_idx is not None :
344
356
return _foi_average (out , foi_idx )
0 commit comments