Loading...
Loading...
Open-source Python package for exploring, visualizing, and analyzing human neurophysiological data including EEG, MEG, sEEG, and ECoG.
npx skill4agent add tondevrel/scientific-agent-skills mneimport mne
import numpy as np# 1. Load data
raw = mne.io.read_raw_fif("sample_audvis_raw.fif")
# Or: raw = mne.io.read_raw_edf("eeg.edf")
# 2. Filter and cleaning
raw.filter(l_freq=1, h_freq=40) # Bandpass filter
raw.notch_filter(freqs=[50, 100]) # Remove power line noise
# 3. Find events and create Epochs
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, event_id={'stimulus': 1}, tmin=-0.2, tmax=0.5)
epochs.average().plot() # Plot Evoked potential
# 4. Frequency analysis
epochs.compute_psd().plot()raw.plot()# Compute forward solution and inverse
fwd = mne.make_forward_solution(raw.info, trans, src, bem)
inv = mne.minimum_norm.make_inverse_operator(raw.info, fwd, cov)
stc = mne.minimum_norm.apply_inverse(evoked, inv)
stc.plot()from mne.connectivity import spectral_connectivity
# Compute connectivity between channels
con, freqs, times, n_epochs, n_tapers = spectral_connectivity(
epochs, method='coh', mode='multitaper')