Skip to content

Instantly share code, notes, and snippets.

@teonbrooks
Last active August 29, 2015 13:56
Show Gist options
  • Save teonbrooks/9102945 to your computer and use it in GitHub Desktop.
Save teonbrooks/9102945 to your computer and use it in GitHub Desktop.
EDF concatenated file stim channel fix using the .mat
import numpy as np
import scipy as sp
import mne
mat = sp.io.loadmat('trig_s2.mat')
triggers, latency, urevent, duration, epoch = zip(*np.ravel(mat['triggers']))
latency = np.array(latency).ravel()
triggers = np.array(triggers, int).ravel()
raw = mne.fiff.edf.read_raw_edf(raw.info,'s2_2.edf', preload=True)
stim_channel = np.zeros(raw.last_samp+1)
stim_channel[latency] = triggers
picks = mne.fiff.pick_types(meg=False, stim=True)
raw._data[picks] = stim_channel
raw.save('s2_2_stim_fixed.fif', verbose=False)
raw_fixed = mne.fiff.Raw('s2_2_stim_fixed.fif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment