コード例 #1
0
    def start_recording(self):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        self.recording = True
        i = 0
        while True:
            # params: write samples, write event, send samples, send events
            print(u'starting recording ...')
            error = pylink.getEYELINK().startRecording(1, 1, 1, 1)
            print(u'returned %s' % error)
            if not error:
                break
            if i > self.MAX_TRY:
                raise Exception(
                    "Error in libeyelink.libeyelink.start_recording(): Failed "
                    "to start recording!")
                self.close()
                clock.expend()
            i += 1
            print(
                ("WARNING libeyelink.libeyelink.start_recording(): Failed to "
                 "start recording (attempt %d of %d)") % (i, self.MAX_TRY))
            pylink.msecDelay(100)
        # don't know what this is
        print(u'Start realtime mode ...')
        pylink.msecDelay(100)
        pylink.beginRealTimeMode(100)
        # wait a bit until samples start coming in
        print(u'Wait for block start ...')
        pylink.msecDelay(100)
        if not pylink.getEYELINK().waitForBlockStart(100, 1, 0):
            raise Exception(
                "Error in libeyelink.libeyelink.start_recording(): Failed to "
                "start recording (waitForBlockStart error)!")
        print(u'done ...')
コード例 #2
0
	def set_backdrop(self, canvas, prepped_backdrop_image=None):
	
		"""<DOC>
		Set backdrop image of Eyelink computer. For performance, it can be
		useful sometimes to already prepare the image to send to the eyelink in
		the prepare phase. This prepared image can be optionally supplied in
		prepped_backdrop_image (a  3 dimensional list with hor-lines x ver-lines
		x pixels) Otherwise, supplying the canvas is enough and this function
		will take care of the conversion
		
		Arguments:
		canvas -- an openexp canvas
		
		Keyword arguments:
		prepped_backdrop_image -- an image in the (list x list x tuple) format
								  required by pylink
		</DOC>"""
		
		if self.experiment.canvas_backend != 'legacy':
			raise exceptions.runtime_error( \
				'prepare_backdrop requires the legacy back-end')
						
		if not prepped_backdrop_image is None: 
			if	type(prepped_backdrop_image) == list:
				width = len(prepped_backdrop_image[0])
				height = len(prepped_backdrop_image)
				pylink.getEYELINK().bitmapBackdrop(width,height,prepped_backdrop_image,0,0,width,height,0,0,pylink.BX_MAXCONTRAST)
			else:
				raise exceptions.runtime_error("Backdrop image has invalid format")
		else:
			backdrop = prepare_backdrop(canvas)
			width = canvas.surface.get_width()
			height = canvas.surface.get_height()		
			pylink.getEYELINK().bitmapBackdrop(width,height,backdrop,0,0,width,height,0,0,pylink.BX_MAXCONTRAST)
コード例 #3
0
ファイル: libeyelink.py プロジェクト: neuropil/PyGaze
    def start_recording(self):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        self.recording = True
        i = 0
        while True:
            # params: write samples, write event, send samples, send events
            print(u'starting recording ...')
            error = pylink.getEYELINK().startRecording(1, 1, 1, 1)
            print(u'returned %s' % error)
            if not error:
                break
            if i > self.MAX_TRY:
                raise Exception(
                    "Error in libeyelink.libeyelink.start_recording(): Failed "
                    "to start recording!")
                self.close()
                clock.expend()
            i += 1
            print(
                ("WARNING libeyelink.libeyelink.start_recording(): Failed to "
                 "start recording (attempt %d of %d)") % (i, self.MAX_TRY))
            pylink.msecDelay(100)
        # don't know what this is
        print(u'Start realtime mode ...')
        pylink.msecDelay(100)
        pylink.beginRealTimeMode(100)
        # wait a bit until samples start coming in
        print(u'Wait for block start ...')
        pylink.msecDelay(100)
        if not pylink.getEYELINK().waitForBlockStart(100, 1, 0):
            raise Exception(
                "Error in libeyelink.libeyelink.start_recording(): Failed to "
                "start recording (waitForBlockStart error)!")
        print(u'done ...')
コード例 #4
0
	def calibrate(self, beep=True, target_size=16):

		"""<DOC>
		Starts eyelink calibration.

		Keyword arguments:
		beep			--	Indicates whether or not the calibration target #
							should beep when jumping. (default=True)
		target_size		--	The size of the calibration target. (default=16)

		Exceptions:
		Raises an exceptions.runtime_error on failure.
		</DOC>"""

		if self.recording:
			raise exceptions.runtime_error( \
				u'Trying to calibrate after recording has started')

		self.cal_beep = beep
		self.cal_target_size = target_size

		# attempt calibrate; confirm abort when esc pressed
		while True:
			pylink.getEYELINK().doTrackerSetup()
			if not self.experiment.eyelink_esc_pressed: 
				break
			else:
				self.confirm_abort_experiment()
				self.experiment.eyelink_esc_pressed = False
コード例 #5
0
 def stop(self):
     """cose file and stop tracking"""
     self.el.sendMessage("END")
     pl.endRealTimeMode()
     pl.getEYELINK().setOfflineMode()
     # el.sendCommand("set_offline_mode = YES")
     self.el.closeDataFile()
コード例 #6
0
	def wait_for_event(self, event):

		"""<DOC>
		Waits until an event has occurred.

		Arguments:
		event	-- An EyeLink event, such as pylink.STARTSACC.

		Returns:
		A tuple (timestamp, event). The event is in float_data format. The #
		timestamp is in experiment time.

		Exceptions:
		Raises an exceptions.runtime_error on failure.
		</DOC>"""

		if not self.recording:
			raise exceptions.runtime_error( \
				u'Please start recording before collecting eyelink data')
		if self.eye_used == None:
			self.set_eye_used()
		t_0 = self.experiment.time()
		while True:
			d = 0
			while d != event:
				d = pylink.getEYELINK().getNextData()
			# ignore d if its event occured before t_0:
			float_data = pylink.getEYELINK().getFloatData()
			if float_data.getTime() - self.get_eyelink_clock_async() > t_0:
				break
		return float_data.getTime() - self.get_eyelink_clock_async(), float_data
コード例 #7
0
ファイル: libeyelink.py プロジェクト: tamizhiniyan/PyGaze
    def stop_recording(self):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        self.recording = False
        pylink.endRealTimeMode()
        pylink.getEYELINK().setOfflineMode()
        pylink.msecDelay(500)
コード例 #8
0
ファイル: libeyelink.py プロジェクト: AA33/PyGaze
	def wait_for_event(self, event):

		"""See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

		if not self.recording:
			raise Exception( \
				"Error in libeyelink.libeyelink.wait_for_event(): Recording was not started before collecting eyelink data!")

		if self.eye_used == None:
			self.set_eye_used()
		if self.eventdetection == 'native':
			d = 0
			while d != event:
				d = pylink.getEYELINK().getNextData()
			return pylink.getEYELINK().getFloatData()

		if event == 5:
			outcome = self.wait_for_saccade_start()
		elif event == 6:
			outcome = self.wait_for_saccade_end()
		elif event == 7:
			outcome = self.wait_for_fixation_start()
		elif event == 8:
			outcome = self.wait_for_fixation_end()
		elif event == 3:
			outcome = self.wait_for_blink_start()
		elif event == 4:
			outcome = self.wait_for_blink_end()
		else:
			raise Exception( \
				"Error in libeyelink.libeyelink.wait_for_event: eventcode %s is not supported" \
				% event)
		return outcome
コード例 #9
0
    def wait_for_event(self, event):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        if not self.recording:
            raise Exception(
                "Error in libeyelink.libeyelink.wait_for_event(): Recording "
                "was not started before collecting eyelink data!")

        if self.eye_used == None:
            self.set_eye_used()
        if self.eventdetection == 'native':
            d = 0
            while d != event:
                d = pylink.getEYELINK().getNextData()
            return pylink.getEYELINK().getFloatData()

        if event == 5:
            outcome = self.wait_for_saccade_start()
        elif event == 6:
            outcome = self.wait_for_saccade_end()
        elif event == 7:
            outcome = self.wait_for_fixation_start()
        elif event == 8:
            outcome = self.wait_for_fixation_end()
        elif event == 3:
            outcome = self.wait_for_blink_start()
        elif event == 4:
            outcome = self.wait_for_blink_end()
        else:
            raise Exception(
                ("Error in libeyelink.libeyelink.wait_for_event: eventcode %s "
                 "is not supported") % event)
        return outcome
コード例 #10
0
ファイル: libeyelink.py プロジェクト: tamizhiniyan/PyGaze
    def start_recording(self):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        self.recording = True
        i = 0
        while True:
            # params: write samples, write event, send samples, send events
            error = pylink.getEYELINK().startRecording(1, 1, 1, 1)

            if not error:
                break
            if i > self.MAX_TRY:
                raise Exception( \
                 "Error in libeyelink.libeyelink.start_recording(): Failed to start recording!")
                self.close()
                clock.expend()
            i += 1
            print( \
             "WARNING libeyelink.libeyelink.start_recording(): Failed to start recording (attempt %d of %d)" \
             % (i, self.MAX_TRY))
            pylink.msecDelay(100)
        # don't know what this is
        pylink.pylink.beginRealTimeMode(100)
        # wait a bit until samples start coming in
        if not pylink.getEYELINK().waitForBlockStart(100, 1, 0):
            raise Exception( \
             "Error in libeyelink.libeyelink.start_recording(): Failed to start recording (waitForBlockStart error)!")
コード例 #11
0
ファイル: libeyelink.py プロジェクト: AA33/PyGaze
	def start_recording(self):

		"""See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

		self.recording = True
		i = 0
		while True:
			# params: write samples, write event, send samples, send events
			error = pylink.getEYELINK().startRecording(1, 1, 1, 1)
			
			if not error:
				break
			if i > self.MAX_TRY:
				raise Exception( \
					"Error in libeyelink.libeyelink.start_recording(): Failed to start recording!")
				self.close()
				clock.expend()
			i += 1
			print( \
				"WARNING libeyelink.libeyelink.start_recording(): Failed to start recording (attempt %d of %d)" \
				% (i, self.MAX_TRY))
			pylink.msecDelay(100)
		# don't know what this is
		pylink.pylink.beginRealTimeMode(100)
		# wait a bit until samples start coming in
		if not pylink.getEYELINK().waitForBlockStart(100, 1, 0):
			raise Exception( \
				"Error in libeyelink.libeyelink.start_recording(): Failed to start recording (waitForBlockStart error)!")
