/
Experiment.py
181 lines (160 loc) · 7.42 KB
/
Experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python
import random, csv
from psychopy import visual, event, core, data, gui, misc
import numpy as np
import Instructions, AnchorTask, CIDTask, SpanTask, ImageReelTask, ImageQuestionTask
# some variables
interTaskTime = 3
interTaskTime2 = 6
debug = False #True
set_fullscr = True #False
resolution = (1920,1200)
#resolution = (1600,900)
#resolution = (800,450)
responses = ['yes','no']
taskAnchors = [['15'],['2','25'],['13,000','200,000']]
folderNames = [[''],['winter','summer'],['']]
comparativeQuestions = ['Is Big Ben taller or shorter than 15 meters high?',
u'Is the annual average temperature in the UK higher or lower than [anchor]\u00B0?',
u'Is the average price of a new car in the UK higher or lower than \u00A3[anchor]?']
comparativeOptions = [['taller','shorter'],
['higher','lower'],
['higher','lower']]
absoluteQuestions = ['How tall is Big Ben?',
'What is the annual average temperature in the UK?',
'What is the average price of a new car in the UK?']
units = [' metres',
u'\u00B0C',
u'\u00A3']
# Admin
expInfo = {'date':data.getDateStr(),'ID':1,'gender':['male','female','other'],'age':17,'native language':['','English','other']}
#present a dialogue to change params
ok = False
while(not ok):
expInfo = {'date':data.getDateStr(),'ID':1,'gender':['male','female','other'],'age':17,'native language':['','English','other']}
dlg = gui.DlgFromDict(expInfo, title='Experiment', fixed=['date'],order=['date','ID','gender','age'])
if dlg.OK:
misc.toFile('lastParams.pickle', expInfo)#save params to file for next time
if expInfo['native language'] != "":
ok = True
else:
dlg.OK = False
else:
core.quit()#the user hit cancel so exit
# setup data file
fileName = 'Data/' + 'Subject' + str(expInfo['ID']) + '_' + expInfo['date'] + '.csv'
# Read in counterbalancing etc.
# Adapted from http://stackoverflow.com/questions/14091387/creating-a-dictionary-from-a-csv-file
reader = csv.DictReader(open('Files/ExpStructure.csv'))
result = []
for row in reader:
if row['id'] == str(expInfo['ID']):
result = row
if result['whichExpt.First'] == '1':
taskOrder = [1,2,3]
else:
taskOrder = [1,2,3]
anchors = [taskAnchors[0],taskAnchors[1][int(result['E1anchor']) - 1],taskAnchors[2][int(result['E2anchor']) - 1]]
#imageFolders = [folderNames[0],folderNames[1],folderNames[2][int(result['E1anchor']) - 1]]
imageFolders = [folderNames[0],folderNames[1][int(result['E1anchor']) - 1],folderNames[2]]
for i in [1,2]:
comparativeQuestions[i] = comparativeQuestions[i].replace('[anchor]',anchors[i])
#if result['wordKey'] == "P":
# responses = [responses[1],responses[0]]
dataFile = open(fileName, 'w') #a simple text file with 'comma-separated-values'
dataFile.write('subject = ' + str(expInfo['ID']) + "; date = " + str(expInfo['date']) + ";gender = " + str(expInfo['gender']) + ";age =" + str(expInfo['age']) + "; native language = " + str(expInfo['native language']) + '\n')
dataFile.write('taskOrder = ' + str(taskOrder) + "; responses (Q,P) = " + str(responses) + '\n')
dataFile.close()
#create a window to draw in
myWin = visual.Window(resolution, winType='pyglet',allowGUI=False,units='norm', color=(0,0,0), fullscr = set_fullscr)
instructions = visual.TextStim(myWin,pos=[0,0],text="",height=.08,alignHoriz='center',wrapWidth=1.2)
CIDtext = 'Place your index fingers on the space bar now. \n\n Respond as soon as you recognize the word.'
CIDtext2 = 'Place your index fingers on the space bar now. \n\n Respond as soon as you recognize the word.'
SpanText = "You will now be shown letters one at a time. Please memorize them and recall them in order when asked."
ImageReelText = "You will now be shown a number of images. Please look carefully at them and keep them in mind. You will later be asked questions relating to the season depicted. \n \n Press any key to continue."
BetweenText = []
txt = 'This is the end of the first round of tasks. There will be two more rounds similar to this one. \n\n'
#txt += 'In the "DOES IT HAVE MEANING?" task, please respond as quickly as possible. '
#txt += '\n\nThe Q key will always correspond to "' + responses[0]
#txt += '" and the P key to "' + responses[1] + '". Make sure your index fingers rest on these keys.\n\n'
txt += 'Take a short break if you want to. Press any key to continue to the next block of the experiment.'
BetweenText.append(txt)
txt = 'This is the end of the second round of tasks. There will be one more round similar to this one. \n\n'
#txt += 'In the "DOES IT HAVE MEANING?" task, please respond as quickly as possible. '
#txt += '\n\nThe Q key will always correspond to "' + responses[0]
#txt += '" and the P key to "' + responses[1] + '". Make sure your index fingers rest on these keys.\n\n'
txt += 'Take a short break if you want to. Press any key to continue to the next block of the experiment.'
BetweenText.append(txt)
instr = Instructions.Instructions(myWin,responses)
instr.Run()
for tsk in range(3):
if tsk == 1:
# priming
instructions.setText(ImageReelText)
instructions.draw()
myWin.flip()
event.waitKeys()
myWin.flip()
#core.wait(interTaskTime-.5)
#myWin.flip()
core.wait(0.5)
task = ImageReelTask.Task(myWin,"Files/images/" + imageFolders[taskOrder[tsk]-1])
else:
task = AnchorTask.Task(myWin,fileName,tsk+1,comparativeQuestions[taskOrder[tsk]-1],units[taskOrder[tsk]-1],comparativeOptions[taskOrder[tsk]-1],1)
task.Run()
if tsk == 1:
core.wait(.5)
which = "season"
task = ImageQuestionTask.Task(myWin,fileName,tsk+1,which,imageFolders[taskOrder[tsk]-1])
task.Run()
if tsk == 0:
instructions.setText(CIDtext)
else:
instructions.setText(CIDtext2)
instructions.draw()
myWin.flip()
if tsk == 0:
core.wait(interTaskTime2-.5)
myWin.flip()
core.wait(0.5)
else:
core.wait(interTaskTime-.5)
myWin.flip()
core.wait(0.5)
task = CIDTask.Task(myWin,fileName,tsk+1,taskOrder[tsk],responses,debug)
task.Run()
core.wait(interTaskTime-.5)
myWin.flip()
core.wait(0.5)
if tsk != 1:
task = AnchorTask.Task(myWin,fileName,tsk+1,absoluteQuestions[taskOrder[tsk]-1],units[taskOrder[tsk]-1],comparativeOptions[taskOrder[tsk]-1],2)
task.Run()
if tsk < 2:
instructions.setText(SpanText)
instructions.draw()
myWin.flip()
if tsk == 0:
core.wait(interTaskTime2-.5)
myWin.flip()
core.wait(0.5)
else:
core.wait(interTaskTime-.5)
myWin.flip()
core.wait(0.5)
task = SpanTask.Task(myWin,fileName,tsk+1)
task.Run()
instructions.setText(BetweenText[tsk])
instructions.draw()
myWin.flip()
event.waitKeys()
endText = "This is the end of the experiment. \n\n"
endText += "Thank you for your participation."
instructions.setText(endText)
instructions.draw()
myWin.flip()
done = False
while not done:
for key in event.getKeys():
if key in ['escape']:
done = True
core.quit()