def _addBlinkEvent(self, startEvent): btime = EyeTracker._last_mouse_event_time if startEvent: # Create a blink start EyeTracker._last_event_start = btime EyeTracker._eye_state = "BLINK" eye_evt = [ 0, 0, 0, # device id (not currently used) Device._getNextEventID(), EventConstants.BLINK_START, btime, btime, btime, 0, 0, 0, EyeTrackerConstants.RIGHT_EYE, 0 ] else: # Create a blink end eye_evt = [ 0, 0, 0, Device._getNextEventID(), EventConstants.BLINK_END, btime, btime, btime, 0, 0, 0, EyeTrackerConstants.RIGHT_EYE, btime - EyeTracker._last_event_start, 0 ] EyeTracker._last_event_start = 0.0 self._addNativeEventToBuffer(eye_evt)
def _addFixationEvent(self, startEvent, end_pos=None): ftime = EyeTracker._last_mouse_event_time gaze = self._latest_gaze_position if startEvent: eye_evt = [ 0, 0, 0, Device._getNextEventID(), EventConstants.FIXATION_START, ftime, ftime, ftime, 0, 0, 0, EyeTrackerConstants.RIGHT_EYE, gaze[0], gaze[1], ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 5, EyeTrackerConstants.PUPIL_DIAMETER_MM, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 0 ] EyeTracker._last_event_start = ftime EyeTracker._last_start_event_pos = gaze EyeTracker._eye_state = "FIX" else: start_event_time = EyeTracker._last_event_start end_event_time = ftime event_duration = end_event_time - start_event_time s_gaze = self._last_start_event_pos e_gaze = end_pos a_gaze = (s_gaze[0] + e_gaze[0]) / 2, (s_gaze[1] + e_gaze[1]) / 2 EyeTracker._last_event_start = 0.0 EyeTracker._last_start_event_pos = None eye_evt = [ 0, 0, 0, Device._getNextEventID(), EventConstants.FIXATION_END, ftime, ftime, ftime, 0, 0, 0, EyeTrackerConstants.RIGHT_EYE, event_duration, s_gaze[0], s_gaze[1], ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 4, EyeTrackerConstants.PUPIL_DIAMETER_MM, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, e_gaze[0], e_gaze[1], ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 5, EyeTrackerConstants.PUPIL_DIAMETER_MM, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, a_gaze[0], a_gaze[1], ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 4.5, EyeTrackerConstants.PUPIL_DIAMETER_MM, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 0 ] self._addNativeEventToBuffer(eye_evt)
def _add_gaze_sample(self, gaze_on_surface_datum, gaze_datum, logged_time): native_time = gaze_datum["timestamp"] iohub_time = self._trackerTimeInPsychopyTime(native_time) metadata = { "experiment_id": 0, # experiment_id, iohub fills in automatically "session_id": 0, # session_id, iohub fills in automatically "device_id": 0, # device_id, keep at 0 "event_id": Device._getNextEventID(), # iohub event unique ID "device_time": native_time, "logged_time": logged_time, "time": iohub_time, "confidence_interval": -1.0, "delay": (logged_time - iohub_time), "filter_id": False, } position = self._gaze_in_display_coords(gaze_on_surface_datum) sample = data_parse.eye_sample_from_gaze_3d(position, gaze_datum, metadata) self._addNativeEventToBuffer(sample) self._latest_sample = sample self._latest_gaze_position = position
def _addSample(self, sample_time): if self._latest_gaze_position: gx, gy = self._latest_gaze_position status = 0 else: gx, gy = EyeTrackerConstants.UNDEFINED, EyeTrackerConstants.UNDEFINED status = 2 pupilSize = 5 monoSample = [ 0, 0, 0, Device._getNextEventID(), EventConstants.MONOCULAR_EYE_SAMPLE, sample_time, sample_time, sample_time, 0, 0, 0, EyeTrackerConstants.RIGHT_EYE, gx, gy, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, pupilSize, EyeTrackerConstants.PUPIL_DIAMETER_MM, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, status ] self._latest_sample = monoSample self._addNativeEventToBuffer(monoSample)
def _add_pupil_sample(self, pupil_datum, logged_time): native_time = pupil_datum["timestamp"] iohub_time = self._trackerTimeInPsychopyTime(native_time) metadata = { "experiment_id": 0, # experiment_id, iohub fills in automatically "session_id": 0, # session_id, iohub fills in automatically "device_id": 0, # device_id, keep at 0 "event_id": Device._getNextEventID(), # iohub event unique ID "device_time": native_time, "logged_time": logged_time, "time": iohub_time, "confidence_interval": -1.0, "delay": (logged_time - iohub_time), "filter_id": False, } sample = data_parse.eye_sample_from_pupil(pupil_datum, metadata) self._addNativeEventToBuffer(sample) self._latest_sample = sample
def _addSaccadeEvent(self, startEvent, sacc_start_pos, sacc_end_pos): stime = EyeTracker._last_mouse_event_time if startEvent: eye_evt = [ 0, 0, 0, Device._getNextEventID(), EventConstants.SACCADE_START, stime, stime, stime, 0, 0, 0, EyeTrackerConstants.RIGHT_EYE, sacc_start_pos[0], sacc_start_pos[1], ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 5, EyeTrackerConstants.PUPIL_DIAMETER_MM, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 0 ] EyeTracker._eye_state = 'SACC' EyeTracker._last_event_start = stime sacc_amp_xy = math.fabs(math.hypot(*EyeTracker._sacc_amplitude)) saccade_duration = 2.2 * sacc_amp_xy + 21.0 saccade_duration = saccade_duration / 1000.0 # convert to seconds EyeTracker._sacc_end_time = stime + saccade_duration EyeTracker._last_start_event_pos = sacc_start_pos self._latest_gaze_position = sacc_end_pos else: start_event_time = EyeTracker._last_event_start end_event_time = EyeTracker._sacc_end_time event_duration = end_event_time - start_event_time s_gaze = sacc_start_pos s_pupilsize = 4 e_gaze = sacc_end_pos e_pupilsize = 5 eye_evt = [ 0, 0, 0, Device._getNextEventID(), EventConstants.SACCADE_END, end_event_time, end_event_time, end_event_time, 0, 0, 0, EyeTrackerConstants.RIGHT_EYE, event_duration, EyeTracker._sacc_amplitude[0], # e_amp[0], EyeTracker._sacc_amplitude[1], # e_amp[1], 0, # e_angle, s_gaze[0], s_gaze[1], ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, s_pupilsize, EyeTrackerConstants.PUPIL_DIAMETER_MM, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, e_gaze[0], e_gaze[1], ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, e_pupilsize, EyeTrackerConstants.PUPIL_DIAMETER_MM, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, ET_UNDEFINED, 0 ] EyeTracker._eye_state = 'FIX' EyeTracker._sacc_end_time = 0 self._addNativeEventToBuffer(eye_evt)
def _getIOHubEventObject(self, native_event_data): """The _getIOHubEventObject method is called by the ioHub Server to convert new native device event objects that have been received to the appropriate ioHub Event type representation. The Tobii ioHub eye tracker implementation uses a callback method to register new native device events with the ioHub Server. Therefore this method converts the native Tobii event data into an appropriate ioHub Event representation. Args: native_event_data: object or tuple of (callback_time, native_event_object) Returns: tuple: The appropriate ioHub Event type in list form. """ try: logged_time, device_event_time, iohub_event_time, data_delay, eye_data_event = native_event_data event_type = EventConstants.BINOCULAR_EYE_SAMPLE left_gaze_x, left_gaze_y = eye_data_event[ 'left_gaze_point_on_display_area'] right_gaze_x, right_gaze_y = eye_data_event[ 'right_gaze_point_on_display_area'] status = 0 if eye_data_event['left_gaze_point_validity'] > 0: left_gaze_x, left_gaze_y = self._eyeTrackerToDisplayCoords( (left_gaze_x, left_gaze_y)) else: status += 20 if eye_data_event['right_gaze_point_validity'] > 0: right_gaze_x, right_gaze_y = self._eyeTrackerToDisplayCoords( (right_gaze_x, right_gaze_y)) else: status += 2 right_gx, right_gy, right_gz = eye_data_event[ 'right_gaze_origin_in_trackbox_coordinate_system'] left_gx, left_gy, left_gz = eye_data_event[ 'left_gaze_origin_in_trackbox_coordinate_system'] confidenceInterval = 0.0 binocSample = [ 0, 0, 0, # device id (not currently used) Device._getNextEventID(), event_type, device_event_time, logged_time, iohub_event_time, confidenceInterval, data_delay, 0, # filtered id (always 0 right now) left_gaze_x, left_gaze_y, EyeTrackerConstants.UNDEFINED, left_gx, left_gy, left_gz, EyeTrackerConstants.UNDEFINED, # Left Eye Angle x EyeTrackerConstants.UNDEFINED, # Left Eye Angle y EyeTrackerConstants.UNDEFINED, # Left Camera Sensor position x EyeTrackerConstants.UNDEFINED, # Left Camera Sensor position y eye_data_event['left_pupil_diameter'], EyeTrackerConstants.PUPIL_DIAMETER_MM, EyeTrackerConstants.UNDEFINED, # Left pupil size measure 2 EyeTrackerConstants. UNDEFINED, # Left pupil size measure 2 type EyeTrackerConstants.UNDEFINED, # Left PPD x EyeTrackerConstants.UNDEFINED, # Left PPD y EyeTrackerConstants.UNDEFINED, # Left velocity x EyeTrackerConstants.UNDEFINED, # Left velocity y EyeTrackerConstants.UNDEFINED, # Left velocity xy right_gaze_x, right_gaze_y, EyeTrackerConstants.UNDEFINED, # Right Eye Angle z right_gx, right_gy, right_gz, EyeTrackerConstants.UNDEFINED, # Right Eye Angle x EyeTrackerConstants.UNDEFINED, # Right Eye Angle y EyeTrackerConstants. UNDEFINED, # Right Camera Sensor position x EyeTrackerConstants. UNDEFINED, # Right Camera Sensor position y eye_data_event['right_pupil_diameter'], EyeTrackerConstants.PUPIL_DIAMETER_MM, EyeTrackerConstants.UNDEFINED, # Right pupil size measure 2 EyeTrackerConstants. UNDEFINED, # Right pupil size measure 2 type EyeTrackerConstants.UNDEFINED, # Right PPD x EyeTrackerConstants.UNDEFINED, # Right PPD y EyeTrackerConstants.UNDEFINED, # right velocity x EyeTrackerConstants.UNDEFINED, # right velocity y EyeTrackerConstants.UNDEFINED, # right velocity xy status ] self._latest_sample = binocSample if eye_data_event['left_gaze_point_validity'] == eye_data_event[ 'right_gaze_point_validity'] == 0: self._latest_gaze_position = None elif eye_data_event['left_gaze_point_validity'] == eye_data_event[ 'right_gaze_point_validity'] == 1: self._latest_gaze_position = [ (right_gaze_x + left_gaze_x) / 2.0, (right_gaze_y + left_gaze_y) / 2.0 ] elif eye_data_event['left_gaze_point_validity'] == 1: self._latest_gaze_position = [left_gaze_x, left_gaze_y] elif eye_data_event['right_gaze_point_validity'] == 1: self._latest_gaze_position = [right_gaze_x, right_gaze_y] self._last_callback_time = logged_time return binocSample except Exception: printExceptionDetailsToStdErr() return None