spectral connectivity for source estimate without epochs

What is a simple way to calculate a spectral connectivity for source estimates from non-epoched raw data?

While running

label_ts = mne.extract_label_time_course(sources, labels, src, mode='mean_flip',
                                         return_generator=True)

fmin = 8.
fmax = 13.
sfreq = 256
con = mne_connectivity.spectral_connectivity_epochs(
    label_ts, method='coh', sfreq=sfreq, fmin=fmin,
    fmax=fmax, mt_adaptive=True)

I’m getting an error

File "/home/white/APPS/anaconda3/envs/mne/lib/python3.10/site-packages/mne_connectivity/spectral/epochs.py", line 691, in _get_and_verify_data_sizes
    this_n_signals, this_n_times = this_data.shape
ValueError: not enough values to unpack (expected 2, got 1)

This error probably means that sources were calculated from non-epoched data (i.e. by mne.minimum_norm.apply_inverse_raw()).

What would be the simplest solution to this problem?

  • operating system: Kubuntu 22

Dear Tomasz,
The simplest way is to reshape the data in 3D format as channels x times x trials or vertices x times x trials, something like-

stc_raw.data.reshape((1,stc_raw.data.shape[0], stc_raw.data.shape[1]))

In you case the format would be labels x times x 1

Cheers.

2 Likes

Thank you!
Your hint helped me to solve the problem. In fact the simplest solution is to redefine label_ts as:

label_ts = [label_ts]

It is somehow strange that algorithm does not accept 1 copy of label_ts with lower dimension. It seems it would be easy to fix it by developers.

2 Likes

That’s even better.