如何设置精神病患者每次试验的刺激方向

2024-09-28 03:15:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python语言和精神病相当陌生。我通过创建虚拟实验来练习。在这里,我试图创建一个关于贝叶斯大脑的实验。非垂直线将呈现给参与者,而参与者不需要响应,只是暴露。然后对于最后一次试验(它在监视器上停留较长时间等待响应),则期望参与者判断最后一次试验是否垂直?(在暴露于非垂直线之后,我希望看到垂直感的变化)。在

然而,有太多的事情我不能从网上学到。我很确定你们可以很容易地帮我。在

我的主要问题是:如何设置生产线的方向?我发现了刺激但不知道如何在“在线”刺激下使用它。下面我附上了我迄今为止所做的代码。另外,我用#添加了一些额外的问题。在

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

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

Tags: thefromimportevent参与者visualdrawflip
1条回答
网友
1楼 · 发布于 2024-09-28 03:15:43

有几件事你想做的不同。我已经更新了您的代码,并用注释“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.

相关问题 更多 >

    热门问题