Repository: mne-tools/mne-python

Issue:
.EDF data file import in a file and have an error
hey 
when i try to import a  data in mne i got this error 

> ValueError: DigMontage is a only a subset of info. There are 27 channel positions not present in the DigMontage. The required channels are: ['TIME_STAMP_s', 'TIME_STAMP_ms', 'COUNTER', 'INTERPOLATED', 'RAW_CQ', 'BATTERY', 'MarkerIndex', 'MarkerType', 'MarkerValueInt', 'MARKER_HARDWARE', 'CQ_AF3', 'CQ_F7', 'CQ_F3', 'CQ_FC5', 'CQ_T7', 'CQ_P7', 'CQ_O1', 'CQ_O2', 'CQ_P8', 'CQ_T8', 'CQ_FC6', 'CQ_F4', 'CQ_F8', 'CQ_AF4', 'CQ_OVERALL', 'CQ_CMS', 'CQ_DRL']

This is the code i m using

```python
import mne

mne.set_log_level("WARNING")

raw = mne.io.read_raw_edf("eaw.edf", preload=True)
raw.rename_channels(lambda s: s.strip("."))

montage = mne.channels.make_standard_montage("standard_1020")
raw.set_montage(montage, match_case=False)

raw.set_eeg_reference("average")

print(raw)
print(raw.info)

raw.plot_psd(fmax=50)
raw.plot(duration=5, n_channels=30)
```


Discussion:
your channels are either not marked as EEG channel (use
set_channel_types
https://mne.tools/dev/generated/mne.io.Raw.html#mne.io.Raw.set_channel_types)
or simply not present with correct name in the montage

This question comes up a lot, maybe it should get added to the FAQ
also we should improve the error message in set_montage with a suggestion
on how to fix this

>


Resolving patch:
diff --git a/mne/channels/montage.py b/mne/channels/montage.py
--- a/mne/channels/montage.py
+++ b/mne/channels/montage.py
@@ -731,12 +731,15 @@ def _backcompat_value(pos, ref_pos):
         not_in_montage = [name for name, use in zip(info_names, info_names_use)
                           if use not in ch_pos_use]
         if len(not_in_montage):  # DigMontage is subset of info
-            missing_coord_msg = 'DigMontage is only a subset of info. ' \
-                                'There are %s channel position%s ' \
-                                'not present in the DigMontage. ' \
-                                'The required channels are: %s' \
-                                % (len(not_in_montage), _pl(not_in_montage),
-                                   not_in_montage)
+            missing_coord_msg = (
+                'DigMontage is only a subset of info. There are '
+                f'{len(not_in_montage)} channel position{_pl(not_in_montage)} '
+                'not present in the DigMontage. The required channels are:\n\n'
+                f'{not_in_montage}.\n\nConsider using inst.set_channel_types '
+                'if these are not EEG channels, or use the on_missing '
+                'parameter if the channel positions are allowed to be unknown '
+                'in your analyses.'
+            )
             if on_missing == 'raise':
                 raise ValueError(missing_coord_msg)
             elif on_missing == 'warn':


Test patch:
diff --git a/mne/channels/tests/test_montage.py b/mne/channels/tests/test_montage.py
--- a/mne/channels/tests/test_montage.py
+++ b/mne/channels/tests/test_montage.py
@@ -1192,8 +1192,11 @@ def test_set_montage_with_sub_super_set_of_ch_names():
     # montage is a SUBset of info
     _MSG = 'subset of info. There are 2 .* not present in the DigMontage'
     info = create_info(ch_names=list('abcdfgh'), sfreq=1, ch_types='eeg')
-    with pytest.raises(ValueError, match=_MSG):
+    with pytest.raises(ValueError, match=_MSG) as exc:
         info.set_montage(montage)
+    # plus suggestions
+    assert exc.match('set_channel_types')
+    assert exc.match('on_missing')
 
 
 def test_heterogeneous_ch_type():