def closest_matches_monocular(ref_pts, pupil_pts, max_dispersion=(1 / 15.0)):
 ref = ref_pts
 pupil0 = pupil_pts
 pupil0_ts = np.array([p['timestamp'] for p in pupil0])
 def find_nearest_idx(array, value):
  idx = np.searchsorted(array, value, side='left')
  try:
   if (abs((value - array[(idx - 1)])) < abs((value - array[idx]))):
    return (idx - 1)
   else:
    return idx
  except IndexError:
   return (idx - 1)
 matched = []
 if pupil0:
  for r in ref_pts:
   closest_p0_idx = find_nearest_idx(pupil0_ts, r['timestamp'])
   closest_p0 = pupil0[closest_p0_idx]
   dispersion = (max(closest_p0['timestamp'], r['timestamp']) - min(closest_p0['timestamp'], r['timestamp']))
   if (dispersion < max_dispersion):
    matched.append({'ref': r, 'pupil': closest_p0})
   else:
    pass
 return matched

def closest_matches_monocular ( ref_pts , pupil_pts , max_dispersion = ( 1 / 15.0 ) ) : ref = ref_pts pupil0 = pupil_pts pupil0_ts = np . array ( [ p [ 'timestamp' ] for p in pupil0 ] ) def find_nearest_idx ( array , value ) : idx = np . searchsorted ( array , value , side = 'left' ) try : if ( abs ( ( value - array [ ( idx - 1 ) ] ) ) < abs ( ( value - array [ idx ] ) ) ) : return ( idx - 1 ) else : return idx except IndexError : return ( idx - 1 ) matched = [ ] if pupil0 : for r in ref_pts : closest_p0_idx = find_nearest_idx ( pupil0_ts , r [ 'timestamp' ] ) closest_p0 = pupil0 [ closest_p0_idx ] dispersion = ( max ( closest_p0 [ 'timestamp' ] , r [ 'timestamp' ] ) - min ( closest_p0 [ 'timestamp' ] , r [ 'timestamp' ] ) ) if ( dispersion < max_dispersion ) : matched . append ( { 'ref' : r , 'pupil' : closest_p0 } ) else : pass return matched
get pupil positions closest in time to ref points .