Images appearing as black boxes after many trials
Hi I am hoping someone can help me with a rather weird problem. I am working on an experiment that is >1000 trials. The experiment uses a "mouse contingent window" in which the subjects should move the mouse around a gray screen to locate an image "hidden" below the mask. This part of the code is working fine. However I am running into a problem consistently after (about) 900 trials: the image appears as a black box. There also distractors (just circles) drawn, but they are not affected.
I have tried switching the backend from PsychoPy to xpyriment | legacy, but with the later two I immediately get an AttributeError 'pygame.Surface object has no attribute 'units'. I have copied the critical part of the code below, any help would be greatly appreciated!
import psychopy from psychopy import visual import numpy import pygame from PIL import Image from openexp.mouse import mouse my_mouse = mouse(exp) # the filename of the image # the images were previously in the file pool, but I moved them thinking this might help... it didnt.. fpath = 'C:\\Users\\Allgm1\\Desktop\\DejansExpra\\stimuli\\' fname = fpath+ var.object + var.version + '.jpg' # some of this I took from something I found online before.. not sure where from... I would bet Edwins stuff maskImageSize = 256 meshx,meshy = numpy.meshgrid(range(-maskImageSize/2,maskImageSize/2),range(-maskImageSize/2,maskImageSize/2)) imgArray = numpy.ones((maskImageSize,maskImageSize,4),numpy.uint8)*128 maskimage = Image.fromarray(imgArray,mode='RGBA') # target stim = psychopy.visual.ImageStim(win,fname,pos=var.stimpos) # distractors distractor1 = psychopy.visual.Circle(win,radius=75, pos=var.d1pos, fillColor = [1,0,1]) distractor2 = psychopy.visual.Circle(win,radius=75, pos=var.d2pos, fillColor = [0,1,1]) distractor3 = psychopy.visual.Circle(win,radius=75, pos=var.d3pos, fillColor = [1,-1,-1]) # mask mask = psychopy.visual.ImageStim(win,maskimage,interpolate='linear') mask.setSize((max(win.size)*2,max(win.size)*2)) windowSize = 10.0 t0 = clock.time() while True: # Get MOUSE position (x, y), timestamp = my_mouse.get_pos() distance = ((var.txpos-x)**2 + (var.typos2-y)**2)**0.5 if distance < 50: t1 = clock.time() break # ... and draw a mouse-contingent window imgArray[:,:,3] = 255*(1-numpy.exp(-(meshx/windowSize)**2-(meshy/windowSize)**2)) maskimage = Image.fromarray(imgArray,mode='RGBA') mask.setImage(maskimage) maskcenter = (x,-y) mask.setPos(maskcenter) distractor1.draw() distractor2.draw() distractor3.draw() stim.draw() mask.draw() win.flip() # show the target again stim.draw() win.flip() # decide with left or right mouse button while True: # until mouse is clicked button = my_mouse.get_pressed() if button != (0,0,0): t2 = clock.time() break # search time var.search_time = t1-t0 # RT var.reaction_time = t2-t1 # Accuracy # left is 1, right is 3 # create buttoname variable for correct answer comparison if button == 1: buttonname = "left_button" elif button == 1: buttonname = "right_button" elif button == 1: buttonname = "scroll" # checks if the button pressed corresponds to the correct answer if var.correct_response == buttonname: var.correct = 1 else: var.correct = 0
what I have tried:
1. let it run without drawing the mask - same error
2. draw 10 targets instead of 1 to see if it is some sort of memory problem - this leads to the images incrementally going black. so again after approx. 800-900 trials, 4 out of the 10 images consistently turn black at every trial. After x more trials it is 6 and so on until at some point all of them turn black at every trial. again, the distractor circles are not affected..
Any idea what is going on? Or do I need to specify something to make the problem more clear?
Thanks in advance!