コード例 #12
0
    def drift_correction(self, pos=None, fix_triggered=False):
        """<DOC>
        Performs drift correction and falls back to the calibration screen if
        necessary
    
        Keyword arguments:
        pos -- the coordinate (x,y tuple) of the drift correction dot or None
               for the display center (default = None)
        fix_triggered -- a boolean indicating whether drift correction should
                         be fixation triggered, rather than spacebar triggered
                         (default = False)

        Returns:
        True on success, False on failure
    
        Exceptions:
        Raises an exceptions.runtime_error on error
        </DOC>"""

        if fix_triggered:
            return self.fix_triggered_drift_correction(pos)
        if pos == None:
            pos = x_size / 2, y_size / 2

        pylink.pylink.beginRealTimeMode(100)

        pylink.getEYELINK().doDriftCorrect(pos[0], pos[1], 0, 1)
コード例 #13
0
    def drift_correct(self, pos=None, fix_triggered=False):
        """<DOC>
        Performs drift correction and falls back to the calibration screen if
        necessary
    
        Keyword arguments:
        pos -- the coordinate (x,y tuple) of the drift correction dot or None
               for the display center (default = None)
        fix_triggered -- a boolean indicating whether drift correction should
                         be fixation triggered, rather than spacebar triggered
                         (default = False)

        Returns:
        True on success, False on failure
    
        Exceptions:
        Raises an exceptions.runtime_error on error
        </DOC>"""
        # Generate custom calibration stimuli
        genv = eyelink_display.calibration_display(self.sres[0], self.sres[1],
                                                   self.tracker, self.win)

        if fix_triggered:
            return self.fix_triggered_drift_correction(pos)
        if pos == None:
            pos = w / 2, h / 2

        pylink.openGraphicsEx(genv)

        pylink.getEYELINK().doDriftCorrect(pos[0], pos[1], 0, 1)
コード例 #14
0
	def start_recording(self):

		"""<DOC>
		Starts recording of gaze samples.

		Exceptions:
		Raises an exceptions.runtime_error on failure.
		</DOC>"""

		self.recording = True
		i = 0
		while True:
			# Params: write  samples, write event, send samples, send events
			error = pylink.getEYELINK().startRecording(1, 1, 1, 1)
			if not error:
				break
			if i > self.MAX_TRY:
				raise exceptions.runtime_error( \
					u'Failed to start recording (startRecording error)')
			i += 1
			print u'libeyelink.start_recording(): failed to start recording (attempt %d of %d)' \
				% (i, self.MAX_TRY)
			pylink.msecDelay(100)
		# Don't know what this is
		pylink.pylink.beginRealTimeMode(100)
		# Wait for a bit until samples start coming in (I think?)
		if not pylink.getEYELINK().waitForBlockStart(100, 1, 0):
			raise exceptions.runtime_error( \
				u'Failed to start recording (waitForBlockStart error)')
