我在 Matlab 方面有一些经验,但对 PsychoPy 很陌生。
现在我想在两个图像之间不断切换,直到有键盘响应。每个图像应在屏幕上准确停留 100 毫秒,我希望能够验证是否是这种情况(例如在日志文件中)。
我通过在 win.flip() 之后使用 core.wait(.084) 来做对了——在一个大约 100 毫秒的 60Hz 屏幕上。我通过使用 win.logOnFlip() 将每个翻转的帧写入日志文件来验证它
但我相信我可以更精确,我只知道如何根据帧来定义图像的持续时间。
函数 core.wait() 只需要几秒钟的时间,而不是帧,对吗?
如果您能给我一些关于如何实现(和验证)6 帧图像呈现的提示,我将不胜感激。
提前致谢
最好的
塞巴斯蒂安
这是我的代码:
import os # for file/folder operations
from psychopy import visual, event, core, gui, data, logging
# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)
# screen size in pixels
scrsize = (600,400)
# gather info participant
exp_name = 'MyFirstPsychoPy'
exp_info = {
'participant': '',
}
dlg = gui.DlgFromDict(dictionary=exp_info, title=exp_name)
# if user pressed cancel quit
if dlg.OK == False:
core.quit()
# Get date and time
exp_info['date'] = data.getDateStr()
exp_info['exp_name'] = exp_name
#save a log file for detail verbose info
filename = _thisDir + os.sep + 'data/%s_%s_%s' %(exp_info['participant'], exp_name, exp_info['date'])
# print filename #to see if path correct
logFile = logging.LogFile(filename+'.log', level=logging.DEBUG)
logging.console.setLevel(logging.WARNING) # outputs to the screen, not a file
# Create a window small window
win = visual.Window(size=scrsize, color='white', units='pix', fullscr=False)
# or go full screen
#win = visual.Window([1280,1024], fullscr=True, allowGUI=False, waitBlanking=True)
# this is supposed to record all frames
win.setRecordFrameIntervals(True)
# show instructions until spacebar
start_message = visual.TextStim(win,
text="hello. you will see mondrians. press space to respond.",
color='red', height=20)
event.clearEvents()
keys = event.getKeys(keyList=['space', 'escape']) #allow only space and escape keys
while len(keys) == 0:
start_message.draw()
win.flip()
keys = event.getKeys(keyList=['space', 'escape'])
if len(keys)>0:
break
print keys #show on output screen
keys = event.clearEvents() # empty keys
keys = event.getKeys(keyList=['space', 'escape'])
# define 2 pictures
bitmap1 = visual.ImageStim(win, 'Mondrians/Mask_1.bmp', size=scrsize)
bitmap2 = visual.ImageStim(win, 'Mondrians/Mask_2.bmp', size=scrsize)
bitmap = bitmap1
# Initialize clock to register response time
rt_clock = core.Clock()
rt_clock.reset() # set rt clock to 0
# show alternating pics until response
frameN = 0
while len(keys) == 0:
if bitmap == bitmap1:
bitmap = bitmap2
else:
bitmap = bitmap1
bitmap.draw()
win.logOnFlip(msg='frame=%i' %frameN, level=logging.DEBUG) #record the time of win.flip() in the log file
win.flip() # show image
frameN = frameN + 1
core.wait(.084) # wait 100 ms
keys = event.getKeys(keyList=['space', 'escape']) #record resp
# if response stop
if len(keys)>0:
rt = rt_clock.getTime()
break
print keys, rt #show resp and rt on screen
win.saveFrameIntervals(filename+'.log', clear=True)
win.close()
core.quit()