OS (e.g. Win10): Linux
PsychoPy version (e.g. 1.84.x): v1.84.2
Standard Standalone? y If not then what?:
What are you trying to achieve?:
I have build a Navon experiment (with Builder, than compiled the script),
where hierarchially structered letter stimuli shall show up on
different positions on the screen for 40ms. Afterwards a mask should
cover the stimulus until the participant’s response and the end of the
trial. The problem is, that sometimes the images do not show up at all
or just a grey field appears. More importantly the problem gets bigger
to the end of the experiment, where often no images are shown at all.
The first images of the experiment are often shown quite well. It seems
as if the same problem also happens with sound, but not that worse.
What did you try to make it work?:
I have already tried to run it on a windows system. It did not help. Additionally I
deleted the mask images, but the problem also appears without the mask
directly after the target image. I also closed all other windows while
running the experiment.
What specifically went wrong when you tried that?:
The same Problem appears. But there is no error message. However on the
Linux System we do have problems with inconsistent frame rate and
dropped frames (not on Windows, apparently).
This is the core code of the problem
#!/usr/bin/env python2
-- coding: utf-8 --
“”“
This experiment was created using PsychoPy2 Experiment Builder (v1.84.2),
on Do 09 Mär 2017 14:18:14 CET
If you publish work using this script please cite the PsychoPy publications:
Peirce, JW (2007) PsychoPy - Psychophysics software in Python.
Journal of Neuroscience Methods, 162(1-2), 8-13.
Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy.
Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008
"”"
from future import absolute_import, division
from psychopy import locale_setup, gui, visual, core, data, event, logging, sound
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os # handy system and path functions
import sys # to get file system encoding
Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(file)).decode(sys.getfilesystemencoding())
os.chdir(_thisDir)
Store info about the experiment session
expName = u’basic’ # from the Builder filename that created this script
expInfo = {u’session’: u’001’, u’participant’: u’’}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo[‘date’] = data.getDateStr() # add a simple timestamp
expInfo[‘expName’] = expName
Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = thisDir + os.sep + u’data/%s%s_%s’ % (expInfo[‘participant’], expName, expInfo[‘date’])
An ExperimentHandler isn’t essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version=’’,
extraInfo=expInfo, runtimeInfo=None,
originPath=None,
savePickle=True, saveWideText=True,
dataFileName=filename)
save a log file for detail verbose info
logFile = logging.LogFile(filename+’.log’, level=logging.EXP)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for ‘escape’ or other condition => quit the exp
Start Code - component code to be run before the window creation
Setup the Window
win = visual.Window(
size=(1920, 1200), fullscr=True, screen=0,
allowGUI=True, allowStencil=False,
monitor=‘testMonitor’, color=[-1.000,-1.000,-1.000], colorSpace=‘rgb’,
blendMode=‘avg’, useFBO=True)
store frame rate of monitor if we can measure it
expInfo[‘frameRate’] = win.getActualFrameRate()
if expInfo[‘frameRate’] != None:
frameDur = 1.0 / round(expInfo[‘frameRate’])
else:
frameDur = 1.0 / 60.0 # could not measure, so guess
Initialize components for Routine “Trails_L”
Trails_LClock = core.Clock()
Fixation_L = visual.TextStim(win=win, name=‘Fixation_L’,
text=’+’,
font=‘Arial’,
pos=(0, 0), height=0.2, wrapWidth=None, ori=0,
color=‘white’, colorSpace=‘rgb’, opacity=1,
depth=0.0);
local_sound = sound.Sound(‘A’, secs=-1)
local_sound.setVolume(1)
ISI_L = core.StaticPeriod(win=win, screenHz=expInfo[‘frameRate’], name=‘ISI_L’)
local_stim = visual.ImageStim(
win=win, name=‘local_stim’,
image=‘sin’, mask=None,
ori=0, pos=[0,0], size=(0.368, 0.600),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-4.0)
Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
set up handler to look after randomisation of conditions etc
exp_local = data.TrialHandler(nReps=40, method=‘random’,
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions(’…/Paradigms/Navon_material/conditions_local_Navon.csv’),
seed=None, name=‘exp_local’)
thisExp.addLoop(exp_local) # add the loop to the experiment
thisExp_local = exp_local.trialList[0] # so we can initialise stimuli with some values
abbreviate parameter names if possible (e.g. rgb = thisExp_local.rgb)
if thisExp_local != None:
for paramName in thisExp_local.keys():
exec(paramName + ‘= thisExp_local.’ + paramName)
for thisExp_local in exp_local:
currentLoop = exp_local
# abbreviate parameter names if possible (e.g. rgb = thisExp_local.rgb)
if thisExp_local != None:
for paramName in thisExp_local.keys():
exec(paramName + ‘= thisExp_local.’ + paramName)
# ------Prepare to start Routine "Trails_L"-------
t = 0
Trails_LClock.reset() # clock
frameN = -1
continueRoutine = True
routineTimer.add(5.500000)
# update component parameters for each repeat
local_sound.setSound('/home/wenhart/Dokumente/Experimente Psychopy/Paradigms/Navon_material/GlobalLocalTask.iqzip_FILES/Signal.wav', secs=0.050)
KeyL = event.BuilderKeyResponse()
# keep track of which components have finished
Trails_LComponents = [Fixation_L, local_sound, KeyL, ISI_L, local_stim]
for thisComponent in Trails_LComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "Trails_L"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = Trails_LClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *Fixation_L* updates
if t >= 3.0 and Fixation_L.status == NOT_STARTED:
# keep track of start time/frame for later
Fixation_L.tStart = t
Fixation_L.frameNStart = frameN # exact frame index
Fixation_L.setAutoDraw(True)
frameRemains = 3.0 + 0.500- win.monitorFramePeriod * 0.75 # most of one frame period left
if Fixation_L.status == STARTED and t >= frameRemains:
Fixation_L.setAutoDraw(False)
# start/stop local_sound
if t >= 3 and local_sound.status == NOT_STARTED:
# keep track of start time/frame for later
local_sound.tStart = t
local_sound.frameNStart = frameN # exact frame index
local_sound.play() # start the sound (it finishes automatically)
frameRemains = 3 + 0.050- win.monitorFramePeriod * 0.75 # most of one frame period left
if local_sound.status == STARTED and t >= frameRemains:
local_sound.stop() # stop the sound (if longer than duration)
# *KeyL* updates
if t >= 3.5 and KeyL.status == NOT_STARTED:
# keep track of start time/frame for later
KeyL.tStart = t
KeyL.frameNStart = frameN # exact frame index
KeyL.status = STARTED
# keyboard checking is just starting
win.callOnFlip(KeyL.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
frameRemains = 3.5 + 2- win.monitorFramePeriod * 0.75 # most of one frame period left
if KeyL.status == STARTED and t >= frameRemains:
KeyL.status = STOPPED
if KeyL.status == STARTED:
theseKeys = event.getKeys(keyList=['h', 's'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
if KeyL.keys == []: # then this was the first keypress
KeyL.keys = theseKeys[0] # just the first key pressed
KeyL.rt = KeyL.clock.getTime()
# was this 'correct'?
if (KeyL.keys == str(corrAns)) or (KeyL.keys == corrAns):
KeyL.corr = 1
else:
KeyL.corr = 0
# a response ends the routine
continueRoutine = False
# *local_stim* updates
if t >= 3.5 and local_stim.status == NOT_STARTED:
# keep track of start time/frame for later
local_stim.tStart = t
local_stim.frameNStart = frameN # exact frame index
local_stim.setAutoDraw(True)
frameRemains = 3.5 + 0.100- win.monitorFramePeriod * 0.75 # most of one frame period left
if local_stim.status == STARTED and t >= frameRemains:
local_stim.setAutoDraw(False)
# *ISI_L* period
if t >= 0 and ISI_L.status == NOT_STARTED:
# keep track of start time/frame for later
ISI_L.tStart = t
ISI_L.frameNStart = frameN # exact frame index
ISI_L.start(3-t)
elif ISI_L.status == STARTED: # one frame should pass before updating params and completing
# updating other components during *ISI_L*
local_stim.setPos((0.6,0.375))
local_stim.setImage(GL_fileName)
# component updates done
ISI_L.complete() # finish the static period
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in Trails_LComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "Trails_L"-------
for thisComponent in Trails_LComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
local_sound.stop() # ensure sound has stopped at end of routine
# check responses
if KeyL.keys in ['', [], None]: # No response was made
KeyL.keys=None
# was no response the correct answer?!
if str(corrAns).lower() == 'none':
KeyL.corr = 1 # correct non-response
else:
KeyL.corr = 0 # failed to respond (incorrectly)
# store data for exp_local (TrialHandler)
exp_local.addData('KeyL.keys',KeyL.keys)
exp_local.addData('KeyL.corr', KeyL.corr)
if KeyL.keys != None: # we had a response
exp_local.addData('KeyL.rt', KeyL.rt)
thisExp.nextEntry()
completed 40 repeats of ‘exp_local’
thisExp.abort() # or data files will save again on exit
win.close()
core.quit()