コード例 #15
0
ファイル: libeyelink.py プロジェクト: AA33/PyGaze
	def stop_recording(self):

		"""See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

		self.recording = False
		pylink.endRealTimeMode()
		pylink.getEYELINK().setOfflineMode()
		pylink.msecDelay(500)
コード例 #16
0
    def send_command(self, cmd):
        """
		Writes a message to the eyelink
	
		In:
		cmd: the eyelink command to be executed
		"""

        pylink.getEYELINK().sendCommand(cmd)
コード例 #17
0
    def log(self, msg):
        """
		Writes a message to the eyelink data file
	
		In:
		msg: the message to be logged
		"""

        pylink.getEYELINK().sendMessage(msg)
コード例 #18
0
    def status_msg(self, msg):
        """
		Sets the eyelink status message, which is displayed on the 
		eyelink pc
	
		In:
		msg: the status message
		"""

        pylink.getEYELINK().sendCommand("record_status_message '%s'" % msg)
コード例 #19
0
    def log_var(self, var, val):
        """
		Writes a variable to the eyelink data file
	
		In:
		var: the variable name
		val: the value
		"""

        pylink.getEYELINK().sendMessage("var %s %s" % (var, val))
コード例 #20
0
ファイル: libeyelink.py プロジェクト: psederberg/OpenSesame
	def log(self, msg):

		"""
		Writes a message to the eyelink data file
	
		In:
		msg: the message to be logged
		"""

		pylink.getEYELINK().sendMessage(msg)
コード例 #21
0
ファイル: libeyelink.py プロジェクト: psederberg/OpenSesame
	def send_command(self, cmd):

		"""
		Writes a message to the eyelink
	
		In:
		cmd: the eyelink command to be executed
		"""
	
		pylink.getEYELINK().sendCommand(cmd)
コード例 #22
0
	def log(self, msg):

		"""<DOC>
		Writes a message to the eyelink data file
	
		Arguments:
		msg -- the message to be logged
		</DOC>"""

		pylink.getEYELINK().sendMessage(msg)
コード例 #23
0
    def stop_recording(self):
        """
		Stop recording of gaze samples
		"""

        self.recording = False

        pylink.endRealTimeMode()
        pylink.getEYELINK().setOfflineMode()
        pylink.msecDelay(500)
コード例 #24
0
	def stop_recording(self):

		"""<DOC>
		Stops recording of gaze samples.
		</DOC>"""

		self.recording = False
		pylink.endRealTimeMode()
		pylink.getEYELINK().setOfflineMode()
		pylink.msecDelay(500)
コード例 #25
0
	def send_command(self, cmd):

		"""<DOC>
		Sends a command to the eyelink.

		Arguments:
		cmd		--	The eyelink command to be executed.
		</DOC>"""

		pylink.getEYELINK().sendCommand(cmd)
コード例 #26
0
ファイル: libeyelink.py プロジェクト: psederberg/OpenSesame
	def log_var(self, var, val):

		"""
		Writes a variable to the eyelink data file
	
		In:
		var: the variable name
		val: the value
		"""

		pylink.getEYELINK().sendMessage("var %s %s" % (var, val))
コード例 #27
0
ファイル: libeyelink.py プロジェクト: psederberg/OpenSesame
	def status_msg(self, msg):

		"""
		Sets the eyelink status message, which is displayed on the 
		eyelink pc
	
		In:
		msg: the status message
		"""
	
		pylink.getEYELINK().sendCommand("record_status_message '%s'" % msg)
コード例 #28
0
ファイル: libeyelink.py プロジェクト: psederberg/OpenSesame
	def stop_recording(self):

		"""
		Stop recording of gaze samples
		"""
	
		self.recording = False	

		pylink.endRealTimeMode();
		pylink.getEYELINK().setOfflineMode();                          
		pylink.msecDelay(500);                 
コード例 #29
0
	def status_msg(self, msg):

		"""<DOC>
		Sets the eyelink status message, which is displayed on the eyelink #
		experimenter pc.

		Arguments:
		msg		--	The status message.
		</DOC>"""

		pylink.getEYELINK().sendCommand("record_status_message '%s'" % msg)
コード例 #30
0
    def send_command(self, cmd):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        try:
            result = pylink.getEYELINK().sendCommand(cmd)

            if result != None:
                return result

        except Exception:
            pylink.getEYELINK().sendCommand(cmd)
コード例 #31
0
	def log_var(self, var, val):

		"""<DOC>
		Writes a variable to the eyelink data file. This is a shortcut for #
		eyelink.log("var %s %s" % (var, val)).

		Arguments:
		var		-- The variable name.
		val		-- The value.
		</DOC>"""

		pylink.getEYELINK().sendMessage("var %s %s" % (var, val))
コード例 #32
0
ファイル: libeyelink.py プロジェクト: psederberg/OpenSesame
	def calibrate(self):

		"""
		Starts eyelink calibration
	
		Exceptions:
		Raises an exceptions.runtime_error on failure		
		"""
	
		if self.recording:
			raise exceptions.runtime_error("Trying to calibrate after recording has started")	
	
		pylink.getEYELINK().doTrackerSetup()
コード例 #33
0
    def calibrate(self):
        """
		Starts eyelink calibration
	
		Exceptions:
		Raises an exceptions.runtime_error on failure		
		"""

        if self.recording:
            raise exceptions.runtime_error(
                "Trying to calibrate after recording has started")

        pylink.getEYELINK().doTrackerSetup()
コード例 #34
0
ファイル: EyelinkWrapper.py プロジェクト: wanjam/WM_utilities
def EyelinkSendTabMsg(infolist, el=pylink.getEYELINK()):
    """ Sends tab-delimited message to EDF

    **Author** : Wanja Mössing, WWU Münster | [email protected] \n
    *July 2017*

    Parameters
    ----------
    infolist : list
        a list with information. The first item in the list is used as
        event-definition (e.g., ['trialOnset', 1, 'Condition X', 0.78])
        Can take strings, integers, floats
    el: Eyelink object
        ...as returned by, e.g., EyelinkStart()
    """
    # if it's not a list convert
    if not isinstance(infolist, list):
        infolist = [infolist]
    # prepend identifier if necessary
    if infolist[0] is not '>':
        infolist.insert(0, '>')
    # make it a tab delimited list and convert everything to string
    msg = '\t'.join(str(i) for i in infolist)
    # send to Eyetracker
    el.sendMessage(msg)
    return
コード例 #35
0
    def sample(self):
        """
		Gets the most recent gaze sample from the eyelink
	
		Returns:
		A tuple (x, y) containing the coordinates of the sample
	
		Exceptions:
		Raises an exceptions.runtime_error on failure		
		"""

        if not self.recording:
            raise exceptions.runtime_error(
                "Please start recording before collecting eyelink data")

        if self.eye_used == None:
            self.set_eye_used()

        s = pylink.getEYELINK().getNewestSample()
        if s != None:
            if self.eye_used == self.right_eye and s.isRightSample():
                gaze = s.getRightEye().getGaze()
            elif self.eye_used == self.left_eye and s.isLeftSample():
                gaze = s.getLeftEye().getGaze()

        return gaze
コード例 #36
0
def EyelinkSendTabMsg(infolist, el=pylink.getEYELINK()):
    """ Sends tab-delimited message to EDF

    **Author** : Wanja Mössing, WWU Münster | [email protected] \n
    *July 2017*

    Parameters
    ----------
    infolist : list
        a list with information. The first item in the list is used as
        event-definition (e.g., ['trialOnset', 1, 'Condition X', 0.78])
        Can take strings, integers, floats
    el: Eyelink object
        ...as returned by, e.g., EyelinkStart()
    """
    # if it's not a list convert
    if not isinstance(infolist, list):
        infolist = [infolist]
    # prepend identifier if necessary
    if infolist[0] is not '>':
        infolist.insert(0, '>')
    # make it a tab delimited list and convert everything to string
    msg = '\t'.join(str(i) for i in infolist)
    # send to Eyetracker
    el.sendMessage(msg)
    return
コード例 #37
0
    def manual_drift_correction(self, pos):
        """
		Performs a manual, i.e. spacebar-triggered drift correction.

		Arguments:
		pos		--	The positionf or the drift-correction target.

		Returns:
		True if drift correction was successfull, False otherwise.
		"""

        self.draw_drift_correction_target(pos[0], pos[1])
        self.eyelink_graphics.esc_pressed = False
        try:
            # The 0 parameters indicate that the display should not be cleared
            # and we should not be allowed to fall back to the set-up screen.
            error = pylink.getEYELINK().doDriftCorrect(pos[0], pos[1], 0, 0)
        except:
            error = -1
        # A 0 exit code means successful drift correction
        if error == 0:
            return True
        # If escape was pressed, we present the confirm abort screen
        if self.eyelink_graphics.esc_pressed:
            self.confirm_abort_experiment()
        # If 'q' was pressed, we drop back to the calibration screen
        else:
            self.calibrate()
        return False
コード例 #38
0
ファイル: EyelinkWrapper.py プロジェクト: wanjam/WM_utilities
def EyelinkDriftCheck(targetloc=(1920, 1080),
                      el=pylink.getEYELINK()):
    """ Performs Driftcheck for Eyelink 1000+.

    **Author** : Wanja Mössing, WWU Münster | [email protected] \n
    *July 2017*

    Parameters:
    ----------
    target : tuple
        two-item tuple width & height in px
    el       :
        Eyelink object, optional
    """
    # drift check
    try:
        el.sendMessage("STOP_REC_4_DRIFTCHECK")
        # wait 100ms to catch final events
        pylink.msecDelay(100)
        # stop the recording
        el.stopRecording()
        res = el.doDriftCorrect(targetloc[0], targetloc[1], 1, 1)
        # clear tracker display and draw box at center
        el.sendCommand("clear_screen 0")
        el.sendCommand("set_idle_mode")
        pylink.msecDelay(50)
        # re-start recording
        el.startRecording(1, 1, 1, 1)
    except:
        res = EyelinkCalibrate(targetloc, el)
    return res
コード例 #39
0
	def pupil_size(self):

		"""<DOC>
		Gets the most recent pupil size.

		Returns:
		A float corresponding to the pupil size (in arbitrary units). The #
		value -1 indicates missing data.

		Exceptions:
		Raises an exceptions.runtime_error on failure.
		</DOC>"""

		if not self.recording:
			raise exceptions.runtime_error( \
				u'Please start recording before collecting eyelink data')
		if self.eye_used == None:
			self.set_eye_used()
		s = pylink.getEYELINK().getNewestSample()
		if s == None:
			ps = -1
		elif self.eye_used == self.right_eye and s.isRightSample():
			ps = s.getRightEye().getPupilSize()
		elif self.eye_used == self.left_eye and s.isLeftSample():
			ps = s.getLeftEye().getPupilSize()
		else:
			ps = -1
		return ps
コード例 #40
0
	def sample(self):

		"""<DOC>
		Gets the most recent gaze sample.

		Returns:
		A tuple (x, y) containing the coordinates of the sample. The value #
		(-1, -1) indicates missing data.

		Exceptions:
		Raises an exceptions.runtime_error on failure.
		</DOC>"""

		if not self.recording:
			raise exceptions.runtime_error( \
				u'Please start recording before collecting eyelink data')
		if self.eye_used == None:
			self.set_eye_used()
		s = pylink.getEYELINK().getNewestSample()
		if s == None:
			gaze = -1, -1
		elif self.eye_used == self.right_eye and s.isRightSample():
			gaze = s.getRightEye().getGaze()
		elif self.eye_used == self.left_eye and s.isLeftSample():
			gaze = s.getLeftEye().getGaze()
		else:
			gaze = -1, -1
		return gaze
コード例 #41
0
    def pupil_size(self):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        if not self.recording:
            raise Exception(
                "Error in libeyelink.libeyelink.pupil_size(): Recording was "
                "not started before collecting eyelink data!")
        if self.eye_used == None:
            self.set_eye_used()
        # get newest sample
        s = pylink.getEYELINK().getNewestSample()
        # check if sample is new
        if s != None:
            # right eye
            if self.eye_used == self.right_eye and s.isRightSample():
                ps = s.getRightEye().getPupilSize()
            # left eye
            elif self.eye_used == self.left_eye and s.isLeftSample():
                ps = s.getLeftEye().getPupilSize()
            # invalid
            else:
                ps = -1
            # set new pupil size as previous pupil size
            self.prevps = ps
        # if no new sample is available, use old data
        else:
            ps = self.prevps
        return ps
コード例 #42
0
	def log(self, msg):

		"""<DOC>
		Writes a message to the eyelink data file.

		Arguments:
		msg		--	The message to be logged.
		</DOC>"""
		
		# sendMessage() is not Unicode safe, so we need to strip all Unicode
		# characters from the message
		if type(msg) == unicode:
			msg = msg.encode('ascii','ignore')
		if type(msg) == str:
			msg = msg.decode('ascii','ignore')
		pylink.getEYELINK().sendMessage(msg)
コード例 #43
0
ファイル: libeyelink.py プロジェクト: neuropil/PyGaze
    def manual_drift_correction(self, pos):
        """
		Performs a manual, i.e. spacebar-triggered drift correction.

		Arguments:
		pos		--	The positionf or the drift-correction target.

		Returns:
		True if drift correction was successfull, False otherwise.
		"""

        self.draw_drift_correction_target(pos[0], pos[1])
        self.eyelink_graphics.esc_pressed = False
        try:
            # The 0 parameters indicate that the display should not be cleared
            # and we should not be allowed to fall back to the set-up screen.
            error = pylink.getEYELINK().doDriftCorrect(pos[0], pos[1], 0, 0)
        except:
            error = -1
        # A 0 exit code means successful drift correction
        if error == 0:
            return True
        # If escape was pressed, we present the confirm abort screen
        if self.eyelink_graphics.esc_pressed:
            self.confirm_abort_experiment()
        # If 'q' was pressed, we drop back to the calibration screen
        else:
            self.calibrate()
        return False
コード例 #44
0
    def _get_eyelink_clock_async(self, time_used=None):
        """
        Retrieve time differenece between tracker timestamps and
        current clock time upheld in the pygaze environment.

        Note that this is not guaranteed to be a static time difference, the
        clocks might run at different speeds. Therefore you should consider
        running this function every time you utilize on this time difference.

        Returns:
        The tracker time minus the clock time
        """
        if time_used == None:
            return pylink.getEYELINK().trackerTime() - clock.get_time()
        else:
            return time_used - pylink.getEYELINK().trackerTime()
コード例 #45
0
def EyelinkCalibrate(targetloc=(1920, 1080), el=pylink.getEYELINK()):
    """ Performs calibration for Eyelink 1000+.

    **Author** : Wanja Mössing, WWU Münster | [email protected] \n
    *July 2017*

    Parameters:
    ----------
    target : tuple
        two-item tuple width & height in px
    el     :
        Eyelink object, optional
    """
    el.sendMessage("STOP_REC_4_RECAL")
    # wait 100ms to catch final events
    pylink.msecDelay(100)
    # stop the recording
    el.stopRecording()
    # do the calibration
    el.doTrackerSetup(targetloc[0], targetloc[1])
    # clear tracker display and draw box at center
    el.sendCommand("clear_screen 0")
    el.sendCommand("set_idle_mode")
    pylink.msecDelay(50)
    # re-start recording
    el.startRecording(1, 1, 1, 1)
    return el
コード例 #46
0
ファイル: EyelinkWrapper.py プロジェクト: wanjam/WM_utilities
def EyelinkCalibrate(targetloc=(1920, 1080),
                     el=pylink.getEYELINK()):
    """ Performs calibration for Eyelink 1000+.

    **Author** : Wanja Mössing, WWU Münster | [email protected] \n
    *July 2017*

    Parameters:
    ----------
    target : tuple
        two-item tuple width & height in px
    el     :
        Eyelink object, optional
    """
    el.sendMessage("STOP_REC_4_RECAL")
    # wait 100ms to catch final events
    pylink.msecDelay(100)
    # stop the recording
    el.stopRecording()
    # do the calibration
    el.doTrackerSetup(targetloc[0], targetloc[1])
    # clear tracker display and draw box at center
    el.sendCommand("clear_screen 0")
    el.sendCommand("set_idle_mode")
    pylink.msecDelay(50)
    # re-start recording
    el.startRecording(1, 1, 1, 1)
    return el
コード例 #47
0
ファイル: libeyelink.py プロジェクト: psederberg/OpenSesame
	def sample(self):

		"""
		Gets the most recent gaze sample from the eyelink
	
		Returns:
		A tuple (x, y) containing the coordinates of the sample
	
		Exceptions:
		Raises an exceptions.runtime_error on failure		
		"""	
	
		if not self.recording:
			raise exceptions.runtime_error("Please start recording before collecting eyelink data")
	
		if self.eye_used == None:
			self.set_eye_used()
		
		s = pylink.getEYELINK().getNewestSample()
		if s != None:
			if self.eye_used == self.right_eye and s.isRightSample():
				gaze = s.getRightEye().getGaze()
			elif self.eye_used == self.left_eye and s.isLeftSample():
				gaze = s.getLeftEye().getGaze()
		
		return gaze
コード例 #48
0
def EyelinkDriftCheck(targetloc=(1920, 1080), el=pylink.getEYELINK()):
    """ Performs Driftcheck for Eyelink 1000+.

    **Author** : Wanja Mössing, WWU Münster | [email protected] \n
    *July 2017*

    Parameters:
    ----------
    target : tuple
        two-item tuple width & height in px
    el       :
        Eyelink object, optional
    """
    # drift check
    try:
        el.sendMessage("STOP_REC_4_DRIFTCHECK")
        # wait 100ms to catch final events
        pylink.msecDelay(100)
        # stop the recording
        el.stopRecording()
        res = el.doDriftCorrect(targetloc[0], targetloc[1], 1, 1)
        # clear tracker display and draw box at center
        el.sendCommand("clear_screen 0")
        el.sendCommand("set_idle_mode")
        pylink.msecDelay(50)
        # re-start recording
        el.startRecording(1, 1, 1, 1)
    except:
        res = EyelinkCalibrate(targetloc, el)
    return res
コード例 #49
0
ファイル: libeyelink.py プロジェクト: neuropil/PyGaze
    def pupil_size(self):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        if not self.recording:
            raise Exception(
                "Error in libeyelink.libeyelink.pupil_size(): Recording was "
                "not started before collecting eyelink data!")
        if self.eye_used == None:
            self.set_eye_used()
        # get newest sample
        s = pylink.getEYELINK().getNewestSample()
        # check if sample is new
        if s != None:
            # right eye
            if self.eye_used == self.right_eye and s.isRightSample():
                ps = s.getRightEye().getPupilSize()
            # left eye
            elif self.eye_used == self.left_eye and s.isLeftSample():
                ps = s.getLeftEye().getPupilSize()
            # invalid
            else:
                ps = -1
            # set new pupil size as previous pupil size
            self.prevps = ps
        # if no new sample is available, use old data
        else:
            ps = self.prevps
        return ps
コード例 #50
0
    def connected(self):
        """
		Returs the status of the eyelink connection.
	
		Returns:
		True if connected, False otherwise
		"""

        return pylink.getEYELINK().isConnected()
コード例 #51
0
def gc_window():
    global gaze_timer
    global inbox
    dt = pylink.getEYELINK().getNewestSample()  # check for new sample update
    if (dt != None):  # Gets the gaze position of the latest sample
        if eye_used == right_eye:
            gx, gy = dt.getRightEye().getGaze()
        elif eye_used == left_eye:
            gx, gy = dt.getLeftEye().getGaze()

    if xbdr[0] < gx < xbdr[1] and ybdr[0] < gy < ybdr[
            1]:  #is gaze within the update region
        if (
                time.clock() - gaze_timer
        ) > GCWINDOW:  #if YES: compare current time and gcwindow onset against GCDURATION
            pylink.getEYELINK().sendMessage('WindowOffset')
            inbox = True
    else:
        gaze_timer = time.clock()
コード例 #52
0
	def connected(self):

		"""<DOC>
		Returns the status of the eyelink connection.

		Returns:
		True if connected, False otherwise.
		</DOC>"""

		return pylink.getEYELINK().isConnected()
コード例 #53
0
	def calibrate(self, beep=True, target_size=16):

		"""<DOC>
		Starts eyelink calibration
		
		Keyword arguments:
		beep -- indicates whether the calibration target should beep (default=True)
		target_size -- the size of the calibration target (default=16)
	
		Exceptions:
		Raises an exceptions.runtime_error on failure		
		</DOC>"""
	
		if self.recording:
			raise exceptions.runtime_error("Trying to calibrate after recording has started")	
	
		self.cal_beep = beep
		self.cal_target_size = target_size
		pylink.getEYELINK().doTrackerSetup()
コード例 #54
0
    def set_eye_used(self):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        self.eye_used = pylink.getEYELINK().eyeAvailable()
        if self.eye_used == self.right_eye:
            self.log_var("eye_used", "right")
        elif self.eye_used == self.left_eye or self.eye_used == self.binocular:
            self.log_var("eye_used", "left")
            self.eye_used = self.left_eye
        else:
            print("WARNING libeyelink.libeyelink.set_eye_used(): Failed to "
                  "determine which eye is being recorded")
コード例 #55
0
    def wait_for_event(self, event):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        if not self.recording:
            raise Exception(
                "Error in libeyelink.libeyelink.wait_for_event(): Recording "
                "was not started before collecting eyelink data!")

        if self.eye_used == None:
            self.set_eye_used()
        if self.eventdetection == 'native':
            # since the link buffer was not have been polled, old data has
            # accumulated in the buffer -- so ignore events that are old:
            t0 = clock.get_time()  # time of call
            while True:
                d = pylink.getEYELINK().getNextData()
                if d == event:
                    float_data = pylink.getEYELINK().getFloatData()
                    # corresponding clock_time
                    tc = float_data.getTime() - self._get_eyelink_clock_async()
                    if tc > t0:
                        return tc, float_data

        if event == 5:
            outcome = self.wait_for_saccade_start()
        elif event == 6:
            outcome = self.wait_for_saccade_end()
        elif event == 7:
            outcome = self.wait_for_fixation_start()
        elif event == 8:
            outcome = self.wait_for_fixation_end()
        elif event == 3:
            outcome = self.wait_for_blink_start()
        elif event == 4:
            outcome = self.wait_for_blink_end()
        else:
            raise Exception(
                ("Error in libeyelink.libeyelink.wait_for_event: eventcode %s "
                 "is not supported") % event)
        return outcome
コード例 #56
0
def calibrate():
    """
    Calibrates eye-tracker using psychopy stimuli.
    """

    # Generate custom calibration stimuli
    genv = eyelink_display.calibration_display(w,h,tracker,win)

    if realconnect:
        # Set calibration type
        pylink.getEYELINK().setCalibrationType('HV%d'%(cnum))

        # Set calibraiton pacing
        pylink.getEYELINK().setAutoCalibrationPacing(paval)

        # Execute custom calibration display
        print '*' * 150
        print 'Calibration Mode'
        print '*' * 150
        pylink.openGraphicsEx(genv)

        # Calibrate
        pylink.getEYELINK().doTrackerSetup(w, h)
    else:
        genv.dummynote()
コード例 #57
0
 def pupil_cue(self,p_ma,p_min,p_max):
     if p_ma < p_min: #pupil size less than 1SD from baseline
         im = Image.new("RGB", (stim_size), "red")
         im.save("red.png")
         iaps_cue.setImage("red.png")
         iaps_cue.setAutoDraw(True)
         pylink.getEYELINK().sendMessage('redimage')
         print('red image, moving_avg=%s, min=%s, max=%s'%(p_ma,p_min,p_max))
         print(t)
     elif p_ma > p_max:#pupil size greater than 1SD from baseline            
         im = Image.new("RGB", (stim_size), "green")
         im.save("green.png")
         iaps_cue.setImage("green.png")
         iaps_cue.setAutoDraw(True)
         pylink.getEYELINK().sendMessage('greenimage')
         print('green image, moving_avg=%s, min=%s, max=%s'%(p_ma,p_min,p_max))
         print(t)
         
     else: #pupil size greater than 1SD from baseline            
         im = Image.new("RGB", (stim_size), "blue")
         im.save("blue.png")
         iaps_cue.setImage("blue.png")
         iaps_cue.setAutoDraw(True)
         pylink.getEYELINK().sendMessage('blueimage')
         print('blue image, moving_avg=%s, min=%s, max=%s'%(p_ma,p_min,p_max))
         print(t)
コード例 #58
0
    def close(self, full_close=True):
        """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""

        self.eyelink_graphics.close()
        if self.recording:
            self.stop_recording()
        # close data file and transfer it to the experimental PC
        print(u"libeyelink.libeyelink.close(): Closing data file")
        pylink.getEYELINK().closeDataFile()
        pylink.msecDelay(500)
        print(u"libeyelink.libeyelink.close(): Transferring {} to {}".format( \
            self.eyelink_data_file, self.local_data_file))
        # During data transfer, suppress output
        _out = sys.stdout
        with open(os.devnull, 'w') as fd:
            sys.stdout = fd
            pylink.getEYELINK().receiveDataFile(self.eyelink_data_file,
                                                self.local_data_file)
            sys.stdout = _out
        pylink.msecDelay(500)
        print(u"libeyelink.libeyelink.close(): Closing eyelink")

        ### EDITED 12-08-2020 BY ALEX HOOGERBRUGGE
        ### ADDED THE CONDITIONAL. TO RESTORE, REMOVE THIS FILE AND RENAME
        ### LIBEYELINK_ORIGINAL.PY TO LIBEYELINK.PY
        if full_close:
            pylink.getEYELINK().close()

        pylink.msecDelay(500)
