def calibrate_eye(self,eye_channel,realign_mark,realign_timebin,eye_medfilt_win=21,eye_gausfilt_sigma=3):
'''
Args
eye_channel (list):
the first element is the channel name for the horizontal eye position
the second element is the channel name for the vertial eye position
realign_mark (string):
event marker used to align eye positions
realign_timebin (list):
a period of time relative to the realign_mark.
Example: [0,100]
eye_medfilt_win (int):
parameter for the median filter to smooth the eye movement trajectory
eye_gausfilt_sigma (int):
sigma of the gaussian kernel to smooth the eye movement trajectory
Return:
-
'''
samp_time = 1000.0/self.sampling_rate[eye_channel[0]]
# medfilt eye x, y position
lamb_medfilt = lambda ite:signal.medfilt(ite,eye_medfilt_win)
self.data_df[eye_channel[0]] = self.data_df[eye_channel[0]].apply(lamb_medfilt)
self.data_df[eye_channel[1]] = self.data_df[eye_channel[1]].apply(lamb_medfilt)
# gaussian filt eye x,y position
lamb_gausfilt = lambda ite:ndimage.filters.gaussian_filter1d(ite,eye_gausfilt_sigma)
self.data_df[eye_channel[0]] = self.data_df[eye_channel[0]].apply(lamb_gausfilt)
self.data_df[eye_channel[1]] = self.data_df[eye_channel[1]].apply(lamb_gausfilt)
# align eye to realign_mark, realign_timebin uses realign_mark as reference
realign_poinnum = (self.data_df[realign_mark]/samp_time).values
start_points = realign_poinnum + realign_timebin[0]/samp_time
points_num = int((realign_timebin[1]-realign_timebin[0])/samp_time)
for channel in eye_channel:
align_points = list()
for idx in self.data_df.index:
start_point = start_points[idx]
if ~np.isnan(start_point):
start_point = int(start_point)
end_point = start_point + points_num
align_point = self.data_df[channel].loc[idx][start_point:end_point]
align_point = align_point.mean()
else:
align_point = np.nan
align_points.append(align_point)
self.data_df[channel] = self.data_df[channel] - align_points
# find all saccades for all trials
评论列表
文章目录