コード例 #1
0
ファイル: ant.py プロジェクト: sho-87/cognitive-battery
    def display_flanker(self, flanker_type, location, direction):
        # Left flanker
        if direction == "left":
            if flanker_type == "congruent":
                stimulus = self.img_left_congruent
            elif flanker_type == "incongruent":
                stimulus = self.img_left_incongruent
            else:
                stimulus = self.img_left_neutral
        # Right flanker
        else:
            if flanker_type == "congruent":
                stimulus = self.img_right_congruent
            elif flanker_type == "incongruent":
                stimulus = self.img_right_incongruent
            else:
                stimulus = self.img_right_neutral

        # Offset the flanker stimulus to above/below fixation
        if location == "top":
            display.image(
                self.screen, stimulus, "center",
                self.screen_y/2 - self.flanker_h - self.TARGET_OFFSET)
        elif location == "bottom":
            display.image(self.screen, stimulus, "center",
                          self.screen_y/2 + self.TARGET_OFFSET)
コード例 #2
0
    def display_flanker(self, flanker_type, location, direction):
        # Left flanker
        if direction == "left":
            if flanker_type == "congruent":
                stimulus = self.img_left_congruent
            elif flanker_type == "incongruent":
                stimulus = self.img_left_incongruent
            else:
                stimulus = self.img_left_neutral
        # Right flanker
        else:
            if flanker_type == "congruent":
                stimulus = self.img_right_congruent
            elif flanker_type == "incongruent":
                stimulus = self.img_right_incongruent
            else:
                stimulus = self.img_right_neutral

        # Offset the flanker stimulus to above/below fixation
        if location == "top":
            display.image(
                self.screen, stimulus, "center",
                self.screen_y / 2 - self.flanker_h - self.TARGET_OFFSET)
        elif location == "bottom":
            display.image(self.screen, stimulus, "center",
                          self.screen_y / 2 + self.TARGET_OFFSET)
コード例 #3
0
    def run(self):
        # Instructions
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.font, "Attentional Network Test",
                     "center", self.screen_y / 2 - 300)
        display.text(
            self.screen, self.font,
            "Keep your eyes on the fixation cross at the "
            "start of each trial:", 100, self.screen_y / 2 - 200)
        display.image(self.screen, self.img_fixation, "center",
                      self.screen_y / 2 - 150)
        display.text(self.screen, self.font,
                     "A set of arrows will appear somewhere on the screen:",
                     100, self.screen_y / 2 - 100)
        display.image(self.screen, self.img_left_incongruent, "center",
                      self.screen_y / 2 - 50)
        display.text(
            self.screen, self.font,
            "Use the Left / Right arrow keys to indicate "
            "the direction of the CENTER arrow.", 100, self.screen_y / 2 + 50)
        display.text(self.screen, self.font,
                     "In example above, you should press the Left arrow.", 100,
                     self.screen_y / 2 + 100)
        display.text_space(self.screen, self.font, "center",
                           (self.screen_y / 2) + 300)
        pygame.display.flip()

        display.wait_for_space()

        # Instructions Practice
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.font,
                     "We'll begin with some practice trials...", "center",
                     "center")
        display.text_space(self.screen, self.font, "center",
                           self.screen_y / 2 + 100)
        pygame.display.flip()

        display.wait_for_space()

        # Practice trials
        self.run_block(0, 1, "practice")

        # Instructions Practice End
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.font,
                     "We will now begin the main trials...", 100,
                     self.screen_y / 2 - 50)
        display.text(self.screen, self.font,
                     "You will not receive feedback after each trial.", 100,
                     self.screen_y / 2 + 50)
        display.text_space(self.screen, self.font, "center",
                           self.screen_y / 2 + 200)
        pygame.display.flip()

        display.wait_for_space()

        # Main task
        for i in range(self.NUM_BLOCKS):
            self.run_block(i, self.NUM_BLOCKS, "main")

        # Create trial number column
        self.all_data["trial"] = list(range(1, len(self.all_data) + 1))

        # Rearrange the dataframe
        columns = [
            'trial', 'block', 'congruency', 'cue', 'location', 'fixationTime',
            'ITI', 'direction', 'response', 'correct', 'RT'
        ]
        self.all_data = self.all_data[columns]

        # End screen
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.font, "End of task", "center", "center")
        display.text_space(self.screen, self.font, "center",
                           self.screen_y / 2 + 100)
        pygame.display.flip()

        display.wait_for_space()

        print("- ANT complete")

        return self.all_data
