Note
Go to the end to download the full example code.
Quickstart Tour: Load, Inspect Events, Scroll#
This example mirrors the four steps of the EEGLAB Quickstart guide on the checked-in tutorial dataset: load the sample dataset, read the summary that the main window shows, explore event values, read the dataset comments, and open the scrolling channel browser. Everything runs headless.
Load the sample dataset (File > Load existing dataset).
from pathlib import Path
import eegprep
from eegprep import eeg_checkset, eegplot, pop_comments, pop_editeventvals, pop_loadset
REPO_ROOT = Path(eegprep.__file__).resolve().parents[2] # sphinx-gallery defines no __file__
dataset = REPO_ROOT / "sample_data" / "eeglab_data.set"
EEG = pop_loadset(dataset)
EEG = eeg_checkset(EEG)
print("setname:", EEG["setname"])
print("channels:", EEG["nbchan"], "frames/epoch:", EEG["pnts"], "epochs:", EEG["trials"])
print("srate:", EEG["srate"], "Hz epoch range:", (EEG["xmin"], EEG["xmax"]), "s")
print("data shape:", EEG["data"].shape)
print("events:", len(EEG["event"]))
setname: Continuous EEG Data
channels: 32 frames/epoch: 30504 epochs: 1
srate: 128.0 Hz epoch range: (0.0, 238.3046875) s
data shape: (32, 30504)
events: 154
Exploring event values (Edit > Event values).
Event indices are 1-based, matching the dialog and EEGLAB.
event_fields = sorted(EEG["event"][0].keys())
print("event fields:", event_fields)
for index in (1, 2, 3):
event = EEG["event"][index - 1]
print(index, {field: event[field] for field in event_fields})
print("latency is 1-based samples; urevent is a 0-based index into EEG['urevent']")
types = sorted({str(event["type"]) for event in EEG["event"]})
print("event types:", types)
print("counts:", {t: sum(str(e["type"]) == t for e in EEG["event"]) for t in types})
event fields: ['latency', 'position', 'type', 'urevent']
1 {'latency': 129.00875, 'position': 2, 'type': 'square', 'urevent': 0}
2 {'latency': 218.00874999999996, 'position': 2, 'type': 'square', 'urevent': 1}
3 {'latency': 267.5481362500059, 'position': array([], dtype=float64), 'type': 'rt', 'urevent': 2}
latency is 1-based samples; urevent is a 0-based index into EEG['urevent']
event types: ['rt', 'square']
counts: {'rt': 74, 'square': 80}
The dialog’s edits are available as command-line actions. Sorting by latency is the same call the dialog records in the history.
EEG = pop_editeventvals(EEG, 'sort', {'latency' 0});
About this dataset (Edit > About this dataset).
EEG, comments_com = pop_comments(EEG, "", "Quickstart tour of the tutorial dataset.", return_com=True)
print(comments_com)
print("comments:", EEG["comments"])
EEG = pop_comments(EEG, '', 'Quickstart tour of the tutorial dataset.');
comments: Quickstart tour of the tutorial dataset.
Scrolling through the data (Plot > Channel data (scroll)).
show=False builds the browser model without opening a Qt window, so the
same call is usable in scripts and tests.
browser = eegplot(EEG, winlength=5, dispchans=16, title="Scroll channel activities", show=False)
print("browser type:", type(browser).__name__)
print("window length (s):", browser.state.winlength, "displayed channels:", browser.state.dispchans)
print("browsed channels:", browser.data.n_channels, "samples:", browser.data.total_samples)
print("event overlays:", len(browser.state.events))
print("first channels:", [chan["labels"] for chan in EEG["chanlocs"][:5]])
browser type: BrowserModel
window length (s): 5.0 displayed channels: 16
browsed channels: 32 samples: 30504
event overlays: 154
first channels: ['FPz', 'EOG1', 'F3', 'Fz', 'F4']
Total running time of the script: (0 minutes 0.021 seconds)