审判者和心理测验时间 [英] Trialhandler and time measuring in psychopy

查看:165
本文介绍了审判者和心理测验时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于执行No-NoGo任务,我想使用data.TrialHandler类来整理图片:

For a go-NoGo Task I want to organize pictures with the data.TrialHandler class from psychopy:

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

现在,我想编写一个循环,在其中将精神病患者放入字典中,呈现第一组图片(例如A_n),然后转到第二组,直到第六组.我尝试了以下方法:

Now I want to code a loop in which psychopy is going into the dictionary, is presenting the first set of pictures (e.g. A_n) and afterwards is going to the second set until the sixth set. I tried the following:

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

对于标题,我问了一个额外的问题:组合和关联多个词典

for the header I ask an extra question: 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()

此代码中存在一些问题:首先,它仅一次展示一个pictuere六次,而没有展示六张不同的图片[1]

There are a few problems in this code: first it only presents one pictuere for six times, but not six different pictures [1]

其次,一个完全不同的问题[2]是计时员的问题,以及审时人员正在做的准确性的节省,但是对于每个审判而言.因此,它将每个试验的所有RT相加.我想获取每个图像的RT.我尝试了一些事情,例如刺激的额外刺激和最终的额外循环,这给了我最后的RT,但不是每一个. ->在下面回答!

and secondly a totally different problem [2] ist the time measuring and the saving of the accuracy which the trialhandler is doing, but for each trial. So it adds up all the RT's for each trial. I want to get the RT's for each image. I tried a few things like an extra stimulus.trialhandler for the stimuli and an extraloop in the end which gives me the last RT but not each. --> is answered below!!!

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

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

I know these four questions are a lot for one question, but maybe somebody can give me some good ideas of how I can solve these... Thanks everybody!

推荐答案

(A)这与您的问题无关,但可以提高性能. 该行:

(A) This isn't relevant to your question but will improve performance. The line:

bitmap = visual.ImageStim(win)

不应在循环内发生.即您应该只初始化每个刺激一次,然后在一个循环内您只需更新该刺激的属性即可,例如与bitmap.setImage(...).因此,请将此初始化行移至顶部,在此处创建TextStims.

Shouldn't occur within the loop. i.e. you should initialise each stimulus only once, then within a loop you just update that the properties of that stimulus, e.g. with bitmap.setImage(…). So shift this initialisation line to the top, where you create the TextStims.

(B)[已删除:我没有注意第一个代码块.]

(B) [deleted: I hadn't paid attention to the first code block.]

(C)

bitmap.draw(pictures)

此行不带任何参数.它应该只是bitmap.draw().无论如何,还不清楚图片"指的是什么.请记住,Python区分大小写.这与上面循环中定义的图片"不同.我猜您想更新显示的图片?在那种情况下,那么您需要在此循环中而不是在上面的循环中执行bitmap.setImage(…)行,在该循环中您将始终绘制固定的图片,因为这是每次尝试中唯一设置的图片.

This line doesn't take any arguments. It should just be bitmap.draw(). And anyway, it isn't clear what 'pictures' refers to. Remember that Python is case sensitive. This isn't the same thing as 'Pictures' defined in the loop above. I'm guessing that you want to update what picture is being shown? In that case, then you need to be doing the bitmap.setImage(…) line within this loop, not above, where you will always be drawing a fixed picture as that is the only one that gets set on each trial.

(D)重新发送RT,每个试用版仅保存一次(检查缩进).如果要为每个图像保存一个,则需要再次缩进这些行.此外,每次尝试在数据输出中仅获得一行.如果您希望每个试验记录多个RT,则需要为其指定唯一的名称,例如rt_1,rt_2,…,rt_6,因此它们分别显示在单独的列中.例如您可以在此循环中使用枚举器:

(D) Re the RTs, you are saving this only once per trial (check the indentation). If you want to save one per image, you need to indent these lines again. Also, you only get one line per trial in the data output. If you want to record multiple RTs per trial, you will need to give them unique names, e.g. rt_1, rt_2, …, rt_6 so they each appear in a separate column. e.g. you could use an enumerator for this loop:

for i, picture in enumerate(Piclist)
    # lots of code
    # then save data:
     trials.addData('rt_'+str(i), rt)

这篇关于审判者和心理测验时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