Writting .mff files into BIDS, problems with write_raw_bids

Hello, new to mne-python and could use some help. I’m currently trying to convert raw data from mff files into BIDS. At the moment I can read in and create a BIDS data structure with raw mff data, but I cannot convert a .bin file (from the mff file) into fif format.

At the moment my program looks like this:

import matplotlib
import pathlib

import mne
import mne_bids

matplotlib.use('Qt5Agg')
mne.set_log_level('warning') 

raw_fname = pathlib.Path('subject_data') / 'WM_1_isi0_s1c_20191110_020011.mff'
raw = mne.io.read_raw_egi(raw_fname)

out_path = pathlib.Path('out_data2/sample_BIDS') #Into which directory the data should go

bids_path = mne_bids.BIDSPath(subject='01',
                              session='01',
                              task='WM1 isi0',
                              datatype='eeg',
                              root=out_path) 

mne_bids.write_raw_bids(raw, bids_path=bids_path, events_data=events, format='FIF', allow_preload=True,
                        event_id=event_id, overwrite=True)

And spits out this error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Input In [6], in <cell line: 9>()
      1 out_path = pathlib.Path('out_data2/sample_BIDS') #Into which directory the data should go
      3 bids_path = mne_bids.BIDSPath(subject='01',
      4                               session='01',
      5                               task='WM1 isi0',
      6                               datatype='eeg',
      7                               root=out_path) #An object that specifies the location of BIDS files
----> 9 mne_bids.write_raw_bids(raw, bids_path=bids_path, events_data=events, format='FIF', allow_preload=True,
     10                         event_id=event_id, overwrite=True)

File <decorator-gen-585>:12, in write_raw_bids(raw, bids_path, events_data, event_id, anonymize, format, symlink, empty_room, allow_preload, montage, acpc_aligned, overwrite, verbose)

File ~\anaconda3\envs\mne\lib\site-packages\mne_bids\write.py:1668, in write_raw_bids(***failed resolving arguments***)
   1663 make_dataset_description(bids_path.root, name=" ", overwrite=False)
   1665 _sidecar_json(raw, task=bids_path.task, manufacturer=manufacturer,
   1666               fname=sidecar_path.fpath, datatype=bids_path.datatype,
   1667               emptyroom_fname=associated_er_path, overwrite=overwrite)
-> 1668 _channels_tsv(raw, channels_path.fpath, overwrite)
   1670 # create parent directories if needed
   1671 _mkdir_p(os.path.dirname(data_path))

File ~\anaconda3\envs\mne\lib\site-packages\mne_bids\write.py:110, in _channels_tsv(raw, fname, overwrite)
    108 # get the manufacturer from the file in the Raw object
    109 _, ext = _parse_ext(raw.filenames[0])
--> 110 manufacturer = MANUFACTURERS[ext]
    112 ignored_channels = IGNORED_CHANNELS.get(manufacturer, list())
    114 status, ch_type, description = list(), list(), list()

KeyError: '.bin'

-----------------------------------

It appears that write_raw_bids is having problems converting .bin files into an fif format, though it could definitely be something else.

Hello, I’m not familiar with this file format, is that generated by EGI systems?

Because there’s currently a pull request to add support for EGI to MNE-BIDS, meaning it’s not yet officially supported:

Also pinging @sappelhoff and @mscheltienne who probably followed this development more closely than I did! Also I think I remember @cbrnr was once dealing with MFF files, but I might be mistaken.

Handing out tags here like candy!!! :lollipop:

In any case,
best of luck!

Richard

1 Like

Sorry, I never worked with MFF (at least as far as I can remember :laughing:).

1 Like

Hello,

EEG datasets have to be converted to one of the formats for BIDS. Quoting the write_raw_bids page:

The original file is simply copied over if the original file format is BIDS-supported for that datatype. Otherwise, this function will convert to a BIDS-supported file format while warning the user. For EEG and iEEG data, conversion will be to BrainVision format; for MEG, conversion will be to FIFF.

And at the moment, mne-bids does not recognize what the .bin extension corresponds to and how to convert it to BrainVision format. I’m adding support in the PR linked by @richard but I still have to fix a couple of bugs… I’ll try to find time this week.

Best,
Mathieu

1 Like