如何在心理学中为每个试验设置刺激的方向

how to set the orientation of the stimulus for each trial in psychopy

我对 python 语言和心理学还很陌生。我正在通过创建虚拟实验来练习它。在这里,我试图创建一个关于贝叶斯大脑的实验。非垂直线将呈现给参与者,而参与者不会有任何反应,只是曝光。那么对于最后一次试行(它在显示器上停留更长的时间以得到响应),期望参与者判断最后一次试行是否垂直? (在暴露于非垂直线之后,我期待看到垂直度感知的变化)。

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

我的主要问题是;如何设置线的方向?我找到了 stim.ori 但不确定如何在 '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')

#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()

有几件事你想做一些不同的事情。我已经更新了您的代码并用注释 "CHANGE" 标记了更改。改变刺激的方向在精神病学中非常一致,因此 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.