Skip to content

Instantly share code, notes, and snippets.

@ycanerol
Created March 5, 2020 16:16
Show Gist options
  • Save ycanerol/93aeeadab865f5d5ea6ac1cc05d8717c to your computer and use it in GitHub Desktop.
Save ycanerol/93aeeadab865f5d5ea6ac1cc05d8717c to your computer and use it in GitHub Desktop.
Read the stimulus times from bininfo.mat and write it in the required format for phy plugin EventMarker.
"""
Read the stimulus times from bininfo.mat and write it in the required
format for phy plugin EventMarker.
"""
import h5py
from pathlib import Path
import numpy as np
fp = Path(folder)
with h5py.File(Path(folder, 'bininfo.mat'), mode='r') as f:
stimsamples = f['bininfo']['stimsamples'][()].astype(int).squeeze()
sampling_rate = f['bininfo']['fs'][:].squeeze()
eventmarkers = np.cumsum(np.hstack((0, stimsamples))) / sampling_rate
eventmarkers = eventmarkers[:-1]
stimuli_dir = (fp.parent/'stimuli').glob('*.txt')
eventmarkernames = sorted([str(name.stem) for name in stimuli_dir],
key=lambda name: int(name.split('_')[0]))
np.savetxt(fp/'eventmarkers.txt', eventmarkers, fmt='%.6f')
np.savetxt(fp/'eventmarkernames.txt', eventmarkernames, fmt='%s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment