Hello ! Sorry for my poor english, I’m a french student
In order to analyze EEG data obtained in resting-state in several volunteers, I was interested in connectivity using mne_connectivity and the following code:
con_epochs = spectral_connectivity_epochs(epochs, method="pli", mode="multitaper", faverage=True,n_jobs=1)
plot_sensors_connectivity(rawm.info, con_epochs.get_data(output="dense")[:,:,0],picks=['Fp1', 'Fp2', 'F7', 'F3', 'Fz', 'F4', 'F8', 'FT9', 'FC5', 'FC1', 'FC2', 'FC6', 'FT10', 'T7', 'C3', 'Cz', 'C4', 'T8', 'TP9', 'CP5', 'CP1', 'CP2', 'CP6', 'TP10', 'P7', 'P3', 'Pz', 'P4', 'P8', 'O1', 'O2', 'EOG', 'Fpz', 'AF7', 'AF3', 'AF4', 'AF8', 'F5', 'F1', 'F2', 'F6', 'FT7', 'FC3', 'FC4', 'FT8', 'C5', 'C1', 'C2', 'C6', 'TP7', 'CP3', 'CPz', 'CP4', 'TP8', 'P5', 'P1', 'P2', 'P6', 'PO7', 'PO3', 'POz', 'PO4', 'PO8', 'Oz'],cbar_label="Connectivité", n_con=20, cmap="RdBu")
tmin=0.0
times=epochs.times[epochs.times>=tmin]
con_epochs_raveled_array=con_epochs.get_data(output="raveled")
n_channels=epochs.info["nchan"]
n_connections=(n_channels*n_channels-n_channels)/2
global_con_epochs=np.sum(con_epochs_raveled_array, axis=0)/n_connections
global_con_epochs=global_con_epochs[0]
t_con_max=np.argmax(global_con_epochs)
con_epochs_matrix=con_epochs.get_data(output="dense")[:,:,0]
fig=plt.figure()
I got a connectivity matrix for each topic (a table of 61 columns by 61 rows that looks like this :
I’ve made an average table with the data from all my volunteers and I’d like to enter this average matrix into mne in order to use it for connectivity analysis and get the same figure as with my previous code. On the other hand, I’m having problems with the format of my matrix not being read correctly. Here’s my code for now :
import mne
import numpy as np
import matplotlib.pyplot as plt
import mne_connectivity
from mne.datasets import sample
from mne_connectivity import viz
from mne_connectivity.viz import plot_sensors_connectivity
from mne.connectivity import spectral_connectivity_epochs, plot_sensors_connectivity
mat = np.load('C:/Users/33678/OneDrive/Documents/Master 2/Stage/tableau_numpy.npy', allow_pickle=True)
mat_sans_nan = np.nan_to_num(mat, nan=0.0)
ch_names = ['F8', 'F2', 'AF8', 'AF4', 'FP2', 'Fz', 'FC1', 'FPz', 'F1', 'AF3', 'F3', 'FP1', 'FC3', 'C1', 'AF7', 'F7', 'F5', 'FC5', 'C3', 'FT7', 'C5', 'CP3', 'FT9', 'T7', 'CP5', 'CP1', 'TP7', 'P5', 'P3', 'P1', 'CPz', 'P7', 'PO7', 'Pz', 'PO3', 'O1', 'PO2', 'Oz', 'PO4', 'P2', 'CP2' ,'O2' ,'P4', 'PO8', 'P6', 'CP4', 'P8', 'CP6', 'TP8', 'C4', 'C2', 'C6', 'T8', 'FP4', 'FC2', 'FT8', 'FC8', 'FT10' ,'F6', 'F4', 'F10']
ch_info = mne.create_info(ch_names, sfreq=1000, ch_types='eeg')
sfreq=1000
ch_types = ['eeg'] * len(ch_names)
raw_array = mne.io.RawArray(mat_sans_nan, ch_info)
print(raw_array._data.shape)
info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
epochs_sans_events = mne.EpochsArray(raw_array, info)
con_epochs= spectral_connectivity_epochs(epochs_sans_events, method="pli", mode="multitaper", faverage=True, sfreq=1000, n_jobs=1)
plot_sensors_connectivity(epochs.info, mat_sans_nan, picks=['F8', 'F2', 'AF8', 'AF4', 'FP2', 'Fz', 'FC1', 'FPz', 'F1', 'AF3', 'F3', 'FP1', 'FC3', 'C1', 'AF7', 'F7', 'F5', 'FC5', 'C3', 'FT7', 'C5', 'CP3', 'FT9', 'T7', 'CP5', 'CP1', 'TP7', 'P5', 'P3', 'P1', 'CPz', 'P7', 'PO7', 'Pz', 'PO3', 'O1', 'PO2', 'Oz', 'PO4', 'P2', 'CP2' ,'O2' ,'P4', 'PO8', 'P6', 'CP4', 'P8', 'CP6', 'TP8', 'C4', 'C2', 'C6', 'T8', 'FP4', 'FC2', 'FT8', 'FC8', 'FT10' ,'F6', 'F4', 'F10'], cbar_label="Connectivité", n_con=20, sfreq=1000, cmap="RdBu")
times = np.arange(tmin, tmax, 1/sfreq)
con_epochs_raveled_array = con_epochs.get_data(output="raveled")
n_channels = epochs.info["nchan"]
n_connections = (n_channels * n_channels - n_channels) / 2
global_con_epochs = np.sum(con_epochs_raveled_array, axis=0) / n_connections
global_con_epochs = global_con_epochs[0]
t_con_max = np.argmax(global_con_epochs)
con_epochs_matrix = con_epochs.get_data(output="dense")[:, :, 0]
fig = plt.figure()
And I got this error message :
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (61, 2) + inhomogeneous part.
Do you have any advice please? I would be very grateful