for t in range(n_trials):
        # put here things that change at the beginning of every trial
        image_trial = 'patch{}.png'.format(block['image_number'][t])
        correct_resp_trial = block['correct_response'][t]
        patch_image.image = os.path.join(directory_stimuli, image_trial)

        # first event
        trial_routine.wait_for_time_limit(
            components=[], 
            time_seconds=fixation_duration, 
            label='fixation_cross')

        # second event
        key, rt = trial_routine.wait_for_keys_or_time_limit(
            components=[patch_image],
            time_seconds=choice_timeout,
            valid_keys=choice_keys,
            label='patch_choice')
        
        # third event
        if rt >= choice_timeout: # if no response was given (key == np.nan is also ok)
            accuracy_trial = np.nan
            message = too_slow_message
        elif key == correct_resp_trial: # if the correct response was given
            accuracy_trial = 1
            message = correct_message
        else: # if the incorrect response was given
            accuracy_trial = 0
            message = incorrect_message
        
        if bl == 0: # only give a message in the learning block
    right_feedback.text = '%s' % stimuli.loc[t, 'right_feedback']

    left_picture.image = os.path.join(os.getcwd(), 'stimuli', 'example_4',
                                      stimuli.loc[t, 'left_image'])
    right_picture.image = os.path.join(os.getcwd(), 'stimuli', 'example_4',
                                       stimuli.loc[t, 'right_image'])

    # first event
    trial_routine.wait_for_time_limit(components=[fixation_cross],
                                      time_seconds=fixation_duration,
                                      label='fixation_cross')

    # second event
    key, rt = trial_routine.wait_for_keys_or_time_limit(
        components=[left_picture, right_picture],
        valid_keys=choice_keys,
        time_seconds=choice_time_limit,
        label='gamble_choice')
    data = data.append(
        {
            'rt': rt,
            'choice': key,
            'trial': t,
            'f_right': stimuli.loc[t, 'right_feedback'],
            'f_left': stimuli.loc[t, 'left_feedback'],
            'i_right': stimuli.loc[t, 'right_image'],
            'i_left': stimuli.loc[t, 'left_image'],
            'trial_type': stimuli.loc[t, 'trial_type'],
        },
        ignore_index=True)  # record the responses
Exemple #3
0
#draw the stimuli
trial_routine = Routine(window=mywin, frames_per_second=frames_per_second, escape_key=escape_key)

for t in range(n_trials):
    # put here things that change every trial
    changing_gamble.text = 'a sure gain of  CHF %s' % rewards[t]

    # first event
    trial_routine.wait_for_time_limit(
        components=[fixation_cross], 
        time_seconds=fixation_duration, 
        label='fixation_cross')

    # second event
    key, rt = trial_routine.wait_for_keys_or_time_limit(
        components=[fixed_gamble, changing_gamble], 
        valid_keys=choice_keys, 
        time_seconds=choice_time_limit, 
        label='gamble_choice')
    data = data.append({'rt':rt, 'choice': key, 'trial': t, 'reward': rewards[t]}, ignore_index=True) # record the responses

    #save data to file
    for label in expInfo.keys():
        data[label] = expInfo[label]
    data.to_csv(fileName + '.csv')
    
#cleanup
mywin.close()
core.quit()
                        escape_key=escape_key)

for t in range(n_trials):
    # put here things that change every trial
    A_feedback.text = '%s' % A_feedback_trials[t]
    B_feedback.text = '%s' % B_feedback_trials[t]

    # first event
    trial_routine.wait_for_time_limit(components=[fixation_cross],
                                      time_seconds=fixation_duration,
                                      label='fixation_cross')

    # second event
    key, rt = trial_routine.wait_for_keys_or_time_limit(
        components=[A_picture, B_picture],
        valid_keys=choice_keys,
        time_seconds=choice_time_limit,
        label='choice')
    data = data.append(
        {
            'rt': rt,
            'choice': key,
            'trial': t,
            'f_A': A_feedback_trials[t],
            'f_B': B_feedback_trials[t]
        },
        ignore_index=True)  # record the responses

    if key == 'q':
        # third event
        trial_routine.wait_for_time_limit(components=[B_feedback],