每次试验的心理复位变量

时间:2015-08-31 18:20:37

标签: python timeline psychopy

我制作了自己的评分量表,这是0到28:18的时间表。它根据人们按压“快速”的速度而变化。或者' b'每个试验的关键。屏幕上显示的内容如下所示:

experiment http://i58.tinypic.com/2hhgoj7.png

我希望每个试验的顶部时间重置为14:09。在每次试验之后是0.5秒的试验间隔,在此期间,一个' +'显示在屏幕上。我遇到的问题是,如果你按下'或者' b'在ITI期间,下一次试验不会在14:09开始。相反,它会被一个' t'或者' b'按时移动时间线。这是我当前的代码,我试图纠正这个问题:

prevPos = 0
trialNum=0
b_list=[]
t_list=[]
key=[]

# loop through pictures
for eachPic in catPictures:
    b_list=[]
    t_list=[]
    timer = core.CountdownTimer(TrialDuration)
    while timer.getTime() > 0:
        for key in event.getKeys():
            if key in ['escape']:
                core.quit() # quit if they press escape
            if key in ['b']:
                # add keypress to list for each keypress. then move cursor proportionally to length of this list
                b_list.append(key)
                prevPos+=len(b_list)
            if key in ['t']:
                t_list.append(key)
                prevPos-=len(t_list)

    # set upper and lower limits to where cursor can go (which will later be halved to restrict range of cursor on the screen)
        if prevPos <= -849:
            prevPos = -849
        elif prevPos >=849:
            prevPos = 849
        # make absolute position so pos_absolute becomes a range from 0 to 300 (based on 28:18 min movie)
        pos_absolute = prevPos + 849
        # need to have range of 1698 (# of seconds in 28:18)
        # need to have range of 1698 (# of seconds in 28:18)
        # current range is 0 to 849 (which is 50% of 1698)
        seconds =  pos_absolute

        Image2 = visual.ImageStim(window)
        #curbImage2.setSize = ((0.5,0.5), units = 'norm')
        # make a little higher than the absolute middle
        Image2.setPos([0,100])
        # use each image (i in curbImages)
        Image2.setImage(catPictures[trialNum])

        # define cursor that moves along timeline
        cursorImage = visual.ImageStim(window)
        cursorImage.setImage(directoryStim+'cursor.png')
        # make cursor move by however big prevPos is
        cursorImage.setPos([int(prevPos)*.5,int(400)])
        # make the line
        timeline = visual.SimpleImageStim(win=window, image=directoryStim+'line.png', units='pix', pos=[0, 400])
    event.clearEvents() # get rid of other, unprocessed events

        # print min and max values next to timeline
        min = visual.TextStim(window, '0:00', color='Black', pos=[-500, 400])
        max = visual.TextStim(window, '28:18', color='Black', pos=[500, 400])
        # print constantly updating time value
        timeText = visual.TextStim(window,'%d:%02d' % (seconds/60, seconds % 60),color='Black',wrapWidth=1080,font='Verdana', pos=[0,465], height=50)

        ## now put everything on the screen
        Image2.draw(window)
        min.draw(window)
        max.draw(window)
        timeText.draw(window)
        timeline.draw(window)
        cursorImage.draw(window)
    ## flip so it actually appears
        window.flip()

    ITI = visual.TextStim(window, '+', pos=[0,0], height=50, color='Black')
    ITI.draw(window)
    window.flip()
    core.wait(.5,.5)
    trialNum+=1
    prevPos = 0
    b_list =[]
    t_list=[]
    key=[] 

在每次试用开始时,如何让我的时间线重置为14:09(又名prevPos = 0),即使有人按下&#39;或者&#39; b&#39;在审判结束时还是在审讯间隔期间?

2 个答案:

答案 0 :(得分:1)

在代码的最后一行,试试这个:

event.clearEvents()

在您的ITI期间按下的键进入缓冲区,因此下次您致电event.getKeys()时将收集这些键。通过调用clearEvents(),您可以刷新该缓冲区。

答案 1 :(得分:1)

  1. 在内部for循环下缩进内容。
  2. event.clearEvents()移至while - 循环之前 或core.wait之后。这就是你开始倾听新事物的地方 按键。等待期间的压力将返回 在下一个周期中调用event.getKeys() 而环。这就是它立即移动光标的原因。没有 真正有理由让event.clearEvents()拥有它 因为你只是在while循环中监听事件。这就是我的原因 建议您移动它而不是插入新的。
  3. 启动心理刺激是非常重要的 并且有时可能需要几百毫秒。没有 有必要创建几个新的ImageStimsTextStims 每次试验。
  4. pos_absoluteseconds是多余的。您只能使用seconds
  5. 一种风格的东西:而不是stim.setPos(x)你现在可以stim.pos = x等所有其他属性。这是从现在开始设置激励属性的首选方法(更清晰的代码,允许对属性进行更多操作)。
  6. 以下是带有上述更改的清理代码:

    # Stimuli
    Image2 = visual.ImageStim(window)
    cursorImage = visual.ImageStim(window)
    min = visual.TextStim(window, '0:00', color='Black', pos=[-500, 400])
    max = visual.TextStim(window, '28:18', color='Black', pos=[500, 400])
    timeText = visual.TextStim(window,color='Black',wrapWidth=1080,font='Verdana', pos=[0,465], height=50)
    ITI = visual.TextStim(window, '+', pos=[0,0], height=50, color='Black')
    timeline = visual.SimpleImageStim(win=window, image=directoryStim+'line.png', units='pix', pos=[0, 400])
    timer = core.CountdownTimer(TrialDuration)
    
    # loop through pictures
    trialNum=0
    for eachPic in catPictures:
        prevPos = 0
        key=[]
        b_list=[]
        t_list=[]
        timer.reset()
        event.clearEvents() # get rid of other, unprocessed events
        while timer.getTime() > 0:
            for key in event.getKeys():
                if key in ['escape']:
                    core.quit() # quit if they press escape
                if key in ['b']:
                    # add keypress to list for each keypress. then move cursor proportionally to length of this list
                    b_list.append(key)
                    prevPos+=len(b_list)
                if key in ['t']:
                    t_list.append(key)
                    prevPos-=len(t_list)
    
            # set upper and lower limits to where cursor can go (which will later be halved to restrict range of cursor on the screen)
            if prevPos <= -849:
                prevPos = -849
            elif prevPos >=849:
                prevPos = 849
            # make absolute position so pos_absolute becomes a range from 0 to 300 (based on 28:18 min movie)
            # need to have range of 1698 (# of seconds in 28:18)
            # need to have range of 1698 (# of seconds in 28:18)
            # current range is 0 to 849 (which is 50% of 1698)
            seconds =  prevPos + 849
    
            #curbImage2.size = ((0.5,0.5), units = 'norm')
            # make a little higher than the absolute middle
            Image2.pos = [0,100]
            # use each image (i in curbImages)
            Image2.image = catPictures[trialNum]
    
            # define cursor that moves along timeline
            cursorImage.image = directoryStim+'cursor.png'
            # make cursor move by however big prevPos is
            cursorImage.pos = [int(prevPos)*.5,int(400)]
            timeText.text = '%d:%02d' % (seconds/60, seconds % 60))
    
            ## now put everything on the screen
            Image2.draw(window)
            min.draw(window)
            max.draw(window)
            timeText.draw(window)
            timeline.draw(window)
            cursorImage.draw(window)
            ## flip so it actually appears
            window.flip()
    
        ITI.draw(window)
        window.flip()
        core.wait(.5,.5)
        trialNum+=1
    

    请注意,我还删除了b_listkey等几个看似不必要的重置。