<jupyter_start><jupyter_text>===========================================================Plot single trial activity, grouped by ROI and sorted by RT===========================================================This will produce what is sometimes called an event relatedpotential / field (ERP/ERF) image.The EEGLAB example file - containing an experiment with button press responsesto simple visual stimuli - is read in and response times are calculated.Regions of Interest are determined by the channel types (in 10/20 channelnotation, even channels are right, odd are left, and 'z' are central). Themedian and the Global Field Power within each channel group is calculated,and the trials are plotted, sorting by response time.<jupyter_code># Authors: <NAME> <<EMAIL>>
#
# License: BSD (3-clause)

import mne
from mne.event import define_target_events
from mne.channels import make_1020_channel_selections

print(__doc__)<jupyter_output><empty_output><jupyter_text>Load EEGLAB example data (a small EEG dataset)<jupyter_code>data_path = mne.datasets.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 = mne.io.read_raw_eeglab(fname, eog=eog, montage=montage,
                             stim_channel=False)
events = mne.events_from_annotations(raw, event_id)[0]<jupyter_output><empty_output><jupyter_text>Create Epochs<jupyter_code># 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 = mne.Epochs(raw, events=new_events, tmax=tmax + .1,
                    event_id={"square": 2})<jupyter_output><empty_output><jupyter_text>Plot using GFP<jupyter_code># Parameters for plotting
order = rts.argsort()  # sorting from fast to slow trials

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

# The actual plots (GFP)
epochs.plot_image(group_by=selections, order=order, sigma=1.5,
                  overlay_times=rts / 1000., combine='gfp',
                  ts_args=dict(vlines=[0, rts.mean() / 1000.]))<jupyter_output><empty_output><jupyter_text>Plot using median<jupyter_code>epochs.plot_image(group_by=selections, order=order, sigma=1.5,
                  overlay_times=rts / 1000., combine='median',
                  ts_args=dict(vlines=[0, rts.mean() / 1000.]))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14543446244477173, 'fraction_numerical': 0.019882179675994108, 'mean_word_length': 4.67223382045929, 'pattern_counts': {'":': 3, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '184924', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 919, 'n_tokens_neox': 852, 'n_words': 231, 'path': 'stable/_downloads/e52b6a53120d8703a6509530cf6251dc/plot_roi_erpimage_by_rt.ipynb', 'repo_name': 'drammock/mne-tools.github.io', 'size': '2745'}