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")
Exemple #2
0
    def _start(self):
        self._session = None
        if self.config.getboolean('GENERAL', 'log_session'):
            subject, session = _prompt_participant_information()
            self._subject = subject
            self._session = session
            self._filename_suffix = '{0}.{0}-{1}'.format(subject.strip(), session.strip())

        control.start(subject_id=int(self._subject))

        if self._session is not None:
            self.data.add_subject_info('session: ' + self._session)
Exemple #3
0
def perform_simon_task():
    """Performs a Simon Task experiment."""

    exp = design.Experiment("Simon Task")
    control.initialize(exp)

    exp = design_experiment(exp, POSITIONS, COLORS, PAIRINGS)

    exp.data_variable_names = [
        "pairing", "position", "color", "key", "reaction_time"
    ]

    control.start()
    execute_experiment(exp, INSTRUCTION_TEXT, KEY_MAPPING, PAIRINGS)
    control.end()
        b.set_factor("Condition", condition)
        t = design.Trial()
        t.add_stimulus(blocks[condition][0])
        t.add_stimulus(blocks[condition][1])
        b.add_trial(t)
        exp.add_block(b)
exp.add_block(exp.blocks[0].copy())


# IO
trigger = exp.keyboard  # For USB (keyboad emulation) trigger
#trigger = io.TriggerInput(io.ParallelPort(SCAN_TRIGGER_LTP_ADDRESS))  # For LTP trigger


# RUN
control.start()
stimuli.TextLine("Waiting for trigger...").present()
trigger.wait(SCAN_TRIGGER)  # Initial scanner sync
exp.clock.reset_stopwatch()
for block in exp.blocks:
    start = exp.clock.stopwatch_time
    block.trials[0].stimuli[1].play()
    exp.clock.wait((BLOCK_LENGTH * TR - TR/2) * 1000 - \
                   block.trials[0].stimuli[0].present(),
                   function=exp.keyboard.check)
    protocol.add_event(block.get_factor("Condition"), start,
                       exp.clock.stopwatch_time)
    trigger.wait(SCAN_TRIGGER)  # Sync to scanner for next block start

if not os.path.isdir("protocols"):
    os.mkdir("protocols")
Exemple #5
0
reminder_if_incorrect_response = stimuli.TextScreen(
    "Your response was incorrect. Instructions reminder:",
    heading_size=40,
    text=REMINDER_INSTRUCTIONS)
experiment_instructions = stimuli.TextScreen(
    "So, you're all set for the experiment! Instructions:",
    heading_size=40,
    text=EXPERIMENT_INSTRUCTIONS)
exp_1.data_variable_names = [
    "Sex", "Trial Number", "Block", "Task Type", "Frame Shape",
    "Number of Circles", "Congruent Trial", "Correct Key", "RT",
    "Correct Response"
]

kb = io.Keyboard()

control.start(skip_ready_screen=True)

training(TRAINING_TRIALS)
experiment(BLOCKS, EXPERIMENT_TRIALS_PER_BLOCK)

current_dir = os.getcwd() + '/'
data_dir = "data"
misc.data_preprocessing.write_concatenated_data(
    os.path.join(current_dir, data_dir),
    file_name='experiment_1',
    output_file='experiment_1_data.csv',
    delimiter=',',
    to_R_data_frame=False,
    names_comprise_glob_pattern=False)
#control.set_develop_mode(True)

exp = control.initialize()

npt = NumerosityProductionTask(experiment=exp,
        dot_radius = 8, area_radius = 300,
        dot_colour = (0, 255,0), # changing colours requires Expyriment 0.8
        background_colour = (0,0,0), gap = 2,
        more_key = misc.constants.K_UP,
        less_key = misc.constants.K_DOWN,
        enter_key = misc.constants.K_RETURN,
        use_mouse = True)


### start ###
control.start(exp)

