mne-tools / mne-connectivity

Connectivity algorithms that leverage the MNE-Python API.
https://mne.tools/mne-connectivity/dev/index.html
BSD 3-Clause "New" or "Revised" License
66 stars 34 forks source link

read_connectivity crashes with KeyError when reading older files #109

Closed drammock closed 1 year ago

drammock commented 1 year ago

Describe the bug

When trying to load a file saved about a year ago, read_connectivity crashes (traceback below).

Steps to reproduce

Here's a file that fails this way: http://dan.mccloy.info/f2f-f2f_009-attend-theta-band-7sec-envelope-correlation.nc

from mne_connectivity import read_connectivity
read_connectivity('f2f-f2f_009-attend-theta-band-7sec-envelope-correlation.nc')

Expected results

the file is loaded.

Actual results

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/Documents/academics/research/ilabs/ftof/connectivity/analysis/make-xarrays.py in <module>
     78                 conn_fname = (f'{slug}-{n_sec}sec-envelope-correlation.nc')
     79                 conn_fpath = os.path.join(conn_dir, conn_fname)
---> 80                 conn = mne_connectivity.read_connectivity(conn_fpath)
     81                 # envelope correlations
     82                 conn_matrix = conn.get_data('dense').squeeze()

/opt/mne/connectivity/mne_connectivity/io.py in read_connectivity(fname)
     99 
    100     # get the data as a new connectivity container
--> 101     conn = _xarray_to_conn(conn_da, cls_func)
    102     return conn

/opt/mne/connectivity/mne_connectivity/io.py in _xarray_to_conn(array, cls_func)
     45 
     46     # write event IDs
---> 47     event_id_keys = np.atleast_1d(array.attrs.pop('event_id_keys')).tolist()
     48     event_id_vals = np.atleast_1d(array.attrs.pop('event_id_vals')).tolist()
     49     event_id = {key: val for key, val in zip(event_id_keys, event_id_vals)}

KeyError: 'event_id_keys'

Additional information

looks like it was caused by #58 if I had to venture a guess.