Issues with mne .24 and mne bids 0.8

  • MNE-Python version: 0.24.0 / 0.23.0
  • MNE_BIDS version: 0.7, 0.8
  • operating system: linux/windows

Dear all, first of all apologies for the spam over the past few days. I am in a bit of a rush to finish some analysis and a pipeline for the project I am working on.

I have recently updated mne from 0.23 to 0.24. As I did so, I also updated mne_bids from 0.7 to 0.8 to use the most up to date packages.

Unfortunately, that caused a few issues with my existing code that I am having a hard time figuring out. First of all, with the most up to date packages, the saving of my data to bids does not seem to work anymore. As discussed in a separate thread, I received the ieeg electrodes reconstruction files from somewhere else. I am then creating the montage based on those. Following the creation of the montage, I am saving the data to BIDS. Here is the function doing so:

import numpy as np
import mne
from mne_bids import (write_raw_bids, BIDSPath)

def save_to_bids(raw, elec_recon_file=None, bids_root=None, subject_id=None, session=None,
                 task=None, data_type=None, line_freq=None):
    # Formatting the electrodes reconstruction file:
    # Loading the electrodes coordinates in a data frame:
    elec_coord_raw = np.genfromtxt(elec_recon_file, dtype=str, delimiter=' ',
                                   comments=None, encoding='utf-8')

    # Declaring the dict to store the electrodes location:
    electrode_tsv = dict()

    # Converting each column to a list:
    for i, name in enumerate(['name', 'x', 'y', 'z']):
        electrode_tsv[name] = elec_coord_raw[:, i].tolist()

    # Get the channels name
    ch_names = electrode_tsv['name']
    # load in the xyz coordinates as a float
    elec = np.empty(shape=(len(ch_names), 3))
    for ind, axis in enumerate(['x', 'y', 'z']):
        elec[:, ind] = list(map(float, electrode_tsv[axis]))
    # Converting the elec position to meters as required by the coordinate system
    elec = elec / 1000.
    # --------------------------------------------------------------------------------------------------------------
    # Preparing the raw file for saving:
    # Making the montage:
    montage = mne.channels.make_dig_montage(ch_pos=dict(zip(ch_names, elec)),

    print('Created %s channel positions' % len(ch_names))
    print(dict(zip(ch_names, elec)))

    # Declaring the line noise, as required by BIDS:['line_freq'] = line_freq
    raw.set_montage(montage, on_missing='warn')

    # ----------------------------------------------------------------------------------------------------------
    # Separating the data based on the channel types. If there is EEG and iEEG in the signal, we need to save
    # them into separate files to be BIDS compliant, otherwise it will fail:
    channel_types = raw.get_channel_types()
    # Then getting the eeg channels specifically
    if 'seeg' in channel_types or 'ecog' in channel_types:
        # Creating an mne raw object with only the ieeg channels
        ieeg_raw = raw.copy().pick_types(ecog=True, seeg=True, ecg=True, emg=True)

        # Creating the BIDS path:
        bids_path = BIDSPath(subject=subject_id, session=session,
                             task=task, datatype=data_type, root=bids_root)
        write_raw_bids(ieeg_raw, bids_path, overwrite=True, format='auto')

    # Saving the eeg channels separately:
    if 'eeg' in channel_types:
        # Getting the EEG channels:
        eeg_raw = raw.copy().pick_types(eeg=True)
        # Creating the BIDSPath for the eeg data:
        bids_path_eeg = BIDSPath(subject=subject_id, session=session,
                                 task=task, datatype='eeg', root=bids_root)
        write_raw_bids(eeg_raw, bids_path_eeg, overwrite=True, format='auto')

    return None

Unfortunately, while this function worked fine with mne 0.23 and mne_bids 0.7, I am now receiving this error:

Writing electrodes file to...  /hpc/XNAT/COGITATE/ECoG/phase_2/processed/bids/sub-SF102/ses-V1/ieeg/sub-SF102_ses-V1_electrodes.tsv
Writing coordsytem file to...  /hpc/XNAT/COGITATE/ECoG/phase_2/processed/bids/sub-SF102/ses-V1/ieeg/sub-SF102_ses-V1_coordsystem.json
Traceback (most recent call last):
  File "/hpc/users/alexander.lepauvre/sw/github/ECoG/data_preparation/", line 427, in <module>
  File "/hpc/users/alexander.lepauvre/sw/github/ECoG/data_preparation/", line 408, in data_preparation
    save_to_BIDs(, preload=False),
  File "/hpc/users/alexander.lepauvre/sw/github/ECoG/data_preparation/", line 122, in save_to_BIDs
    write_raw_bids(ieeg_raw, bids_path, overwrite=True, format='auto')
  File "/hpc/users/alexander.lepauvre/.conda/envs/mne_ecog02/lib/python3.9/site-packages/mne_bids/", line 1470, in write_raw_bids
    _write_dig_bids(bids_path, raw, overwrite, verbose)
  File "/hpc/users/alexander.lepauvre/.conda/envs/mne_ecog02/lib/python3.9/site-packages/mne_bids/", line 372, in _write_dig_bids
    _write_electrodes_tsv(raw, electrodes_path,
  File "/hpc/users/alexander.lepauvre/.conda/envs/mne_ecog02/lib/python3.9/site-packages/mne_bids/", line 144, in _write_electrodes_tsv
    if _check_ch_locs([ch]):
  File "/hpc/users/alexander.lepauvre/.conda/envs/mne_ecog02/lib/python3.9/site-packages/mne/utils/", line 359, in _check_ch_locs
    chs = info['chs']
TypeError: list indices must be integers or slices, not str

Process finished with exit code 1

And nothing gets saved at all.

I have attempted downgrading mne_bids to 0.7 to investigate whether the issue is due to mne_bids, but this wasn’t the case, I am receiving exactly the same error with the previous version of mne_bids.

In order to further investigate this issue, I attempted to replicate the tutorial of mne_bids to save ieeg data to bids. Unfortunately, there I witnessed another error. When giving the following commands:

import os.path as op
import shutil
from pprint import pprint

import numpy as np

import mne
from mne_bids import (write_raw_bids, BIDSPath,
                      read_raw_bids, print_dir_tree)
misc_path = mne.datasets.misc.data_path(force_update=True)

# The electrode coords data are in the tsv file format
# which is easily read in using numpy
fname = misc_path + '/ecog/sample_ecog_electrodes.tsv'
data = np.loadtxt(fname, dtype=str, delimiter='\t',
                  comments=None, encoding='utf-8')

The following error appears:

Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "___\envs\mne_24\lib\site-packages\numpy\lib\", line 1067, in loadtxt
    fh =, 'rt', encoding=encoding)
  File "___\envs\mne_24\lib\site-packages\numpy\lib\", line 193, in open
    return, mode, encoding=encoding, newline=newline)
  File "___\envs\mne_24\lib\site-packages\numpy\lib\", line 533, in open
OSError: ___\mne_data\MNE-misc-data/ecog/sample_ecog_electrodes.tsv not found.

It seems that the download of the ecog data fails, as I can only see this in the miscellaneous directory:

The sample_ecog_electrodes.tsv is missing, despite the download of the data being successful.

I am therefore somewhat stuck to investigate whether the issue when attempting to saving the data to bids is due to a difference in format between what I am doing and what write_BIDS expects, or whether the issue lies somewhere else.

Has anyone an idea of what might be causing these issues?

Please let me know if there is anything else I can provide/do to help solve this issue.

Kind regards,



the tutorial is outdated and does not work with the latest version of the misc dataset anymore.

An updated version can be found in the documentation of the current development version of MNE-BIDS (which will soon be released as MNE-BIDS 0.9):

I’m not sure if the example code will work with MNE-BIDS 0.8, though, or whether you’ll have to wait for MNE-BIDS 0.9 (few more days)


1 Like