Created
May 13, 2014 16:46
-
-
Save lindemann09/d9c1d7e7e82e1330ed96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Operation Signs Spatial Associations. | |
Use arrow keys | |
""" | |
from expyriment import design, control, stimuli | |
from expyriment.misc import constants | |
PLUS = "plus" | |
MINUS = "minus" | |
control.set_develop_mode(False) | |
########### DESIGN #################### | |
exp = design.Experiment(name="OSSA1", | |
background_colour = constants.C_GREY, | |
foreground_colour = constants.C_BLACK, | |
text_font = "freesans", text_size=28) | |
# Design: 2 response mappings x 8 stimuli x 10 repetitions | |
for response_mapping in ["left_plus", "right_plus"]: | |
block = design.Block() | |
block.set_factor("mapping", response_mapping) | |
#add trials to block | |
for sign in [PLUS, MINUS]: | |
trial = design.Trial() | |
trial.set_factor("sign", sign) | |
block.add_trial(trial, copies=24) | |
block.shuffle_trials() | |
exp.add_block(block) | |
exp.add_bws_factor('mapping_order', ['left_plus_first', 'right_plus_first']) | |
#prepare data output | |
exp.data_variable_names = ["block", "mapping", "trial", "sign", "ISI", | |
"btn", "RT", "error"] | |
#set further variables | |
t_fixcross = 500 | |
min_max_ISI = [200, 750] # [min, max] inter_stimulus interval | |
ITI = 1000 | |
t_error_screen = 2000 | |
no_training_trials = 5 | |
######### INITIALIZE ############## | |
control.initialize(exp) | |
# Prepare and preload some stimuli | |
blankscreen = stimuli.BlankScreen() | |
blankscreen.preload() | |
fixcross = stimuli.FixCross() | |
fixcross.preload() | |
error_beep = stimuli.Tone(duration=700, frequency=2000) | |
error_beep.preload() | |
#define a trial | |
def run_trial(cnt, trial): | |
# present Fixation cross and prepare trial in the meantime | |
fixcross.present() | |
exp.clock.reset_stopwatch() | |
ISI = design.randomize.rand_int(min_max_ISI[0], min_max_ISI[1]) | |
sign = trial.get_factor("sign") | |
target = stimuli.TextLine(text=str(sign), text_size=36) | |
target.preload() | |
exp.clock.wait(t_fixcross - exp.clock.stopwatch_time) | |
#present blankscreen for a random interval | |
blankscreen.present() | |
exp.clock.wait(ISI) | |
# Present target & record button response | |
target.present() | |
btn, rt = exp.keyboard.wait([constants.K_LEFT, constants.K_RIGHT]) | |
#Error feedback if required | |
if block.get_factor("mapping") == "left_plus": | |
error = (sign == MINUS and btn == constants.K_LEFT) or \ | |
(sign == PLUS and btn == constants.K_RIGHT) | |
else: | |
error = (sign == PLUS and btn == constants.K_LEFT) or \ | |
(sign == MINUS and btn == constants.K_RIGHT) | |
#write data and clean up while inter-trial-interval | |
blankscreen.present() | |
if error: | |
error_beep.present() | |
exp.clock.wait(t_error_screen) | |
exp.data.add([block.id, block.get_factor("mapping"), | |
cnt, sign, ISI, btn, rt, int(error)]) | |
exp.data.save() | |
target.unload() | |
exp.clock.wait(ITI) | |
######### START ############## | |
control.start(exp) | |
# permute block order across subjects | |
if exp.get_permuted_bws_factor_condition('mapping_order') == "right_plus_first": | |
exp.swap_blocks(0, 1) | |
# Run the actual experiment | |
for block in exp.blocks: | |
# Show instruction screen | |
if block.get_factor("mapping") == "left_plus": | |
instruction = "Press LEFT arrow key for '{0}'\n".format(PLUS) + \ | |
"and RIGHT arrow key for '{0}".format(MINUS) | |
else: | |
instruction = "Press LEFT arrow key for '{0}'\n".format(MINUS) + \ | |
"and RIGHT arrow key for '{0}".format(PLUS) | |
stimuli.TextScreen("Word Classification Task", instruction + | |
"\n\nPress space bar to start training.").present() | |
exp.keyboard.wait(constants.K_SPACE) | |
#training trials | |
for cnt in range(0, no_training_trials): | |
trial = block.get_random_trial() | |
run_trial(-1 * (1 + cnt), trial) #training trails has negative trial numbers | |
# Show instruction screen | |
stimuli.TextScreen("Attention!", instruction + | |
"\n\nThe experimental block starts now.").present() | |
exp.keyboard.wait(constants.K_SPACE) | |
# experimental trials | |
for cnt, trial in enumerate(block.trials): | |
run_trial(cnt, trial) | |
####### END EXPERIMENT ######## | |
control.end(goodbye_text="Thank you very much for participating in our experiment", | |
goodbye_delay=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment