psychopy.org | Reference | Downloads | Github

Fixation Cross Problem

If this template helps then use it. If not then just delete and start from scratch.

OS Win10
PsychoPy version 3.0.0b12
**Standard Standalone? y
**What are you trying to achieve?:
I want to make a random fixation over 3 different times (8s, 10s, 12s), I do everything like in link below: Question about how to make a fixation cross appear for various durations

**What did you try to make it work?:
Im trying to make an experinent with random video and random cross fixation time

Below are some screenshots form my work, please help me, to fix this problem


Here u have my code:
#!/usr/bin/env python

-- coding: utf-8 --

“”"
This experiment was created using PsychoPy3 Experiment Builder (v3.0.0b12),
on styczeń 29, 2019, at 22:40
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, sound, gui, visual, core, data, event, logging, clock
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))
os.chdir(_thisDir)

Store info about the experiment session

psychopyVersion = ‘3.0.0b12’
expName = ‘video’ # from the Builder filename that created this script
expInfo = {‘participant’: ‘’, ‘session’: ‘001’}
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
expInfo[‘psychopyVersion’] = psychopyVersion

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=‘C:\Users\WINDOWS 10\Desktop\video i dĹşwiek\video.py’,
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=(1024, 768), fullscr=True, screen=0,
allowGUI=False, allowStencil=False,
monitor=‘testMonitor’, color=[0,0,0], 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 “start”

startClock = core.Clock()
powitanie = visual.TextStim(win=win, name=‘powitanie’,
text=‘Za chwilÄ™ weĹşmiesz udziaĹ‚ w badaniu\n’,
font=‘Arial’,
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color=‘white’, colorSpace=‘rgb’, opacity=1,
languageStyle=‘LTR’,
depth=0.0);

Initialize components for Routine “trial”

trialClock = core.Clock()
text = visual.TextStim(win=win, name=‘text’,
text=’+’,
font=‘Arial’,
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color=‘white’, colorSpace=‘rgb’, opacity=1,
languageStyle=‘LTR’,
depth=0.0);
movie = visual.MovieStim3(
win=win, name=‘movie’,
noAudio = False,
filename=lista,
ori=0, pos=(0, 0), opacity=1,
depth=-1.0,
)

Initialize components for Routine “end”

