Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fname = '/home/jrking/Desktop/R0174_block1_1.13.17.sqd'
- from mne.io.pick import channel_type
- raw = read_raw_kit(fname)
- stim_channel = [ii for ii in range(len(raw.info['chs']))
- if channel_type(raw.info, ii) == 'stim'][0]
- raw.load_data()
- def fix_trigger_channel(data, shortest_event=3):
- diff = np.diff(data) # isolate onset and offsets by taking derivative
- starts = np.where(diff > 0)[0] # keep onsets indices only
- good = np.where(np.diff(starts) >= shortest_event)[0]
- new_data = np.zeros_like(data) # create a new trigger channels
- # for each good start, fill the array with 50 times the actual trigger value
- for t in range(shortest_event):
- new_data[starts[good] + t] = data[starts[good] + shortest_event]
- return new_data
- # Clean raw trigger channel to ensure that the values are either = trigger or 0 (no transition < 1 time sample)
- raw._data[stim_channel] = fix_trigger_channel(255 - raw._data[stim_channel])
- events = find_events(raw, stim_channel='STI 014', shortest_event=1)
- # only keep the relevant events
- good = np.where(events[:, 2] <= 27)[0]
- events = events[good]
- # somehow, only every other event seem to be important
- events = events[::2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement