def trial(self, stimulus, good_cat): """ :param stimulus: stim.image :param good_cat: category of the stim (int) :return: A list Index 0 = 0 if bad answer, 1 if good answer Index 1 = Reaction time """ t = 0 # Create trial clock and event.Key key_resp = event.BuilderKeyResponse() trial_clock = core.Clock() # Add status to trial components trial_components = [stimulus, key_resp, self.primer] for thisComponent in trial_components: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED trial_clock.reset() continue_routine = True # Trial routine while continue_routine: # Using while method to adjust loop to screen frame rate for more precise EEG trigger t = trial_clock.getTime() if t < self.primer_time and self.primer.status == NOT_STARTED: # Start trial if self.params["EEG"]: self.pport.send_signal(1) self.primer_activation(True) self.primer.status = STARTED elif self.stim_end > t >= self.primer_time: #Stimulus period self.primer_activation(False) if stimulus.status == NOT_STARTED: # If stimulus just appeared key_resp.tStart = t key_resp.status = STARTED # Accept answer from now key_resp.keys = [] key_resp.clock.reset() event.clearEvents() if self.params["EEG"]: # Trigger identification # 20 Category 1 # 21 Category 2 self.pport.send_signal(20 + int(good_cat)) stimulus.setAutoDraw(True) stimulus.status = STARTED elif t >= self.stim_end and stimulus.status == STARTED: # End of stimulus period stimulus.setAutoDraw(False) stimulus.status = STOPPED if key_resp.status == STARTED and t <= self.trial_end: # If still no answer, show answer option self.txt_categorisation_choices.setAutoDraw(True) elif stimulus.status == STOPPED and key_resp.status == STOPPED: # If stimulus is finished and answer, end routine self.txt_categorisation_choices.setAutoDraw(False) continue_routine = False elif t >= self.trial_end: # If no more time self.txt_categorisation_choices.setAutoDraw(False) key_resp.status = STOPPED continue_routine = False if key_resp.status == STARTED: # If expecting a key press these_keys = event.getKeys() if len(these_keys) > 0: # at least one key was pressed if self.params["EEG"]: self.pport.send_signal(30 + int(good_cat)) key_resp.keys = these_keys[-1] # just the last key pressed key_resp.rt = key_resp.clock.getTime() key_resp.status = STOPPED self.win.flip() # Adjust loop to screen frame rate # VF answer, give feedback and send trigger according to category and accuracy # Trigger identification # 40 Category 1 and bad # 41 Category 1 and good # 50 Category 2 and bad # 51 Category 2 and good score = 0 if key_resp.keys == self.params["Key_answer"][0]: if good_cat == 0: score = 1 instruction = visual.TextStim( self.win, text=self.txt_ins["Feedback_good"], pos=(0.0, 0.0), color="green") instruction.draw() else: instruction = visual.TextStim( self.win, text=self.txt_ins["Feedback_bad"], pos=(0.0, 0.0), color="red") instruction.draw() if self.params["EEG"]: self.pport.send_signal(40 + int(score)) elif key_resp.keys == self.params["Key_answer"][1]: if good_cat == 1: score = 1 instruction = visual.TextStim( self.win, text=self.txt_ins["Feedback_good"], pos=(0.0, 0.0), color="green") instruction.draw() else: instruction = visual.TextStim( self.win, text=self.txt_ins["Feedback_bad"], pos=(0.0, 0.0), color="red") instruction.draw() if self.params["EEG"]: self.pport.send_signal(50 + int(score)) elif key_resp.keys == "q" or key_resp.keys == "escape": core.quit() else: if key_resp.rt == 0: write_instruction(self.txt_ins["Wrong_key"], self.txt_ins["Key_to_continue"], self.win, "black") else: key_resp.rt = 0 write_instruction(self.txt_ins["Too_long"], self.txt_ins["Key_to_continue"], self.win, "black") self.win.flip() core.wait(self.feedback_time) return [score, key_resp.rt]
def categorization_routine(self): # Activate saving on BIOSEMI (need to be added in BIOSEMI config) if self.params["EEG"]: self.pport.send_signal(254) # Write instruction and practice if it's block 1 write_instruction(self.txt_ins["Cat_ins1"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["Cat_ins2"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["Cat_ins3"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["Cat_ins4"], self.txt_ins["Key_to_continue"], self.win, "Black") countdown(self.txt_ins["Practice_countdown"], 5, self.win, "Black") self.practice_routine() write_instruction(self.txt_ins["VF_rdy"], self.txt_ins["Key_to_continue"], self.win, "Black") # Start the trials countdown(self.txt_ins["Cat_countdown"], 5, self.win, "Black") for n in range(self.params["N_block"]): if self.params["EEG"]: self.pport.send_signal(10 + n + 1) # Iterate in blocks if n > 0: # Write instruction between blocks write_instruction(self.txt_ins["Cat_between_bloc"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["VF_rdy"], self.txt_ins["Key_to_continue"], self.win, "Black") countdown(self.txt_ins["Cat_countdown"], 5, self.win, "Black") for i in range(self.params["Trial_per_block"]): # Iterate in trials stimulus_category = self.cat_trials_list[ n * self.params["Trial_per_block"] + i][1] stimulus_name = self.cat_trials_list[ n * self.params["Trial_per_block"] + i][2] stimulus = self.cat_trials_list[ n * self.params["Trial_per_block"] + i][0] trial = self.trial(stimulus, stimulus_category) # Add data to this entry self.cat_data.addData("Block", n + 1) self.cat_data.addData("Index", i + 1) self.cat_data.addData("Resultat", trial[0]) self.cat_data.addData("TR", trial[1]) self.cat_data.addData("Stim", stimulus_name) self.cat_data.addData("Cat", stimulus_category) if self.params["Orientation"] == "True": stim_orientation = self.cat_trials_list[ n * self.params["Trial_per_block"] + i][3] self.cat_data.addData("Orientation", stim_orientation) self.cat_data.nextEntry() # Deactivate saving on BIOSEMI (need to be added in BIOSEMI config) if self.params["EEG"]: self.pport.send_signal(255) write_instruction(self.txt_ins["Cat_end"], self.txt_ins["Key_to_continue"], self.win, "Black")
def sj_routine(self, block): """ :param block: Determine which block is it Routine for 1 block of similarity judgement """ # Activate saving on BIOSEMI (need to be added in BIOSEMI config) if self.params["EEG"]: self.pport.send_signal(254) # Write instruction and practice if it's block 1 if block == 1: write_instruction(self.txt_ins["SJ_ins1"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["SJ_ins2"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["SJ_ins3"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["SJ_ins4"], self.txt_ins["Key_to_continue"], self.win, "Black") countdown(self.txt_ins["Practice_countdown"], 5, self.win, "Black") self.practice_routine() write_instruction(self.txt_ins["Practice_end"], self.txt_ins["Key_to_continue"], self.win, "Black") else: write_instruction(self.txt_ins["SJ_ins5"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["SJ_ins6"], self.txt_ins["Key_to_continue"], self.win, "Black") #Start the trials countdown(self.txt_ins["SJ_countdown"], 5, self.win, "Black") for n in range(self.params["SJ_trial"]): #Iterate in trials stim1_cat = self.sj_trials_list[n]["cat_stim1"] stim1_name = self.sj_trials_list[n]["stim1_name"] stim2_name = self.sj_trials_list[n]["stim2_name"] stim1 = self.sj_trials_list[n]["stim1"] stim2 = self.sj_trials_list[n]["stim2"] trial_type = self.sj_trials_list[n]["type"] trial = self.trial([stim1, stim2], trial_type, stim1_cat, block) #Add data to this entry self.sj_data.addData("Block", block) self.sj_data.addData("Index", n + 1) self.sj_data.addData("Score", trial) self.sj_data.addData("Type", trial_type) self.sj_data.addData("Cat_stim1", stim1_cat) if self.params["Orientation"] == "True": stim1_orientation = self.sj_trials_list[n]["ori1"] stim2_orientation = self.sj_trials_list[n]["ori2"] self.sj_data.addData("Stim1_orientation", stim1_orientation) self.sj_data.addData("Stim2_orientation", stim2_orientation) self.sj_data.addData("Stim1", stim1_name) self.sj_data.addData("Stim2", stim2_name) self.sj_data.nextEntry() # Deactivate saving on BIOSEMI (need to be added in BIOSEMI config) if self.params["EEG"]: self.pport.send_signal(255)
if len(params["Cat_folder"]) > 1 : for cat_folder in params["Cat_folder"] : all_names.append(os.listdir(params["Stim_list_folder"] + cat_folder)) else : all_names = os.listdir(params["Stim_list_folder"]) if "SJ_trial" in params : sj_trials = sj_trials(params=params, win=win, exp_info=exp_info, txt_ins=txt_ins, stimulus_list= all_names) cat_trials = CatTrials(win=win, params=params, txt_ins=txt_ins, exp_info=exp_info, stimulus_list= all_names) if "N_deviant" in params : oddball_trials = OddballTrials(params=params, win=win, exp_info=exp_info, txt_ins=txt_ins, stimulus_list=all_names) write_instruction(txt_ins["Intro"], txt_ins["Key_to_continue"], win, "Black") if "SJ_trial" in params: sj_trials.sj_routine(1) if "N_deviant" in params: oddball_trials.oddball_routine(1) cat_trials.categorization_routine() if "SJ_trial" in params: sj_trials.sj_routine(2) if "N_deviant" in params: oddball_trials.oddball_routine(2) write_instruction(txt_ins["Exp_end"], txt_ins["Key_to_continue"], win, "Black") win.close() if params["Trial_per_block"] > 0 : if exp_info["Exp"] == "Fish" : p_info = get_info_from_dlg({txt_ins["Q1"]: txt_ins["A1"],
def oddball_routine(self,block): # Activate saving on BIOSEMI (need to be added in BIOSEMI config) if self.params["EEG"]: self.pport.send_signal(254) for i,trial_structure in enumerate(self.oddball_trials_structure): # Write instruction according to trial number if i == 0 : if block == 1 : write_instruction(self.txt_ins["Oddball_ins1"], self.txt_ins["Key_to_continue"],self.win, "Black") write_instruction(self.txt_ins["Oddball_ins2"], self.txt_ins["Key_to_continue"],self.win, "Black") write_instruction(self.txt_ins["Oddball_ins3"], self.txt_ins["Key_to_continue"], self.win, "Black") else : write_instruction(self.txt_ins["Oddball_ins4"], self.txt_ins["Key_to_continue"], self.win, "Black") write_instruction(self.txt_ins["Oddball_ins5"], self.txt_ins["Key_to_continue"], self.win, "Black") else : write_instruction(self.txt_ins["Oddball_pause1"], self.txt_ins["Key_to_continue"],self.win, "Black") write_instruction(self.txt_ins["Oddball_pause2"], self.txt_ins["Key_to_continue"],self.win, "Black") # VF trial_type trial_type = "Different" if self.stim_trials_list[i][0][1][0] == self.stim_trials_list[i][1][1][0]: trial_type = "Same" rts = self.oddball_trial(trial_structure, self.stim_trials_list[i], trial_type, block) for rt in rts: self.oddball_data.addData("RT", rt) self.oddball_data.addData("Type", trial_type) self.oddball_data.addData("Standard", self.stim_trials_list[i][0][1]) self.oddball_data.addData("Deviant", self.stim_trials_list[i][1][1]) self.oddball_data.addData("Block", block) self.oddball_data.nextEntry() # Deactivate saving on BIOSEMI (need to be added in BIOSEMI config) if self.params["EEG"]: self.pport.send_signal(255)