コード例 #1
0
ファイル: check_exit.py プロジェクト: ociepkam/Go_No-Go
def check_exit(key='f7', part_id='', beh=None, triggers_list=None):
    stop = event.getKeys(keyList=[key])
    if len(stop) > 0:
        save_beh(beh, part_id)
        save_triggers(triggers_list, part_id)
        logging.critical('Experiment finished by user! {} pressed.'.format(key))
        exit(1)
コード例 #2
0
def show_info(win, file_name, text_size, screen_width, insert=''):
    """
    Clear way to show info message into screen.
    :param name: part name
    :param data: beh data
    :param win:
    :param file_name:
    :param screen_width:
    :param text_size:
    :param insert: extra text for read_text_from_file
    :return:
    """
    hello_msg = read_text_from_file(os.path.join(file_name), insert=insert)
    hello_msg = visual.TextStim(win=win,
                                antialias=True,
                                font=u'Arial',
                                text=hello_msg,
                                height=text_size,
                                wrapWidth=screen_width,
                                color=u'black',
                                alignHoriz='center',
                                alignVert='center')
    hello_msg.draw()
    win.flip()
    key = event.waitKeys(keyList=['q', 'return', 'space'])
    if key == ['q']:
        logging.critical('Experiment finished by user! {} pressed.'.format(
            key[0]))
        exit(0)
    win.flip()
コード例 #3
0
def show_info(win, file_name, text_size, screen_width, insert='', show_time=999999):
    """
    Clear way to show info message into screen.
    :param name: part name
    :param data: beh data
    :param win:
    :param file_name:
    :param screen_width:
    :param text_size:
    :param insert: extra text for read_text_from_file
    :return:
    """
    hello_msg = read_text_from_file(os.path.join(file_name), insert=insert)
    hello_msg = visual.TextStim(win=win, antialias=True, font=u'Arial',
                                text=hello_msg, height=text_size,
                                wrapWidth=screen_width, color=u'black',
                                alignHoriz='center', alignVert='center')
    hello_msg.draw()
    timer = clock.Clock()
    win.callOnFlip(timer.reset)
    event.clearEvents()
    win.flip()

    while timer.getTime() < show_time:
        event.clearEvents(eventType='mouse')
        key = event.getKeys()
        if key in [['q'], ['return'], ['space']]:
            if key == ['q']:
                logging.critical('Experiment finished by user! {} pressed.'.format(key[0]))
                exit(0)
            break
    win.flip()
コード例 #4
0
    def mri_trigger(self):
        self.time_of_last_tr = self.clock.getTime()
        self.current_tr += 1
        self.target_trigger_time = self.start_time + (self.current_tr +
                                                      1) * self.tr

        logging.critical('Registered MRI trigger')
コード例 #5
0
    def event(self):
        if self.session.simulate_mri_trigger:
            current_time = self.session.clock.getTime()
            if current_time - self.session.target_trigger_time > 0:
                self.key_event(key=self.session.mri_trigger_key)
                logging.critical('Simulated trigger at %s' % current_time)

        super(MRITrial, self).event()
コード例 #6
0
ファイル: show_info.py プロジェクト: ociepkam/grafy
def show_image(win, file_name, size, key='q'):
    image = visual.ImageStim(win=win, image=os.path.join('images', file_name), interpolate=True, size=size)
    image.draw()
    win.flip()
    clicked = event.waitKeys(keyList=[key, 'return', 'space'])
    if clicked == [key]:
        logging.critical('Experiment finished by user! {} pressed.'.format(key[0]))
        exit(0)
    win.flip()
コード例 #7
0
ファイル: show_info.py プロジェクト: ociepkam/grafy
def show_info(win, file_name, text_size, screen_width, insert='', key='q', color='black'):
    hello_msg = read_text_from_file(os.path.join(file_name), insert=insert)
    hello_msg = visual.TextStim(win=win, antialias=True, font=u'Arial',
                                text=hello_msg, height=text_size,
                                wrapWidth=screen_width, color=color,
                                alignHoriz='center', alignVert='center')
    hello_msg.draw()
    win.flip()
    clicked = event.waitKeys(keyList=[key, 'return', 'space'])
    if clicked == [key]:
        logging.critical('Experiment finished by user! {} pressed.'.format(key[0]))
        exit(0)
    win.flip()
コード例 #8
0
def show_info(win,
              file_name,
              text_size,
              screen_width,
              insert='',
              part_id=None,
              beh=None,
              triggers_list=None):
    """
    Clear way to show info message into screen.
    :param win:
    :param file_name:
    :param screen_width:
    :param text_size:
    :param insert: extra text for read_text_from_file
    :return:
    """
    hello_msg = read_text_from_file(os.path.join('messages', file_name),
                                    insert=insert)
    hello_msg = visual.TextStim(win=win,
                                antialias=True,
                                font=u'Arial',
                                text=hello_msg,
                                height=text_size,
                                wrapWidth=screen_width,
                                color=u'black',
                                alignHoriz='center',
                                alignVert='center')
    hello_msg.draw()
    win.flip()
    key = event.waitKeys(keyList=['f7', 'return', 'space'])
    if key == ['f7']:
        save_beh(beh, part_id)
        save_triggers(triggers_list, part_id)
        logging.critical(
            'Experiment finished by user! {} pressed.'.format(key))
        exit(1)
    win.flip()
