2017-06-07 15 views
0

私の実験では、簡単な反応時間テストを作成しています。それには4ブロックあり、それぞれ6回の試行があります。私は練習ラウンドではあるが、画面上にブロックの最初の試行を提示することができた(しかし、刺激は現れる)。しかし、私は多数のリストを作成する必要があるか(つまり、異なる試行のために異なる刺激を保持するか)、あるいは私の既存のループの特性を変えなければならないかどうかはわかりません。私のコードは以下の通りです:複数のリストとループのコーディング

from psychopy import visual, core, event #import some libraries from PsychoPy 
import psychopy.event 

#Create the code for saving the data at some point 


#create a window 
mywin = visual.Window([1920,1080], monitor="testMonitor", units="deg") 
mywin.update() 

# create the six stimuli: 
Target = visual.TextStim(mywin, text = "text default") 
text_stim_list = [] # a list to hold them 
Stim_text = ["Berlin", "Paris", "London", "Nice", "Vienna", "Charming"] # 
their content 

#the positions of the stimuli 
positions = [ 
(-10, 10), 
(10, 10), 
(-10, -10), 
(10, -10), 
(-1, -10), 
(1, 10), 
] 

#Initial message to participants about the study 
message1 = visual.TextStim(mywin, text = "You have been captured by the 
plotters. As a test to see if you have information regarding the event, an 
on screen test will be adminstered. Press Spacebar when ready") 
message1.draw() 
mywin.update() 

#this will wait for a button press confirmation from p's to continue 
response = event.waitKeys(keyList = ['space',], timeStamped = True) 

#Initial message to participants about the study 
message1 = visual.TextStim(mywin, text = "On the next screen, you will be 
presented with a practice round of stimuli. Press Q if any of the cities are 
familiar, or press P if you do not recognise the cities") 
message1.draw() 
mywin.update() 

#this will wait for a button press confirmation from p's to continue 
response = event.waitKeys(keyList = ['space',], timeStamped = True) 

#Loop for drawing the stimulus 
#code for the keyboard response 
keys = psychopy.event.waitKeys(keyList=["q", "p"]) 

#Practice round-should it be stopped by a button press? 

for frameN in range(7*60): 
# draw each stim *on each frame* 
for i in range(len(Stim_text)): 
    Target.setPos(positions[i]) 
    Target.setText(Stim_text[i]) 
    Target.draw() 
# now flip the window (after all stimuli drawn) 
mywin.flip() 

#Initial message to participants about the study 
message1 = visual.TextStim(mywin, text = "On the next screen, the cities 
which 
our intelligence tells us are at risk will be presented. Press Q if any are 
familiar, press P if not blah blah blah.. press space when ready") 
message1.draw() 
mywin.update() 
response = event.waitKeys(keyList = ['space',], timeStamped = True)#wait for 
subjects to state they are ready 

#Cities block 
#First trial 

print Stim_text 
del Stim_text[1,2] 
print Stim_text 

私はそれはのように、それ以外の場合は非常に多くのリストを持っている意味がありませんLOOP-の属性を変更する伴うだろう、かなり確信しています。一般的に

ネイサン

+0

TrialHandlerクラスhttp://www.psychopy.org/api/data.html#psychopy.data.TrialHandlerに目を通す必要があります.TrialHandlerは無料であなたのために多くの煩わしさを処理します(データの保存と保存、そう)。使用方法については、コーダーのデモを確認してください。外部条件ファイル(例:.csvまたは.xlsx)から位置やその他の変数を読み取ることができます。これは、コード内にハードコードされたリストとして条件を入力するよりも、編集や保守が簡単です。 –

答えて

0

、私はこのようなものだろう:マイクは省を含め、あなたのためにこれの多くを行うことができますpsychopy.data.TrialHandlerに見て、コメントで指摘したように

# Run the code inside this loop four times 
for block in range(4): 
    for i, position in enumerate(positions): 
     # Prepare stimulus 
     Target.pos = position 
     Target.text = Stim_text[i] 

     # Show it 
     Target.draw() 
     win.flip() 

     # Collect response and score it 
     key = event.waitKeys(keyList=['q', 'p'])[0] # Just get the first response key 
     # Save response here somehow. 

をデータ。また、メッセージごとに新しいvisual.TextStimを生成する必要はありません。既存のテキストを目的のテキストで更新するだけです。

関連する問題