Hi Michael !
Thank you very much for your response! I have changed the path for my file and this problem seems to be solved now, thanks to you!
But, unfortunately, other errors appear in my code (probably hidden by the first). I think these errors come from my code for images. I really tried to fix it!! But I failed every time…
I’m really sorry to ask for your help again, but maybe you could have some ideas ?
The (new) problem:
When I run my code, the window closes and Psychopy sends me this long error message:
38.4492 ERROR Couldn't make sense of requested image.
Traceback (most recent call last):
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\basevisual.py", line 832, in _createTexture
im = tex.copy().transpose(Image.FLIP_TOP_BOTTOM)
AttributeError: 'ImageStim' object has no attribute 'copy'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\roman\Desktop\essai_image_psycho\psycho_essai_1_images_lastrun.py", line 321, in <module>
image_lateralisation.setImage(imageLat[imageLat_order[cur_imageLat]])
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\image.py", line 302, in setImage
setAttribute(self, 'image', value, log)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\tools\attributetools.py", line 141, in setAttribute
setattr(self, attrib, value)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\tools\attributetools.py", line 32, in __set__
newValue = self.func(obj, value)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\image.py", line 289, in image
wrapping=False)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\basevisual.py", line 837, in _createTexture
raise AttributeError(msg)
AttributeError: Couldn't make sense of requested image.
##### Experiment ended. #####
I precise that this code works perfectly when I don’t use images (but only words). So, the logic of the method seems to be great and the problem may come from my code for images itself. Moreover, I tried to use the TrialHandler
function to import and load my data, but without any results. Thus, here I display the first version of my code and I join the two versions at the end. Here comes the monster:
import xlrd, random
from psychopy import visual
random.seed()
# I define the number of items that I will use in my entire experiment
num_items = 6
# I put the reference to increment 'mot' and 'imageLat' counters through the experiment
cur_mot = 0
cur_imageLat = 0
#I create a window to display images
win = visual.Window(size =[1366, 768], fullscr = True, monitor = 'testMonitor', screen = 0, units = 'height')
# I load and read the file
in_file = 'essai_image_1.xlsx'
inbook = xlrd.open_workbook(in_file)
insheet = inbook.sheet_by_index(0)
# I create empty lists for each variables
imageLat = [] #this will contain images
valence_image = []
mot = []
valence_mot = []
# I loop the file to fill lists precising where are each values
for rowx in range(1,num_items+1):
row = insheet.row_values(rowx)
imageLat.append(visual.ImageStim(win = win, name = 'image_Lateralisation', size = [0.67, 0.35], image = row[0], mask = None, ori = 0, opacity = 1, flipHoriz = False, flipVert = False))
valence_image.append(row[1])
mot.append(row[2])
valence_mot.append(row[3])
# I create two combined lists and fill them
mot_order = [] #combined list to randomize the lists 'mot' and 'valence_mot' together
imageLat_order = [] #combined list to randomize 'imageLat' and 'valence_image' together
for i in range(num_items):
mot_order.append(i)
imageLat_order.append(i)
# I randomize separatly each combined list to have two different random orders
random.shuffle(mot_order)
random.shuffle(imageLat_order)
#I try to draw my current image at the begining of the Test Routine (it must be wrong)
for trial in range(num_items):
cur_imageLat = imageLat[imageLat_order[trial]]
stim.setImage(cur_imageLat)
cur_imageLat.draw()
# I log all data that I need
thixExp.addData('image_lat', imageLat[imageLat_order[cur_imageLat]])
thisExp.addData('valence_image', valence_image[imageLat_order[cur_imageLat]])
thisExp.addData('mot', mot[mot_order[cur_mot]])
thisExp.addData('valence_mot', valence_mot[mot_order[cur_mot]])
# I increment 'mot' and 'imageLat' counters to update the counters at each trial
cur_imageLat = cur_imageLat+1
cur_mot = cur_mot+1
I really don’t know where the problem is. If you, or someone else has any suggestions, I would be very very grateful!
The two versions of my experiment:
first code: psycho_essai_1_images.psyexp (16.1 KB)
second code with TrialHandler
: psycho_essai_2_images.psyexp (14.4 KB)
Romane.