MEG Skill (Modality Layer)
Overview
meg-skill is the NeuroClaw modality-layer interface skill responsible for all MEG (magnetoencephalography) 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 implementation code or concrete commands.
- All concrete execution is delegated to MNE-Python (via
claw-shell) and companion scripts.
- Companion scripts in
scripts/ provide reference implementations for time-frequency analysis and source localization.
Core workflow (never bypassed):
- Identify input MEG data format (.fif Elekta/Neuromag, .ds CTF, .con KIT/Yokogawa).
- Ensure T1w structural MRI is available for source localization (via
smri-skill if not yet processed).
- Generate a numbered execution plan clearly stating WHAT needs to be done.
- 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 via
claw-shell.
- After execution, save all outputs in a clean directory structure (
meg_output/).
Research use only.
Quick Reference (Common MEG Tasks)
| Task |
What needs to be done |
Implementation via |
Expected output |
| Load & validation |
Read raw MEG, check channel types, info metadata |
MNE-Python (mne.io) |
Raw object + validation report |
| Maxwell filtering |
Signal-space separation (SSS) for Elekta systems |
MNE-Python (mne.preprocessing.maxwell_filter) |
Cleaned raw MEG |
| Filtering |
Band-pass, notch (line noise removal at 50/60 Hz) |
MNE-Python (raw.filter, raw.notch_filter) |
Filtered raw data |
| Epoching |
Segment continuous data around events |
MNE-Python (mne.Epochs) |
Epoched data |
| ICA artifact removal |
Remove cardiac, ocular, environmental artifacts |
MNE-Python (mne.preprocessing.ICA) |
Cleaned epochs |
| Time-frequency analysis |
Morlet wavelet multitaper, Hilbert transform |
scripts/time_frequency.py |
TFR maps (power, ITC) |
| Source localization |
Forward/inverse modeling (MNE, dSPM, beamformer) |
MNE-Python + FreeSurfer |
Source estimates in brain space |
| Source-space connectivity |
Coherence, PLV, dPLI between source parcels |
MNE-Python (mne_connectivity) |
Connectivity matrices |
| Sensor-level connectivity |
Coherence, PLV between sensor pairs |
MNE-Python |
Sensor connectivity |
| Evoked responses |
Average epochs, compute ERPs/ERFs |
MNE-Python (epochs.average) |
Evoked NIfTI/fif files |
Supported MEG File Formats
| Format |
System |
Extension |
Reader |
| Elekta/Neuromag |
VectorView, TRIUX |
.fif |
mne.io.read_raw_fif |
| CTF |
CTF MEG systems |
.ds |
mne.io.read_raw_ctf |
| KIT/Yokogawa |
KIT, Ricoh |
.con, .mrk |
mne.io.read_raw_kit |
| BIDS MEG |
Any (BIDS format) |
.meg.fif |
mne.io.read_raw_fif |
Core Processing Pipeline
Stage 1: Data Loading & Validation
- Load raw MEG data and validate channel types (magnetometers, gradiometers, EEG, EOG, ECG, STIM)
- Check sampling rate, duration, and channel count
- Report bad channels if annotated
Stage 2: Preprocessing
- Maxwell filtering (SSS/tSSS): for Elekta systems, remove environmental noise
- Band-pass filtering: typically 1–100 Hz for sensor-level analysis
- Notch filter: remove power line noise (50 Hz or 60 Hz)
- Downsampling: optional, to reduce computation (e.g., 1000 Hz → 250 Hz)
Stage 3: Artifact Removal (ICA)
- Run ICA (FastICA, Infomax, or Picard)
- Auto-detect and remove cardiac (ECG), ocular (EOG), and muscle artifacts
- Correlate ICA components with ECG/EOG channels
Stage 4: Epoching & Averaging
- Segment around events of interest
- Baseline correction
- Reject bad epochs (amplitude threshold, autoreject)
- Compute evoked responses (ERFs)
Stage 5: Time-Frequency Analysis (via scripts/time_frequency.py)
- Morlet wavelet or multitaper spectral analysis
- Compute power spectral density per frequency band (δ/θ/α/β/γ)
- Inter-trial coherence (ITC)
Stage 6 (Optional): Source Localization
- Requires T1w MRI from
smri-skill and FreeSurfer cortical reconstruction
- Compute forward model (BEM or sphere)
- Apply inverse solution (MNE, dSPM, sLORETA, or LCMV beamformer)
- Output source estimates on cortical surface
Scripts
scripts/time_frequency.py
Computes time-frequency representations from MEG epochs.
python skills/meg-skill/scripts/time_frequency.py \
--epochs /path/to/epochs.fif \
--output /path/to/meg_output/tfr/ \
--freq-min 1 --freq-max 100 --freq-steps 40 \
--method morlet \
--baseline -0.2 0.0
Standard Output Layout
meg_output/
├── preprocessed/ # Filtered, cleaned raw MEG
├── epochs/ # Epoched data (.fif)
├── evoked/ # Averaged evoked responses (.fif, .nii.gz)
├── tfr/ # Time-frequency results
│ ├── power_*.nii.gz
│ └── itc_*.nii.gz
├── source/ # Source estimates (if source localization run)
│ ├── stc_*.lh.stc
│ └── stc_*.rh.stc
├── connectivity/ # Connectivity matrices (if requested)
├── qc/ # Quality control reports
└── logs/
Installation (Handled by dependency-planner)
No manual installation required at this layer.
When first used, meg-skill automatically calls dependency-planner to install MNE-Python and dependencies via conda.
Important Notes & Limitations
- MEG data is large (hundreds of MB to GB per recording); ensure sufficient disk space.
- Maxwell filtering (SSS) is specific to Elekta/Neuromag systems; CTF and KIT systems use different approaches.
- Source localization requires co-registered T1w MRI and MEG sensor positions (head position indicator coils or digitized head shape).
- MNE-Python is the primary backend; all MEG processing is built on MNE.
- MEG has millisecond temporal resolution but lower spatial resolution than fMRI.
- BIDS-MEG format follows the BIDS extension for MEG: https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/02-magnetoencephalography.html
- This skill is for research workflows; not for clinical decision-making.
When to Call This Skill
- When the user provides MEG data (.fif, .ds, .con) and requests preprocessing, artifact removal, or analysis.
- When time-frequency analysis or source localization is needed for MEG data.
- When MEG connectivity analysis (sensor-level or source-level) is requested.
- When
eeg-skill handles EEG but the data also includes MEG channels.
- When dataset skills (e.g.,
Cam-CAN) delegate MEG processing.
Complementary / Related Skills
eeg-skill → EEG processing (MEG and EEG share many MNE-Python tools)
smri-skill → T1w structural preprocessing (required for source localization)
freesurfer-tool → cortical reconstruction for source-space analysis
nibabel-skill → NIfTI I/O for surface/volume data
brain-visualization → MEG source overlay visualization
nilearn-tool → post-hoc statistical analysis on source estimates
Reference
Created At: 2026-05-06 12:19 HKT
Last Updated At: 2026-05-06 12:19 HKT
Author: chengwang96
1---2name: meg-skill3description: Use this skill whenever the user wants to process MEG (magnetoencephalography) data including source localization, time-frequency analysis, connectivity analysis, sensor-level preprocessing, or MEG-specific feature extraction. Triggers include: 'MEG', 'MEG processing', 'MEG source localization', 'MEG connectivity', 'magnetoencephalography', 'beamformer', 'time-frequency', 'MEG preprocessing', or any request involving MEG data files (.fif, .con, .ds).4license: MIT License (NeuroClaw custom skill – freely modifiable within t5---6# MEG Skill (Modality Layer)
7
8## Overview
9
10`meg-skill` is the NeuroClaw **modality-layer** interface skill responsible for all MEG (magnetoencephalography) data processing tasks.
11
12It strictly follows the NeuroClaw hierarchical design principles:
13- This skill **only describes WHAT needs to be done** and **which tool skill to delegate to**.
14- It contains **no implementation code or concrete commands**.
15- All concrete execution is delegated to MNE-Python (via `claw-shell`) and companion scripts.
16- Companion scripts in `scripts/` provide reference implementations for time-frequency analysis and source localization.
17
18**Core workflow (never bypassed):**
191. Identify input MEG data format (.fif Elekta/Neuromag, .ds CTF, .con KIT/Yokogawa).
202. Ensure T1w structural MRI is available for source localization (via `smri-skill` if not yet processed).
213. Generate a **numbered execution plan** clearly stating WHAT needs to be done.
224. Present the full plan, estimated runtime, resource requirements, and risks to the user and wait for explicit confirmation ("YES" / "execute" / "proceed").
235. On confirmation, delegate every step via `claw-shell`.
246. After execution, save all outputs in a clean directory structure (`meg_output/`).
25
26**Research use only.**
27
28---
29
30## Quick Reference (Common MEG Tasks)
31
32| Task | What needs to be done | Implementation via | Expected output |
33|---|---|---|---|
34| Load & validation | Read raw MEG, check channel types, info metadata | MNE-Python (`mne.io`) | Raw object + validation report |
35| Maxwell filtering | Signal-space separation (SSS) for Elekta systems | MNE-Python (`mne.preprocessing.maxwell_filter`) | Cleaned raw MEG |
36| Filtering | Band-pass, notch (line noise removal at 50/60 Hz) | MNE-Python (`raw.filter`, `raw.notch_filter`) | Filtered raw data |
37| Epoching | Segment continuous data around events | MNE-Python (`mne.Epochs`) | Epoched data |
38| ICA artifact removal | Remove cardiac, ocular, environmental artifacts | MNE-Python (`mne.preprocessing.ICA`) | Cleaned epochs |
39| Time-frequency analysis | Morlet wavelet multitaper, Hilbert transform | `scripts/time_frequency.py` | TFR maps (power, ITC) |
40| Source localization | Forward/inverse modeling (MNE, dSPM, beamformer) | MNE-Python + FreeSurfer | Source estimates in brain space |
41| Source-space connectivity | Coherence, PLV, dPLI between source parcels | MNE-Python (`mne_connectivity`) | Connectivity matrices |
42| Sensor-level connectivity | Coherence, PLV between sensor pairs | MNE-Python | Sensor connectivity |
43| Evoked responses | Average epochs, compute ERPs/ERFs | MNE-Python (`epochs.average`) | Evoked NIfTI/fif files |
44
45---
46
47## Supported MEG File Formats
48
49| Format | System | Extension | Reader |
50|---|---|---|---|
51| Elekta/Neuromag | VectorView, TRIUX | `.fif` | `mne.io.read_raw_fif` |
52| CTF | CTF MEG systems | `.ds` | `mne.io.read_raw_ctf` |
53| KIT/Yokogawa | KIT, Ricoh | `.con`, `.mrk` | `mne.io.read_raw_kit` |
54| BIDS MEG | Any (BIDS format) | `.meg.fif` | `mne.io.read_raw_fif` |
55
56---
57
58## Core Processing Pipeline
59
60### Stage 1: Data Loading & Validation
61- Load raw MEG data and validate channel types (magnetometers, gradiometers, EEG, EOG, ECG, STIM)
62- Check sampling rate, duration, and channel count
63- Report bad channels if annotated
64
65### Stage 2: Preprocessing
66- **Maxwell filtering** (SSS/tSSS): for Elekta systems, remove environmental noise
67- **Band-pass filtering**: typically 1–100 Hz for sensor-level analysis
68- **Notch filter**: remove power line noise (50 Hz or 60 Hz)
69- **Downsampling**: optional, to reduce computation (e.g., 1000 Hz → 250 Hz)
70
71### Stage 3: Artifact Removal (ICA)
72- Run ICA (FastICA, Infomax, or Picard)
73- Auto-detect and remove cardiac (ECG), ocular (EOG), and muscle artifacts
74- Correlate ICA components with ECG/EOG channels
75
76### Stage 4: Epoching & Averaging
77- Segment around events of interest
78- Baseline correction
79- Reject bad epochs (amplitude threshold, autoreject)
80- Compute evoked responses (ERFs)
81
82### Stage 5: Time-Frequency Analysis (via `scripts/time_frequency.py`)
83- Morlet wavelet or multitaper spectral analysis
84- Compute power spectral density per frequency band (δ/θ/α/β/γ)
85- Inter-trial coherence (ITC)
86
87### Stage 6 (Optional): Source Localization
88- Requires T1w MRI from `smri-skill` and FreeSurfer cortical reconstruction
89- Compute forward model (BEM or sphere)
90- Apply inverse solution (MNE, dSPM, sLORETA, or LCMV beamformer)
91- Output source estimates on cortical surface
92
93---
94
95## Scripts
96
97### `scripts/time_frequency.py`
98Computes time-frequency representations from MEG epochs.
99
100```bash
101python skills/meg-skill/scripts/time_frequency.py \
102 --epochs /path/to/epochs.fif \
103 --output /path/to/meg_output/tfr/ \
104 --freq-min 1 --freq-max 100 --freq-steps 40 \
105 --method morlet \
106 --baseline -0.2 0.0
107```
108
109---
110
111## Standard Output Layout
112
113```
114meg_output/
115├── preprocessed/ # Filtered, cleaned raw MEG
116├── epochs/ # Epoched data (.fif)
117├── evoked/ # Averaged evoked responses (.fif, .nii.gz)
118├── tfr/ # Time-frequency results
119│ ├── power_*.nii.gz
120│ └── itc_*.nii.gz
121├── source/ # Source estimates (if source localization run)
122│ ├── stc_*.lh.stc
123│ └── stc_*.rh.stc
124├── connectivity/ # Connectivity matrices (if requested)
125├── qc/ # Quality control reports
126└── logs/
127```
128
129---
130
131## Installation (Handled by dependency-planner)
132
133No manual installation required at this layer.
134When first used, `meg-skill` automatically calls `dependency-planner` to install MNE-Python and dependencies via conda.
135
136---
137
138## Important Notes & Limitations
139
140- MEG data is large (hundreds of MB to GB per recording); ensure sufficient disk space.
141- Maxwell filtering (SSS) is specific to Elekta/Neuromag systems; CTF and KIT systems use different approaches.
142- Source localization requires co-registered T1w MRI and MEG sensor positions (head position indicator coils or digitized head shape).
143- MNE-Python is the primary backend; all MEG processing is built on MNE.
144- MEG has millisecond temporal resolution but lower spatial resolution than fMRI.
145- BIDS-MEG format follows the BIDS extension for MEG: https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/02-magnetoencephalography.html
146- This skill is for research workflows; not for clinical decision-making.
147
148---
149
150## When to Call This Skill
151
152- When the user provides MEG data (.fif, .ds, .con) and requests preprocessing, artifact removal, or analysis.
153- When time-frequency analysis or source localization is needed for MEG data.
154- When MEG connectivity analysis (sensor-level or source-level) is requested.
155- When `eeg-skill` handles EEG but the data also includes MEG channels.
156- When dataset skills (e.g., `Cam-CAN`) delegate MEG processing.
157
158---
159
160## Complementary / Related Skills
161
162- `eeg-skill` → EEG processing (MEG and EEG share many MNE-Python tools)
163- `smri-skill` → T1w structural preprocessing (required for source localization)
164- `freesurfer-tool` → cortical reconstruction for source-space analysis
165- `nibabel-skill` → NIfTI I/O for surface/volume data
166- `brain-visualization` → MEG source overlay visualization
167- `nilearn-tool` → post-hoc statistical analysis on source estimates
168
169---
170
171## Reference
172- MNE-Python: https://mne.tools/
173- Gramfort et al. (2013): MEG and EEG data analysis with MNE-Python
174- Taulu & Simola (2006): Spatiotemporal signal space separation (SSS)
175- BIDS MEG: https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/02-magnetoencephalography.html
176- Cam-CAN dataset: https://www.cam-can.org/
177
178Created At: 2026-05-06 12:19 HKT
179Last Updated At: 2026-05-06 12:19 HKT
180Author: chengwang96