mne-tools / mne-bids

MNE-BIDS is a Python package that allows you to read and write BIDS-compatible datasets with the help of MNE-Python.
https://mne.tools/mne-bids/
BSD 3-Clause "New" or "Revised" License
131 stars 85 forks source link

KeyError: 'syst' when calling write_raw_bids #666

Closed weiyongxu closed 3 years ago

weiyongxu commented 3 years ago

Describe the bug

Hi,

I have this error when trying to write the raw fif file to bids format. Could you help me check this?

Thanks, Weiyong Xu

Steps to reproduce

import mne from mne_bids import BIDSPath, write_raw_bids raw = mne.io.read_raw_fif('raw.fif') bids_path = BIDSPath(subject='01', session='01', run='05',datatype='meg',root='./bids_dataset') write_raw_bids(raw, bids_path=bids_path)

a link to a small, anonymized portion of the data:

raw.zip

Actual results


KeyError Traceback (most recent call last) /autocibr/cibr/homes/wexu/Scripts/MNE_Scripts/ChildBrain/test_bids_bug.py in 11 raw = mne.io.read_raw_fif('raw.fif') 12 bids_path = BIDSPath(subject='01', session='01', run='05',datatype='meg',root='./bids_dataset') ---> 13 write_raw_bids(raw, bids_path=bids_path)

~/.conda/envs/my_MNE_0.22.0/lib/python3.8/site-packages/mne_bids/write.py in write_raw_bids(failed resolving arguments) 1239 _sidecar_json(raw, bids_path.task, manufacturer, sidecar_path.fpath, 1240 bids_path.datatype, overwrite, verbose) -> 1241 _channels_tsv(raw, channels_path.fpath, overwrite, verbose) 1242 1243 # create parent directories if needed

~/.conda/envs/my_MNE_0.22.0/lib/python3.8/site-packages/mne_bids/write.py in _channels_tsv(raw, fname, overwrite, verbose) 108 if _channel_type in get_specific: 109 _channel_type = coil_type(raw.info, idx, _channel_type) --> 110 ch_type.append(map_chs[_channel_type]) 111 description.append(map_desc[_channel_type]) 112 low_cutoff, high_cutoff = (raw.info['highpass'], raw.info['lowpass'])

KeyError: 'syst'

Additional information

I am using the latest mne-python(0.22.0) and mne bids (0.6).

hoechenberger commented 3 years ago

Hello, thanks for reporting this issue! It appears we're currently not handling the syst channel type correctly (or, actually, not at all). We'll look into this.

agramfort commented 3 years ago

in the BIDS MEG standard to what type of channel should this correspond to?

https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/02-magnetoencephalography.html

what does this channel actually contain for you?

jasmainak commented 3 years ago

can we have a failsafe mechanism so that unknown channels are encoded as "other" or something of that sort as suggested in #668 ?

ancpJR commented 3 years ago

Hi all, this is what I could find out about the channel: It seems to be tagged SYS201 in the fif file and seems to be specific to the Triux system. I could not find any description of its function in the Triux system manuals and in the few files I looked it had different values but the value was constant over a measurement. In mne's picks.py it is described as "System status channel information (on Triux systems only)". However, mne does not seem to do anything with it except handling it in the info structure. There was a discussion among mne developers from 2013 on the channel: https://github.com/mne-tools/mne-python/issues/694 and this is how it was resolved: https://github.com/mne-tools/mne-python/pull/703/files. It received the type 'syst' (for pick) and the 'kind' = 900 (FIFFV_SYST_CH). A superficial search for program code that explicitly uses 'syst' or 'SYS201' did not reveal anything that indicates use for analyses.

Long story short, the channel does not seem to contribute information required at the level of data analysis Since it channel does not seem to fit into any of the channels defined in BIDS I think the type OTHER would be a good choice.

hoechenberger commented 3 years ago

Thanks for sharing your research results, @ancpJR!

agramfort commented 3 years ago

see https://github.com/mne-tools/mne-bids/pull/674