質問編集履歴

1

ソースコードを全文記載しました

2021/04/19 07:58

投稿

aca_ffk
aca_ffk

スコア3

test CHANGED
File without changes
test CHANGED
@@ -42,6 +42,280 @@
42
42
 
43
43
  ```python
44
44
 
45
+ # -*- coding: utf-8 -*-
46
+
47
+
48
+
49
+ from psychopy import visual, core, event, gui, data, misc
50
+
51
+ import numpy, os , random,time,csv
52
+
53
+
54
+
55
+ #参加者IDの取得
56
+
57
+ try:
58
+
59
+ expInfo = misc.fromFile('lastParams.pickle')
60
+
61
+ except:
62
+
63
+ expInfo = {'Participant':'001'}
64
+
65
+
66
+
67
+ expInfo['dateStr']=data.getDateStr()
68
+
69
+ dlg = gui.DlgFromDict(expInfo, title='Experiment', fixed=['dataStr'])
70
+
71
+ if dlg.OK:
72
+
73
+ misc.toFile('lastParams.pickle',expInfo)
74
+
75
+ else:
76
+
77
+ core.quit()
78
+
79
+
80
+
81
+ #結果の保存場所
82
+
83
+ results = []
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+ colorDic = {
94
+
95
+ u'赤': {'rgb': ( 1, -1,-1), 'type': '1'},
96
+
97
+ u'黄': {'rgb': ( 1, 1,-1), 'type': '2'},
98
+
99
+ u'青': {'rgb': (-1, -1, 1), 'type': '3'}
100
+
101
+ }
102
+
103
+
104
+
105
+ charConditionList = [
106
+
107
+ {'kanjiChar': u'赤', 'color': u'赤'},
108
+
109
+ {'kanjiChar': u'黄', 'color': u'赤'},
110
+
111
+ {'kanjiChar': u'青', 'color': u'赤'},
112
+
113
+ {'kanjiChar': u'赤', 'color': u'黄'},
114
+
115
+ {'kanjiChar': u'黄', 'color': u'黄'},
116
+
117
+ {'kanjiChar': u'青', 'color': u'黄'},
118
+
119
+ {'kanjiChar': u'赤', 'color': u'青'},
120
+
121
+ {'kanjiChar': u'黄', 'color': u'青'},
122
+
123
+ {'kanjiChar': u'青', 'color': u'青'}
124
+
125
+ ]
126
+
127
+
128
+
129
+ text = '今から色のついたもじがでてきます。\n文字の意味ではなく文字の色に基づいて\nボタンをおしてください。\n文字が赤色ならキーボードの1を、\n黄色なら2を、青色なら3をおしてください。\nこの指示が読めたらスペースキーを押してください\n'
130
+
131
+
132
+
133
+ myWin = visual.Window(fullscr=True, monitor="Default", allowGUI=False, units="norm", color=(1,1,1))
134
+
135
+ instText = visual.TextStim(myWin,text = text,pos=(0,0),color = (-1,-1,-1),height=0.1)
136
+
137
+
138
+
139
+ instText.draw()
140
+
141
+ myWin.flip()
142
+
143
+
144
+
145
+ keyList = event.waitKeys(keyList=['space'])
146
+
147
+
148
+
149
+ #反応時間計測のための設定
150
+
151
+ stopwatch = core.Clock()
152
+
153
+
154
+
155
+ M=1
156
+
157
+ N = len(charConditionList)
158
+
159
+
160
+
161
+ for m in range(M):
162
+
163
+ r = list(range(N))
164
+
165
+ numpy.random.shuffle(r)
166
+
167
+ for i, currentState in enumerate(r):
168
+
169
+ myWin = visual.Window(fullscr=True, monitor="Default", allowGUI=False, units="norm", color=(1,1,1))
170
+
171
+ charCondition = charConditionList[currentState]
172
+
173
+ colorData = colorDic[charCondition['color']]
174
+
175
+ kanjiCharData = colorDic[charCondition['kanjiChar']]
176
+
177
+ char = charCondition['kanjiChar']
178
+
179
+ myText = visual.TextStim(myWin,text = char,pos=(0,0),color = colorData['rgb'],height=0.2)
180
+
181
+ myText.draw()
182
+
183
+ myWin.flip()
184
+
185
+
186
+
187
+ #参加者の反応測定開始
188
+
189
+ #前回の刺激提示の影響を消去する
190
+
191
+ event.clearEvents()
192
+
193
+
194
+
195
+ #ストップウォッチをリセット
196
+
197
+ stopwatch.reset()
198
+
199
+ #参加者の反応をリセット
200
+
201
+ Responded = False
202
+
203
+
204
+
205
+ #ストップウォッチをリセットしてからstopwatch.getTime()で測定した時間が一秒を超えるまで以下の処理を実行
206
+
207
+ while stopwatch.getTime() < 1:
208
+
209
+ #もしこれまでに反応がないようなら event.waitKeysで反応を抜き出す
210
+
211
+ #Respondedには反応と反応時間が入る
212
+
213
+ if not Responded:
214
+
215
+ Responded = event.getKeys(keyList=['1','2','3'],timeStamped=stopwatch)
216
+
217
+
218
+
219
+ #もし一秒たっても反応がないならno responseと反応時間なしで処理する
220
+
221
+ if not Responded:
222
+
223
+ Responded = [('no respose', 0)]
224
+
225
+
226
+
227
+ #参加者の測定終了
228
+
229
+
230
+
231
+
232
+
233
+ #正解と不正解のフィードバック
234
+
235
+ if Responded[0][0] == 'no respose':
236
+
237
+ fbText = visual.TextStim(myWin, text = u'無反応',pos=(0,-0.3),color=(-1,-1,-1),height=0.2)
238
+
239
+ rtText = visual.TextStim(myWin, text = str(Responded[0][1])+u'秒',pos=(0,-0.5),color=(-1,-1,-1),height=0.2)
240
+
241
+ #保存用の結果
242
+
243
+ correctIncorrect = None
244
+
245
+
246
+
247
+ elif Responded[0][0] == colorData['type']:
248
+
249
+ fbText = visual.TextStim(myWin, text = u'正解',pos=(0,-0.3),color=(-1,-1,-1),height=0.2)
250
+
251
+ rtText = visual.TextStim(myWin, text = str(Responded[0][1])+u'秒',pos=(0,-0.5),color=(-1,-1,-1),height=0.2)
252
+
253
+ #保存用の結果
254
+
255
+ correctIncorrect = True
256
+
257
+ else:
258
+
259
+ fbText = visual.TextStim(myWin, text = u'不正解',pos=(0,-0.3),color=(-1,-1,-1),height=0.2)
260
+
261
+ rtText = visual.TextStim(myWin, text = str(Responded[0][1])+u'秒',pos=(0,-0.5),color=(-1,-1,-1),height=0.2)
262
+
263
+ #保存用の結果
264
+
265
+ correctIncorrect = False
266
+
267
+
268
+
269
+ #上記で設定したフィードバックと反応時間の書き込み
270
+
271
+ fbText.draw()
272
+
273
+ rtText.draw()
274
+
275
+
276
+
277
+ kanjiCharType = kanjiCharData['type']
278
+
279
+ colorType = colorData['type']
280
+
281
+
282
+
283
+ results.append([
284
+
285
+ N*m + i,
286
+
287
+ kanjiCharType,
288
+
289
+ colorType,
290
+
291
+ colorType==kanjiCharType,
292
+
293
+ Responded[0][0],
294
+
295
+ correctIncorrect,
296
+
297
+ Responded[0][1]
298
+
299
+ ])
300
+
301
+
302
+
303
+
304
+
305
+ myText = visual.TextStim(myWin,text = u'+',pos=(0,0),color = (-1,-1,-1),height=0.2)
306
+
307
+ myText.draw()
308
+
309
+ myWin.flip()
310
+
311
+ core.wait(0.5)
312
+
313
+
314
+
315
+ ~~~~~~~~~~~~~~~~~該当箇所~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
316
+
317
+
318
+
45
319
  curD = os.getcwd()
46
320
 
47
321
  datafile = open(os.path.join(curD, 'log', 'Sub{0}_{1}.csv'.format(expInfo['Participant'],
@@ -58,6 +332,8 @@
58
332
 
59
333
 
60
334
 
335
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336
+
61
337
 
62
338
 
63
339
  ```