コード例 #4
0
    def display_trial(self, trial_num, data, trial_type):
        # Check for a quit press after stimulus was shown
        for event in pygame.event.get():
            if event.type == KEYDOWN and event.key == K_F12:
                sys.exit(0)

        # Display fixation
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_fixation, "center", "center")
        pygame.display.flip()

        display.wait(data["fixationTime"][trial_num])

        # Display cue
        self.screen.blit(self.background, (0, 0))

        cue_type = data["cue"][trial_num]

        if cue_type == "nocue":
            # Display fixation in the center
            display.image(self.screen, self.img_fixation, "center", "center")
        elif cue_type == "center":
            # Display cue in the center
            display.image(self.screen, self.img_cue, "center", "center")
        elif cue_type == "double":
            # Display fixation in the center
            display.image(self.screen, self.img_fixation, "center", "center")

            # Display cue above and below fixation
            display.image(
                self.screen, self.img_cue, "center",
                self.screen_y / 2 - self.fixation_h - self.TARGET_OFFSET)
            display.image(self.screen, self.img_cue, "center",
                          self.screen_y / 2 + self.TARGET_OFFSET)
        elif cue_type == "spatial":
            cue_location = data["location"][trial_num]

            # Display fixation in the center
            display.image(self.screen, self.img_fixation, "center", "center")

            # Display cue at target location
            if cue_location == "top":
                display.image(
                    self.screen, self.img_cue, "center",
                    self.screen_y / 2 - self.fixation_h - self.TARGET_OFFSET)
            elif cue_location == "bottom":
                display.image(self.screen, self.img_cue, "center",
                              self.screen_y / 2 + self.TARGET_OFFSET)

        pygame.display.flip()

        # Display cue for certain duration
        display.wait(self.CUE_DURATION)

        # Prestim interval with fixation
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_fixation, "center", "center")
        pygame.display.flip()

        display.wait(self.PRE_STIM_FIXATION_DURATION)

        # Display flanker target
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_fixation, "center", "center")

        self.display_flanker(data["congruency"][trial_num],
                             data["location"][trial_num],
                             data["direction"][trial_num])
        pygame.display.flip()

        start_time = int(round(time.time() * 1000))

        # Clear the event queue before checking for responses
        pygame.event.clear()
        response = "NA"
        wait_response = True
        while wait_response:
            for event in pygame.event.get():
                if event.type == KEYDOWN and event.key == K_LEFT:
                    response = "left"
                    wait_response = False
                elif event.type == KEYDOWN and event.key == K_RIGHT:
                    response = "right"
                    wait_response = False
                elif event.type == KEYDOWN and event.key == K_F12:
                    sys.exit(0)

            end_time = int(round(time.time() * 1000))

            # If time limit has been reached, consider it a missed trial
            if end_time - start_time >= self.FLANKER_DURATION:
                wait_response = False

        # Store reaction time and response
        rt = int(round(time.time() * 1000)) - start_time
        data.set_value(trial_num, 'RT', rt)
        data.set_value(trial_num, 'response', response)

        correct = 1 if response == data["direction"][trial_num] else 0
        data.set_value(trial_num, 'correct', correct)

        # Display feedback if practice trials
        if trial_type == "practice":
            self.screen.blit(self.background, (0, 0))
            if correct == 1:
                display.text(self.screen, self.font, "correct", "center",
                             "center", (0, 255, 0))
            else:
                display.text(self.screen, self.font, "incorrect", "center",
                             "center", (255, 0, 0))
            pygame.display.flip()

            display.wait(self.FEEDBACK_DURATION)

        # Display fixation during ITI
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_fixation, "center", "center")
        pygame.display.flip()

        iti = self.ITI_MAX - rt - data["fixationTime"][trial_num]
        data.set_value(trial_num, 'ITI', iti)

        display.wait(iti)
コード例 #5
0
ファイル: sart.py プロジェクト: y1ngyang/cognitive-battery
    def display_trial(self, i, data):
        # Randomly choose font size for this trial
        size_index = random.randint(0, len(self.stim_fonts) - 1)
        trial_font = self.stim_fonts[size_index]

        key_press = 0
        data.set_value(i, 'RT', 1150)

        # Display number
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, trial_font, str(data["stimulus"][i]),
                     "center", "center", (255, 255, 255))
        pygame.display.flip()

        # Get start time in ms
        start_time = int(round(time.time() * 1000))

        # Clear the event queue before checking for responses
        pygame.event.clear()
        wait_response = True
        while wait_response:
            for event in pygame.event.get():
                if event.type == KEYDOWN and event.key == K_SPACE:
                    key_press = 1
                    data.set_value(i, 'RT',
                                   int(round(time.time() * 1000)) - start_time)
                elif event.type == KEYDOWN and event.key == K_F12:
                    sys.exit(0)

            end_time = int(round(time.time() * 1000))

            # Stop this loop if stim duration has passed
            if end_time - start_time >= self.STIM_DURATION:
                wait_response = False

        # Display mask
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_mask, "center", "center")
        pygame.display.flip()

        wait_response = True
        while wait_response:
            for event in pygame.event.get():
                if event.type == KEYDOWN and event.key == K_SPACE:
                    if key_press == 0:
                        key_press = 1
                        data.set_value(
                            i, 'RT',
                            int(round(time.time() * 1000)) - start_time)
                elif event.type == KEYDOWN and event.key == K_F12:
                    sys.exit(0)

            end_time = int(round(time.time() * 1000))

            # Stop this loop if mask duration has passed
            if end_time - start_time >= self.MASK_DURATION:
                wait_response = False

        # Check if response is correct
        if data["stimulus"][i] == 3:
            if key_press == 0:
                accuracy = 1
            else:
                accuracy = 0
        else:
            if key_press == 0:
                accuracy = 0
            else:
                accuracy = 1

        # Store key press data in dataframe
        data.set_value(i, 'key press', key_press)
        data.set_value(i, 'accuracy', accuracy)
        data.set_value(i, 'stimSize', self.STIMSIZES_PT[size_index])
コード例 #6
0
ファイル: ant.py プロジェクト: sho-87/cognitive-battery
    def run(self):
        # Instructions
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.font, "Attentional Network Test",
                     "center", self.screen_y/2 - 300)
        display.text(self.screen, self.font,
                     "Keep your eyes on the fixation cross at the "
                     "start of each trial:",
                     100, self.screen_y/2 - 200)
        display.image(self.screen, self.img_fixation,
                      "center", self.screen_y/2 - 150)
        display.text(self.screen, self.font,
                     "A set of arrows will appear somewhere on the screen:",
                     100, self.screen_y/2 - 100)
        display.image(self.screen, self.img_left_incongruent,
                      "center", self.screen_y/2 - 50)
        display.text(self.screen, self.font,
                     "Use the Left / Right arrow keys to indicate "
                     "the direction of the CENTER arrow.",
                     100, self.screen_y/2 + 50)
        display.text(self.screen, self.font,
                     "In example above, you should press the Left arrow.",
                     100, self.screen_y/2 + 100)
        display.text_space(self.screen, self.font,
                           "center", (self.screen_y/2) + 300)
        pygame.display.flip()

        display.wait_for_space()

        # Instructions Practice
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.font,
                     "We'll begin with a some practice trials...",
                     "center", "center")
        display.text_space(self.screen, self.font,
                           "center", self.screen_y/2 + 100)
        pygame.display.flip()

        display.wait_for_space()

        # Practice trials
        self.run_block(0, 1, "practice")

        # Instructions Practice End
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.font,
                     "We will now begin the main trials...",
                     100, self.screen_y/2 - 50)
        display.text(self.screen, self.font,
                     "You will not receive feedback after each trial.",
                     100, self.screen_y/2 + 50)
        display.text_space(self.screen, self.font,
                           "center", self.screen_y/2 + 200)
        pygame.display.flip()

        display.wait_for_space()

        # Main task
        for i in range(self.NUM_BLOCKS):
            self.run_block(i, self.NUM_BLOCKS, "main")

        # Create trial number column
        self.all_data["trial"] = range(1, len(self.all_data) + 1)

        # Rearrange the dataframe
        columns = ['trial', 'block', 'congruency', 'cue', 'location',
                   'fixationTime', 'ITI', 'direction',
                   'response', 'correct', 'RT']
        self.all_data = self.all_data[columns]

        # End screen
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.font, "End of task", "center", "center")
        display.text_space(self.screen, self.font,
                           "center", self.screen_y/2 + 100)
        pygame.display.flip()

        display.wait_for_space()

        print "- ANT complete"

        return self.all_data
コード例 #7
0
ファイル: ant.py プロジェクト: sho-87/cognitive-battery
    def display_trial(self, trial_num, data, trial_type):
        # Check for a quit press after stimulus was shown
        for event in pygame.event.get():
            if event.type == KEYDOWN and event.key == K_F12:
                sys.exit(0)

        # Display fixation
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_fixation, "center", "center")
        pygame.display.flip()

        display.wait(data["fixationTime"][trial_num])

        # Display cue
        self.screen.blit(self.background, (0, 0))

        cue_type = data["cue"][trial_num]

        if cue_type == "nocue":
            # Display fixation in the center
            display.image(self.screen, self.img_fixation, "center", "center")
        elif cue_type == "center":
            # Display cue in the center
            display.image(self.screen, self.img_cue, "center", "center")
        elif cue_type == "double":
            # Display fixation in the center
            display.image(self.screen, self.img_fixation, "center", "center")

            # Display cue above and below fixation
            display.image(
                self.screen, self.img_cue, "center",
                self.screen_y/2 - self.fixation_h - self.TARGET_OFFSET)
            display.image(self.screen, self.img_cue,
                          "center", self.screen_y/2 + self.TARGET_OFFSET)
        elif cue_type == "spatial":
            cue_location = data["location"][trial_num]

            # Display fixation in the center
            display.image(self.screen, self.img_fixation, "center", "center")

            # Display cue at target location
            if cue_location == "top":
                display.image(
                    self.screen, self.img_cue, "center",
                    self.screen_y/2 - self.fixation_h - self.TARGET_OFFSET)
            elif cue_location == "bottom":
                display.image(self.screen, self.img_cue, "center",
                              self.screen_y/2 + self.TARGET_OFFSET)

        pygame.display.flip()

        # Display cue for certain duration
        display.wait(self.CUE_DURATION)

        # Prestim interval with fixation
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_fixation, "center", "center")
        pygame.display.flip()

        display.wait(self.PRE_STIM_FIXATION_DURATION)

        # Display flanker target
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_fixation, "center", "center")

        self.display_flanker(data["congruency"][trial_num],
                             data["location"][trial_num],
                             data["direction"][trial_num])
        pygame.display.flip()

        start_time = int(round(time.time() * 1000))

        # Clear the event queue before checking for responses
        pygame.event.clear()
        response = "NA"
        wait_response = True
        while wait_response:
            for event in pygame.event.get():
                if event.type == KEYDOWN and event.key == K_LEFT:
                    response = "left"
                    wait_response = False
                elif event.type == KEYDOWN and event.key == K_RIGHT:
                    response = "right"
                    wait_response = False
                elif event.type == KEYDOWN and event.key == K_F12:
                    sys.exit(0)

            end_time = int(round(time.time() * 1000))

            # If time limit has been reached, consider it a missed trial
            if end_time - start_time >= self.FLANKER_DURATION:
                wait_response = False

        # Store reaction time and response
        rt = int(round(time.time() * 1000)) - start_time
        data.set_value(trial_num, 'RT', rt)
        data.set_value(trial_num, 'response', response)

        correct = 1 if response == data["direction"][trial_num] else 0
        data.set_value(trial_num, 'correct', correct)

        # Display feedback if practice trials
        if trial_type == "practice":
            self.screen.blit(self.background, (0, 0))
            if correct == 1:
                display.text(self.screen, self.font, "correct",
                             "center", "center", (0, 255, 0))
            else:
                display.text(self.screen, self.font, "incorrect",
                             "center", "center", (255, 0, 0))
            pygame.display.flip()

            display.wait(self.FEEDBACK_DURATION)

        # Display fixation during ITI
        self.screen.blit(self.background, (0, 0))
        display.image(self.screen, self.img_fixation, "center", "center")
        pygame.display.flip()

        iti = self.ITI_MAX - rt - data["fixationTime"][trial_num]
        data.set_value(trial_num, 'ITI', iti)

        display.wait(iti)
