-
Notifications
You must be signed in to change notification settings - Fork 1
/
frametimestomat.py
47 lines (40 loc) · 1.31 KB
/
frametimestomat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 12 11:15:11 2018
@author: ycan
"""
from os.path import join as pjoin
import scipy.io
import iofuncs as iof
import analysis_scripts as asc
def savenpztomat(exp_name, savedir=None):
"""
Convert frametime files in .npz to .mat for interoperability
with MATLAB users.
savedir
"""
exp_dir = iof.exp_dir_fixer(exp_name)
_, metadata = asc.read_spikesheet(exp_dir)
monitor_delay = metadata['monitor_delay(s)']
for i in range(1, 100):
print(i)
try:
ft_on, ft_off = asc.readframetimes(exp_name, i, returnoffsets=True)
except ValueError as e:
if str(e).startswith('No frametimes'):
break
else:
raise
# Convert to milliseconds b/c that is the convertion in MATLAB scripts
ft_on = (ft_on - monitor_delay)*1000
ft_off = (ft_off - monitor_delay)*1000
stimname = iof.getstimname(exp_dir, i)
if savedir is None:
savedir = pjoin(exp_dir, 'frametimes')
savename = pjoin(savedir, stimname)
print(savename)
scipy.io.savemat(savename+'_frametimings',
{'ftimes':ft_on,
'ftimes_offsets':ft_off},
appendmat=True)