Beispiel #1
0
rewards[0] += 1
n_trials = len(rewards)

#create the dataframe
data = pd.DataFrame([])

#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')
    
beginning_transfer_block_message = TextStim(win=mywin, text="A block of trials will start now. Here, you will no longer receive feedback.", color=text_beginning_block, height=text_height)
messages_beginning = [beginning_learning_block_message, beginning_transfer_block_message]

end_transfer_message = TextStim(win=mywin, color=text_beginning_block, height=text_height)

#create the dataframe
data = pd.DataFrame([])

#draw the stimuli
trial_routine = Routine(window=mywin, frames_per_second=frames_per_second, escape_key=escape_key)

for bl in range(n_blocks):
    block = blocks[bl]

    trial_routine.wait_for_time_limit(
            components=[messages_beginning[bl]], 
            time_seconds=message_beginning_duration, 
            label='message_beginning')

    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
                        frames_per_second=frames_per_second,
                        escape_key=escape_key)

for t in range(n_trials):
    # put here things that change every trial
    left_feedback.text = '%s' % stimuli.loc[t, 'left_feedback']
    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'],