<jupyter_start><jupyter_text>`eeg-01`: Data visualizationThis demo introduces the basics of EEG visualization using an example dataset. We'll inspect raw (and processed) EEG data for artifacts, and visualization the location of EEG electrodes.<jupyter_code>import os
import matplotlib.pyplot as plt
from mne.io import read_raw_fif<jupyter_output><empty_output><jupyter_text>Loading dataWe'll load in a simple EEG dataset acquired while a subject received visual and auditory stimuli. The data stored as [`.fif`](https://bids-specification.readthedocs.io/en/stable/99-appendices/06-meg-file-formats.htmlneuromagelektamegin) file format commonly used with MEG. The resulting [`Raw`](https://mne.tools/stable/generated/mne.io.Raw.htmlmne.io.Raw) data object has a variety of useful attributes and methods.<jupyter_code># Specify path to raw data
raw_fn = '../eeg-data/sub-01_task-audvis_raw.fif'

# Load raw data
data_raw = read_raw_fif(raw_fn, preload=True, verbose=False)
print(data_raw)<jupyter_output><Raw | sub-01_task-audvis_raw.fif, 70 x 166800 (277.7 s), ~92.1 MB, data loaded><jupyter_text>Inspecting the raw dataIt can be useful to inspect the raw data across a variety of frequencies. Certain artifacts will be present at all frequencies; e.g. EOG (electrooculogram) artifacts generated by eyeblinks. Other artifacts are prominent only at selective frequencies. Line noise, for example, will be prominent at 60 Hz (in America). EMG (electromyogram) artifacts caused by facial muscles tends to impact the higher frequencies (roughly >50 Hz).<jupyter_code>%matplotlib osx
data_raw.plot();<jupyter_output>Channels marked as bad: none<jupyter_text>Inspecting preprocessed dataTo provide some contrast, we'll also inspect preprocessed data (more on preprocessing in the next demo). For now, we can take for granted that filtering and artifact removal have been applied to the raw data.<jupyter_code># Specify path to preprocessed data
prep_fn = '../eeg-data/sub-01_task-audvis_preproc_raw.fif'

## Load preprocessed data
data_prep = read_raw_fif(prep_fn, preload=True, verbose=False)
print(data_prep)
%matplotlib osx
data_prep.plot();<jupyter_output>Channels marked as bad: ['EEG 053']<jupyter_text>Channel layoutTo get a sense of where the sensors/electrodes are located on the subject's head, we can extract the channel layout from the data and plot the locations. We can also plot standardized ("idealized") channel locations (e.g. the [10-20 system](https://en.wikipedia.org/wiki/10%E2%80%9320_system_(EEG))).<jupyter_code>from mne.channels import find_layout
from mne.viz import plot_layout

# Extract channel layout from data object
layout = find_layout(data_prep.info)

# Plot channel layout
%matplotlib inline
plot_layout(layout);
# Create standard 1020 channel locations
from mne.channels import make_standard_montage

ten_twenty_montage = make_standard_montage('standard_1020')
print(ten_twenty_montage)

# Plot standard electrode locations
%matplotlib osx
fig = ten_twenty_montage.plot(kind='3d')
fig.gca().view_init(azim=70, elev=15)
ten_twenty_montage.plot(kind='topomap', show_names=False);<jupyter_output><DigMontage | 0 extras (headshape), 0 HPIs, 3 fiducials, 94 channels>
4 duplicate electrode labels found:
T7/T3, T8/T4, P7/T5, P8/T6
Plotting 90 unique labels.
Creating RawArray with float64 data, n_channels=90, n_times=1
    Range : 0 ... 0 =      0.000 ...     0.000 secs
Ready.
4 duplicate electrode labels found:
T7/T3, T8/T4, P7/T5, P8/T6
Plotting 90 unique labels.
Creating RawArray with float64 data, n_channels=90, n_times=1
    Range : 0 ... 0 =      0.000 ...     0.000 secs
Ready.
{'fraction_non_alphanumeric': 0.08992805755395683, 'fraction_numerical': 0.03237410071942446, 'mean_word_length': 5.548913043478261, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '540618', 'license': 'MIT', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1137, 'n_words': 383, 'path': 'eeg-01/eeg-01-visualization.ipynb', 'repo_name': '2021-NEU502b/demos', 'size': '3614'}