def trial(self):

        if P.development_mode:
            print(self.image_name, self.mask_type)

        trial_countdown = CountDown(900) # 15 minutes
        while trial_countdown.remaining() > 0:
            q = pump(True)
            if key_pressed(sdl2.SDLK_DELETE, queue=q):
                # press 'Del' to skip trial
                break
            elif key_pressed(sdl2.SDLK_ESCAPE, queue=q):
                # Press 'escape' to pause and calibrate
                trial_countdown.pause()
                self.el.calibrate()
                self.el.drift_correct()
                self.el.start(P.trial_number)
                trial_countdown.resume()
                continue
            
            if trial_countdown.elapsed() >= self.first_warning_onset and not self.first_warning_played:
                self.warning_signal.play()
                self.first_warning_played = True
            if trial_countdown.elapsed() >= self.second_warning_onset and not self.second_warning_played:
                self.warning_signal.play()
                self.second_warning_played = True

            pos = self.el.gaze()
            fill()
            if int(pos[0]) != -32768: # if gaze not lost
                self.gaze_offscreen = time.time()
            if (pos[0] < 0) or (pos[0] > P.screen_x) or (pos[1] < 0) or (pos[1] > P.screen_y):
                pass
            elif (time.time() - self.gaze_offscreen) < self.gaze_timeout:
                blit(self.arrangement, 5, P.screen_c)
                if self.mask is not None and trial_countdown.elapsed() < self.mask_off_time:
                    blit(self.mask, 5, pos)
            flip()

        return {
            "trial_num":   P.trial_number,
            "block_num":   P.block_number,
            "arrangement": self.image_name,
            "mask_type":   self.mask_type
        }
Example #2
0
    def get_ambient_level(self, period=1):
        """Determines the average ambient noise level from the input stream over a given period.
		Gives a 3-second countdown before starting to help the user ensure they are quiet.
		
		Args:
			period (numeric, optional): The number of seconds to record input for. Defaults to one
				second.

		Returns:
			int: The average of the peaks of all samples recorded during the period.

		"""
        warn_msg = (
            "Please remain quiet while the ambient noise level is sampled. "
            "Sampling will begin in {0} second{1}.")
        peaks = []

        wait_period = CountDown(3)
        while wait_period.counting():
            ui_request()
            fill()
            remaining = int(math.ceil(wait_period.remaining()))
            s = "" if remaining == 1 else "s"  # to avoid "1 seconds"
            message(warn_msg.format(remaining, s),
                    location=P.screen_c,
                    registration=5)
            flip()

        self.stream.start()
        fill()
        flip()
        sample_period = CountDown(period)
        while sample_period.counting():
            ui_request()
            peaks.append(self.stream.sample().peak)
        self.stream.stop()
        return sum(peaks) / float(len(peaks))