Skip to content

Issues with time-resolved spectral connectivity #90

Closed
@adam2392

Description

@adam2392

"Hello everyone,

I’m currently using MNE connectivity to perform a functional connectivity analysis in a single epoch. With this said, I’ve read some threads where concerns were raised about using spectral_connectivity/spectral_connectivity_epochs on a single epoch.In such case we are advised to perform a time spectral connectivity analysis on the epoch. As my goal is to obtain connectivity in the following structure-(n_nodes,n_nodes,n_freqs), I tried to use the follwing functions: spectral_connectivity_time with mode=“multitaper”, SpectralConnectivity and EpochSpectralConnectivity. The code snippets are provided below and contain also the errors. At the snippets we only try to analyze theta and alpha freqs and the df_V[“data_ref”][0] represent a session of neurofeedback training in visual modality. Notice that this df_V[“data_ref”][0] is composed by 30 epochs so we are using the index 0 to access to the first epoch.

Thank you all,
Best Regards

MNE version: 0.24.1
-MNE connectivity version: 0.4.dev0
operating system: Windows 10
Option 1: spectral_connectivity_time

#fmin=df_V[“IAF”][0]+2
#fmax=30
sfreq = df_V[“Data_REF”][0].info[‘sfreq’] # the sampling frequency
tmin = 0.0 # exclude the baseline period
con_trial = mne_connectivity.spectral_connectivity_time(df_V[“Data_REF”][0][0], method=‘plv’, mode=‘multitaper’,
sfreq=sfreq, foi=((4,8),(8,12)))
conmat_trial = con_trial.get_data(output=‘dense’)[:, :, 0]
#mne_connectivity.viz.plot_sensors_connectivity(df_V[“Data_REF”][0].info,conmat_trial)
#fig=plot_connectivity_circle(conmat_trial, df_V[“Data_REF”][0][0].info[‘ch_names’])
#fig[0].savefig(“fig.png”, facecolor=fig[0].get_facecolor())
#mean=Mean_Lower_Triangle(conmat_trial)
print(conmat_trial)

This raises an error on spectral connectivity time- UnboundLocalError: local variable ‘f_vec’ referenced before assignment. Notice that i tried using freqs instead of foi but i gaves me also errors.

Option 2: SpectralConnectivity function. In this case the error seems to be the parameters of the input array as it asks for a list/ [ np.ndarray ] with the following structure [epochs], n_estimated_nodes, [freqs], [times]). As my array has only 3 dimension (with the third being times), it gives me an error like the one below. It seems that he is considering the data as beeing on the frequency domain.

#fmin=df_V[“IAF”][0]+2
#fmax=30
sfreq = df_V[“Data_REF”][0].info[‘sfreq’] # the sampling frequency
tmin = 0.0 # exclude the baseline period
x=df_V[“Data_REF”][0].get_data()
con_trial = mne_connectivity.SpectralConnectivity(x[0], method=‘imcoh’,n_nodes=32, names=df_V[“Data_REF”][0][0].info[‘ch_names’],
n_epochs_used=1, freqs=[2,[[4,8],[8,12]]])
conmat_trial = con_trial.get_data(output=‘dense’)[:, :, 0]
#mne_connectivity.viz.plot_sensors_connectivity(df_V[“Data_REF”][0].info,conmat_trial)
#fig=plot_connectivity_circle(conmat_trial, df_V[“Data_REF”][0][0].info[‘ch_names’])
#fig[0].savefig(“fig.png”, facecolor=fig[0].get_facecolor())
#mean=Mean_Lower_Triangle(conmat_trial)
print(conmat_trial)
ValueError: conflicting sizes for dimension ‘freqs’: length 30001 on the data but length 2 on coordinate ‘freqs’

in:x=df_V[“Data_REF”][0].get_data()
print(x[0])
x.ndim

out:
[[ 4.49762816e-06 9.10974306e-06 1.40401711e-05 … -2.35420393e-06
2.98088536e-06 4.50267834e-06]
[ 2.14575434e-05 2.40399849e-05 2.74856399e-05 … 1.00799157e-04
9.36656125e-05 8.75125799e-05]
[-1.22865745e-05 -1.71034458e-05 -2.26082490e-05 … -3.30322897e-05
-4.07222123e-05 -4.48906183e-05]
…
[-1.47824244e-05 -1.98617468e-05 -2.26040034e-05 … -9.73291995e-05
-1.05251876e-04 -1.06747114e-04]
[ 3.01504084e-06 3.02932533e-06 1.05186535e-08 … -1.11299831e-04
-1.15024991e-04 -1.15647967e-04]
[-5.38182499e-05 -5.08062563e-05 -4.83661139e-05 … -3.87917777e-05
-3.52674487e-05 -3.18219798e-05]]
3

This last error seems to apply also to the function- EpochSpectralConnectivity

Originally posted by @pedro3714 in #73 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions