Repository: mne-tools/mne-bids

Issue:
ValueError: Unknown coil of type 5 for channel EOG061
I'm using MNE-bids on an MEG dataset. The output and traceback sequence are given below.

```
Opening raw data file /home/nicholasblauch/MEG/FST/orig/sub-01/ses-03/FST_ER3.fif...
This filename (/home/nicholasblauch/MEG/FST/orig/sub-01/ses-03/FST_ER3.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, raw.fif.gz, raw_sss.fif.gz or raw_tsss.fif.gz
    Read a total of 14 projection items:
        mag_ssp.fif : PCA-v1 (1 x 306)  idle
        mag_ssp.fif : PCA-v2 (1 x 306)  idle
        mag_ssp.fif : PCA-v3 (1 x 306)  idle
        mag_ssp.fif : PCA-v4 (1 x 306)  idle
        mag_ssp.fif : PCA-v5 (1 x 306)  idle
        mag_ssp.fif : PCA-v6 (1 x 306)  idle
        mag_ssp.fif : PCA-v7 (1 x 306)  idle
        mag_ssp.fif : PCA-v8 (1 x 306)  idle
        mag_ssp.fif : PCA-v9 (1 x 306)  idle
        grad_ssp.fif : PCA-v1 (1 x 306)  idle
        grad_ssp.fif : PCA-v2 (1 x 306)  idle
        grad_ssp.fif : PCA-v3 (1 x 306)  idle
        grad_ssp.fif : PCA-v4 (1 x 306)  idle
        grad_ssp.fif : PCA-v5 (1 x 306)  idle
    Range : 45000 ... 166999 =     45.000 ...   166.999 secs
Ready.
Current compensation grade : 0
Creating folder: /home/nicholasblauch/MEG/FST/sub-01/ses-01/meg
<ipython-input-87-05598c422f8f>:19: RuntimeWarning: This filename (/home/nicholasblauch/MEG/FST/orig/sub-01/ses-03/FST_ER3.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, raw.fif.gz, raw_sss.fif.gz or raw_tsss.fif.gz
  raw_file=full_raw_file, output_path=output_path, overwrite=True)

Writing '/home/nicholasblauch/MEG/FST/dataset_description.json'...

{
    "Name": " ",
    "BIDSVersion": "1.1.1 (draft)"
}
Traceback (most recent call last):

  File "<ipython-input-87-05598c422f8f>", line 19, in <module>
    raw_file=full_raw_file, output_path=output_path, overwrite=True)

  File "/home/nicholasblauch/anaconda3/envs/mne/lib/python3.6/site-packages/mne_bids/mne_bids.py", line 626, in raw_to_bids
    eeg_gnd, verbose)

  File "/home/nicholasblauch/anaconda3/envs/mne/lib/python3.6/site-packages/mne_bids/mne_bids.py", line 450, in _sidecar_json
    ('EEGPlacementScheme', _infer_eeg_placement_scheme(raw)),

  File "/home/nicholasblauch/anaconda3/envs/mne/lib/python3.6/site-packages/mne_bids/utils.py", line 542, in _infer_eeg_placement_scheme
    if coil_type(raw.info, ch_idx) == 'eeg':

  File "/home/nicholasblauch/anaconda3/envs/mne/lib/python3.6/site-packages/mne_bids/pick.py", line 70, in coil_type
    'for channel {1}'.format(ch['coil_type'], ch["ch_name"]))

ValueError: Unknown coil of type 5 for channel EOG061
```

Any idea how to fix this?

thanks, Nick


Discussion:
If you do:

```py
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)
```

what do you get?
'eog'

Resolving patch:
diff --git a/mne_bids/utils.py b/mne_bids/utils.py
--- a/mne_bids/utils.py
+++ b/mne_bids/utils.py
@@ -23,7 +23,6 @@
 
 from .config import BIDS_VERSION
 from .io import _parse_ext
-from .pick import coil_type
 
 
 def print_dir_tree(dir):
@@ -509,10 +508,10 @@ def copyfile_eeglab(src, dest):
         if fdt_ext != '.fdt':
             raise IOError('Expected extension {} for linked data but found'
                           ' {}'.format('.fdt', fdt_ext))
-        sh.copyfile(fdt_path, fname_dest+'.fdt')
+        sh.copyfile(fdt_path, fname_dest + '.fdt')
 
         # Write a new .set file with an updated pointer
-        head, tail = op.split(fname_dest+'.fdt')
+        head, tail = op.split(fname_dest + '.fdt')
         eeg['data'] = tail
         savemat(dest, eeg, appendmat=False)
 
@@ -538,10 +537,7 @@ def _infer_eeg_placement_scheme(raw):
     """
     placement_scheme = 'n/a'
     # Check if the raw data contains eeg data at all
-    for ch_idx in range(len(raw.ch_names)):
-        if coil_type(raw.info, ch_idx) == 'eeg':
-            break
-    else:
+    if 'eeg' not in raw:
         return placement_scheme
 
     # How many of the channels in raw are based on the extended 10/20 system


Test patch:
diff --git a/mne_bids/tests/test_mne_bids.py b/mne_bids/tests/test_mne_bids.py
--- a/mne_bids/tests/test_mne_bids.py
+++ b/mne_bids/tests/test_mne_bids.py
@@ -18,6 +18,7 @@
 import mne
 from mne.datasets import testing
 from mne.utils import _TempDir, run_subprocess
+from mne.io.constants import FIFF
 
 from mne_bids import raw_to_bids, make_bids_filename
 
@@ -162,10 +163,13 @@ def test_edf():
     data_path = op.join(testing.data_path(), 'EDF')
     raw_fname = op.join(data_path, 'test_reduced.edf')
 
+    raw = mne.io.read_raw_edf(raw_fname, preload=True)
+    raw.rename_channels({raw.info['ch_names'][0]: 'EOG'})
+    raw.info['chs'][0]['coil_type'] = FIFF.FIFFV_COIL_EEG_BIPOLAR
+
     raw_to_bids(subject_id=subject_id, session_id=session_id, run=run,
-                task=task, raw_file=raw_fname, output_path=output_path,
+                task=task, raw_file=raw, output_path=output_path,
                 overwrite=True, kind='eeg')
-
     cmd = ['bids-validator', '--bep006', output_path]
     run_subprocess(cmd, shell=shell)