def mount_design(self): """ Creates a list of expyriment.design.Block objects, creates trials and loads the experimental stim according to the class parameters Returns ------- exp_design: list of expyriment.design.Block objects list containing the blocks, trials and stimuli ready to run """ block_list = [design.Block(name='run%d' % block + 1 for block in range(self.n_block))] run_list = [open(filename) for filename in sorted(os.listdir(self.stim_list))] for block in range(self.n_block): for line in run_list[block].readlines(): trial = design.Trial() stim = stimuli.TextLine("+") trial.add_stimulus(stim) block_list[block].add_trial(trial) self.exp.add_block(block_list[block])
def prepare_trial(self, block): trial = design.Trial() # TODO: practice = e['Practice'] if 'Practice' in e else False labels = self.labels[block.get_factor('target_titles')][:block.get_factor('num_targets')] positions = TrailMaking.make_random_positions( self.exp.screen.window_size, self.radius, block.get_factor('num_targets'), self.exp.config.getfloat('DESIGN', 'min_distance_of_targets') * self.radius, self.exp.config.getfloat('DESIGN', 'attempts_before_reducing_min_distance')) for lab, pos in zip(labels, positions): stim = stimuli.Circle(radius=self.radius, position=pos, colour=self.colour_target, anti_aliasing=self.antialiasing) label = stimuli.TextBox(lab, (self.radius*2, self.radius*2), text_size=int(self.stimulus_relative_text_size * self.radius), position=[pos[0], pos[1] - self.stimulus_text_correction_y * self.radius], text_justification=1, text_colour=self.colour_target_label, text_font=self.target_font) trial.add_stimulus(stim) trial.add_stimulus(label) return(trial)
def startTrial(NUMBER, OPERATOR): #fixcross.preload() exp = design.Experiment("MATH") control.initialize(exp) control.start() fixcross = stimuli.FixCross() txt_input = io.TextInput("= ") stimuli.TextScreen("MATH GAME", "STARTING in 10 secs", heading_size=40, text_size=60).present() exp.clock.wait(2000) #stim -1 fixcross.preload() fixcross.present() exp.clock.wait(10000) b = design.Block() for i in range(0, 10): #FOR 10 TRIALS b.clear_trials() b = design.Block() print(i) tr = atl.arithmetictriall1(NUMBER, OPERATOR) print(tr) for trel in tr[0]: t = design.Trial() s = stimuli.TextLine(text=str(trel), text_size=120, text_colour=misc.constants.C_GREEN) t.add_stimulus(s) b.add_trial(t) #print(b.trials) exp.add_block(b) #START TEST: ONSCREEN for b in exp.blocks: fixcross.present() exp.clock.wait(100) for t in b.trials: t.stimuli[0].present() exp.clock.wait(1000) print(b) exp.clock.reset_stopwatch() answer = txt_input.get() try: answer = int(answer) if answer == tr[1]: print("Correct") else: print("incorrect") except: print("incorrect")
def create_trial(Stimulus, Type, Filenumber): trial = design.Trial() trial.set_factor("Stimulus", Stimulus) trial.set_factor("Type", Type) trial.set_factor('Filenumber', int(Filenumber)) # must write "int" because Filenumber = numpy.float64 due to pandas when 'pandas.read_csv' (wouldn't happen with csv but then would have to generate headers) Image_Stimulus = 'Stimuli_Resize/{} {} {}.jpg'.format( Stimulus, Type, Filenumber ) # each {} is filed by a factor in the presented format () order trial.add_stimulus(stimuli.Picture(Image_Stimulus)) return trial
def prepare_trial(self, key): trial = design.Trial() for key_pos in key: trial.add_stimulus( stimuli.TextLine( key_pos, position=self.stimulus_offset, text_colour=self.stimulus_colour, text_size=self.stimulus_text_size)) trial.set_factor('sequence', key) trial.set_factor('sequence_length', len(key)) return(trial)
def trial_generator(task, N): if task[0] == "mixed_task": N = N // 2 b = design.Block() b.set_factor("task_type", task[0]) for specific_task in task[1]: for my_trial in specific_task: t = design.Trial() t.set_factor("shape", my_trial[0]) t.set_factor("filling", my_trial[1]) s = stimuli.Picture(my_trial[2]) t.add_stimulus(s) b.add_trial(t, copies=N) b.shuffle_trials() return b
def createBlock(COLORS, blockname, exp): # i/p list 'COLORS' and RETURNS a stimuli block 'b' #for level in ["LEVEL 1"]:#,"LEVEL 2"]: #print(level) b = design.Block(name=blockname) b.set_factor("level", blockname) #blockname as level for color in COLORS: t = design.Trial() t.set_factor("COLOR", color[0]) #print(type(color[1])) #print(color[0]) s = stimuli.Rectangle([200, 200], position=[0, 0], colour=color[1]) t.add_stimulus(s) b.add_trial(t, copies=1) #b.shuffle_trials() #never use this line #print(b.trials) exp.add_block(b) return b # b IS AN EXPERIMENT TRIAL <INPUT LIST 'COLORS' is coverted to Experiment object>
def prepare_trial(self, block, item, id): trial = design.Trial() if id: trial._id = id bx = block.get_factor('num_boxes')**(0.5) sz = self.canvas_size / bx ctr = self.canvas_size / 2 for k in item: if k == 'C': trial.set_factor(k, self.exp._invert_colour(item[k])) else: trial.set_factor(k, item[k]) s = stimuli.Rectangle([sz, sz], position=[(item['P'] % bx + 0.5) * sz - ctr, (item['P'] // bx + 0.5) * sz - ctr], colour=item['C']) trial.add_stimulus(s) return (trial)
def design_experiment(exp, positions, colors, pairings): """Designs a Simon Task experiment.""" for pair_name, pairing in pairings.items(): b = design.Block() b.set_factor("pairing", pair_name) for pos_name, position in positions.items(): for color_name, color in colors.items(): t = design.Trial() t.set_factor("position", pos_name) t.set_factor("color", color_name) s = stimuli.Rectangle((50, 50), position=position, colour=color) t.add_stimulus(s) b.add_trial(t, copies=2) b.shuffle_trials() exp.add_block(b) return exp
control.set_develop_mode(False) control.defaults.window_mode = True control.defaults.window_size = [800, 600] control.defaults.initialize_delay = 0 exp = design.Experiment(name="My Experiment") control.initialize(exp) conditions = load_df("../bws_study.csv").dropna().groupby("Condition") print() #[data for nr, data in conditions] for nr, data in conditions: block = design.Block(name="Condition" + str(int(nr))) block.set_factor("Condition", nr) for nr, sents in data.iterrows(): t = design.Trial() t.set_factor("ItemNum", sents["Item"]) for sent in ["S1", "S2", "S3", "S4", "S5", "S6", "S7"]: s = stimuli.TextLine(text=sents[sent], text_size=20) t.add_stimulus(s) block.add_trial(t) exp.add_block(block) exp.add_bws_factor("FallsWennCondition", ["Wenn-Condition", "Falls-Condition"]) exp.add_bws_factor("GabGabCondition", ["GabGab-Condition", "GabnichtGab-Condition"]) print() #exp control.start() names_to_ids = {block.name: block.id for block in exp.blocks} if exp.get_permuted_bws_factor_condition("FallsWennCondition") == "Wenn-Condition":
key, rt = exp_1.keyboard.wait(keys=[MALE_SEX_KEY, FEMALE_SEX_KEY]) if key == MALE_SEX_KEY: sex = 'Male' elif key == FEMALE_SEX_KEY: sex = 'Female' return (sex) STIM_DIR = 'Stimuli/' #I decided not to implement a loop for these three blocks, since I would need to use a dictionary to create variable names from strings. The popular opinion is that it is not advisable pure_shape_block = design.Block() for shape in ['diamond', 'square']: for number in [2, 3]: trial = design.Trial() trial.set_factor('block', 'pure_shape') trial.set_factor('task', 'shape') trial.set_factor('shape', shape) trial.set_factor('number_of_circles', number) pngname = os.path.join(STIM_DIR, 'shape_{}_{}_circles.png'.format(shape, number)) trial.add_stimulus(stimuli.Picture(pngname)) pure_shape_block.add_trial(trial) pure_shape_block.shuffle_trials() pure_filling_block = design.Block() for shape in ['diamond', 'square']: for number in [2, 3]: trial = design.Trial() trial.set_factor('block', 'pure_filling')
from expyriment import design, control, stimuli control.defaults.window_mode = True control.defaults.window_size = [800, 600] design.defaults.experiment_background_colour = (230, 230, 70) exp = design.Experiment(name="Cool Experiment") control.initialize(exp) block_one = design.Block("Our only block") tmp_trial = design.Trial() cross = stimuli.FixCross(colour=(0, 0, 0)) cross.preload() tmp_trial.add_stimulus(cross) block_one.add_trial(tmp_trial) exp.add_block(block_one) control.start() for b in exp.blocks: for t in b.trials: t.stimuli[0].present() exp.keyboard.wait() control.end()
def prepare_trial(self, block): trial = design.Trial() return (trial)
""" import random from expyriment import design, control, stimuli NTRIALS = 20 ITI = 1000 # inter trial interval MAX_RESPONSE_TIME = 2000 AUDIO_STIMULUS = 'click.wav' exp = design.Experiment(name="AudioVisual Detection") control.initialize(exp) blankscreen = stimuli.BlankScreen() visual_trial = design.Trial() visual_trial.add_stimulus(stimuli.FixCross(size=(50, 50), line_width=4)) audio_trial = design.Trial() audio_trial.add_stimulus(stimuli.Audio(AUDIO_STIMULUS)) visual_block = design.Block("visual") for i in range(NTRIALS): visual_block.add_trial(visual_trial) exp.add_block(visual_block) audio_block = design.Block("audio") for i in range(NTRIALS): audio_block.add_trial(audio_trial) exp.add_block(audio_block)
def startTrial(NUMBER,OPERATOR): w, h = 10, 3; Matrix = [[0 for x in range(w)] for y in range(h)] # Define 2D array #fixcross.preload() exp = design.Experiment("MATH") control.initialize(exp) control.start() fixcross = stimuli.FixCross(size=(40,40),colour=misc.constants.C_WHITE,position=(0,200)) txt_input=io.TextInput("= ") inputNAME=io.TextInput("ENTER NAME: ") VolunteerNAME = inputNAME.get() # First input by volunteer Matrix[2][1]=VolunteerNAME stimuli.TextScreen("MATH GAME -LEVEL 1",". . . RELAX . . .\n\n\n\n\n\n+\n\nlook at fixcross\n\n\nSTARTS IN 10 SECONDS",heading_size=40,text_size=20,heading_colour=misc.constants.C_WHITE,text_colour=misc.constants.C_WHITE).present() exp.clock.wait(10000) #stim -1 REMOVE # ON COMMISSION fixcross.preload() fixcross.present() exp.clock.wait(10000) # REMOVE # ON COMMISSION b = design.Block() for i in range (0,10): # cOMMISSION : 3->10 #FOR 10 TRIALS b.clear_trials() b = design.Block() print(i) tr=atl.arithmetictriall1(NUMBER,OPERATOR) print(tr) for trel in tr[0]: t=design.Trial() s = stimuli.TextLine(text=str(trel),text_size=200,text_colour=misc.constants.C_GREEN) t.add_stimulus(s) b.add_trial(t) #print(b.trials) exp.add_block(b) #START TEST: ONSCREEN #tx0=time.time() fixcross.present() exp.clock.wait(1000) #tx1=time.time()-tx0 #print("ttt %d"%tx1) #xcount = 1 #debug fixcross timings (previously increasing time b=1) for b in exp.blocks: for t in b.trials: t.stimuli[0].present() exp.clock.wait(800) #>1000 #xcount=0 print(b) #exp.clock.reset_stopwatch() t0=time.time() answer = txt_input.get() responsetime=time.time()-t0 #response time try: answer=int(answer) if answer==tr[1]: print("Correct") Matrix[0][i]=5 Matrix[1][i]=responsetime else: print("incorrect") Matrix[0][i]=-5 Matrix[1][i]=responsetime except: print("incorrect") Matrix[0][i]=-5 Matrix[1][i]=responsetime fixcross.present() exp.clock.wait(5000) control.end() #print(Matrix) return Matrix
blankscreen = stimuli.BlankScreen() instructions = stimuli.TextScreen( "Instructions", f"""From time to time, a Circle will appear at the center of screen. Your task is to press the space bar key as quickly as possible when you see it (We measure your reaction-time). There will be {3*NTRIALS} trials in total. Press the space bar to start.""") ###### 1.A --> Definition of the only two possible trials made up of two stimuli "Blue/Red" #Stimulus red visual_trial_red = design.Trial() visual_trial_red.add_stimulus(stimuli.Circle(radius=100, colour=(255, 0, 0))) #Stimulus blue visual_trial_blue = design.Trial() visual_trial_blue.add_stimulus(stimuli.Circle(radius=100, colour=(0, 0, 255))) ###### 1.B --> Definition of Associated Blocks "Blue/Red" visual_block_red = design.Block("red") # Buidlding red block with 5 stimuli for i in range(NTRIALS): visual_block_red.add_trial(visual_trial_red)