endClock = core.Clock()
koniecc = visual.TextStim(win=win, name=‘koniecc’,
text=‘DziÄ™kujemy za udziaĹ‚ w badaniu’,
font=‘Arial’,
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color=‘white’, colorSpace=‘rgb’, opacity=1,
languageStyle=‘LTR’,
depth=0.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

------Prepare to start Routine “start”-------

t = 0
startClock.reset() # clock
frameN = -1
continueRoutine = True
routineTimer.add(2.000000)

update component parameters for each repeat

keep track of which components have finished

startComponents = [powitanie]
for thisComponent in startComponents:
if hasattr(thisComponent, ‘status’):
thisComponent.status = NOT_STARTED

-------Start Routine “start”-------

while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = startClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame

# *powitanie* updates
if t >= 0 and powitanie.status == NOT_STARTED:
    # keep track of start time/frame for later
    powitanie.tStart = t
    powitanie.frameNStart = frameN  # exact frame index
    powitanie.setAutoDraw(True)
frameRemains = 2 - win.monitorFramePeriod * 0.75  # most of one frame period left
if powitanie.status == STARTED and t >= frameRemains:
    powitanie.setAutoDraw(False)

# 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 startComponents:
    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 “start”-------

for thisComponent in startComponents:
if hasattr(thisComponent, “setAutoDraw”):
thisComponent.setAutoDraw(False)

set up handler to look after randomisation of conditions etc

random_video = data.TrialHandler(nReps=5, method=‘random’,
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions(‘conditions.xlsx’),
seed=None, name=‘random_video’)
thisExp.addLoop(random_video) # add the loop to the experiment
thisRandom_video = random_video.trialList[0] # so we can initialise stimuli with some values

abbreviate parameter names if possible (e.g. rgb = thisRandom_video.rgb)

if thisRandom_video != None:
for paramName in thisRandom_video:
exec(’{} = thisRandom_video[paramName]’.format(paramName))

for thisRandom_video in random_video:
currentLoop = random_video
# abbreviate parameter names if possible (e.g. rgb = thisRandom_video.rgb)
if thisRandom_video != None:
for paramName in thisRandom_video:
exec(’{} = thisRandom_video[paramName]’.format(paramName))

# ------Prepare to start Routine "trial"-------
t = 0
trialClock.reset()  # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
# keep track of which components have finished
trialComponents = [text, movie]
for thisComponent in trialComponents:
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED

# -------Start Routine "trial"-------
while continueRoutine:
    # get current time
    t = trialClock.getTime()
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *text* updates
    if t >= 0.0 and text.status == NOT_STARTED:
        # keep track of start time/frame for later
        text.tStart = t
        text.frameNStart = frameN  # exact frame index
        text.setAutoDraw(True)
    frameRemains = time - win.monitorFramePeriod * 0.75  # most of one frame period left
    if text.status == STARTED and t >= frameRemains:
        text.setAutoDraw(False)
    
    # *movie* updates
    if t >= 0.0 and movie.status == NOT_STARTED:
        # keep track of start time/frame for later
        movie.tStart = t
        movie.frameNStart = frameN  # exact frame index
        movie.setAutoDraw(True)
    frameRemains = 0.0 + 1.0- win.monitorFramePeriod * 0.75  # most of one frame period left
    if movie.status == STARTED and t >= frameRemains:
        movie.setAutoDraw(False)
    
    # 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 trialComponents:
        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 "trial"-------
for thisComponent in trialComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
# the Routine "trial" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

completed 5 repeats of ‘random_video’

------Prepare to start Routine “end”-------

t = 0
endClock.reset() # clock
frameN = -1
continueRoutine = True
routineTimer.add(12.000000)

update component parameters for each repeat

keep track of which components have finished

endComponents = [koniecc]
for thisComponent in endComponents:
if hasattr(thisComponent, ‘status’):
thisComponent.status = NOT_STARTED

-------Start Routine “end”-------

while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = endClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame

# *koniecc* updates
if t >= 10 and koniecc.status == NOT_STARTED:
    # keep track of start time/frame for later
    koniecc.tStart = t
    koniecc.frameNStart = frameN  # exact frame index
    koniecc.setAutoDraw(True)
frameRemains = 10 + 2- win.monitorFramePeriod * 0.75  # most of one frame period left
if koniecc.status == STARTED and t >= frameRemains:
    koniecc.setAutoDraw(False)

# 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 endComponents:
    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 “end”-------

for thisComponent in endComponents:
if hasattr(thisComponent, “setAutoDraw”):
thisComponent.setAutoDraw(False)

these shouldn’t be strictly necessary (should auto-save)

thisExp.saveAsWideText(filename+’.csv’)
thisExp.saveAsPickle(filename)
logging.flush()

make sure everything is closed down

thisExp.abort() # or data files will save again on exit
win.close()
core.quit()

If you post code here, please do this:

as otherwise it is unreadable. But also please don’t paste the entire code of your experiment. It will just put people off from even reading your post. If necessary, just attach your Builder .psyexp file. If people need to, they can download that, and generate your code if necessary.

Also please actually specify what your problem is. (although I can guess in this case, please try to make it easier for people to help you by describing all aspects of the situation).

Suggestions:

  • don’t use full absolute paths to your stimuli. Currently the experiment is presumably on your desktop. No doubt you’ll want to move it somewhere more sensible at some point, or even on to another lab computer. Then all of your paths will break. So instead, use relative paths (relative to your .psyexp file), which are both shorter, and allow your experiment to be move anywhere (even to another operating system).
  • don’t use Windows-style \, use / instead, to avoid heartache.
  • Your actual problem: you need to specify times for every row in your conditions file. At the moment, you have blank values for all but three trials.

Ok. Thanks for help and information about how to put code if its needed. I will edit the paths.

“Your actual problem: you need to specify times for every row in your conditions file. At the moment, you have blank values for all but three trials.”

How i can do this? Please help me.

That is something you do in your spreadsheet (as in the Excel screenshot you provided above).