stimuli.TextScreen(heading= "Numerosity Production Task",
                   text="Use mouse wheel or up/down keys to change numerosity.\n" +
                   "Press mouse button or ENTER to accept estimation.").present()
exp.keyboard.wait()
exp.data_variable_names = ["estimation", "latency"]

while True:

    # make numerosity production estimation
    estim, rt = npt.estimation(max_number = 100, start_value = 0,
                        scroll_out_direction = "E")
    # save data
    exp.data.add([estim, rt])
Exemple #7
0
    symbol.plot(c4)

    c4.preload()
    t.add_stimulus(c4)

    # adding trial to block
    b.add_trial(t)

exp.add_block(b)

exp.data_variable_names = [
    "subjID", "runID", "TrialID", "decisionTime", "EstSnackID", "EstSource"
]
### START ###
control.start(experiment=None,
              auto_create_subject_id=None,
              subject_id=subjID,
              skip_ready_screen=False)
#control.start(exp,skip_ready_screen=True)
for block in exp.blocks:
    for trial in block.trials:

        trial.stimuli[0].present()
        exp.clock.wait(2000)

        trial.stimuli[1].present()
        exp.clock.wait(1000)

        trial.stimuli[2].present()
        exp.clock.wait(1000)

        trial.stimuli[3].present()
Exemple #8
0
    rand = random.choice(L)
    visual_block_random.name == rand

    if (random == "red"):

        visual_block_random.add_trial(visual_trial_red)

    else:

        visual_block_random.add_trial(visual_trial_blue)

exp.add_block(visual_block_random)

########## *******************  PART 2.Experiment ******************* ####################

control.start(skip_ready_screen=True)  #begining experiment
instructions.present()
exp.keyboard.wait()

exp.clock.wait(3000)

for b in exp.blocks:  # moving through each block

    for t in b.trials:  # iterating over stimuli inside each code

        blankscreen.present()
        exp.clock.wait(ITI)  # Fixed time between each stimulus.
        exp.clock.wait(random.randint(
            1000,
            2000))  # Random time between 1 and 3 sec. between each stimulus.
        t.stimuli[0].present()  # Printing stimulus.
Exemple #9
0
m = LdMatrix(matrixSize, windowSize)  # Create Matrix

instructionRectangle = stimuli.Rectangle(
    size=(windowSize[0], m.gap * 2 + cardSize[1]),
    position=(0, -windowSize[1] / float(2) +
              (2 * m.gap + cardSize[1]) / float(2)),
    colour=constants.C_DARKGREY)

picturesExamples = np.random.permutation(picturesExamples)

presentationOrder = newRandomPresentation()
presentationOrder = presentationOrder[0:3]

control.initialize(exp)
control.start(exp, auto_create_subject_id=True, skip_ready_screen=True)

nPict = 0
for nCard in presentationOrder:
    m._matrix.item(nCard).setPicture(picturesExamplesFolder +
                                     picturesExamples[nPict])
    nPict += 1

mouse = io.Mouse()  # Create Mouse instance
mouse.set_logging(True)  # Log mouse
mouse.hide_cursor(True, True)  # Hide cursor

setCursor(arrow)

bs = stimuli.BlankScreen(bgColor)  # Create blank screen
m.plotDefault(bs, True)  # Draw default grid
Exemple #10
0
from expyriment import stimuli, control, design, io, misc

from config import windowMode, windowSize, restBGColor, restCrossColor, restCrossSize, restCrossThickness

control.defaults.window_mode = windowMode
control.defaults.window_size = windowSize

exp = design.Experiment('Rest')  # Save experiment name
control.initialize(exp)
control.start(exp, auto_create_subject_id=True, skip_ready_screen=True)
bs = stimuli.BlankScreen(restBGColor)  # Create blank screen
cross = stimuli.FixCross(size=restCrossSize, colour=restCrossColor, line_width=restCrossThickness)  # Create cross
cross.plot(bs)
kb=io.Keyboard()
bs.present()


