在 Python/Psychopy 中复制随机视觉刺激
Duplicating random visual stimuli in Python/Psychopy
使用Python/Psychopy。我在屏幕中央呈现 3 个随机视觉刺激 1 秒 (imgList1)。然后我在屏幕 (imgList) 的右上角呈现 3 个其他随机视觉刺激。在 50% 的情况下,我需要第二组刺激 (imgList) 与第一组 (imgList1) 相同。我如何访问在第 1 部分随机选择的刺激,然后我可以使用该信息显示那些相同的信息?我不确定如何跟踪我最初随机选择的图像的结果。
这是我的代码:
#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 中选择的图像的列表。当您绘制它们时,它们不会去任何地方。您以后仍然可以访问该列表(只要您不删除或覆盖)。只需掷硬币(select 一个介于 0 和 1 之间的随机数,并检查是否小于 0.5。如果是,则在次级刺激中使用 pics
,如果不是,则使用 targetset
(第二个位置列表)。您可能会发现这值得抽象为一个函数。
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
某处)
if r.random() < 0.5:
drawSet(pics,location)
else:
drawSet(targetset,location)
使用Python/Psychopy。我在屏幕中央呈现 3 个随机视觉刺激 1 秒 (imgList1)。然后我在屏幕 (imgList) 的右上角呈现 3 个其他随机视觉刺激。在 50% 的情况下,我需要第二组刺激 (imgList) 与第一组 (imgList1) 相同。我如何访问在第 1 部分随机选择的刺激,然后我可以使用该信息显示那些相同的信息?我不确定如何跟踪我最初随机选择的图像的结果。
这是我的代码:
#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 中选择的图像的列表。当您绘制它们时,它们不会去任何地方。您以后仍然可以访问该列表(只要您不删除或覆盖)。只需掷硬币(select 一个介于 0 和 1 之间的随机数,并检查是否小于 0.5。如果是,则在次级刺激中使用 pics
,如果不是,则使用 targetset
(第二个位置列表)。您可能会发现这值得抽象为一个函数。
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
某处)
if r.random() < 0.5:
drawSet(pics,location)
else:
drawSet(targetset,location)