Repository: mne-tools/mne-bids

Issue:
KeyError: 'syst' when calling write_raw_bids
#### 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](https://github.com/mne-tools/mne-bids/files/5731777/raw.zip)



#### Actual results
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/autocibr/cibr/homes/wexu/Scripts/MNE_Scripts/ChildBrain/test_bids_bug.py in <module>
     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).



Discussion:
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.
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?

can we have a failsafe mechanism so that unknown channels are encoded as "other" or something of that sort as suggested in #668 ? 
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. 

Thanks for sharing your research results, @ancpJR!

Resolving patch:
diff --git a/mne_bids/utils.py b/mne_bids/utils.py
--- a/mne_bids/utils.py
+++ b/mne_bids/utils.py
@@ -72,7 +72,7 @@ def _get_ch_type_mapping(fro='mne', to='bids'):
                        meggradaxial='MEGGRADAXIAL', megmag='MEGMAG',
                        megrefgradaxial='MEGREFGRADAXIAL',
                        meggradplanar='MEGGRADPLANAR', megrefmag='MEGREFMAG',
-                       ias='MEGOTHER')
+                       ias='MEGOTHER', syst='MEGOTHER')
 
     elif fro == 'bids' and to == 'mne':
         mapping = dict(EEG='eeg', MISC='misc', TRIG='stim', EMG='emg',


Test patch:
diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py
--- a/mne_bids/tests/test_write.py
+++ b/mne_bids/tests/test_write.py
@@ -2246,3 +2246,16 @@ def test_convert_brainvision(dir_name, fname, reader, _bids_validate):
         suffix='channels', extension='.tsv')
     channels_tsv = _from_tsv(channels_fname)
     assert channels_tsv['units'][0] == 'n/a'
+
+
+def test_write_fif_triux():
+    """Test writing Triux files."""
+    data_path = testing.data_path()
+    triux_path = op.join(data_path, 'SSS', 'TRIUX')
+    tri_fname = op.join(triux_path, 'triux_bmlhus_erm_raw.fif')
+    raw = mne.io.read_raw_fif(tri_fname)
+    bids_root = _TempDir()
+    bids_path = BIDSPath(
+        subject="01", session="01", run="01", datatype="meg", root=bids_root
+    )
+    write_raw_bids(raw, bids_path=bids_path, overwrite=True)