1

go-NoGo タスクの場合、psychopy の data.TrialHandler クラスを使用して写真を整理したいと思います。

trials = data.TrialHandler(ImageList, nReps=1, method='random')

ここで、サイコピーが辞書に入り、最初の一連の画像 (例: A_n) を提示し、その後、6 番目のセットまで 2 番目のセットに移動するループをコーディングしたいと考えています。私は次のことを試しました:

import glob, os, random, sys, time
import numpy.random as rnd
from psychopy import visual, core, event, monitors, gui, logging, data
im_a = glob.glob('./a*')   # upload pictures of the a-type, gives out a List of .jpg-files
im_n = glob.glob('./n*')   # n-type
im_e = glob.glob('./e*')   # e-type

# combining Lists of Pictures
A_n = im_a + im_n
N_a = im_n + im_a
A_e = im_a + im_e
E_a = im_e + im_a
E_n = im_e + im_n
N_e = im_n + im_e

# making a Dictionary of Pictures and Conditions
PicList = [A_n, N_a, A_e, E_a, E_n, N_e]   # just the six Combinations
CondList = [im_a,im_n,im_a,im_e,im_e,im_n] # images that are in the GO-Condition
ImageList = []
for imagelist, condition in zip(PicList, CondList):
    ImageList.append({'imagelist':imagelist,'condition':condition}) # to associate the picturelist with the GO Conditionlist

ヘッダーについて、追加の質問をします: Combining and associating multiple dictionaries

# Set Experiment
win = visual.Window(color='white',units='pix', fullscr=False)
fixCross=visual.TextStim(win,text='+',color='black',pos=(0.0,0.0), height=40)
corrFb = visual.TextStim(win,text='O',height=40,color='green',pos=[0,0])
incorrFb = visual.TextStim(win,text='X',height=40, color='red',pos=[0,0])


# Start Experiement
trials = data.TrialHandler(ImageList, nReps=1, method='random')
rt_clock = core.Clock()
bitmap = visual.ImageStim(win)
for liste in ImageList[0:5]: # to loop through all 6 conditions
     keys = []   
     for i,Pictures in enumerate(liste): # to loop through all pictures in each condition
           bitmap.setImage(Pictures) # attribute error occurs, not if I use Pictures[0][0], even though in this case every pictures is the same
           bitmap.draw() 
           win.flip()
           rt_clock.reset()
           resp = False
           while rt_clock.getTime() < 2.0: # timelimit is defined 2 s
                if not resp:
                      resp = event.getKeys(keyList=['space'])
                      rt = rt_clock.getTime()
           if bool(resp) is (Pictures in CondList):  # at this point python should have access to the Dictionary in which the associated GO Pictures are saved
                corrFb.draw()
                accu=1 # doesn't work yet
           else:
                incorrFb.draw() 
                accu=0
           win.flip()
           core.wait(0.5)
           trials.addData('rt_'+str(i), rt) # is working well when loop: if trial in trials: ...; in this case trialHAndler is not used, therefor trials.addData is not working
           trials.addData('accu_'+str(i), accu)
trials.saveAsExcel(datanames)
core.quit()

このコードにはいくつかの問題があります: まず、1 つの画像を 6 回だけ表示しますが、6 つの異なる画像は表示しません [1]。

第二に、まったく別の問題 [2] は、時間の測定と、試行ごとに試行担当者が行っている精度の保存です。したがって、各試行のすべての RT が合計されます。各画像のRTを取得したい。私は、刺激のための追加のstimuls.trialhandlerや、最後に最後のRTを提供するextraloopのようないくつかのことを試しましたが、それぞれではありません. --> 以下に回答します!!!

for stimuli in stimulus: stimulus.addData('rt', rt) 

これらの 4 つの質問は 1 つの質問に対して多くのことを知っていますが、誰かがこれらを解決する方法について良いアイデアを教えてくれるかもしれません... みんなありがとう!

4

2 に答える 2

2

[1] というラベルが付いた問題の理由は、変更されない PicList[0][0] に画像を設定したためです。マイクが上記で示唆しているように、次のものが必要です::

for i,thisPic in enumerate(PicList):
     bitmap.setImage(thisPic) #not PicList[0][0]

しかし、実際にトライアルハンドラーを使用してトライアルを処理するには、基本に戻る必要があるかもしれません ;-)

1 つの辞書が 1 つの試行を表す辞書の単一のリストを作成し、それらを順番に実行します (「ランダム」ではなく「順次」リストを使用するように TrialHandler に指示します)。したがって、現在使用しているループは、条件辞書のリストを作成するためのものであり、試行を実行するためのものではありません。次に、その 1 つのリストを試行ハンドラーに渡します::

trials = TrialHandler(trialTypes = myCondsListInOrder, nReps=1, method='sequential')
for thisTrial in trials:
    pic = thisTrial['pic']
    stim.setImage(pic)
    ...
    trials.addData('rt', rt)
    trials.addData('acc',acc)

また、Excel形式ではなく、「ロングワイド」形式を使用してデータを出力します::

trials.saveAsWideText('mydataFile.csv')

ご多幸をお祈りします、ジョン

于 2014-05-12T14:25:19.787 に答える
0

(A) これは質問とは関係ありませんが、パフォーマンスが向上します。この線:

bitmap = visual.ImageStim(win)

ループ内で発生してはなりません。つまり、各刺激を 1 回だけ初期化し、ループ内でその刺激のプロパティを更新するだけです。たとえば、bitmap.setImage(…) を使用します。したがって、この初期化行を、TextStims を作成する先頭に移動します。

(B) [削除: 最初のコード ブロックに注意を払っていませんでした。]

(ハ)

bitmap.draw(pictures)

この行は引数を取りません。bitmap.draw() である必要があります。とにかく、「写真」が何を指しているのかは明確ではありません。Python では大文字と小文字が区別されることに注意してください。これは、上記のループで定義された 'Pictures' と同じではありません。表示されている画像を更新したいと思いますか?その場合、上ではなく、このループ内で bitmap.setImage(…) 行を実行する必要があります。ここでは、試行ごとに設定される唯一の画像であるため、常に固定画像を描画します。

(D) RT については、これを試行ごとに 1 回だけ保存しています (インデントを確認してください)。画像ごとに 1 つ保存する場合は、これらの行を再度インデントする必要があります。また、データ出力では試行ごとに 1 行しか得られません。トライアルごとに複数の RT を記録する場合は、rt_1、rt_2、…、rt_6 などの一意の名前を付けて、それぞれが別の列に表示されるようにする必要があります。たとえば、このループに列挙子を使用できます。

for i, picture in enumerate(Piclist)
    # lots of code
    # then save data:
     trials.addData('rt_'+str(i), rt)
于 2014-05-12T10:50:47.733 に答える