在 Python/Psychopy 中复制随机视觉刺激 [英] Duplicating random visual stimuli in Python/Psychopy

查看:48
本文介绍了在 Python/Psychopy 中复制随机视觉刺激的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Python/Psychopy.我向屏幕中心呈现 3 个随机视觉刺激 1 秒钟 (imgList1).然后我在屏幕的右上角 (imgList) 呈现其他 3 个随机视觉刺激.在 50% 的情况下,我需要第二组刺激 (imgList) 与第一组 (imgList1) 相同.我如何访问在第 1 部分随机选择的刺激,然后我可以使用该信息显示相同的刺激?我不确定如何跟踪我最初随机选择的图像的结果.

Using Python/Psychopy. I am presenting 3 random visual stimuli to the center of the screen for 1 second (imgList1). I am then presenting 3 other random visual stimuli to the upper right of the screen (imgList). On 50% of occasions I need the second group of stimuli (imgList) to be the same as the first (imgList1). How do i access which stimuli were randomly selected at part 1 so i can then use that information to display those same ones thereafter? I am not sure how to keep track of what results from my initial randomly selected images.

这是我的代码:

#make initial stimuli
imgList1 = glob.glob(os.path.join('stim','*.png'))
random.shuffle(imgList1)
targetset = [visual.ImageStim(window, img) for img in imgList1]

setlocation = [(-2,0),(0,0),(2,0)]
random.shuffle(setlocation)

#make second group of stimuli
imgList = glob.glob(os.path.join('stim', '*.png'))
random.shuffle(imgList)
pics = [visual.ImageStim(window, img) for img in imgList[:3]]

location = [(1,2),(3,3),(5,5)]
random.shuffle(location)

#display initial stimuli set
for i in range(3):
    targetset[i].pos = setlocation[i]
    targetset[i].draw()

window.flip()
core.wait(1)

#display secondary stimuli
for i in range(3):
    pics[i].pos = location[i]
    pics[i].draw()
    window.flip()
    core.wait(.25)

core.wait(3)
window.close()
quit()

推荐答案

targetset 是包含您从 imgList1 中选择的图像的列表.当你画它们时,它们不会去任何地方.您稍后仍可以访问该列表(只要您不删除或覆盖).只需抛硬币(选择 0 到 1 之间的随机数并检查是否小于 0.5.如果是,则在次要刺激中使用 pics,如果不使用 targetset(使用第二个位置列表).您可能会发现这值得抽象为一个函数.

targetset is the list that has your chosen images from imgList1. They don't go anywhere when you draw them. You can still access that list later (as long as you don't delete or overwrite). Just flip a coin (select a random number between 0 and 1 and check if less than 0.5. If so use pics in the secondary stimuli, if not use targetset (with the second location list). You might find this worth abstracting to a function.

def drawSet (imgs,locs):
    for(i,l) in (imgs,locs):
        i.pos = l
        i.draw()
        window.flip()
        core.wait(0.25)

然后你可以将它用于 drawSet(targetset,setlocation)drawSet(pics,location)drawSet(targetset,location)随机(假设你在某处import random as r)

Then you would use this for drawSet(targetset,setlocation) and drawSet(pics,location) or drawSet(targetset,location) with random (assuming you import random as r somewhere)

if r.random() < 0.5:
    drawSet(pics,location)
else:
    drawSet(targetset,location)

这篇关于在 Python/Psychopy 中复制随机视觉刺激的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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