psychopy.org | Reference | Downloads | Github

Experiment prematurely ends after changing stimulus and window units

Hi, I was attempting to obtain the coordinates of one of my stimuli in centimeters. I noticed that it was in units of height. When I changed the units of the window and stimulus to cm and ran the experiment, it would prematurely end between 2-4 trials instead of running through the 5 it was programmed to do.

Originally the code read:

win = visual.Window(
    size=(Width, Height), fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=backgroundColor, colorSpace='rgb',
    blendMode='avg', useFBO=True, 
    units='height')

# set up handler to look after randomisation of conditions etc
trials_2 = data.TrialHandler(nReps=5, method='sequential', 
    extraInfo=expInfo, originPath=-1,
    trialList=[None],
    seed=None, name='trials_2')
thisExp.addLoop(trials_2)  # add the loop to the experiment
thisTrial_2 = trials_2.trialList[0]  # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisTrial_2.rgb)
if thisTrial_2 != None:
    for paramName in thisTrial_2:
        exec('{} = thisTrial_2[paramName]'.format(paramName))

counter = 0
randInt = random.uniform(0.1, 0.3)


for thisTrial_2 in trials_2:
    
    randInt = random.uniform(-0.2, 0.1)
        
    polygon = visual.Rect(
        win=win, name='polygon',
        width=(0.02, 0.02)[0], height=(0.02, 0.02)[1], 
        ori=0, pos=(randInt, randInt),
        lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
        fillColor=stimuliColor, fillColorSpace='rgb',
        opacity=1, depth=0.0, interpolate=True)

However, when I change the units of the window and stimuli like this:

# Create window
win = visual.Window(
    size=[Width,Height], fullscr=True, screen=int(settingsGui.data[3]),
    winType='pyglet', allowGUI=False, allowStencil=True, 
    monitor='testMonitor', color=backgroundColor, colorSpace='rgb',
    blendMode='avg', useFBO=True, units='cm')

for thisTrial_2 in trials_2:
    
    randInt = random.uniform(-0.2, 0.1)
        
    polygon = visual.Rect(
        win=win, name='polygon', units='cm',
        width=0.4, height=0.4,
        ori=0, pos=(randInt, randInt),
        lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
        fillColor=stimuliColor, fillColorSpace='rgb',
        opacity=1, depth=0.0, interpolate=True)

It does not loop through all of the trials. Is there a way to fix this? Any help would be appreciated.

Hi There,

are there any error messages in the stdout portion of runner view?

Thanks,
Becca

Hi there, sorry for the late answer. I do not get any error messages running it. Alternatively, could I just use convertToPix and then pix2cm to perform the same task? The program seems to work just fine if I do not change the units.

EDIT: I resolved the issue by using:

convert_pix = posToPix(polygon)
convert_cm = psychopy.tools.monitorunittools.pix2cm(convert_pix, testMonitor)
print("coordinates (cm):", convert_cm)

Which prints the converted coordinates in cm.