コード例 #9
0
    def key_event(self, key):

        if key in ['esc', 'escape', 'q']:
            self.events.append(
                [-99, self.session.clock.getTime() - self.start_time])

            self.session.logging.info('run canceled by user')
            self.session.stop()
            self.stop()

        if key == 'p':
            self.session.pausing = True

        if (key == self.parameters['left_key']) and ('correct'
                                                     not in self.parameters):
            self.parameters['rt'] = self.session.clock.getTime(
            ) - self.start_time
            logging.critical('Left key press')
            if self.parameters['direction'] == 180:
                self.parameters['correct'] = True
            else:
                self.parameters['correct'] = False

            self.parameters['rt'] = self.session.clock.getTime(
            ) - self.start_time

        if (key == self.parameters['right_key']) and ('correct'
                                                      not in self.parameters):
            self.parameters['rt'] = self.session.clock.getTime(
            ) - self.start_time
            logging.critical('Right key press')
            if self.parameters['direction'] == 0:
                self.parameters['correct'] = True
            else:
                self.parameters['correct'] = False

        super(RDMTrial, self).key_event(key)
コード例 #10
0
ファイル: main.py プロジェクト: ociepkam/Stroop_linear
def check_exit(key='f7'):
    stop = event.getKeys(keyList=[key])
    if len(stop) > 0:
        logging.critical(
            'Experiment finished by user! {} pressed.'.format(key))
        exit(1)
コード例 #11
0
ファイル: main.py プロジェクト: ociepkam/Stroop_linear
def abort_with_error(err):
    logging.critical(err)
    raise Exception(err)
コード例 #12
0
ファイル: main.py プロジェクト: ociepkam/TRANS_MOD
def run_trial(win, k, n, ans_type, config, feedback, feedb):
    response_clock = core.Clock()
    trial = Trial(k, n, ans_type)
    trial.prepare_to_draw(win, config)

    idx_info = visual.TextStim(win,
                               color='black',
                               pos=(500, 400),
                               height=50,
                               text=i)
    acc = None
    corr = [None, None]
    rt = []
    trial.draw(True)
    idx_info.setAutoDraw(True)
    win.callOnFlip(response_clock.reset)
    event.clearEvents()
    win.flip()

    clicked = []
    while response_clock.getTime() < config["trial_time"] and len(clicked) < 2:
        for idx, ans in enumerate(trial.answers):
            if mouse.isPressedIn(ans["frame"]) and ans["frame"].opacity == 0:
                rt.append(response_clock.getTime())
                ans["frame"].opacity = 1
                clicked.append(idx)
                win.flip()
                time.sleep(config["click_show_time"])
                ans["frame"].opacity = 0
                win.flip()
        if config["trial_time"] - response_clock.getTime(
        ) < config['SHOW_CLOCK']:
            clock_image.setAutoDraw(True)
        check_exit(config["exit_key"])
        win.flip()
    if len(clicked):
        corr[0] = trial.answers[clicked[0]]["corr"]
    if len(set(clicked)) == 2:
        corr[1] = trial.answers[clicked[1]]["corr"]
        acc = 1 if corr[0] and corr[1] else 0

    if feedback:
        for ans in trial.answers:
            if ans["corr"]:
                ans["frame"].lineColor = config["frame_answer_color"]
                ans["frame"].opacity = 1
        if acc and len(set(clicked)) == 2:
            feedb["pos"].setAutoDraw(True)
        elif len(clicked) == 2:
            feedb["neg"].setAutoDraw(True)
        else:
            feedb["no"].setAutoDraw(True)
        win.flip()
        if config["feedback_time"] > 0:
            time.sleep(config["feedback_time"])
        elif config["feedback_time"] == -1:
            press_space_msg.setAutoDraw(True)
            win.flip()
            key = event.waitKeys(keyList=['f7', 'space'])
            if key == ['f7']:
                logging.critical(
                    'Experiment finished by user! {} pressed.'.format(key[0]))
                exit(0)
        # else:
        #     key = event.waitKeys(["space", config["exit_key"]])
        #     if key == config["exit_key"]:
        #         logging.critical('Experiment finished by user! {} pressed.'.format(key))
        #         exit(1)
    for _, v in feedb.items():
        v.setAutoDraw(False)
    trial.draw(False)
    idx_info.setAutoDraw(False)
    clock_image.setAutoDraw(False)
    press_space_msg.setAutoDraw(False)
    win.flip()
    time.sleep(config["wait_time"])
    rt += [None, None]
    return corr[0], corr[1], acc, rt[0], rt[1]
