wPLI output values

  • MNE version: e.g. 0.24.0
  • mne_connectivity version 0.3
  • operating system: Windows 11

Hi all,
I have some questions about calculating the connectivity using wPLI. I have tried to calculate wPLI for one chunk of my epoch data.
To split my epochs into shorter segments I am using code as below:

 segments=[epochs[condition].copy().crop(i,i+time,include_tmax=True) for i
                     in range(int(epochs.tmin),int(epochs.tmax),time)] 

From which I have the list of epoch objects for different time segments, which contain the events for blocks.
image

  1. Taking 1 event

image
using code below:

con_split_epochs = mne_connectivity.spectral_connectivity_epochs(split_epochs[8][0], method='wpli',
            mode='fourier', sfreq=500, fmin=4 , fmax=12 ,faverage=True,
            mt_adaptive=False, n_jobs=1) 

and from that, I got my connectivity values equal to one between nodes.

  1. Taking all blocks (3 events)
    I have tried to do the same but this time using the data from 3 blocks.
    image
    In this case, I got values as below:

I would like to ask why the all values in the first examples are equal to 1? In the second example, are data are averaged for all events? It is possible to get data from events separately or they are averaged before calculating connectivity? Why when I am calculating connectivity for events separately the connectivity is always equal to 1?

Best,
Marta :slightly_smiling_face:

Hi! Looks like a very interesting question! It’s a bit hard to follow what you’re trying to do. Could you try and replicate this with the MNE sample data please?

Hi! I have used the eegbci data because they have longer epochs. Here is the code :slight_smile:

#%% 
from mne import Epochs, pick_types, events_from_annotations
from mne.channels import make_standard_montage
from mne.io import concatenate_raws, read_raw_edf
from mne.datasets import eegbci
import mne_connectivity
import pandas as pd

#%% data 
tmin, tmax = 0, 4.
event_id = dict(hands=2, feet=3)
subject = 1
runs = [6, 10, 14]  # motor imagery: hands vs feet

# load data 
raw_fnames = eegbci.load_data(subject, runs)
raw = concatenate_raws([read_raw_edf(f, preload=True) for f in raw_fnames])
eegbci.standardize(raw)  # set channel names
montage = make_standard_montage('standard_1005')
raw.set_montage(montage)

# strip channel names of "." characters
raw.rename_channels(lambda x: x.strip('.'))

events, _ = events_from_annotations(raw, event_id=dict(T1=2, T2=3))
picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                   exclude='bads')
# epochs
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
                baseline=None, preload=True)

#%% split epochs into 1 second events 

time_of_segment = 1
segment_list = [epochs['feet'].copy().crop(i,i+time_of_segment,
                include_tmax=True) for i in range(int(epochs.tmin), int(epochs.tmax),time_of_segment)] 

# We have here 24 events for each time segment 

#%% EXAMPLE 1
# caclulate the connectivity for time segment 0-1
data = segment_list[0]
con = mne_connectivity.spectral_connectivity_epochs(data, method='wpli',
            mode='fourier', sfreq=epochs.info['sfreq'], fmin = 6, fmax= 12 ,faverage=True,
            n_jobs=1) 

# get da
ch_names = data.ch_names
df_one_segment = pd.DataFrame(con.get_data('dense').reshape(len(ch_names),len(ch_names)),
                columns = ch_names, index = ch_names)

# is it average across events before? 

#%%  EXAMPLE 2
# caclulate the connectivity for one event from time segment 0-1
data = segment_list[0][0]
con = mne_connectivity.spectral_connectivity_epochs(data, method='wpli',
            mode='fourier', sfreq=epochs.info['sfreq'], fmin = 6, fmax= 12 ,faverage=True,
            n_jobs=1) 

# get data
df_one_event = pd.DataFrame(con.get_data('dense').reshape(len(ch_names),len(ch_names)),
                columns = ch_names, index = ch_names)

# this always returns 1? -> even when I have longer events 20s 

I’m not 100% sure what you’re trying to do but maybe it’s returning all ones to denote that the epoch perfectly matches itself since this is done over epochs. It does make sense that it should compute connectivity just for that epoch so I’m not sure, maybe @adam2392 knows.

I’m happy to help point you in the right direction to try and get where you’re going but I think I’m a bit lost why you are only using one epoch, it would be really helpful if you could explain at a high-level what you’re trying to do.

EDIT: Perhaps you are interested in computing the spectral connectivity over time for each epoch as in mne_connectivity.spectral_connectivity_time — MNE-Connectivity 0.3 documentation.

EDIT2: I would refer to the development documentation, the stable documentation examples don’t render (cc @adam2392, I know I should open an issue but I’m being lazy, sorry) MNE-Connectivity — MNE-Connectivity 0.4dev0 documentation

Hmm not sure why the documentation is not rendering… will take a look.

I’m not 100% sure what you’re trying to do but maybe it’s returning all ones to denote that the epoch perfectly matches itself since this is done over epochs. It does make sense that it should compute connectivity just for that epoch so I’m not sure, maybe @adam2392 knows.

@mkkubins spectral_connectivity_epochs assumes one connectivity structure that is fixed across all Epochs in the dataset. I can’t really follow what the problem is right now unfortunately, so lmk if that doesn’t answer your question.

mne_connectivity.spectral_connectivity_epochs — MNE-Connectivity 0.5.0 documentation See the Notes section.

Thanks for the answer @adam2392 and @alexrockhill, I am looking for something like mne_connectivity.spectral_connectivity_time however I can see that it doesn’t work for wPLI? Are there any other options to calculate the wPLI for one epoch?

Yes unfortunately, there is no time-resolved version.

There was some work by another user that coded (non-wPLI) it themselves, and the logic should hold for wPLI as well. The issue has stalled though on integrating it into mne-connectivity.

1 Like

stable docs are rendering correctly now: Examples — MNE-Connectivity 0.3 documentation

Thanks @alexrockhill for letting me know.

1 Like

Thanks for the answer! I will have a look into this one :slight_smile:

Hi, did you found out why the method had given all ones eventually? I just faced the same problem.

hello! I’ve run into the same problem when I trying to analysis resting-state data. Have you found a solution yet?