Skill Tracer
Skills › Scientific Agent Skills › neurokit2 › eeg.md

eeg.md

204 lines · skills/neurokit2/references/eeg.md at 5f2bc03

Open on GitHub
1# EEG and microstates
2
3Checked **2026-10-01** against NeuroKit2 0.2.13 stable source/runtime,
4the official EEG/microstate APIs, and SPR EEG/MEG guidance.
5

EEG and microstates

Checked 2026-10-01 against NeuroKit2 0.2.13 stable source/runtime, the official EEG/microstate APIs, and SPR EEG/MEG guidance.

Raw lines 1 to 5
6## Scope
7
8NeuroKit2 does not expose an `eeg_process()` equivalent to its ECG/EDA pipelines.
9It provides selected feature, QC, re-reference, MNE, source, and microstate helpers.
10Use MNE or another validated EEG framework for the full acquisition/preprocessing
11workflow, while recording every transform and bad-segment decision.
13For NumPy input, NeuroKit2 EEG functions expect shape:
15```text
16(channels, time_samples)
17```
19Do not pass `(time, channels)` silently. Preserve channel names/order, montage,
20reference, sensor locations, units (typically volts in MNE), sampling rate, and bad
21channel/segment annotations.

Scope

NeuroKit2 does not expose an eeg_process() equivalent to its ECG/EDA pipelines. It provides selected feature, QC, re-reference, MNE, source, and microstate helpers. Use MNE or another validated EEG framework for the full acquisition/preprocessing workflow, while recording every transform and bad-segment decision.

For NumPy input, NeuroKit2 EEG functions expect shape:

(channels, time_samples)

Do not pass (time, channels) silently. Preserve channel names/order, montage, reference, sensor locations, units (typically volts in MNE), sampling rate, and bad channel/segment annotations.

Raw lines 6 to 22
23## Current stable helpers

Current stable helpers

Raw lines 23 to 24
25### Power
27```python
28power = nk.eeg_power(
29 eeg_channels_by_time,
30 sampling_rate=250,
31 frequency_band=["Gamma", "Beta", "Alpha", "Theta", "Delta"],
33```
35The argument is singular `frequency_band`, not `frequency_bands`. The pinned default
36array probe returned one row per channel with:
38```text
39Channel, Gamma, Beta, Alpha, Theta, Delta
40```
42Standard named bands in the docs include Delta 1–4, Theta 4–8, Alpha 8–13, Beta
4313–30, and Gamma 30–80 Hz, with additional sub-bands. Band definitions are conventions,
44not universal physiology. Report exact boundaries, PSD parameters, reference, artifact
45handling, absolute/relative normalization, and usable duration.

Power

power = nk.eeg_power(
    eeg_channels_by_time,
    sampling_rate=250,
    frequency_band=["Gamma", "Beta", "Alpha", "Theta", "Delta"],
)

The argument is singular frequency_band, not frequency_bands. The pinned default array probe returned one row per channel with:

Channel, Gamma, Beta, Alpha, Theta, Delta

Standard named bands in the docs include Delta 1–4, Theta 4–8, Alpha 8–13, Beta 13–30, and Gamma 30–80 Hz, with additional sub-bands. Band definitions are conventions, not universal physiology. Report exact boundaries, PSD parameters, reference, artifact handling, absolute/relative normalization, and usable duration.

Raw lines 25 to 46
47### Bad channels
49```python
50bads, channel_info = nk.eeg_badchannels(
51 eeg_channels_by_time,
52 bad_threshold=0.5,
53 distance_threshold=0.99,
54 show=False,
56```
58Return order is a list plus a DataFrame. The pinned info schema contained `SD`, `Mean`,
59`MAD`, `Median`, `Skewness`, `Kurtosis`, `Amplitude`, interval bounds,
60`n_ZeroCrossings`, and `Bad`.
62This statistical screen is not a universal rejection rule. Review raw data, montage,
63bridging, line noise, drift, channel location, task, and condition. Fit thresholds
64without leaking group/condition outcomes.

Bad channels

bads, channel_info = nk.eeg_badchannels(
    eeg_channels_by_time,
    bad_threshold=0.5,
    distance_threshold=0.99,
    show=False,
)

Return order is a list plus a DataFrame. The pinned info schema contained SD, Mean, MAD, Median, Skewness, Kurtosis, Amplitude, interval bounds, n_ZeroCrossings, and Bad.

This statistical screen is not a universal rejection rule. Review raw data, montage, bridging, line noise, drift, channel location, task, and condition. Fit thresholds without leaking group/condition outcomes.

