Esempio n. 1
0
    def _init_boundary(self, p1, p2):

        if not all([valid_coords(p1), valid_coords(p2)]):
            raise ValueError(
                "'p1' and 'p2' must both be valid (x, y) coordinates.")

        # Ensure p1 is the upper-leftmost point
        x1, y1 = p1
        x2, y2 = p2
        w = abs(x2 - x1)
        h = abs(y2 - y1)
        if x1 > x2:
            x1 = x2
            x2 = x1 + w
        if y1 > y2:
            y1 = y2
            y2 = y1 + h

        if w == 0 or h == 0:
            err = "Cannot create a rectangle boundary with a {0} of 0."
            raise ValueError(err.format("width" if w == 0 else "height"))

        self.__p1 = (x1, y1)
        self.__p2 = (x2, y2)
        self.__center = midpoint(self.__p1, self.__p2)
Esempio n. 2
0
 def center(self, coords):
     if not valid_coords(coords):
         raise ValueError(
             "Boundary center must be a valid set of (x, y) coordinates.")
     dx = coords[0] - self.__center[0]
     dy = coords[1] - self.__center[1]
     self.__p1 = (self.p1[0] + dx, self.p1[1] + dy)
     self.__p2 = (self.p2[0] + dx, self.p2[1] + dy)
     self.__center = tuple(coords)
Esempio n. 3
0
    def within(self, p):
        """Determines whether a given point is within the boundary.

		Args:
			p (:obj:`Tuple` or :obj:`List`): The (x, y) coordinates of the point to
				check against the boundary.
		
		Returns:
			bool: True if the point falls within the boundary, otherwise False.
		
		Raises:
			ValueError: If the given point is not a valid set of (x, y) coordinates.
		
		"""
        if not valid_coords(p):
            raise ValueError(
                "The given value must be a valid set of (x, y) coordinates.")

        return line_segment_len(p, self.center) <= self.radius
Esempio n. 4
0
	def drift_correct(self, location=None, target=None, fill_color=None, draw_target=True):
		"""Checks the accuracy of the EyeLink's calibration by presenting a fixation stimulus
		and requiring the participant to press the space bar while looking directly at it. If
		there is a large difference between the gaze location at the time the key was pressed
		and the true location of the fixation, it indicates that there has been drift in the
		calibration.

		On older EyeLink models (EyeLink I & II), the recorded drift is used to adjust the
		calibration for improved accuracy on future trials. On recent models (EyeLink 1000 and
		up), drift corrections will *check* for drift and prompt the participant to try again
		if the drift is large, but they do not affect the tracker's calibration.

		Args:
			location (Tuple(int, int), optional): The (x,y) pixel coordinates where the drift
				correct target should be located. Defaults to the center of the screen.
			target: A :obj:`Drawbject` or other :func:`KLGraphics.blit`-able shape to use as
				the drift correct target. Defaults to a circular :func:`drift_correct_target`.
			fill_color: A :obj:`List` or :obj:`Tuple` containing an RGBA colour to use for the
				background for the drift correct screen. Defaults to the value of
				``P.default_fill_color``.
			draw_target (bool, optional): A flag indicating whether the function should draw
				the drift correct target itself (True), or whether it should leave it to the
				programmer to draw the target before :meth:`drift_correct` is called (False). 
				Defaults to True.

		Raises:
			TrialException: If repeated EyeLink errors are encountered while attempting to
				perform the drift correct.

		"""
		hide_mouse_cursor()

		target = drift_correct_target() if target is None else target
		draw_target = EL_TRUE if draw_target in [EL_TRUE, True] else EL_FALSE
		location = P.screen_c if location is None else location
		if not valid_coords(location):
			raise ValueError("'location' must be a pair of (x,y) pixel coordinates.")

		try:
			while True:
				if draw_target == EL_TRUE:
					fill(P.default_fill_color if not fill_color else fill_color)
					blit(target, 5, location)
					flip()
				ret = self.doDriftCorrect(location[0], location[1], draw_target, EL_TRUE)
				if ret != 27: # 27 means we hit Esc to enter calibration, so redo drift correct
					break
			if draw_target == EL_TRUE:
				fill(P.default_fill_color if not fill_color else fill_color)
				flip()
			return self.applyDriftCorrect()
		except RuntimeError:
			try:
				self.setOfflineMode()
			except RuntimeError:
				self._unresolved_exceptions += 1
				if self._unresolved_exceptions > 5:
					cso("\n<red>*** Fatal Error: Unresolvable EyeLink Error ***</red>")
					print(full_trace())
					self._unresolved_exceptions = 0
					raise TrialException("EyeLink not ready.")
			return self.drift_correct(location, target, fill_color, draw_target)
Esempio n. 5
0
 def center(self, coords):
     if not valid_coords(coords):
         raise ValueError(
             "The center must be a valid set of (x, y) coordinates.")
     self.__center = tuple(coords)