Hi everyone,
I’m trying to implement a MEG experiment with visual stimuli. I’m using Psychpy (version 1.85.6, Python version 2.7) with the Coder on a MacBook Pro (macOS Sierra 2017, version 10.12.5, 13-inch), which is connected to a Labjack (U3-LV) that sends signals to an Elekta trigger box via digital I/Os.
The design is as below: Each trial consists of 3 visual text appearing at 3 regions (1 per region); each should last for 500 ms (30 frames per region on a 60 HZ refresh rate). The experiment has 8 conditions (x 3 regions), requiring 24 binary-digit combinations, and therefore we need to use 5 FIOs of the labjack.
I was trying to ask labjack to send a specific digital 0/1 combination corresponding to a given condition in a given region at the onset of the visual text stimuli (if frame == 0). The relevant parts of the script are attached below. The stimuli and the digital 0/1 combinations are imported from an .csv file.
[Problem] When connected with Labjack (5 FIOs), Psychopy began to lag after the experiment ran for about 15~20 minutes, and the updates showing in the output window was delayed. Associated with this, some visual stimuli stayed on the screen longer than expected. The situation got worse later and sometimes Psychopy stopped responding.
Not sure if this is relevant, but it seemed that Psychopy required a lot of CPU to run with this script, sometime occupying ~99.5 or 99.9% of the CPU. This problem did not occur when Labjack was not connected, so I’m wondering whether it has to do with those lines that call for Labjack (while 30 frames are drawn at every region).
I have tried the following approaches but none of these solved the above problem:
(1) closing all other applications
(2) running on an oder version of PsychPy (version 1.83.04)
(3) calling the labjack at only one region (instead of three), and further using only 3 FIOs.
Does anyone have an idea about how to deal with this issue?
If I’m missing anything, I’ll be grateful if someone could please let me know.
Thank you!
Sincerely,
Lai
# Timings
framesIntertrial = 30 # in frames. ~ 500 ms on 60 Hz
framesFix = 30 # in frames. ~ 500 ms on 60 Hz
framesTar = 30 # in frames. ~ 500 ms on 60 Hz
# Set up labjacks U3
from psychopy.hardware.labjacks import U3
from labjack import u3
d = u3.U3()
--------
# Displays trials.
for trial in trialList:
# Prepare trial here, before entering the time-critical period
stimRegion1.setText(trial['region1'])
stimRegion2.setText(trial['region2'])
stimRegion3.setText(trial['region3'])
# ACTION: THIS IS THE TIMING CRITICAL PART
# Fixation
win.callOnFlip(clock.reset)
for frame in range(framesFix):
stimFix.draw()
win.flip()
# Blank
for frame in range(framesTar):
stimBlank.draw()
win.flip()
print frame
# Region 1
for frame in range(framesTar):
stimRegion1.draw()
win.flip()
print frame
if frame == 0:
d.setFIOState(2, int(trial['fio2x']))
d.setFIOState(3, int(trial['fio3x']))
d.setFIOState(4, int(trial['fio4x']))
d.setFIOState(5, int(trial['fio5x']))
d.setFIOState(6, int(trial['fio6x']))
# Blank
for frame in range(framesTar):
stimBlank.draw()
win.flip()
print frame
# Region 2
for frame in range(framesTar):
stimRegion2.draw()
win.flip()
print frame
if frame == 0:
d.setFIOState(2, int(trial['fio2y']))
d.setFIOState(3, int(trial['fio3y']))
d.setFIOState(4, int(trial['fio4y']))
d.setFIOState(5, int(trial['fio5y']))
d.setFIOState(6, int(trial['fio6y']))
# Blank
for frame in range(framesTar):
stimBlank.draw()
win.flip()
print frame
# Region 3
for frame in range(framesTar):
stimRegion3.draw()
win.flip()
print frame
if frame == 0:
d.setFIOState(2, int(trial['fio2z']))
d.setFIOState(3, int(trial['fio3z']))
d.setFIOState(4, int(trial['fio4z']))
d.setFIOState(5, int(trial['fio5z']))
d.setFIOState(6, int(trial['fio6z']))
#parallel.setData(int(trial['trigger3']))
# Blank
for frame in range(framesTar):
stimBlank.draw()
win.flip()
# END OF TIMING CRITICAL SECTION