kb.wait(keys=misc.constants.K_q)
Exemple #11
0
WHITE = (255, 255, 255)
GRAY = (127, 127, 127)

# parameters of the grid
n_rows, n_cols = 10, 10
cell_side_length = 50
space_between_cells = 10

# graphic window cell_side_length
W = n_cols * cell_side_length + (n_cols - 1) * space_between_cells
H = n_rows * cell_side_length + (n_rows - 1) * space_between_cells

exp = design.Experiment(name="Herman's Grid", background_colour=GRAY)
#control.set_develop_mode(on=True)  # Comment out for full screen experiment
control.initialize(exp)
control.start(subject_id=1, skip_ready_screen=True)

# construction of the grid
b = stimuli.BlankScreen(GRAY)

quit = False
while not quit:
    b.clear_surface()
    for i_row in range(n_rows):
        for i_col in range(n_cols):
            x_left = i_col * (cell_side_length + space_between_cells
                              ) - cell_side_length // 2 - W // 2
            y_top = i_row * (cell_side_length + space_between_cells
                             ) - cell_side_length // 2 - H // 2
            r = stimuli.Rectangle((cell_side_length, cell_side_length),
                                  BLACK,
Exemple #12
0
Modifications mineures :
    - écran inter-bloc autonomisé, pendant l'entraînement (le sujet passe quand il veut au bloc d'entraînement suivant)
