# Issues with mne .24 and mne bids 0.8

**URL:** <https://mne.discourse.group/t/issues-with-mne-24-and-mne-bids-0-8/3948>\
**Category:** Support & Discussions\
**Tags:** mne-bids\
**Created:** [November 12, 2021, 4:07pm UTC](https://mne.discourse.group/t/issues-with-mne-24-and-mne-bids-0-8/3948 "2021-11-12T16:07:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexLepauvre](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/alexlepauvre/32/254_2.png) [@AlexLepauvre](https://mne.discourse.group/u/AlexLepauvre)\
**Post date:** [November 12, 2021, 4:07pm UTC](https://mne.discourse.group/t/issues-with-mne-24-and-mne-bids-0-8/3948/1 "2021-11-12T16:07:33Z")

</div>

- 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:

```python
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)),
                                            coord_frame='mri')

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

    # Declaring the line noise, as required by BIDS:
    raw.info['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:

```python
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/Experiment1_data_preparation.py", line 427, in <module>
    data_preparation()
  File "/hpc/users/alexander.lepauvre/sw/github/ECoG/data_preparation/Experiment1_data_preparation.py", line 408, in data_preparation
    save_to_BIDs(mne.io.read_raw(fname, preload=False),
  File "/hpc/users/alexander.lepauvre/sw/github/ECoG/data_preparation/mne_bids_converter.py", 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/write.py", 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/dig.py", 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/dig.py", 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/check.py", 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](https://mne.tools/mne-bids/stable/auto_examples/convert_ieeg_to_bids.html) of mne\_bids to save ieeg data to bids. Unfortunately, there I witnessed another error. When giving the following commands:

```python
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:

```python
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "___\envs\mne_24\lib\site-packages\numpy\lib\npyio.py", line 1067, in loadtxt
    fh = np.lib._datasource.open(fname, 'rt', encoding=encoding)
  File "___\envs\mne_24\lib\site-packages\numpy\lib\_datasource.py", line 193, in open
    return ds.open(path, mode, encoding=encoding, newline=newline)
  File "___\envs\mne_24\lib\site-packages\numpy\lib\_datasource.py", 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:

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/571c2488cbb092cd7ee9e111c333219d4f79cf67.png)

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,

Alex

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 13, 2021, 7:04pm UTC](https://mne.discourse.group/t/issues-with-mne-24-and-mne-bids-0-8/3948/2 "2021-11-13T19:04:21Z")

</div>

Hello,

> [@AlexLepauvre](#):
>
> In order to further investigate this issue, I attempted to replicate the [tutorial](https://mne.tools/mne-bids/stable/auto_examples/convert_ieeg_to_bids.html) of mne\_bids to save ieeg data to bids. Unfortunately, there I witnessed another error.

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):  
[https://mne.tools/mne-bids/dev/auto\_examples/convert\_ieeg\_to\_bids.html](https://mne.tools/mne-bids/dev/auto_examples/convert_ieeg_to_bids.html)

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)

Best,  
Richard
