Hello,
I am both a newbie to Psychopy / Programming in Python as well as running fMRI studies.
Nevertheless, I am currently about to set up a PsychoPy Coder based script for an fMRI scan.
The script that I have written works perfectly on my laptop: I have programmed it to show a grey screen until the keyevent ‘5’ is registered and to save any keyboard events (number ‘2’ or ‘4’).
My problem(s):
- I have coupled my stimulus laptop to the fMRI PC at our scanning site. The beamer-based presentation works (experiment is visible), but starting the experiment was not achieved by the scanner trigger. Instead, the exp only started when we pressed the button “5” on our stimulus laptop. Not a final solution, obviously; I would like to take the first trigger signal from the fMRI PC to start my experiment (see code below).
- The responses that our participants gave using a diamond response box were registered by the fMRI PC, but not by our attached stimulus laptop.
The only “key”-registering part in my code at the moment is
from psychopy.hardware import keyboard
[...]
# Record keypress
key_0,rt_intro0, time0 = trial_routine.wait_for_keys(components=list_components, valid_keys=['5'], label=routine_label, globaltime=globalClock)
# As soon as trigger signal is obtained from fMRI ("5"), start presentation and reset globalClock
if '5' in key_0:
# Reset global core clock
globalClock.reset(newT=0.0)
#print(key_0)
The routine wait_for_keys is defined (colleague from a colleague) like this:
def wait_for_keys(self, components, valid_keys, label, globaltime): # "globaltime" added by SK
event.clearEvents() # clear event cache
self.window.logOnFlip(level=logging.EXP, msg='%s onset' % label) # log onset stimuli
self.window.callOnFlip(self.timer.reset)
key_list = np.append(valid_keys, self.escape_key)
timeB = globaltime.getTime() # Line added by SK | Get global time at presentation
while True:
for comp in components:
comp.draw()
self.window.flip()
pressed_keys = event.getKeys(keyList=key_list, timeStamped=self.timer)
if len(pressed_keys)>0:
key, rt = pressed_keys[0] # get the first pressed key and response time
if key == self.escape_key:
self.window.close()
core.quit()
else:
break
self.window.logOnFlip(level=logging.EXP, msg='%s offset' % label) # log offset stimuli
if len(pressed_keys)>0:
return key, rt, timeB # Line added by SK
else:
return np.nan, self.timer.getTime()
Current solutions and questions:
Regarding problem 1, I found the example code fMRI_launchscan. Since I want to launch the scan only prior to the experiment: Am I right with implementing this code instead of my “if ‘5’ in key_0:” part and only use ‘Volumes’ = 1?
Regarding problem: I am not sure, if this is a hardware or software issue. The research team of the scanning site could not help either. If a software issue: Is it possible that the response box input is not registered by our laptop because the psychopy module “keyboard” is not appropriate?
Here are some technical details for the programming:
- Scanner: 3 Tesla Siemens MAGNETOM Prisma Scanner
- Coding Setting: Coder
- PsychoPy version: Psychopy v2020.1.2
- OS system: MacOS 10.14.6
I would be glad for any kind of support, particularly regarding the second problem!
If helpful, I can also append the full code of the experiment.
Best,
Sarah