ValueError occurs while computing spectral_connectivity_time() over epoched data

Hello MNE community!

I’ve been trying to compute EEG connectivity over epoched data from the eegbci dataset but encountered an error while using the mne_connectivity.spectral_connectivity_time() function.

Here is my code:

# loading preprocessed BIDS data
data = mne.io.read_raw_brainvision(vhdr_fname = "C:/...BIDS_preprocessed/...sub-001_ses-03_task-T1f_eeg.vhdr",preload = True)
data.set_montage('standard_1020');
data_csd = mne.preprocessing.compute_current_source_density(data)

# raw into epochs
events = mne.events_from_annotations(data_csd)
t0_epochs = mne.Epochs(data, events[0], event_id = 1, preload = True)
average_t0 = t0_epochs.average() 

# computing PLI
alpha_fr = np.arange(8, 13.5, 0.5)
con_t0 = mne_connectivity.spectral_connectivity_time(
data = average_t0,
freqs = alpha_fr,
method = 'pli',
fmin = 8.0,
fmax = 13.0
)

The error which I encounter while using the mne_connectivity.spectral_connectivity_time() function is the following:

ValueError: not enough values to unpack (expected 3, got 0)

I also tried to give unaveraged data to the funciton and setting the parameter average = True, but then another error occurs:

con_t0 = mne_connectivity.spectral_connectivity_time(
data = t0_epochs,
freqs = alpha_fr,
method = 'pli',
average = True,
fmin = 8.0,
fmax = 13.0
)

ValueError: At least one value in n_cycles corresponds to a 
wavelet longer than the signal. Use less cycles, 
higher frequencies, or longer epochs.

This is my first time analyzing epoched EEG data and I’m slightly puzzled. I will be grateful for some help.

If it is of any use, the average_t0.get_data().shape gives (64, 113). Also, the preprocessed BIDS file can be found here.

  • MNE version: 1.6.1
  • operating system: Windows 11

Hi,

ValueError: not enough values to unpack (expected 3, got 0)

The error with passing in data averaged over epochs occurs because spectral_connectivity_time() expects epoched data with shape (epochs x channels x times), but Epochs.average() returns an Evoked() object with data shape (channels x times).

Even without the error, estimating connectivity from a single epoch will give very noisy estimates, and I could also imagine averaging signals across epochs could lose some of the connectivity information occuring within epochs. Overall this is not the most reliable approach.

Your second approach of passing in epoched data and using average=True is definitely better (connectivity is estimated within each epoch, and then averaged over epochs).

ValueError: At least one value in n_cycles corresponds to a 
wavelet longer than the signal. Use less cycles, 
higher frequencies, or longer epochs.

The issue here comes from the fact that at least one of the Morlet wavelets being used to extract frequency information is too long. Like the error message says, you should either:

  1. Reduce the number of wavelet cycles (controlled with n_cycles, is default 7).
  2. Increase your fmin.
  3. Increase the length of your epochs (the default when calling mne.Epochs is tmin=-0.2 to tmax=0.5 w.r.t. event markers, so 0.7 s epochs).

Hope this helps!

Thank you so much for pointing out that mne.Epochs has the default for tmin and tmax! I managed to make the spectral_connectivity_time() work by adjusting these parameters

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.