80 lines
2.7 KiB
Python
Executable file
80 lines
2.7 KiB
Python
Executable file
#!/usr/bin/python
|
|
import sys
|
|
import os
|
|
fpath = sys.argv[1]
|
|
subjprefix = os.path.basename(fpath).split('_')[0]
|
|
subintid = int(subjprefix.split('-')[1])
|
|
# quick test to be a bit more future-proof in detecting name changes
|
|
assert(subintid > 0)
|
|
assert(len(subjprefix.split('-')[1]) == 2)
|
|
|
|
# TODO make all segments of uniform length with hese segment cuts
|
|
# XXX plus 2s except for last one
|
|
#segment_cut = np.array((
|
|
# 22279,
|
|
# 21828,
|
|
# 21667,
|
|
# 24156,
|
|
# 22893,
|
|
# 21721,
|
|
# 26892,
|
|
# 16800))
|
|
|
|
# how much time does it take for the video signal to appear on the projection
|
|
# screen after the stimulation computer thinks it flipped the video buffer
|
|
# in the MR machine signal needs to travel through an optical DVI connection
|
|
# measured delay is 6-8 video refresh cycles @60 Hz. Correct for the lower
|
|
# bound of this window of uncertainty
|
|
# positive offset indicates that the video actually appears _later_ than the
|
|
# time stamps indicate
|
|
if subintid < 21:
|
|
# scanner subjects
|
|
vsync_msg_onset_delay = 100 # in samples at eyegaze sampling rate (AKA ms)
|
|
else:
|
|
# lab subjects
|
|
vsync_msg_onset_delay = 0
|
|
|
|
import pandas
|
|
import numpy as np
|
|
from cili.util import load_eyelink_dataset
|
|
samp, events = load_eyelink_dataset(fpath)
|
|
# filter for spurious frame idx messages after the end of the recording
|
|
frame_start = np.array(
|
|
[s + vsync_msg_onset_delay
|
|
for s in events.MSG[events.MSG.label == 'FIDX:'].index if s in samp.index])
|
|
samp = samp.loc[frame_start[0]:frame_start[-1] + 100]
|
|
fidx = np.zeros(len(samp), dtype='int')
|
|
frame_start -= frame_start[0]
|
|
for i, start in enumerate(frame_start):
|
|
fidx[start:] = i + 1
|
|
# take any eye (there was only one recorded)
|
|
if 'x_l' in samp.columns:
|
|
x_col = 'x_l'
|
|
y_col = 'y_l'
|
|
coi = samp.loc[:, ['x_l', 'y_l', 'pup_l']]
|
|
else:
|
|
x_col = 'x_r'
|
|
y_col = 'y_r'
|
|
coi = samp.loc[:, ['x_r', 'y_r', 'pup_r']]
|
|
merged = pandas.concat(
|
|
[coi,
|
|
pandas.DataFrame(dict(movie_frame=fidx), index=samp.index)],
|
|
axis=1)
|
|
# place y=0 at the top of the actual movie frame content (not the top of the
|
|
# gray bar!)
|
|
if subjprefix in ('sub-02', 'sub-10', 'sub-20'):
|
|
# movie was centered for those
|
|
merged.loc[:, y_col] -= 239
|
|
elif subintid > 20:
|
|
# lab setup
|
|
# also re-scale to the actual pixel size of the stimulus video
|
|
# native is 1280x720, but was shown at 1920x1080 on lab screen
|
|
merged.loc[:, x_col] /= 1.5
|
|
merged.loc[:, y_col] /= 1.5
|
|
merged.loc[:, y_col] -= 87
|
|
else:
|
|
merged.loc[:, y_col] -= 68
|
|
path_comps = fpath.split('_')
|
|
ofname = '%s_%s_recording-eyegaze_physio.tsv' \
|
|
% ('_'.join(path_comps[:-2]), path_comps[-2])
|
|
merged.to_csv(ofname, index=False, header=False, sep='\t', float_format='%.1f')
|