コード例 #8
0
    def display_trial(self, df, i, r, trial_type):
        # Clear screen
        self.screen.blit(self.background, (0, 0))
        pygame.display.flip()

        # Display number sequence
        self.display_sequence(r['set'])

        # Display probe warning
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.stim_font, "+", "center", "center")
        pygame.display.flip()

        display.wait(self.PROBE_WARN_DURATION)

        # Display blank screen
        display.blank_screen(self.screen, self.background,
                             self.BETWEEN_STIM_DURATION)

        # Display probe
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.stim_font, r['probe'], "center",
                     "center", (0, 0, 255))

        # Display key reminders if practice trials
        if trial_type == "practice":
            display.image(self.screen, self.img_left,
                          450 - self.img_left.get_rect().width / 2,
                          self.screen_y / 2 + 150)

            yes_text = self.font.render("(yes)", 1, (0, 0, 0))
            display.text(self.screen, self.font, yes_text,
                         450 - yes_text.get_rect().width / 2,
                         self.screen_y / 2 + 160)

            display.image(
                self.screen, self.img_right,
                self.screen_x - 450 - self.img_right.get_rect().width / 2,
                self.screen_y / 2 + 150)

            no_text = self.font.render("(no)", 1, (0, 0, 0))
            display.text(self.screen, self.font, no_text,
                         self.screen_x - 450 - no_text.get_rect().width / 2,
                         self.screen_y / 2 + 160)

        pygame.display.flip()

        start_time = int(round(time.time() * 1000))

        # Clear the event queue before checking for responses
        pygame.event.clear()
        wait_response = True
        while wait_response:
            for event in pygame.event.get():
                if event.type == KEYDOWN and event.key == K_LEFT:
                    df.set_value(i, "response", "present")
                    wait_response = False
                elif event.type == KEYDOWN and event.key == K_RIGHT:
                    df.set_value(i, "response", "absent")
                    wait_response = False
                elif event.type == KEYDOWN and event.key == K_F12:
                    sys.exit(0)

            end_time = int(round(time.time() * 1000))

            # If time limit has been reached, consider it a missed trial
            if end_time - start_time >= self.PROBE_DURATION:
                wait_response = False

        # Store RT
        rt = int(round(time.time() * 1000)) - start_time
        df.set_value(i, "RT", rt)

        # Display blank screen
        display.blank_screen(self.screen, self.background,
                             self.BETWEEN_STIM_DURATION)

        # Display feedback
        self.screen.blit(self.background, (0, 0))

        if rt >= self.PROBE_DURATION:
            df.set_value(i, "correct", 0)
            display.text(self.screen, self.font, "too slow", "center",
                         "center", (255, 165, 0))
        else:
            if df["probeType"][i] == df["response"][i]:
                df.set_value(i, "correct", 1)
                display.text(self.screen, self.font, "correct", "center",
                             "center", (0, 255, 0))
            else:
                df.set_value(i, "correct", 0)
                display.text(self.screen, self.font, "incorrect", "center",
                             "center", (255, 0, 0))

        pygame.display.flip()

        display.wait(self.FEEDBACK_DURATION)

        # Display blank screen (ITI)
        display.blank_screen(self.screen, self.background, self.ITI)
