Created
October 6, 2014 14:31
-
-
Save lindemann09/983b60a2594e5bf311a1 to your computer and use it in GitHub Desktop.
Expyriment: Attentional Blink Demo
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
# -*- coding: utf-8 -*- | |
""" | |
Attentional Blink experiment | |
Find the two numbers in the stream. | |
Enter "999" to quit experiment. | |
""" | |
from expyriment import * | |
import random | |
control.set_develop_mode(True) # <-- comment | |
########### DESIGN #################### | |
##Colour schemes: | |
bg_colour = misc.constants.C_GREY | |
#bg_colour = misc.constants.C_BLACK | |
exp = design.Experiment("Blinking_Magnitude", background_colour=bg_colour, | |
foreground_colour = misc.constants.C_BLACK) | |
#Variables: | |
numbers = [1,2,3,4,6,7,8,9] | |
letters = [letter for letter in 'ABCDEFGHJKLMNPQRSTUVWXYZ'] | |
ISI = 100 #Inter-Stimulus-Interval: 100 ms | |
items = 16 #Number of letters per trial (+ 2 Numbers) | |
textsize = 44 #Stimuli size | |
for bl_name in ["Block1"]: | |
block = design.Block(name=bl_name) | |
for lag in range(1,8+1): | |
for t1 in numbers: | |
for t2 in numbers: | |
if t1 != t2: | |
tr = design.Trial() | |
tr.set_factor("lag", lag) | |
tr.set_factor("T1", t1) | |
tr.set_factor("T2", t2) | |
t1pos = design.randomize.rand_int(3,7) | |
tr.set_factor("T1_pos", t1pos) | |
#make rsvp stimulus stream | |
random.shuffle(letters) | |
stream = letters[0:items] | |
stream.insert(t1pos-1, t1) | |
stream.insert(t1pos-1+lag, t2) | |
for stim in stream: | |
tr.add_stimulus(stimuli.TextLine(text=str(stim), | |
text_colour = misc.constants.C_BLACK, | |
text_size=textsize)) | |
block.add_trial(tr) | |
block.shuffle_trials() | |
exp.add_block(block) | |
exp.data_variable_names = ["trial_cnt", "T1_Position", "Time_lag", | |
"T1", "T2", "Difference", | |
"T1_Resp", "T2_Resp", | |
"RT", "Correct", "Reversed"] | |
######### INITIALIZE ############## | |
control.initialize(exp) | |
blank = stimuli.BlankScreen() | |
blank.preload() | |
fixcross = stimuli.FixCross() | |
fixcross.preload() | |
number_input = io.TextInput(message="Answer:", | |
message_text_size = 24, | |
user_text_size = 24, | |
ascii_filter=range(ord("1"), ord("9")+1)) | |
#Trial: | |
def run_trial(trial, trial_cnt): | |
blank.present() | |
exp.clock.wait(1000 - trial.preload_stimuli()) | |
fixcross.present() | |
exp.clock.wait(1000) #1 second Fixation Cross | |
# present stream | |
for stim in trial.stimuli: | |
stim.present() | |
exp.clock.wait(ISI) | |
blank.present() | |
trial.unload_stimuli() | |
exp.clock.reset_stopwatch() | |
input_ok = False | |
while(not input_ok): | |
exp.keyboard.clear() | |
answer = number_input.get() | |
if answer == "999": | |
control.end() | |
quit() | |
if len(answer) == 2: | |
input_ok = True | |
else: | |
stimuli.TextLine("Enter the two numbers:", text_size=24).present() | |
exp.clock.wait(3000) | |
RT = exp.clock.stopwatch_time | |
n1 = answer[0] | |
n2 = answer[1] | |
t1 = trial.get_factor("T1") | |
t2 = trial.get_factor("T2") | |
correct = (t1, t2) == (int(n1), int(n2)) #did the subject enter the correct numbers? | |
reverse = False | |
if not correct: | |
reverse = (t1, t2) == (int(n2), int(n1)) #correct numbers but wrong order? | |
semantic_diff = t2-t1 #semantic difference between the presented numbers | |
exp.data.add([ trial_cnt, trial.get_factor("T1_pos"), | |
trial.get_factor("lag"), | |
t1, t2, abs(semantic_diff), | |
str(n1), str(n2), RT, | |
int(correct), int(reverse)]) | |
exp.data.save() | |
######### START ############## | |
control.start(exp) | |
#instruction: | |
stimuli.TextScreen("Find the two numbers!", "Enter '999' to quit experiment") | |
exp.keyboard.wait(misc.constants.K_SPACE) | |
# training | |
for x in range(10): | |
trial = exp.blocks[0].get_random_trial() | |
run_trial(trial, -1) | |
stimuli.TextScreen(u"Questions?", "", heading_size=40).present() | |
exp.keyboard.wait(misc.constants.K_SPACE) | |
# Experiment | |
for block in exp.blocks: | |
stimuli.TextScreen("Experiment starts now!", u"press space bar...").present() | |
exp.keyboard.wait(misc.constants.K_SPACE) | |
for cnt, trial in enumerate(block.trials): | |
run_trial(trial, cnt) | |
if cnt in [90, 180, 270, 360]: | |
stimuli.TextScreen("Pause!", u"press space bar...").present() | |
exp.keyboard.wait(misc.constants.K_SPACE) | |
####### END EXPERIMENT ######## | |
control.end(goodbye_text="Thank you very much for participating in our experiment", | |
goodbye_delay=2000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment