How to get the 2D eeg connectivity matrix.

  • MNE-Python (1.7.0)
  • operating system: Windows 11

:page_facing_up: Please also provide relevant code snippets – ideally a minimal working example (MWE).

Hello, I’m new to MNE python. I’m trying to use the ‘wpli’ method to get the connectivity between all channels. I need the functional connectivity that shape like (n_channels, n_channels). But indeed, I got the result shape of (1024,1) .I don’t know why.
The dataset I used is DEAP and I splited one trail into 6 segments. One segment as one epoch. The final input data is shape of (6, 32, 1280), 6 is the epoch number, 32 is the channel number, and 1280 is the sampling points.
Please could you help !
The following is my code.

data,label = load_per_subject(1)
data = data[:6,:,:]
epoch = 6
sfreq=128
ch_names=['Fp1', 'AF3', 'F3', 'F7', 'FC5', 'FC1', 'C3', 'T7', 'CP5', 'CP1', 'P3', 'P7', 'PO3',
                               'O1', 'Oz', 'Pz', 'Fp2', 'AF4', 'Fz', 'F4', 'F8', 'FC6', 'FC2', 'Cz', 'C4', 'T8', 'CP6',
                               'CP2', 'P4', 'P8', 'PO4', 'O2']
ch_types=['eeg']*len(ch_names)
info = mne.create_info(ch_names =ch_names,ch_types = ch_types,sfreq= sfreq )
custom_epochs = mne.EpochsArray(data, info)
method = 'wpli'
conn = spectral_connectivity_epochs(
            custom_epochs,
            method=method,
            sfreq=sfreq,
            fmin=4,
            fmax=18,
            faverage=True,
        ).get_data()
print(conn.shape)

Hi,

Try setting output="dense" when calling .get_data(). This will give you the results in a [channels x channels] format.

Without this it is returning the results for each connection as a raveled array.

Cheers,
Thomas

Thank you very much!This helped a lot. Have a nice day. :wink:

1 Like

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