コード例 #9
0
ファイル: sternberg.py プロジェクト: sho-87/cognitive-battery
    def display_trial(self, df, i, r, trial_type):
        # Clear screen
        self.screen.blit(self.background, (0, 0))
        pygame.display.flip()

        # Display number sequence
        self.display_sequence(r['set'])

        # Display probe warning
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.stim_font, "+", "center", "center")
        pygame.display.flip()

        display.wait(self.PROBE_WARN_DURATION)

        # Display blank screen
        display.blank_screen(self.screen, self.background,
                             self.BETWEEN_STIM_DURATION)

        # Display probe
        self.screen.blit(self.background, (0, 0))
        display.text(self.screen, self.stim_font, r['probe'],
                     "center", "center", (0, 0, 255))

        # Display key reminders if practice trials
        if trial_type == "practice":
            display.image(self.screen, self.img_left,
                          450 - self.img_left.get_rect().width/2,
                          self.screen_y/2 + 150)

            yes_text = self.font.render("(yes)", 1, (0, 0, 0))
            display.text(self.screen, self.font, yes_text,
                         450 - yes_text.get_rect().width/2,
                         self.screen_y/2 + 160)

            display.image(
                self.screen, self.img_right,
                self.screen_x - 450 - self.img_right.get_rect().width/2,
                self.screen_y/2 + 150)

            no_text = self.font.render("(no)", 1, (0, 0, 0))
            display.text(self.screen, self.font, no_text,
                         self.screen_x - 450 - no_text.get_rect().width/2,
                         self.screen_y/2 + 160)

        pygame.display.flip()

        start_time = int(round(time.time() * 1000))

        # Clear the event queue before checking for responses
        pygame.event.clear()
        wait_response = True
        while wait_response:
            for event in pygame.event.get():
                if event.type == KEYDOWN and event.key == K_LEFT:
                    df.set_value(i, "response", "present")
                    wait_response = False
                elif event.type == KEYDOWN and event.key == K_RIGHT:
                    df.set_value(i, "response", "absent")
                    wait_response = False
                elif event.type == KEYDOWN and event.key == K_F12:
                    sys.exit(0)

            end_time = int(round(time.time() * 1000))

            # If time limit has been reached, consider it a missed trial
            if end_time - start_time >= self.PROBE_DURATION:
                wait_response = False

        # Store RT
        rt = int(round(time.time() * 1000)) - start_time
        df.set_value(i, "RT", rt)

        # Display blank screen
        display.blank_screen(self.screen, self.background,
                             self.BETWEEN_STIM_DURATION)

        # Display feedback
        self.screen.blit(self.background, (0, 0))

        if rt >= self.PROBE_DURATION:
            df.set_value(i, "correct", 0)
            display.text(self.screen, self.font, "too slow",
                         "center", "center", (255, 165, 0))
        else:
            if df["probeType"][i] == df["response"][i]:
                df.set_value(i, "correct", 1)
                display.text(self.screen, self.font, "correct",
                             "center", "center", (0, 255, 0))
            else:
                df.set_value(i, "correct", 0)
                display.text(self.screen, self.font, "incorrect",
                             "center", "center", (255, 0, 0))

        pygame.display.flip()

        display.wait(self.FEEDBACK_DURATION)

        # Display blank screen (ITI)
        display.blank_screen(self.screen, self.background, self.ITI)