def correlate_eye_world(eye_timestamps, world_timestamps):
 e_ts = eye_timestamps
 w_ts = list(world_timestamps)
 eye_frames_by_timestamp = dict(zip(e_ts, range(len(e_ts))))
 eye_timestamps_by_world_index = [[] for i in world_timestamps]
 frame_idx = 0
 try:
  current_e_ts = e_ts.pop(0)
 except:
  logger.warning('No eye timestamps found.')
  return eye_timestamps_by_world_index
 while e_ts:
  try:
   t_between_frames = ((w_ts[frame_idx] + w_ts[(frame_idx + 1)]) / 2.0)
  except IndexError:
   break
  if (current_e_ts <= t_between_frames):
   eye_timestamps_by_world_index[frame_idx].append(current_e_ts)
   current_e_ts = e_ts.pop(0)
  else:
   frame_idx += 1
 idx = 0
 eye_world_frame_map = []
 for (candidate, world_ts) in zip(eye_timestamps_by_world_index, w_ts):
  if (not candidate):
   e_past_ts = get_past_timestamp(idx, eye_timestamps_by_world_index)
   e_future_ts = get_future_timestamp(idx, eye_timestamps_by_world_index)
   eye_world_frame_map.append(eye_frames_by_timestamp[get_nearest_timestamp(e_past_ts, e_future_ts, world_ts)])
  else:
   eye_world_frame_map.append(eye_frames_by_timestamp[eye_timestamps_by_world_index[idx][(-1)]])
  idx += 1
 return eye_world_frame_map

def correlate_eye_world ( eye_timestamps , world_timestamps ) : e_ts = eye_timestamps w_ts = list ( world_timestamps ) eye_frames_by_timestamp = dict ( zip ( e_ts , range ( len ( e_ts ) ) ) ) eye_timestamps_by_world_index = [ [ ] for i in world_timestamps ] frame_idx = 0 try : current_e_ts = e_ts . pop ( 0 ) except : logger . warning ( 'No eye timestamps found.' ) return eye_timestamps_by_world_index while e_ts : try : t_between_frames = ( ( w_ts [ frame_idx ] + w_ts [ ( frame_idx + 1 ) ] ) / 2.0 ) except IndexError : break if ( current_e_ts <= t_between_frames ) : eye_timestamps_by_world_index [ frame_idx ] . append ( current_e_ts ) current_e_ts = e_ts . pop ( 0 ) else : frame_idx += 1 idx = 0 eye_world_frame_map = [ ] for ( candidate , world_ts ) in zip ( eye_timestamps_by_world_index , w_ts ) : if ( not candidate ) : e_past_ts = get_past_timestamp ( idx , eye_timestamps_by_world_index ) e_future_ts = get_future_timestamp ( idx , eye_timestamps_by_world_index ) eye_world_frame_map . append ( eye_frames_by_timestamp [ get_nearest_timestamp ( e_past_ts , e_future_ts , world_ts ) ] ) else : eye_world_frame_map . append ( eye_frames_by_timestamp [ eye_timestamps_by_world_index [ idx ] [ ( - 1 ) ] ] ) idx += 1 return eye_world_frame_map
this function takes a list of eye timestamps and world timestamps and correlates one eye frame per world frame returns a mapping that correlates a single eye frame index with each world frame index .