Repository: mne-tools/mne-python

Issue:
No stim channels found. Consider specifying them manually using the 'stim_channel' parameter.
Hi,
I got an error when I call 
_mne.find_events(raw=raw, shortest_event=1, verbose=False)_ that I didn't get previously:

_No stim channels found. Consider specifying them manually using the 'stim_channel' parameter._

Why is that? I went back to version 0.17.2


Discussion:
What kind of file did you load? MNE changed the way it imports markers - most likely you can find them in `raw.annotations` now.
I use this database with gdf files: [Brain Invaders 2013a] [https://zenodo.org/record/1494240#.XOKC_6Q6-w5](url)

> Data were acquired with a Nexus (TMSi, The Netherlands) EEG amplifier:
>     Sampling frequency: 512 samples per second
>     Digital Filter: No
>     Electrodes:  16 wet Silver/Silver Chloride electrodes positioned at FP1, FP2, F5, AFz, F6, T7, Cz, T8, P7, P3, Pz, P4, P8, O1, Oz, O2 according to the 10/20 international system
Yes, GDF events are now accessible via `raw.annotations`:

```
import mne
raw = mne.io.read_raw_gdf("1.gdf", preload=True)
```

If you inspect `raw.annotations`, you will find all events in there.
If you want to have events, you can convert annotations to events with `mne.events_from_annotations(raw)` (there are several parameters that influence the mapping from annotation to event, so be sure to check them out).
Great. Thanks!
the mne.find_events function should have told you to use
events_from_annotations if you have no stim channel and annotations....

can someone open a PR?

>


Resolving patch:
diff --git a/mne/event.py b/mne/event.py
--- a/mne/event.py
+++ b/mne/event.py
@@ -678,7 +678,16 @@ def find_events(raw, stim_channel=None, output='onset',
     min_samples = min_duration * raw.info['sfreq']
 
     # pull stim channel from config if necessary
-    stim_channel = _get_stim_channel(stim_channel, raw.info)
+    try:
+        stim_channel = _get_stim_channel(stim_channel, raw.info)
+    except ValueError:
+        if len(raw.annotations) > 0:
+            raise ValueError("No stim channels found, but the raw object has "
+                             "annotations. Consider using "
+                             "mne.events_from_annotations to convert these to "
+                             "events.")
+        else:
+            raise
 
     picks = pick_channels(raw.info['ch_names'], include=stim_channel)
     if len(picks) == 0:


Test patch:
diff --git a/mne/tests/test_event.py b/mne/tests/test_event.py
--- a/mne/tests/test_event.py
+++ b/mne/tests/test_event.py
@@ -8,7 +8,8 @@
 
 from mne import (read_events, write_events, make_fixed_length_events,
                  find_events, pick_events, find_stim_steps, pick_channels,
-                 read_evokeds, Epochs, create_info, compute_raw_covariance)
+                 read_evokeds, Epochs, create_info, compute_raw_covariance,
+                 Annotations)
 from mne.io import read_raw_fif, RawArray
 from mne.utils import _TempDir, run_tests_if_main
 from mne.event import (define_target_events, merge_events, AcqParserFIF,
@@ -362,6 +363,17 @@ def test_find_events():
     assert_array_equal(find_events(raw, 'MYSTI', initial_event=True),
                        [[0, 0, 100], [30, 0, 200]])
 
+    # test error message for raw without stim channels
+    raw = read_raw_fif(raw_fname, preload=True)
+    raw.pick_types(meg=True, stim=False)
+    # raw does not have annotations
+    with pytest.raises(ValueError, match="'stim_channel'"):
+        find_events(raw)
+    # if raw has annotations, we show a different error message
+    raw.set_annotations(Annotations(0, 2, "test"))
+    with pytest.raises(ValueError, match="mne.events_from_annotations"):
+        find_events(raw)
+
 
 def test_pick_events():
     """Test pick events in a events ndarray."""