Raw lines 47 to 65
66### Re-reference, GFP, and dissimilarity
68```python
69rereferenced = nk.eeg_rereference(eeg_channels_by_time, reference="average")
70gfp = nk.eeg_gfp(rereferenced, method="l1")
71diss = nk.eeg_diss(rereferenced, gfp=gfp)
72```
74For array input `eeg_rereference()` returns an array. For MNE input it returns an MNE
75object. Average reference requires adequate channel coverage and bad-channel handling;
76it is not automatically appropriate for sparse montages.
78`eeg_gfp()` defaults to L1 in NeuroKit2, while publications may use other definitions.
79Report method, standardization, normalization, smoothing, and reference.

Re-reference, GFP, and dissimilarity

rereferenced = nk.eeg_rereference(eeg_channels_by_time, reference="average")
gfp = nk.eeg_gfp(rereferenced, method="l1")
diss = nk.eeg_diss(rereferenced, gfp=gfp)

For array input eeg_rereference() returns an array. For MNE input it returns an MNE object. Average reference requires adequate channel coverage and bad-channel handling; it is not automatically appropriate for sparse montages.

eeg_gfp() defaults to L1 in NeuroKit2, while publications may use other definitions. Report method, standardization, normalization, smoothing, and reference.

Raw lines 66 to 80
81## Optional MNE requirements
83Core NeuroKit2 does not install MNE. Stable functions that require it include:
85- `eeg_simulate()` (confirmed by pinned runtime);
86- `mne_data()` and MNE object helpers;
87- `eeg_source()` / `eeg_source_extract()`; and
88- `mne_templateMRI()`.
90Add only the optional package(s) required for the analysis at reviewed exact versions,
91commit/review the resulting `uv.lock`, and install with `uv sync --locked`. Do not
92install the upstream floating `full` extra in an automated workflow without such a
93lock.
95Some MNE helpers download datasets/templates. Treat network access, cache paths,
96licenses, versions, and checksums as study dependencies; do not use them in a
97restricted/offline workflow without prior provisioning.

Optional MNE requirements

Core NeuroKit2 does not install MNE. Stable functions that require it include:

  • eeg_simulate() (confirmed by pinned runtime);
  • mne_data() and MNE object helpers;
  • eeg_source() / eeg_source_extract(); and
  • mne_templateMRI().

Add only the optional package(s) required for the analysis at reviewed exact versions, commit/review the resulting uv.lock, and install with uv sync --locked. Do not install the upstream floating full extra in an automated workflow without such a lock.

Some MNE helpers download datasets/templates. Treat network access, cache paths, licenses, versions, and checksums as study dependencies; do not use them in a restricted/offline workflow without prior provisioning.

Raw lines 81 to 98
99## Source reconstruction
101Stable signature:
103```text
104eeg_source(raw, src, bem, method="sLORETA", show=False, ...)
105```
107It requires an MNE Raw object, source space, BEM/head model, montage/electrode
108locations, and appropriate co-registration. `eeg_source_extract(stc, src, ...)` returns
109region time series from a segmentation.
111A template MRI does not validate localization for an individual or population.
112Report coordinate frames, digitization, head/conductivity model, inverse method,
113regularization, noise covariance, depth/orientation choices, atlas, and uncertainty.
114Do not use NeuroKit2 source estimates for diagnosis, surgical planning, or clinical
115localization.

Source reconstruction

Stable signature:

eeg_source(raw, src, bem, method="sLORETA", show=False, ...)

It requires an MNE Raw object, source space, BEM/head model, montage/electrode locations, and appropriate co-registration. eeg_source_extract(stc, src, ...) returns region time series from a segmentation.

A template MRI does not validate localization for an individual or population. Report coordinate frames, digitization, head/conductivity model, inverse method, regularization, noise covariance, depth/orientation choices, atlas, and uncertainty. Do not use NeuroKit2 source estimates for diagnosis, surgical planning, or clinical localization.

Raw lines 99 to 116
117## Microstates
119### Segmentation
121```python
122out = nk.microstates_segment(
123 eeg_channels_by_time,
124 n_microstates=4,
125 train="gfp",
126 method="kmod",
127 sampling_rate=250,
128 n_runs=50,
129 random_state=42,
131```
133Stable methods include `kmod`, `kmeans`, `kmedoids`, `pca`, `ica`, and `aahc`.
134The pinned 0.2.13 output dict included:
136```text
137Microstates, Sequence, GEV, GEV_per_microstate, GFP,
138Polarity, Info, Info_algorithm
139```
141It did **not** use lowercase `maps`, `labels`, `gfp`, or `gev`. `Microstates` contains
142maps, and `Sequence` is the sample-wise class assignment.

Segmentation

out = nk.microstates_segment(
    eeg_channels_by_time,
    n_microstates=4,
    train="gfp",
    method="kmod",
    sampling_rate=250,
    n_runs=50,
    random_state=42,
)

Stable methods include kmod, kmeans, kmedoids, pca, ica, and aahc. The pinned 0.2.13 output dict included:

Microstates, Sequence, GEV, GEV_per_microstate, GFP,
Polarity, Info, Info_algorithm

It did not use lowercase maps, labels, gfp, or gev. Microstates contains maps, and Sequence is the sample-wise class assignment.

Raw lines 119 to 143
144### Preparation and summaries
146```python
147clean, train_indices, gfp, input_info = nk.microstates_clean(
148 eeg_channels_by_time,
149 sampling_rate=250,
150 train="gfp",
153static = nk.microstates_static(out["Sequence"], sampling_rate=250)
154dynamic = nk.microstates_dynamic(out["Sequence"])
155```
157`microstates_clean()` is a utility for array normalization/standardization and training
158sample selection; it does not implement a full EEG artifact pipeline.
160`microstates_classify()` is experimental and requires two arguments:
162```python
163sequence, maps = nk.microstates_classify(
164 out["Sequence"],
165 out["Microstates"],
167```
169Its classification depends on channel ordering, so it is not a reliable substitute for
170template matching with a defined montage.
172`microstates_findnumber()` returns `(optimal_number, scores_dataframe)`. Choosing a
173state count from the same dataset and then testing selected-state effects can inflate
174research flexibility. Prespecify or cross-validate clustering choices and assess
175initialization stability.

Preparation and summaries

clean, train_indices, gfp, input_info = nk.microstates_clean(
    eeg_channels_by_time,
    sampling_rate=250,
    train="gfp",
)

static = nk.microstates_static(out["Sequence"], sampling_rate=250)
dynamic = nk.microstates_dynamic(out["Sequence"])

microstates_clean() is a utility for array normalization/standardization and training sample selection; it does not implement a full EEG artifact pipeline.

microstates_classify() is experimental and requires two arguments:

sequence, maps = nk.microstates_classify(
    out["Sequence"],
    out["Microstates"],
)

Its classification depends on channel ordering, so it is not a reliable substitute for template matching with a defined montage.

microstates_findnumber() returns (optimal_number, scores_dataframe). Choosing a state count from the same dataset and then testing selected-state effects can inflate research flexibility. Prespecify or cross-validate clustering choices and assess initialization stability.

Raw lines 144 to 176
177## Preprocessing/reporting
179At minimum report:
181- hardware, montage/locations/reference/ground, unit, sample rate, online filters;
182- resampling, offline filters/notches, edge handling, and line frequency;
183- bad channels/segments and interpolation;
184- ocular/muscle/cardiac correction and ICA details;
185- epoch/baseline definitions and retained trials;
186- PSD/time-frequency estimator and normalization;
187- microstate input band/reference, GFP definition, training points, algorithm,
188 state count, runs/seed, polarity, smoothing, and fit/stability; and
189- exact NeuroKit2/MNE versions and observed schemas.
191Avoid frequency-band mental-state labels such as “beta = anxiety” or
192“theta/beta = ADHD.” EEG features are not diagnosis, consciousness monitoring,
193anesthesia control, seizure detection, or neurofeedback validation without a separate
194validated system and intended-use evidence.

Preprocessing/reporting

At minimum report:

  • hardware, montage/locations/reference/ground, unit, sample rate, online filters;
  • resampling, offline filters/notches, edge handling, and line frequency;
  • bad channels/segments and interpolation;
  • ocular/muscle/cardiac correction and ICA details;
  • epoch/baseline definitions and retained trials;
  • PSD/time-frequency estimator and normalization;
  • microstate input band/reference, GFP definition, training points, algorithm, state count, runs/seed, polarity, smoothing, and fit/stability; and
  • exact NeuroKit2/MNE versions and observed schemas.

Avoid frequency-band mental-state labels such as “beta = anxiety” or “theta/beta = ADHD.” EEG features are not diagnosis, consciousness monitoring, anesthesia control, seizure detection, or neurofeedback validation without a separate validated system and intended-use evidence.

Raw lines 177 to 195
196## Sources checked 2026-10-01
198- [Official EEG API](https://neuropsychology.github.io/NeuroKit/functions/eeg.html)
199- [Official microstates API](https://neuropsychology.github.io/NeuroKit/functions/microstates.html)
200- [Stable v0.2.13 EEG source](https://github.com/neuropsychology/NeuroKit/tree/v0.2.13/neurokit2/eeg)
201- [Stable v0.2.13 microstates source](https://github.com/neuropsychology/NeuroKit/tree/v0.2.13/neurokit2/microstates)
202- [Keil et al. (2014), EEG/MEG publication guidelines](https://doi.org/10.1111/psyp.12147)
203- [Keil et al. (2022), frequency/time-frequency guidelines](https://doi.org/10.1111/psyp.14052)
204- [Michel & Koenig (2018), microstate review](https://doi.org/10.1016/j.neuroimage.2017.11.062)