コード例 #13
0
ファイル: main.py プロジェクト: ociepkam/TRANS_MOD
                                                feedb)

        RESULTS.append(
            [i, "train", k, n, ans_type, corr1, corr2, acc, rt1, rt2])
        i += 1
        mean_acc += 1 if acc else 0
    if i > 1:
        mean_acc /= (i - 1)
    else:
        break
    if mean_acc < config["min_training_acc"] and training_nr == 5:
        show_info(win,
                  join('.', 'messages', "end.txt"),
                  text_size=config['TEXT_SIZE'],
                  screen_width=SCREEN_RES[0])
        logging.critical('Training not completed')
        exit(1)
    if mean_acc < config["min_training_acc"]:
        show_info(win,
                  join('.', 'messages', "training_info.txt"),
                  text_size=config['TEXT_SIZE'],
                  screen_width=SCREEN_RES[0])

# EXPERIMENT
show_info(win,
          join('.', 'messages', "instruction2.txt"),
          text_size=config['TEXT_SIZE'],
          screen_width=SCREEN_RES[0],
          key=config["exit_key"])

i = 1
コード例 #14
0
def run_trial(n, feedback=False):
    # Prepare trial
    m = Matrix(n=n, possible_answers=ALL_LINES)
    m.fill_matrix(distractors=config['DISTRACTORS'])
    matrix = TrialMatrix(matrix=m, position=0, window=window, viz_offset=config['VIZ_OFFSET'],
                         text_size=config['TEXT_SIZE'])
    idx_info = visual.TextStim(window, color='black', pos=(500, 400), height=50,
                               text=i)
    stim_time = config['CONST_TIME'] + m.n * config['LEVEL_TIME']
    acc = None
    rt = -1
    window.callOnFlip(response_clock.reset)
    event.clearEvents()

    # draw trial
    matrix.set_auto_draw(True)
    idx_info.setAutoDraw(True)
    frames = create_items_frames(matrix.stimulus_matrix)

    for frame in frames:
        frame.setAutoDraw(True)

    window.flip()

    # run trial
    clicked = []
    while response_clock.getTime() < stim_time and len(clicked) < 2:

        for idx, frame in enumerate(frames):
            if mouse.isPressedIn(frame) and frame.opacity == 0:
                frame.opacity = 1
                clicked.append(idx)
        if stim_time - response_clock.getTime() < config['SHOW_CLOCK']:
            clock_image.draw()
        check_exit()
        window.flip()
    rt = response_clock.getTime()
    time.sleep(config["wait_after_answer"])

    # check answer
    if m.answer_line_type == "column":
        # good_answer = [m.answer_line_number, m.answer_line_number + n*n - n]  # have to click first and last
        good_answer = list(range(m.answer_line_number, m.answer_line_number + n * n, n))  # any two elements in line

    elif m.answer_line_type == "row":
        # good_answer = [m.answer_line_number * n, m.answer_line_number * n + n - 1]  # have to click first and last
        good_answer = list(range(m.answer_line_number * n, m.answer_line_number * n + n))  # any two elements in line
    else:
        raise Exception("Wrong answer type")

    if len(clicked) == 2:
        acc = 1 if clicked[0] in good_answer and clicked[1] in good_answer else 0

    # draw feedback
    if feedback:
        answer_frame = create_answer_frame(m.answer_line_type, m.answer_line_number, n)
        answer_frame.setAutoDraw(True)
        if acc == 1:
            feedb_msg = pos_feedb
        elif acc == 0:
            feedb_msg = neg_feedb
        else:
            feedb_msg = no_feedb
        feedb_msg.setAutoDraw(True)
        window.flip()

        if config["feedback_time"] > 0:
            time.sleep(config["feedback_time"])
        elif config["feedback_time"] == -1:
            press_space_msg.setAutoDraw(True)
            window.flip()
            key = event.waitKeys(keyList=['f7', 'space'])
            if key == ['f7']:
                logging.critical('Experiment finished by user! {} pressed.'.format(key[0]))
                exit(0)

        feedb_msg.setAutoDraw(False)
        answer_frame.setAutoDraw(False)
        press_space_msg.setAutoDraw(False)

    # cleaning
    for frame in frames:
        frame.setAutoDraw(False)
    matrix.set_auto_draw(False)
    idx_info.setAutoDraw(False)
    window.flip()

    time.sleep(config['JITTER_TIME'])

    return acc, rt, stim_time, m.n, m.answer_line_type
コード例 #15
0
ファイル: check_exit.py プロジェクト: ociepkam/SST
def check_exit(key='f7'):
    stop = event.getKeys(keyList=[key])
    if len(stop) > 0:
        logging.critical('Experiment finished by user! {} pressed.'.format(key))
        exit(1)