예제 #1
0
    def run(self, ns, eyetracker, mouse, gaze_debug, debug_sq):
        """
        Run trial
        :param ns: netstation connection
        :param eyetracker: eyetracker
        :return:
        """

        # Show actors on random sides of screen
        left_actor = None
        right_actor = None
        if np.random.rand() < 0.5:
            self.actors[0].stim.pos = [-12, 0]
            self.actors[1].stim.pos = [12, 0]
            left_actor = self.actors[0].actor
            right_actor = self.actors[1].actor
        else:
            self.actors[0].stim.pos = [12, 0]
            self.actors[1].stim.pos = [-12, 0]
            left_actor = self.actors[1].actor
            right_actor = self.actors[0].actor

        event.clearEvents()
        mouse.clickReset()
        resp=None
        self.attn_video.reload(self.win)
        self.win.callOnFlip(send_event, ns, eyetracker, 'pgat', 'pg attn', {'left': left_actor, 'rght': right_actor})
        while resp is None:
            while not self.attn_video.stim.status == visual.FINISHED and resp is None:
                self.attn_video.stim.draw()
                self.win.flip()
                buttons, times = mouse.getPressed(getTime=True)
                if buttons[0] and times[0]>0:
                    resp = 'l'
                elif buttons[2] and times[2]>0:
                    resp = 'r'
            self.attn_video.reload(self.win)

        # Draw images
        self.win.callOnFlip(send_event, ns, eyetracker, 'pgst', 'pg start', {'left': left_actor, 'rght': right_actor})
        for i in range(self.duration_frames):
            for actor in self.actors:
                actor.stim.draw()
            draw_eye_debug(gaze_debug, eyetracker, mouse)
            if gaze_debug is not None:
                self.left_roi.draw()
                self.right_roi.draw()
            if debug_sq is not None:
                debug_sq.draw()
            self.win.flip()
        send_event(ns, eyetracker, 'pgen', "pg end", {'left': left_actor, 'rght': right_actor})
예제 #2
0
    def run(self, ns, eyetracker, mouse, gaze_debug, distractor_set, debug_sq):
        """
        Run the block
        :param ns: connection to netstation
        :param eyetracker: connection to eyetracker
        :returns True if task should continue, False if should quit
        """

        # Compute trial order
        n_movies = len(self.stimuli)
        vid_order = range(n_movies)
        if n_movies < self.trials:
            vid_order = []
            while len(vid_order) < self.trials:
                vid_order.extend(range(n_movies))
        np.random.shuffle(vid_order)

        # Start netstation recording
        send_event(ns, eyetracker, 'blk1', "block start", {'code': self.code})

        # Run trials
        for t in range(self.trials):

            # Synch with netstation in between trials
            if ns is not None:
                ns.sync()

            # Compute random delay period
            iti_frames = self.min_iti_frames+int(np.random.rand()*(self.max_iti_frames-self.min_iti_frames))

            # Reset movie to beginning
            video_idx = vid_order[t]
            self.stimuli[video_idx].reload(self.win)

            # clear any keystrokes before starting
            event.clearEvents()

            # Play movie
            self.win.callOnFlip(self.add_trial_event, ns, eyetracker, 'mov1', 'movie start',
                                {'code': self.code,
                                 'mvmt': self.stimuli[video_idx].movement,
                                 'actr': self.stimuli[video_idx].actor})
            while not self.stimuli[video_idx].stim.status == visual.FINISHED:
                self.stimuli[video_idx].stim.draw()
                draw_eye_debug(gaze_debug, eyetracker, mouse)
                if debug_sq is not None:
                    debug_sq.draw()
                self.win.flip()

            # Tell netstation the movie has stopped
            self.add_trial_event(ns, eyetracker, 'mov2', 'movie end', {})

            # Black screen for delay
            for i in range(iti_frames):
                self.win.flip()

            for trial_event in self.trial_events:
                if ns is not None:
                    ns.send_event(trial_event.code, label=trial_event.label, timestamp=trial_event.timestamp, table=trial_event.table)
            self.trial_events=[]

            # Check user input
            all_keys = event.getKeys()
            if len(all_keys):
                # Quit experiment
                if all_keys[0].upper() in ['Q', 'ESCAPE']:
                    return all_keys[0].upper()
                # Pause block
                elif all_keys[0].upper() == 'P':
                    self.pause()
                # End block
                elif all_keys[0].upper() == 'E':
                    return all_keys[0].upper()
                # Show distractors
                elif all_keys[0].upper() == 'D':
                    distractor_set.show_pictures_and_sounds()
                # Show distractor video
                elif all_keys[0].upper() == 'V':
                    distractor_set.show_video()

                event.clearEvents()

        # Stop netstation recording
        send_event(ns, eyetracker, 'blk2', 'block end', {'code': self.code})
        return []
예제 #3
0
    def run(self, ns, eyetracker, mouse, gaze_debug, distractor_set, debug_sq):
        """
        Run the block
        :param ns - connection to netstation
        :return True if task should continue, False if should quit
        """

        # Compute trial order
        n_trials = len(self.trials)
        trial_order = range(n_trials)
        if n_trials < self.num_trials:
            trial_order = []
            while len(trial_order) < self.num_trials:
                trial_order.extend(range(n_trials))
        np.random.shuffle(trial_order)

        # Start netstation recording
        send_event(ns, eyetracker, 'blk1', "block start", {'code': self.code})

        # Run trials
        for t in range(self.num_trials):
            # Synch with netstation in between trials
            if ns is not None:
                ns.sync()

            # Compute random delay period
            delay_frames = self.min_iti_frames + int(np.random.rand() * (self.max_iti_frames - self.min_iti_frames))

            # clear any keystrokes before starting
            event.clearEvents()

            # Run trial
            trial_idx = trial_order[t]
            cmd=self.trials[trial_idx].run(ns, eyetracker, mouse, gaze_debug, debug_sq)

            # Check user input
            all_keys = event.getKeys()
            if len(all_keys):
                cmd=all_keys[0].upper()
            if cmd is not None:
                # Quit experiment
                if cmd in ['Q', 'ESCAPE']:
                    return cmd
                # Pause block
                elif cmd == 'P':
                    self.pause()
                # End block
                elif cmd == 'E':
                    return cmd
                # Show distractors
                elif cmd == 'D':
                    distractor_set.show_video()
                # # Show distractor video
                # elif cmd == 'V':
                #     distractor_set.show_video()
                # Run preferential gaze
                elif cmd == 'G':
                    return cmd

                event.clearEvents()

            # Black screen for delay
            for i in range(delay_frames):
                self.win.flip()

        # Stop netstation recording
        send_event(ns, eyetracker, 'blk2', 'block end', {'code': self.code})
        return []