"""
===========================================================
Plot single trial activity, grouped by ROI and sorted by RT
===========================================================

This will produce what is sometimes called an event related
potential / field (ERP/ERF) image.

The EEGLAB example file - containing an experiment with button press responses
to simple visual stimuli - is read in and response times are calculated.
Regions of Interest are determined by the channel types (in 10/20 channel
notation, even channels are right, odd are left, and 'z' are central). The
median and the Global Field Power within each channel group is calculated,
and the trials are plotted, sorting by response time.
"""
# Authors: Jona Sassenhagen <jona.sassenhagen@gmail.com>
#
# License: BSD (3-clause)

import mne
from mne.datasets import testing
from mne import Epochs, io, pick_types
from mne.event import define_target_events
from mne.channels import make_1020_channel_selections

print(__doc__)

###############################################################################
# Load EEGLAB example data (a small EEG dataset)
data_path = testing.data_path()
fname = data_path + "/EEGLAB/test_raw.set"
montage = data_path + "/EEGLAB/test_chans.locs"

event_id = {"rt": 1, "square": 2}  # must be specified for str events
eog = {"FPz", "EOG1", "EOG2"}
raw = io.eeglab.read_raw_eeglab(fname, eog=eog, montage=montage,
                                event_id=event_id)
picks = pick_types(raw.info, eeg=True)
events = mne.find_events(raw)

###############################################################################
# Create Epochs

# define target events:
# 1. find response times: distance between "square" and "rt" events
# 2. extract A. "square" events B. followed by a button press within 700 msec
tmax = .7
sfreq = raw.info["sfreq"]
reference_id, target_id = 2, 1
new_events, rts = define_target_events(events, reference_id, target_id, sfreq,
                                       tmin=0., tmax=tmax, new_id=2)

epochs = Epochs(raw, events=new_events, tmax=tmax + .1,
                event_id={"square": 2}, picks=picks)

###############################################################################
# Plot

# Parameters for plotting
order = rts.argsort()  # sorting from fast to slow trials

selections = make_1020_channel_selections(epochs.info, midline="12z")

# The actual plots
for combine_measures in ('gfp', 'median'):
    epochs.plot_image(group_by=selections, order=order, sigma=1.5,
                      overlay_times=rts / 1000., combine=combine_measures,
                      ts_args=dict(vlines=[0, rts.mean() / 1000.]))

@@ -809,80 +809,8 @@
 mne%0A
-from mne.datasets import testing%0Afrom mne import Epochs, io, pick_types%0A
 from
@@ -848,16 +848,16 @@
 _events%0A
+
 from mne
@@ -1060,16 +1060,29 @@
 _path = 
+mne.datasets.
 testing.
@@ -1295,17 +1295,14 @@
 w = 
-io.eeglab
+mne.io
 .rea
@@ -1380,66 +1380,25 @@
     
-   event_id=event_id)%0Apicks = pick_types(raw.info, eeg=Tru
+stim_channel=Fals
 e)%0Ae
@@ -1413,24 +1413,49 @@
 mne.
-find_
 events
-(raw)
+_from_annotations(raw, event_id)%5B0%5D
 %0A%0A##
@@ -1944,16 +1944,20 @@
 pochs = 
+mne.
 Epochs(r
@@ -2011,16 +2011,20 @@
         
+    
 event_id
@@ -2041,21 +2041,8 @@
 : 2%7D
-, picks=picks
 )%0A%0A#
@@ -2126,16 +2126,26 @@
 #%0A# Plot
+ using GFP
 %0A%0A# Para
@@ -2316,56 +2316,304 @@
 lots
-%0Afor combine_measures in ('gfp', 'median'):%0A    
+ (GFP)%0Aepochs.plot_image(group_by=selections, order=order, sigma=1.5,%0A                  overlay_times=rts / 1000., combine='gfp',%0A                  ts_args=dict(vlines=%5B0, rts.mean() / 1000.%5D))%0A%0A###############################################################################%0A# Plot using median%0A%0A
 epoc
@@ -2681,36 +2681,32 @@
                 
-    
 overlay_times=rt
@@ -2728,30 +2728,18 @@
 ine=
-combine_measures,%0A    
+'median',%0A
     

Fix documentation broken by stim_channel deprecation (#5714)