python - 精神病学中的审判处理者和时间测量

标签 python loops time trial psychopy

对于 go-NoGo 任务,我想使用来自 Psychopy 的 data.TrialHandler 类来组织图片:

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

现在我想编写一个循环,其中 Psychopy 进入字典,呈现第一组图片(例如 A_n),然后进入第二组直到第六组。我尝试了以下方法:

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]

其次,一个完全不同的问题 [2] 是每次试验的时间测量和试验处理程序正在执行的准确性的保存。因此它会将每次试验的所有 RT 相加。我想获取每张图像的 RT。我尝试了一些东西,比如一个额外的stimuli.Trialhandler用于刺激,最后还有一个额外的循环,这给了我最后的RT,但不是每一个。 --> 答案如下!!!

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

我知道这四个问题对于一个问题来说很多,但也许有人可以给我一些如何解决这些问题的好主意......谢谢大家!

最佳答案

标记为 [1] 的问题的原因是您将图像设置为永远不会改变的 PicList[0][0]。正如迈克在上面建议的那样,你需要::

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

但也许您需要回到基础知识,以便真正使用试验处理程序来处理您的试验;-)

创建一个字典列表,其中一个字典代表一次试验,然后按顺序运行这些字典(告诉 TrialHandler 使用“顺序”列表而不是“随机”)。因此,您当前使用的循环应该只是创建条件指令列表,而不是运行试验。然后将该列表传递给试验处理程序::

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')

最美好的祝愿, 乔恩

关于python - 精神病学中的审判处理者和时间测量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23605013/

相关文章:

c - MPI 总运行时间

Java日历算术问题

python - 使用 Trello API 和 Python 将成员(member)添加到卡

python - 带有 monkeypatch 的 pytest fixture 参数

python - 将行添加到 csv 文件而不创建中间副本

reactjs - SetTimeout无限循环并运行一次函数

python - 在使用 Redis 发布/订阅的 Python 服务中调试内存泄漏

javascript - 我可以从元素数组创建 Javascript 选择器吗?

java - 永远运行而不停的for循环出错

python - 如何让一个物体拥有暂时的无敌?