Error when using mne_connectivity.spectral_connectivity_time

  • MNE version: 1.0.2
  • MNE-connectivity version: 0.3
  • Python version: 3.9
  • Operating system: Windows 10

I wanted to use spectral_connectivity_time of mne-connectivity on my one-minute long intracerebral EEG data to compute coherence. However, I receive the following error message:

100%|██████████|  : 78/78 [00:05<00:00,   13.11it/s]
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/user1/Documents/ccn/intracerebral/coherence_analysis/codes/main.py", line 50, in <module>
    cohs = mne_connectivity.spectral_connectivity_time(epochs_onemin, names=None, method='coh', indices=None,
  File "C:\Users\user1\Documents\ccn\intracerebral\coherence_analysis\codes\venv\lib\site-packages\mne_connectivity\spectral\time.py", line 223, in spectral_connectivity_time
    conn = EpochSpectroTemporalConnectivity(
  File "C:\Users\user1\Documents\ccn\intracerebral\coherence_analysis\codes\venv\lib\site-packages\mne_connectivity\base.py", line 1036, in __init__
    super(EpochSpectroTemporalConnectivity, self).__init__(
  File "C:\Users\user1\Documents\ccn\intracerebral\coherence_analysis\codes\venv\lib\site-packages\mne_connectivity\base.py", line 943, in __init__
    super(SpectroTemporalConnectivity, self).__init__(
  File "C:\Users\user1\Documents\ccn\intracerebral\coherence_analysis\codes\venv\lib\site-packages\mne_connectivity\base.py", line 414, in __init__
    self._prepare_xarray(data, names=names, indices=indices,
  File "C:\Users\user1\Documents\ccn\intracerebral\coherence_analysis\codes\venv\lib\site-packages\mne_connectivity\base.py", line 495, in _prepare_xarray
    xarray_obj = xr.DataArray(
  File "C:\Users\user1\Documents\ccn\intracerebral\coherence_analysis\codes\venv\lib\site-packages\xarray\core\dataarray.py", line 402, in __init__
    coords, dims = _infer_coords_and_dims(data.shape, coords, dims)
  File "C:\Users\user1\Documents\ccn\intracerebral\coherence_analysis\codes\venv\lib\site-packages\xarray\core\dataarray.py", line 152, in _infer_coords_and_dims
    raise ValueError(
ValueError: conflicting sizes for dimension 'freqs': length 7 on the data but length 63 on coordinate 'freqs'

Here is my minimal code:

import mne
import numpy as np
import mne_connectivity

# read the edf file as a raw type
raw_edf = mne.io.read_raw_edf(input_fname='mydata-edf.edf')

# To obtain Epochs class without actually dividing my time-series data, I will create an Epochs 
# object of size 60 seconds
epochs_onemin = mne.make_fixed_length_epochs(raw_edf, duration=60, preload=True)

# sampling rate of my data
fs = 200

# frequency bands of interest
fois = np.array([[0.5, 1], [1, 2], [2, 4], [4, 8], [8, 12], [12, 16], [16, 32]])
 
# frequencies of Continuous Morlet Wavelet Transform
freqs = np.arange(0.5, 32., 0.5)

# compute coherence
cohs = mne_connectivity.spectral_connectivity_time(epochs_onemin, names=None, method='coh', indices=None,
                                                   sfreq=fs, foi=fois, sm_times=0.5, sm_freqs=1, sm_kernel='hanning',
                                                   mode='cwt_morlet', mt_bandwidth=None, freqs=freqs, n_cycles=5)

I tried to debug to see the problem. As far as I understand, in “time.py” line 202, variable “conn” is initialized as a zeros numpy array of size n_epochs x n_pairs x n_freqs x len(times). Here, n_freqs is defined as the frequencies of interest. In my case, its length is equal to 7. But, later on, at line 223, to create “EpochSpectroTemporalConnectivity” class object, “freq” parameter given is equal to the frequencies of the time-frequency decomposition. In my case, the length of it is equal to 63. I suppose, the reason for this error is the incompetence between the size of frequencies defined while initializing variable “conn” and while creating the “EpochSpectroTemporalConnectivity” object from “conn”.

How can I fix this problem?

@adam2392 is an author of MNE-Connectivy, maybe he has an idea!

Hi @cezanne can you open a GH issue and I’ll take a look?

Thanks!

Hi @adam2392! Sorry for my late reply. Sure, I have just created a GH issue :slight_smile: Thank you for your help!

The issue can be found at

2 Likes

The issue has been resolved in the latest development version of MNE-Connecticity.

1 Like