EEG Skill (Modality Layer)
Overview
eeg-skill is the NeuroClaw modality-layer interface skill responsible for all EEG data processing tasks.
It strictly follows the NeuroClaw hierarchical design principles:
- This skill only describes WHAT needs to be done and which tool skill to delegate to.
- It contains no full implementation code.
- All concrete execution (MNE-Python calls, torchaudio, scipy, file I/O, etc.) is delegated to the dedicated base/tool skill
mne-eeg-tool.
- Waveform-to-spectrogram conversion uses
torchaudio.transforms.MelSpectrogram.
- Frequency-band energy extraction uses continuous wavelet transform (
scipy.signal.cwt with morlet2 wavelet).
Core workflow (never bypassed):
- Identify the user-provided EEG files (BIDS, .set, .edf, .bdf, .fif, etc.).
- Generate a numbered execution plan that clearly states WHAT needs to be done and which tool skill will handle each step.
- Present the full plan, estimated runtime, resource requirements, and risks to the user and wait for explicit confirmation (“YES” / “execute” / “proceed”).
- On confirmation, delegate every step to
mne-eeg-tool via claw-shell.
- After execution, save all outputs in a clean directory structure (
eeg_output/).
Research use only — outputs are for scientific analysis only.
Quick Reference (Common EEG Tasks – Updated 2026-03-25)
| Task |
What needs to be done |
Delegate to which tool skill |
Expected output |
| Load & basic validation |
Read raw EEG + channel locations + events + validation |
claw-shell (via mne-eeg-tool) |
Validation report + raw object |
| Bad-channel detection & interpolation |
Auto-detect + interpolate noisy channels |
claw-shell (via mne-eeg-tool) |
Cleaned raw data |
| Downsampling + filtering |
Resample, high-pass, notch, bandpass filtering |
claw-shell (via mne-eeg-tool) |
Filtered .fif files |
| Artifact removal |
ICA + AutoReject + EOG/ECG regression |
claw-shell (via mne-eeg-tool) |
Cleaned data |
| Continuous data cleaning |
Resting-state pipeline (no events) |
claw-shell (via mne-eeg-tool) |
Cleaned continuous data |
| Re-referencing & epoching |
Average reference (CAR) / REST + epoching + baseline correction |
claw-shell (via mne-eeg-tool) |
Epoched .fif files |
| Waveform to Mel-Spectrogram |
Convert raw waveform to Mel spectrogram using torchaudio |
claw-shell (via mne-eeg-tool) |
Mel-spectrogram tensors (.pt) |
| Frequency-band energy extraction |
Extract δ/θ/α/β/γ band energy using CWT with morlet2 wavelet |
claw-shell (via mne-eeg-tool) |
Per-band power matrices (CSV / .npy) |
| Feature extraction (core) |
Band power, CSP, Hjorth, sample entropy |
claw-shell (via mne-eeg-tool) |
Feature matrices (CSV / .npy / .npz) |
| Advanced features |
Functional connectivity, ERP peaks/latency/AUC, frontal alpha asymmetry, microstates |
claw-shell (via mne-eeg-tool) |
Connectivity matrices, ERP CSV, asymmetry .npy, microstates .fif |
| Full end-to-end pipeline |
Any combination of the above for BCI, emotion, epilepsy, fatigue, etc. |
claw-shell + dependency-planner |
Complete processed dataset + QC report |
Installation (Handled by dependency-planner)
No manual installation required.
When first used, eeg-skill automatically calls dependency-planner to create the isolated neuroclaw-eeg conda environment containing MNE-Python, torchaudio, scipy, and all required packages.
NeuroClaw recommended wrapper script
# Example snippets (for reference in mne-eeg-tool implementation)
# 1. Waveform to Mel-Spectrogram
import torch
import torchaudio.transforms as T
mel_spec = T.MelSpectrogram(
sample_rate=256, # Adjust according to your EEG sampling rate
n_fft=1024,
hop_length=256,
n_mels=128,
f_min=0.5,
f_max=60.0 # Common EEG frequency range
)
spectrogram = mel_spec(waveform) # waveform shape: (channels, time)
# 2. Frequency-band energy extraction using CWT + morlet2
import numpy as np
from scipy.signal import cwt, morlet2
def extract_band_power(signal, fs=256):
widths = np.arange(1, 128) # Adjust according to frequency range
cwt_matrix = cwt(signal, morlet2, widths)
# Example: extract delta (0.5-4 Hz), theta (4-8 Hz), alpha (8-13 Hz), beta (13-30 Hz), gamma (30-60 Hz)
delta_power = np.mean(np.abs(cwt_matrix[low_idx:high_idx])**2, axis=0)
# ... similar processing for other bands
return band_powers
Important Notes & Limitations
- This SKILL.md contains only high-level task descriptions and delegation instructions.
- Waveform-to-spectrogram conversion is handled by
torchaudio.transforms.MelSpectrogram.
- Frequency-band energy extraction is performed via continuous wavelet transform (
scipy.signal.cwt + morlet2 wavelet).
- Long-running operations (ICA on long recordings, CWT on high-density data, connectivity matrices, microstate analysis) are automatically routed to background mode in the
claw tmux session.
- Execution begins only after explicit user confirmation of the full numbered plan.
- All outputs are saved in
./eeg_output/ with clear subfolders (raw/, filtered/, epoched/, features/, spectrograms/, etc.).
When to Call This Skill
- The user provides raw or partially processed EEG data and requests preprocessing, Mel-spectrogram conversion, frequency-band energy extraction, feature engineering, or a full pipeline.
- After
research-idea or method-design when the experiment involves EEG data.
Post-Execution Verification (Harness Integration)
After EEG processing completes, this skill automatically invokes harness-core's VerificationRunner to validate preprocessed data quality:
Integrated verification checks:
from skills.harness_core import VerificationRunner, AuditLogger
import numpy as np
import mne
verifier = VerificationRunner(task_type="eeg_preprocessing")
# 1. EEG data file exists and is readable
verifier.add_check("eeg_file_integrity",
checker=lambda: verify_eeg_file_readable(output_dir),
severity="error"
)
# 2. Channel count matches expected
verifier.add_check("channel_count",
checker=lambda: verify_expected_channels(output_dir, expected_count=64),
severity="warning"
)
# 3. No excessive bad segments (after artifact removal)
verifier.add_check("artifact_removal_success",
checker=lambda: verify_bad_segments_removed(output_dir, max_pct=5),
severity="warning"
)
# 4. Data range plausible (not clipped or saturated)
verifier.add_check("data_range_plausible",
checker=lambda: verify_data_range(output_dir, min_range=-500, max_range=500),
severity="error"
)
# 5. No NaN/Inf values in preprocessed data
verifier.add_check("no_nan_inf",
checker=lambda: verify_no_nan_inf(output_dir),
severity="error"
)
# 6. Frequency spectrum reasonable (no DC offset, reasonable content)
verifier.add_check("frequency_spectrum",
checker=lambda: verify_frequency_spectrum(output_dir),
severity="warning"
)
# 7. Epoching statistics (if applicable)
verifier.add_check("epoch_statistics",
checker=lambda: verify_epoch_count_and_length(output_dir),
severity="warning"
)
# 8. Feature extraction output dimensions
verifier.add_check("feature_matrix_shape",
checker=lambda: verify_feature_matrix_shape(output_dir),
severity="warning"
)
report = verifier.run(output_dir)
# Log verification results
logger = AuditLogger(log_file=f"{output_dir}/eeg_verification.jsonl")
logger.log_validation(
task_name="eeg_preprocessing",
checks_passed=len([r for r in report.results if r.passed]),
checks_failed=len([r for r in report.results if not r.passed]),
warnings=len([r for r in report.results if r.severity == "warning" and not r.passed]),
report_summary=report.to_dict()
)
if report.failed:
raise ValueError(f"EEG preprocessing verification failed: {report.summary}")
Output files generated:
{output_dir}/eeg_verification.jsonl — structured audit log
{output_dir}/.eeg_verification_timestamp — completion marker
Complementary / Related Skills
dependency-planner + conda-env-manager → environment and package installation (MNE-Python + torchaudio + scipy)
mne-eeg-tool → base/tool layer that contains all specific implementation code
harness-core → automated verification and audit logging
Reference
Aligned with NeuroClaw modality-skill pattern (see freesurfer-tool, wmh-segmentation, etc.).
Core libraries: MNE-Python (main), torchaudio.transforms.MelSpectrogram (waveform to spectrogram), scipy.signal.cwt + morlet2 (frequency band energy extraction).
Created At: 2026-03-25 16:00 HKT
Last Updated At: 2026-04-05 02:01 HKT
Author: chengwang96
1---2name: eeg-skill3description: Use this skill whenever the user wants to load, preprocess, epoch, filter, or extract features from EEG data (resting-state, task-based, BCI, clinical, motor imagery, emotion, epilepsy, fatigue, etc.). Triggers include: 'eeg', 'EEG preprocessing', 'EEG feature extraction', 'band power', 'downsample to frequency bands', 'motor imagery BCI', 'emotion EEG', 'epilepsy detection', or any request involving .set/.edf/.bdf/.fif/.bids files.4license: MIT License (NeuroClaw custom skill – freely modifiable within t5---6# EEG Skill (Modality Layer)
7
8## Overview
9
10`eeg-skill` is the NeuroClaw **modality-layer** interface skill responsible for all EEG data processing tasks.
11It strictly follows the NeuroClaw hierarchical design principles:
12
13- This skill **only describes WHAT needs to be done** and **which tool skill to delegate to**.
14- It contains **no full implementation code**.
15- All concrete execution (MNE-Python calls, torchaudio, scipy, file I/O, etc.) is delegated to the dedicated base/tool skill `mne-eeg-tool`.
16- Waveform-to-spectrogram conversion uses `torchaudio.transforms.MelSpectrogram`.
17- Frequency-band energy extraction uses continuous wavelet transform (`scipy.signal.cwt` with `morlet2` wavelet).
18
19**Core workflow (never bypassed):**
20
211. Identify the user-provided EEG files (BIDS, .set, .edf, .bdf, .fif, etc.).
222. Generate a **numbered execution plan** that clearly states WHAT needs to be done and which tool skill will handle each step.
233. Present the full plan, estimated runtime, resource requirements, and risks to the user and wait for explicit confirmation (“YES” / “execute” / “proceed”).
244. On confirmation, delegate every step to `mne-eeg-tool` via `claw-shell`.
255. After execution, save all outputs in a clean directory structure (`eeg_output/`).
26
27**Research use only** — outputs are for scientific analysis only.
28
29## Quick Reference (Common EEG Tasks – Updated 2026-03-25)
30
31| Task | What needs to be done | Delegate to which tool skill | Expected output |
32|-------------------------------------------|----------------------------------------------------------------------------|-----------------------------------------------|------------------------------------------|
33| Load & basic validation | Read raw EEG + channel locations + events + validation | `claw-shell` (via `mne-eeg-tool`) | Validation report + raw object |
34| Bad-channel detection & interpolation | Auto-detect + interpolate noisy channels | `claw-shell` (via `mne-eeg-tool`) | Cleaned raw data |
35| Downsampling + filtering | Resample, high-pass, notch, bandpass filtering | `claw-shell` (via `mne-eeg-tool`) | Filtered .fif files |
36| Artifact removal | ICA + AutoReject + EOG/ECG regression | `claw-shell` (via `mne-eeg-tool`) | Cleaned data |
37| Continuous data cleaning | Resting-state pipeline (no events) | `claw-shell` (via `mne-eeg-tool`) | Cleaned continuous data |
38| Re-referencing & epoching | Average reference (CAR) / REST + epoching + baseline correction | `claw-shell` (via `mne-eeg-tool`) | Epoched .fif files |
39| Waveform to Mel-Spectrogram | Convert raw waveform to Mel spectrogram using torchaudio | `claw-shell` (via `mne-eeg-tool`) | Mel-spectrogram tensors (.pt) |
40| Frequency-band energy extraction | Extract δ/θ/α/β/γ band energy using CWT with morlet2 wavelet | `claw-shell` (via `mne-eeg-tool`) | Per-band power matrices (CSV / .npy) |
41| Feature extraction (core) | Band power, CSP, Hjorth, sample entropy | `claw-shell` (via `mne-eeg-tool`) | Feature matrices (CSV / .npy / .npz) |
42| Advanced features | Functional connectivity, ERP peaks/latency/AUC, frontal alpha asymmetry, microstates | `claw-shell` (via `mne-eeg-tool`) | Connectivity matrices, ERP CSV, asymmetry .npy, microstates .fif |
43| Full end-to-end pipeline | Any combination of the above for BCI, emotion, epilepsy, fatigue, etc. | `claw-shell` + `dependency-planner` | Complete processed dataset + QC report |
44
45## Installation (Handled by dependency-planner)
46
47No manual installation required.
48When first used, `eeg-skill` automatically calls `dependency-planner` to create the isolated `neuroclaw-eeg` conda environment containing MNE-Python, torchaudio, scipy, and all required packages.
49
50## NeuroClaw recommended wrapper script
51
52```python
53# Example snippets (for reference in mne-eeg-tool implementation)
54
55# 1. Waveform to Mel-Spectrogram
56import torch
57import torchaudio.transforms as T
58
59mel_spec = T.MelSpectrogram(
60 sample_rate=256, # Adjust according to your EEG sampling rate
61 n_fft=1024,
62 hop_length=256,
63 n_mels=128,
64 f_min=0.5,
65 f_max=60.0 # Common EEG frequency range
66)
67spectrogram = mel_spec(waveform) # waveform shape: (channels, time)
68
69# 2. Frequency-band energy extraction using CWT + morlet2
70import numpy as np
71from scipy.signal import cwt, morlet2
72
73def extract_band_power(signal, fs=256):
74 widths = np.arange(1, 128) # Adjust according to frequency range
75 cwt_matrix = cwt(signal, morlet2, widths)
76
77 # Example: extract delta (0.5-4 Hz), theta (4-8 Hz), alpha (8-13 Hz), beta (13-30 Hz), gamma (30-60 Hz)
78 delta_power = np.mean(np.abs(cwt_matrix[low_idx:high_idx])**2, axis=0)
79 # ... similar processing for other bands
80 return band_powers
81```
82
83## Important Notes & Limitations
84
85- This SKILL.md contains **only high-level task descriptions and delegation instructions**.
86- Waveform-to-spectrogram conversion is handled by `torchaudio.transforms.MelSpectrogram`.
87- Frequency-band energy extraction is performed via continuous wavelet transform (`scipy.signal.cwt` + `morlet2` wavelet).
88- Long-running operations (ICA on long recordings, CWT on high-density data, connectivity matrices, microstate analysis) are automatically routed to background mode in the `claw` tmux session.
89- Execution begins **only after explicit user confirmation** of the full numbered plan.
90- All outputs are saved in `./eeg_output/` with clear subfolders (raw/, filtered/, epoched/, features/, spectrograms/, etc.).
91
92## When to Call This Skill
93
94- The user provides raw or partially processed EEG data and requests preprocessing, Mel-spectrogram conversion, frequency-band energy extraction, feature engineering, or a full pipeline.
95- After `research-idea` or `method-design` when the experiment involves EEG data.
96
97## Post-Execution Verification (Harness Integration)
98
99After EEG processing completes, this skill **automatically invokes harness-core's VerificationRunner** to validate preprocessed data quality:
100
101**Integrated verification checks**:
102
103```python
104from skills.harness_core import VerificationRunner, AuditLogger
105import numpy as np
106import mne
107
108verifier = VerificationRunner(task_type="eeg_preprocessing")
109
110# 1. EEG data file exists and is readable
111verifier.add_check("eeg_file_integrity",
112 checker=lambda: verify_eeg_file_readable(output_dir),
113 severity="error"
114)
115
116# 2. Channel count matches expected
117verifier.add_check("channel_count",
118 checker=lambda: verify_expected_channels(output_dir, expected_count=64),
119 severity="warning"
120)
121
122# 3. No excessive bad segments (after artifact removal)
123verifier.add_check("artifact_removal_success",
124 checker=lambda: verify_bad_segments_removed(output_dir, max_pct=5),
125 severity="warning"
126)
127
128# 4. Data range plausible (not clipped or saturated)
129verifier.add_check("data_range_plausible",
130 checker=lambda: verify_data_range(output_dir, min_range=-500, max_range=500),
131 severity="error"
132)
133
134# 5. No NaN/Inf values in preprocessed data
135verifier.add_check("no_nan_inf",
136 checker=lambda: verify_no_nan_inf(output_dir),
137 severity="error"
138)
139
140# 6. Frequency spectrum reasonable (no DC offset, reasonable content)
141verifier.add_check("frequency_spectrum",
142 checker=lambda: verify_frequency_spectrum(output_dir),
143 severity="warning"
144)
145
146# 7. Epoching statistics (if applicable)
147verifier.add_check("epoch_statistics",
148 checker=lambda: verify_epoch_count_and_length(output_dir),
149 severity="warning"
150)
151
152# 8. Feature extraction output dimensions
153verifier.add_check("feature_matrix_shape",
154 checker=lambda: verify_feature_matrix_shape(output_dir),
155 severity="warning"
156)
157
158report = verifier.run(output_dir)
159
160# Log verification results
161logger = AuditLogger(log_file=f"{output_dir}/eeg_verification.jsonl")
162logger.log_validation(
163 task_name="eeg_preprocessing",
164 checks_passed=len([r for r in report.results if r.passed]),
165 checks_failed=len([r for r in report.results if not r.passed]),
166 warnings=len([r for r in report.results if r.severity == "warning" and not r.passed]),
167 report_summary=report.to_dict()
168)
169
170if report.failed:
171 raise ValueError(f"EEG preprocessing verification failed: {report.summary}")
172```
173
174**Output files generated**:
175- `{output_dir}/eeg_verification.jsonl` — structured audit log
176- `{output_dir}/.eeg_verification_timestamp` — completion marker
177
178## Complementary / Related Skills
179
180- `dependency-planner` + `conda-env-manager` → environment and package installation (MNE-Python + torchaudio + scipy)
181- `mne-eeg-tool` → base/tool layer that contains all specific implementation code
182- `harness-core` → automated verification and audit logging
183
184## Reference
185
186Aligned with NeuroClaw modality-skill pattern (see `freesurfer-tool`, `wmh-segmentation`, etc.).
187Core libraries: MNE-Python (main), `torchaudio.transforms.MelSpectrogram` (waveform to spectrogram), `scipy.signal.cwt` + `morlet2` (frequency band energy extraction).
188
189---
190Created At: 2026-03-25 16:00 HKT
191Last Updated At: 2026-04-05 02:01 HKT
192Author: chengwang96