コード例 #59
0
ファイル: 6.0_drift.py プロジェクト: hlmpsy/mdl-eyetracking
def gc_drift():
    pylink.getEYELINK().sendMessage("GC_failed")  #send failure message
    core.wait(
        .05
    )  #using psychopy wait statement - Waits 50ms to allow eyelink to prepare
    pylink.getEYELINK().stopRecording()
    pylink.getEYELINK().doDriftCorrect(int(sc[0]), int(sc[1]), 0, 0)
コード例 #60
0
ファイル: 6.4_backup.py プロジェクト: hlmpsy/mdl-eyetracking
 def gc_window(self):
     global inbox
     global Finished
     global Fixation
     global gaze_timer
     dt = pylink.getEYELINK().getNewestSample() # check for new sample update
     if(dt != None): # Gets the gaze position of the latest sample
         if eye_used == self.right_eye:
             gx,gy = dt.getRightEye().getGaze()
         elif eye_used == self.left_eye:
             gx,gy = dt.getLeftEye().getGaze()
         else:
             gx,gy = (-1,-1)
 
     if self.xbdr[0] < gx < self.xbdr[1] and self.ybdr[0] < gy < self.ybdr[1]: #is gaze congingent fixation within the update region
         if (time.clock() - gaze_timer) > self.GCWINDOW: #if YES: compare current time and gcwindow onset against GCDURATION
             pylink.getEYELINK().sendMessage('WindowOffset')
             inbox = True
             Finished = True #allows skipping of gc_drift()
             Fixation = False
     else:
         gaze_timer = time.clock()