def execute_trial_2(block_nb): """Function which runs a block. For each trial, it presents the morph, presents the response window, wait for the right or left answer and record them with the corresponding response time. One trial out of 4, it asks for confidence rating.""" count = 0 # confidence rating 1 trial out of 4 for trial in block_nb.trials: expyriment.stimuli.BlankScreen(colour=BLACK).present() exp.clock.wait(time_waiting) trial.stimuli[0].present() # display the morph exp.clock.wait(time_morph) expyriment.stimuli.BlankScreen(colour=BLACK).present() # black screen exp.clock.wait(time_waiting) response_window.present() #response screen #Wait for an answer and highlight the answer key, rt = exp.keyboard.wait([expyriment.misc.constants.K_LEFT, expyriment.misc.constants.K_RIGHT]) if key == 275 :#pressing right arrow face_right.present() exp.clock.wait(time_waiting) elif key == 276:#pressing left arrow house_left.present() exp.clock.wait(time_waiting) count+=1 if count == 4 : confidence_score = rate_confidence(exp, time_waiting) count = 0 exp.data.add([block_nb.name, trial.id, trial.get_factor('name'), key, rt, confidence_score]) else : exp.data.add([block_nb.name, trial.id, trial.get_factor('name'), key, rt])
def execute_trial_5(block_nb, shuffle=True, param_1=False, param_2=False): """Function which runs blocks. For each trial, it presents the tone, the morph and the response window and save the block name, the trial ID and name, the tone name, the response key and response time. Block is divided into three parts : first half where the tone is predictive of the morph, second half divided into a part where the tone is oppositely predictive of the morph and a part where the tone is unpredictive. Each part calls define_tones() to set lists of tones for houses and faces, then associate_morph_tone() to choose randomly between a pur or 80% tone, to play it and present the morph. 3 morphs are presented with the response window and the confidence scale is presented for the 4th morph. By default, whether the 2nd part is oppositely predictive and 3rd is unpredictive or whether it is the opposite is randomised for each block. It is possible to set block as : predictive-opposite-unpredictive with param_1 = True, (shuffle=False) predictive-unpredictive-opposite with param_2 = True, (shuffle=False) """ # Define the parameters that will be apply in the 3 parts of the block # to define tones as predictive, oppositely predictive or unpredictive param_1 = [{ 'opposite': False, 'unpredictive': False }, { 'opposite': True, 'unpredictive': False }, { 'opposite': False, 'unpredictive': True }] param_2 = [{ 'opposite': False, 'unpredictive': False }, { 'opposite': False, 'unpredictive': True }, { 'opposite': True, 'unpredictive': False }] if shuffle == True: param = random.choice([param_1, param_2]) elif param_1 == True: param = param_1 elif param_2 == True: param = param_2 #### Run the 3 parts count = 0 # confidence rating 1 trial out of 4 #First part : predictive tones for trial in block_nb.trials[:int(nb_of_trials / 2)]: #Select tones associated with houses and faces houses_tones, faces_tones = define_tones(A_high, A_80_high, A_low, A_80_low, *param[0].values()) # Play the tone associated to the morph with time waiting before and # after tone image_noise, tone_name = associate_morph_tone(exp, trial, houses_tones, faces_tones, time_waiting) # display the morph trial.stimuli[0].present() exp.clock.wait(time_morph) expyriment.stimuli.BlankScreen(colour=BLACK).present() # black screen exp.clock.wait(time_waiting) count += 1 key, rt = select_response(exp, time_waiting, response_window, face_right, house_left) exp.data.add([ block_nb.name, param[0], trial.id, trial.get_factor('name'), tone_name, key, rt ]) if count == 4: confidence_score = rate_confidence(exp, time_waiting) count = 0 exp.data.add([ block_nb.name, param[0], trial.id, trial.get_factor('name'), tone_name, key, rt, confidence_score ]) # 2nd part randomly opposite or unpredictive by default for trial in block_nb.trials[int(nb_of_trials / 2):int(3 / 4 * nb_of_trials)]: #Select tones associated with houses and faces houses_tones, faces_tones = define_tones(A_high, A_80_high, A_low, A_80_low, *param[1].values()) # Play the tone associated to the morph with time waiting before and # after tone image_noise, tone_name = associate_morph_tone(exp, trial, houses_tones, faces_tones, time_waiting) # display the morph trial.stimuli[0].present() exp.clock.wait(time_morph) expyriment.stimuli.BlankScreen(colour=BLACK).present() exp.clock.wait(time_waiting) count += 1 key, rt = select_response(exp, time_waiting, response_window, face_right, house_left) exp.data.add([ block_nb.name, param[1], trial.id, trial.get_factor('name'), tone_name, key, rt ]) if count == 4: confidence_score = rate_confidence(exp, time_waiting) count = 0 exp.data.add([ block_nb.name, param[1], trial.id, trial.get_factor('name'), tone_name, key, rt, confidence_score ]) # 3rd part randomly opposite or unpredictive by default for trial in block_nb.trials[int(3 / 4 * nb_of_trials):]: #Select tones associated with houses and faces houses_tones, faces_tones = define_tones(A_high, A_80_high, A_low, A_80_low, *param[2].values()) # Play the tone associated to the morph with time waiting before and # after tone image_noise, tone_name = associate_morph_tone(exp, trial, houses_tones, faces_tones, time_waiting) # display the morph trial.stimuli[0].present() exp.clock.wait(time_morph) expyriment.stimuli.BlankScreen(colour=BLACK).present() exp.clock.wait(time_waiting) count += 1 key, rt = select_response(exp, time_waiting, response_window, face_right, house_left) exp.data.add([ block_nb.name, param[2], trial.id, trial.get_factor('name'), tone_name, key, rt ]) if count == 4: confidence_score = rate_confidence(exp, time_waiting) count = 0 exp.data.add([ block_nb.name, param[2], trial.id, trial.get_factor('name'), tone_name, key, rt, confidence_score ])
def execute_trial_4(block_nb, shuffle=True, param_1=False, param_2=False): """Function which runs blocks. For each trial, it presents the tone, the morph and the response window and save the block name, the trial ID and name, the tone name, the response key and response time. Each part calls define_tones() to set lists of tones for houses and faces, then associate_morph_tone() to choose randomly between a pur or 80% tone, to play it and present the morph. 3 morphs are presented and the response window is presented for the 4th morph with the confidence rate. The association between tones and morphs is : - high tones predict houses and low tones faces with param_1 being True - high tones predict faces and low tones houses with param_2 being True - the association is random between these two possibilities by default, with shuffle being True""" # Define the parameters that will be apply in the block # to define tones as predictive, oppositely predictive or unpredictive param_1 = {'opposite': False, 'unpredictive': False} param_2 = {'opposite': True, 'unpredictive': False} if shuffle == True: param = random.choice([param_1, param_2]) elif param_1 == True: param = param_1 elif param_2 == True: param = param_2 count = 0 # confidence rating 1 trial out of 4 for trial in block_nb.trials: #Select tones associated with houses and faces houses_tones, faces_tones = define_tones(A_high, A_80_high, A_low, A_80_low, *param.values()) # Play the tone associated to the morph with time waiting before and # after tone image_noise, tone_name = associate_morph_tone(exp, trial, houses_tones, faces_tones, time_waiting) # display the morph trial.stimuli[0].present() exp.clock.wait(time_morph) count += 1 response_window.present() #response screen #Wait for an answer and highlight the answer key, rt = exp.keyboard.wait([ expyriment.misc.constants.K_LEFT, expyriment.misc.constants.K_RIGHT ]) if key == 275: #key of pressing right button face_right.present() exp.clock.wait(time_waiting) elif key == 276: #key of pressing leftt button house_left.present() exp.clock.wait(time_waiting) if count == 4: confidence_score = rate_confidence(exp, time_waiting) count = 0 exp.data.add([ block_nb.name, param, trial.id, trial.get_factor('name'), key, rt, confidence_score ]) else: exp.data.add([ block_nb.name, param, trial.id, trial.get_factor('name'), key, rt ])