【问题标题】:how to set the orientation of the stimulus for each trial in psychopy如何为精神病学中的每个试验设置刺激的方向
【发布时间】:2016-03-29 23:47:04
【问题描述】:

我对 python 语言和心理学相当陌生。我正在通过创建虚拟实验来练习它。在这里,我正在尝试创建一个关于贝叶斯大脑的实验。非垂直线将呈现给参与者,而参与者不期望响应,只是暴露。那么对于最后的试验(它在监视器上停留的时间更长才能得到响应),期望参与者判断最后一行试验是否是垂直的? (在暴露于非垂直线之后,我期待看到垂直感的变化)。

但是,我无法从网络上学到很多东西。我很确定你们可以轻松地帮助我。

我的主要问题是;如何设置线的方向?我发现了 stim.ori,但不知道如何在“线”刺激上使用它。下面我附上了到目前为止我制作的代码。另外,我用#添加了一些额外的问题。

我尽量说清楚。对不起,我的英语不好。 谢谢!

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

#create a window
mywin = visual.Window([800,600],monitor="testMonitor", units="deg")

#stimuli
lineo = visual.Line(mywin, start=(-5, -1), end=(-5, 1))
fixation = visual.GratingStim(mywin, size=0.2, pos=[0,0], color = 'black')

#draw the stimuli and update the window
n = 5 # trial number
i = 0
while i < n:
    #fixation
    fixation.draw()
    mywin.flip()
    presses = event.waitKeys(1)
    # stimulus
    orientationlist = [20,30,40,50,60] # I want to draw the orientation info from this list
    x = random.choice(orientationlist)
    lineo.ori((x)) #
    lineo.draw()
    mywin.flip()
    presses= event.waitKeys(2)
    i +=1
    if i == 5: # how do I change the number into the length of the trial; len(int(n) didnt work.
        lineo.draw()
        mywin.flip()
        presses = event.waitKeys(4)
    #quiting
    # I dont know how to command psychopy for quiting the
    # experiment when 'escape' is pressed.

#cleanup
mywin.close()
core.quit()

【问题讨论】:

    标签: python psychopy


    【解决方案1】:

    有一些事情你想做不同的事情。我已经更新了您的代码并使用注释“更改”标记了更改。改变刺激的方向在精神病学中是相当一致的,所以Line 与任何其他视觉刺激类型没有什么不同。

    from psychopy import visual, core, event #import some libraries from PsychoPy
    import random
    
    #create a window
    mywin = visual.Window([800,600],monitor="testMonitor", units="deg")
    
    #stimuli
    lineo = visual.Line(mywin, start=(-5, -1), end=(-5, 1))
    fixation = visual.GratingStim(mywin, size=0.2, pos=[0,0], color = 'black')
    
    orientationlist = [20,30,40,50,60] # CHANGED. No need to redefine on every iteration of the while-loop.
    #draw the stimuli and update the window
    n = 5 # trial number
    
    for i in range(n):  # CHANGED. This is much neater in your case than a while loop. No need to "manually" increment i.
        #fixation
        fixation.draw()
        mywin.flip()
        event.waitKeys(1)  # CHANGED. No need to assign output to anything if it isn't used.
        # stimulus
    
        lineo.ori = random.choice(orientationlist)  # CHANGED. Alternative: lineo.setOri(random.choice(orientationlist)).
        lineo.draw()
        mywin.flip()
        event.waitKeys(2)
    
    # At this point, all the stimuli have been shown. So no need to do an if-statement within the loop. The following code will run at the appropriate time
    lineo.draw()
    mywin.flip()
    event.waitKeys(keyList=['escape'])  # CHANGED. Listen for escape, do not assign to variable
    # CHANGED. No need to call core.quit() or myWin.close() here since python automatically cleans everything up on script end.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      • 1970-01-01
      • 2020-06-12
      相关资源
      最近更新 更多