'''

from expyriment import design, control, stimuli, io, misc
import tkinter
import os
from leepfun import *
# Set develop mode, instead of full-length experiment
dev = False  ###

# Initialize and start experiment
exp = design.Experiment("IOR Task")
control.initialize(exp)
control.start(skip_ready_screen=True, subject_id=ipsubject()
              )  #  get subject number between 1 and 20 from IP address

# Set parameters
# inter-subject parameters
exp_type = 1  ### 1 for type 1 (speed), 0 pour type 2 (motor mapping)
is_square_up = True
is_AP_first = ((exp.subject // 2) % 2)  # type bool (relevant for exp_type = 0)
is_slow_first = (
    (exp.subject // 2) % 2)  # type bool (relevant for exp_type = 1)
is_square_right = (exp.subject % 2 == 0)  # type bool
e0, e1, e2 = 0, 1, 2
if (exp.subject // 4) % 2:
    eccentricity_order = [e0, e1, e2] if exp.subject % 2 else [e0, e2, e1]
else:
    eccentricity_order = [e1, e0, e2] if exp.subject % 2 else [e1, e2, e0]
Exemple #13
0
				s.scale(scaleFactor)
				t.add_stimulus(s)
				b.add_trial(t, copies=1, random_position=True)

				validImages += 1
			else:
				imageNames.remove(imageNames[imageNumber])
		else:
			break

	#b.shuffle_trials()
	exp.add_block(b)

###### RUN EXPERIMENT ######
# exp.save_design("StatLoc_Subject%02d_design.csv" % subjectNumber)
control.start(subject_id=subjectNumber, skip_ready_screen=True) # Start the experiment

stimuli.TextLine("Experiment is Prepped! Waiting for t to begin...").present()
theKeyboard.wait(keys=misc.constants.K_t)
exp.events.log("INITIAL TRIGGER")

fixCross.set_logging(False)

for block in exp.blocks:
	exp.clock.reset_stopwatch()
	exp.events.log("Pre Fixation Start")
	fixCross.present()
	exp.clock.wait(fixationTime)
	exp.events.log("Pre Fixation End: %d" % exp.clock.stopwatch_time)

	exp.events.log(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
Exemple #15
0
    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":
    to_delete = {"Condition2", "Condition6"}
else:
    to_delete = {"Condition1", "Condition5"}

if exp.get_permuted_bws_factor_condition("GabGabCondition") == "GabGab-Condition":
    to_delete.update(["Condition5", "Condition6"])
else:
    to_delete.update(["Condition1", "Condition2"])

print() #exp
for i in to_delete:
    exp.remove_block(exp.find_block(names_to_ids[i])[0])
Exemple #16
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A very short example experiment in 16 lines of pure code.
Participants have to indicate the parity of digits by pressing 
the left arrow key for odd and the right arrow key for even numbers.
"""

from expyriment import control, stimuli, design, misc

digit_list = [1, 2, 3, 4, 6, 7, 8, 9] * 12
design.randomize.shuffle_list(digit_list)

exp = control.initialize()
exp.data_variable_names = ["digit", "btn", "rt", "error"]

control.start(exp)

for digit in digit_list:
    target = stimuli.TextLine(text=str(digit), text_size=80)
    exp.clock.wait(500 - stimuli.FixCross().present() - target.preload())
    target.present()
    button, rt = exp.keyboard.wait(
        [misc.constants.K_LEFT, misc.constants.K_RIGHT])
    error = (button == misc.constants.K_LEFT) == digit % 2
    if error: stimuli.Tone(duration=200, frequency=2000).play()
    exp.data.add([digit, button, rt, int(error)])
    exp.clock.wait(1000 - stimuli.BlankScreen().present() - target.unload())

control.end(goodbye_text="Thank you very much...", goodbye_delay=2000)
Exemple #17
0
from functions2 import MusicSheet
'''
Custom settings
'''
# switch off opengl to avoid screen refesh sync
control.defaults.open_gl = False

# Fast open close and windowed; default: False
#control.set_develop_mode(True)
control.defaults.initialize_delay = 0

'''
Prepare experiment
'''

exp = design.Experiment(name="MusicTraining")

control.initialize(exp)


musicsheet = MusicSheet(screen_size=exp.screen.size)

control.start(subject_id=45)

stimuli.BlankScreen().present(clear=True, update=False)

musicsheet.Field.present(clear=False, update=True)
# Wait for button press
key, rt = exp.keyboard.wait(constants.K_ALL_LETTERS)

control.end(goodbye_text='Thats it', goodbye_delay=1000)
Exemple #18
0
# Create list of note objects
Notes = Notes()
Notes.appendnotes(setup.selection, setup.pos_y, setup.distance)

# Create Piano keyboard on screen
piano = PianoKeyboard(exp.screen.size)

#Randomize order of notes
random.shuffle(Notes)

# Add timer with max time
t = Timer(10000)
'''
Start Training
'''
control.start(subject_id=45)

# Add variable header to data_file; can't be done before control.start
exp._data.add_variable_names(
    ["Trial", "clef", "key", "Expected", "Type_response", "RT"])

# iRun indexes the Notes array; when all notes are shown and nTrails remain, this index is set to 0 and runs again
iRun = 0
'''
Trial function
'''
for iTrial in range(0, setup.nTrials):

    stimuli.BlankScreen().present(clear=True, update=False)

    piano.Canvas.present(clear=False, update=False)
Exemple #19
0
            text_justification=1)
    lstim.plot(screen)
    rstim = stimuli.TextBox(text=lltext, size=box_size, position=llpos, \
            text_justification=1)
    rstim.plot(screen)
    screen.present()
    return ss, llamt, lldel
      
# preload fixation cross for ITI
fixcross = stimuli.FixCross()
fixcross.preload()

# Start Experiment
exp.data_variable_names = ['trial', 'k', 'ssamnt', 'ssdel', \
                            'llamnt', 'lldel', 'choice', 'RT']
control.start(skip_ready_screen=True)

# present instructions
stimuli.TextScreen("Instructions", instructs).present()
response_device.wait()
  
# loop for specified number of trials
trial = 0
kvals = numpy.array([kval])
while trial < ntrials:
    
    # present trial
    ss, llamt, lldel = itc_stair(kval, trial)
    
    # collect behavior
    button, rt = response_device.wait_char(['f','j'])