Repository: mne-tools/mne-bids

Issue:
ValueError: Unknown coil of type 201609 for channel MLC11
It seems like this requires a dedicated issue (I posted this in #119, but ende up being unrelated).
I get an error:
`ValueError: Unknown coil of type 201609 for channel MLC11`

I'm trying to convert CTF system (I think DSQ-3000) data to BIDS and this error comes from `pick.py` file

In that thread I got a suggestion:
- That doesn't look like a valid coil type from MNE at all. see this previous issue: #95 

Following the code from #95:
```python
from mne.io.pick import channel_type
from mne import pick_channels

pick = pick_channels(raw.info['ch_names'], ['EOG061'])
ch_type = channel_type(raw.info, pick)
print(ch_type)
```
I get that the channel type is `mag`. 

Here is a bit more info about that channel:
```json
{'ch_name': u'MLC11', 'unit_mul': 0, 'range': 1.0, 'coord_frame': 1, 'cal': -3.283740062188218e-16, 'coil_type': 201609, 'logno': 1}, {'kind': 1, 'scanno': 32, 'unit': 112, 'loc': array([-0.02937675,  0.05508574,  0.080087  ,  0.72974126,  0.67733105,  -0.09327559, -0.65713925,  0.65713925, -0.36923708, -0.18880069, 0.33074258,  0.92464244])}
```

Its also not only this channel, its 272 of them with this coil type. Otherwise, I have a bunch of other channels with coil type 0 and I have 32 channels that conform to these codes:
```python
FIFF.FIFFV_COIL_CTF_REF_MAG          = 5002
FIFF.FIFFV_COIL_CTF_REF_GRAD         = 5003
FIFF.FIFFV_COIL_CTF_OFFDIAG_REF_GRAD = 5004
```
from [MNE constants](https://github.com/mne-tools/mne-python/blob/master/mne/io/constants.py).

I would gladly dig deeper, but I'm beginner when it comes to MEG and would need a bit of guidance. We have a good team of physicists and radiographer that I can query about technical details, but it would be good to know what to ask them.

By the way, from which file in `.ds` folder is mne or mne_bids pulling this info out?

Any suggestions how to proceed?


Discussion:
okay, so this [part of the code](https://github.com/mne-tools/mne-bids/blob/master/mne_bids/mne_bids.py#L124-L125) is broken. Basically, instead of raising an error, it should fall back on to `MEGOTHER` as the channel type. @monkeyman192 agreed?
@jasmainak yep, sounds reasonable I think.
I am still curious as to why the type isn't in the MNE constants list. Surely it would be better to actually add it to the list so that we have the correct data instead of just 'other'
@monkeyman192, note that MNE is still able to infer that it's a mag, grad or ref_meg. This appears to be sufficient for me already. Perhaps these constants keep changing with new systems, so it doesn't make sense to add all of them in the `constants.py` file? I would suggest fixing the logic there as otherwise, we will hit corner cases all the time.
Yeah, I agree that the logic should be fixed so that we don't have this issue in the future. I just meant that if we did know what the actual specific kind was that it could be added. I wasn't aware that they might be changing/having new types added in newer systems, but if that is the case then it would be inconvenient as you say to have to keep adding them.
As a quick fix, I'm simply substituting the coil type `info['chs'][i]['coil_type']` with 5001 from the constants. This hack did the trick in terms of getting the BIDS conversion working. I will fix it once the new version is up.

Is there anything particularly problematic with this as a temporary solution, will it affect my subsequent usage of the MEG files?
I'm not sure. But note that `mne-bids` should copy your original files if it's CTF data. So, your edits won't carry forward in the saved file ...

We can fix your problem if you provide us with a file and a script to reproduce the problem.

Resolving patch:
diff --git a/examples/convert_eeg_to_bids.py b/examples/convert_eeg_to_bids.py
--- a/examples/convert_eeg_to_bids.py
+++ b/examples/convert_eeg_to_bids.py
@@ -25,7 +25,6 @@
 
 import mne
 from mne.datasets import eegbci
-from mne.io.edf.edf import read_annotations_edf
 
 from mne_bids import write_raw_bids, make_bids_basename
 from mne_bids.utils import print_dir_tree
@@ -94,7 +93,7 @@
 ###############################################################################
 # The annotations stored in the file must be read in separately and converted
 # into a 2D numpy array of events that is compatible with MNE.
-annot = read_annotations_edf(edf_path)
+annot = mne.read_annotations(edf_path)
 raw.set_annotations(annot)
 events, event_id = mne.events_from_annotations(raw)
 
@@ -163,7 +162,7 @@
         edf_path = eegbci.load_data(subject=subj_idx, runs=task_idx)[0]
 
         raw = mne.io.read_raw_edf(edf_path, preload=False, stim_channel=None)
-        annot = read_annotations_edf(edf_path)
+        annot = mne.read_annotations(edf_path)
         raw.set_annotations(annot)
         events, event_id = mne.events_from_annotations(raw)
 
diff --git a/mne_bids/mne_bids.py b/mne_bids/mne_bids.py
--- a/mne_bids/mne_bids.py
+++ b/mne_bids/mne_bids.py
@@ -122,7 +122,7 @@ def _channels_tsv(raw, fname, overwrite=False, verbose=True):
         status.append('bad' if ch in raw.info['bads'] else 'good')
         _channel_type = channel_type(raw.info, idx)
         if _channel_type in get_specific:
-            _channel_type = coil_type(raw.info, idx)
+            _channel_type = coil_type(raw.info, idx, _channel_type)
         ch_type.append(map_chs[_channel_type])
         description.append(map_desc[_channel_type])
     low_cutoff, high_cutoff = (raw.info['highpass'], raw.info['lowpass'])
diff --git a/mne_bids/pick.py b/mne_bids/pick.py
--- a/mne_bids/pick.py
+++ b/mne_bids/pick.py
@@ -44,7 +44,7 @@ def get_coil_types():
                 misc=(FIFF.FIFFV_COIL_NONE,))
 
 
-def coil_type(info, idx):
+def coil_type(info, idx, ch_type='n/a'):
     """Get coil type.
 
     Parameters
@@ -53,6 +53,9 @@ def coil_type(info, idx):
         Measurement info
     idx : int
         Index of channel
+    ch_type : str
+        Channel type to fall back upon if a more specific
+        type is not found
 
     Returns
     -------
@@ -64,5 +67,4 @@ def coil_type(info, idx):
     for key, values in get_coil_types().items():
         if ch['coil_type'] in values:
             return key
-    raise ValueError('Unknown coil of type {0} '
-                     'for channel {1}'.format(ch['coil_type'], ch["ch_name"]))
+    return ch_type


Test patch:
diff --git a/mne_bids/tests/test_pick.py b/mne_bids/tests/test_pick.py
--- a/mne_bids/tests/test_pick.py
+++ b/mne_bids/tests/test_pick.py
@@ -1,7 +1,6 @@
 """Test for the coil type picking function"""
 
 import os.path as op
-import pytest
 
 from mne.datasets import testing
 from mne.io import read_raw_fif
@@ -19,5 +18,4 @@ def test_coil_type():
     assert coil_type(raw.info, 306) == 'misc'
     assert coil_type(raw.info, 315) == 'eeg'
     raw.info['chs'][0]['coil_type'] = 1234
-    with pytest.raises(ValueError):
-        coil_type(raw.info, 0)
+    assert coil_type(raw.info, 0) == 'n/a'