Ok I gave it another shot, but ran into more errors. For reference, here is the flow:
This differs a bit from the other thread, but here is what I’ve done. At the start of my blocks
loop I have a routine (preload
) with a code component. In the begin experiment tab I set the stimulus path and import pandas
(because I need to access this block’s conditions file and extract the stimulus names from 4 columns):
import pandas as pd
stimulus_path = 'C://Users//L//experiment//stimulus_files'
Then in Begin Routine
of that component, using a similar approach to in the other thread:
df = pd.read_excel(block_file) # block file is random choice of 4
print(df) # it works
# I need 4 lists to choose from because I'm presenting 4 stimuli at a time on each trial
targets = []
dists1 = []
dists2 = []
dists3 = []
print(f"{stimulus_path}//{df['target_name'].iloc[0]}.jpg") # this definitely prints the correct path
for row in range(df.shape[0]):#['target_name'].values.tolist():
targets.append(visual.ImageStim(win=win, image=f"{stimulus_path}//{df['target_name'].iloc[row]}.jpg"))
dists1.append(visual.ImageStim(win=win, image=f"{stimulus_path}//{df['dist1_name'].iloc[row]}.jpg"))
dists2.append(visual.ImageStim(win=win, image=f"{stimulus_path}//{df['dist2_name'].iloc[row]}.jpg"))
dists3.append(visual.ImageStim(win=win, image=f"{stimulus_path}//{df['dist3_name'].iloc[row]}.jpg"))
So I printed out the path to the stimuli and it is definitely correct. I then printed out an element of the list, e.g. targets[-1]
and this is what it looks like:
ImageStim(__class__=<class 'psychopy.visual.image.ImageStim'>, autoLog=True, color=array([1., 1., 1.]), colorSpace='rgb', contrast=1.0, depth=0, flipHoriz=False, flipVert=False, image=str(...), interpolate=False, mask=None, maskParams=None, name='unnamed ImageStim', opacity=1.0, ori=0.0, pos=array([0., 0.]), size=array([2.60416667, 2.60416667]), texRes=128, units='height', win=Window(...))
I guess the image=str(...)
means it isn’t being set properly?
Finally, in the actual trial routine, and in the Properties box for each of the stimulus components, I used trials.thisN
to index into the respective lists (for example $targets[trials.thisN]
), and set every repeat.
Here’s the error output:
123.4102 DEPRECATION Couldn't make sense of requested image.
ioHub Server Process Completed With Code: 0
Traceback (most recent call last):
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\basevisual.py", line 831, 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\L\Google Drive\PhD\experiments\ATTMEM\Attmem_PsychoPy\phase_1 - Copy_lastrun.py", line 553, in <module>
target_stim.setImage(targets[trials.thisN])
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 836, in _createTexture
raise AttributeError(msg)
AttributeError: Couldn't make sense of requested image.
C:\Program Files\PsychoPy3\lib\site-packages\numpy\core\records.py:854: FutureWarning: fromrecords expected a list of tuples, may have received a list of lists instead. In the future that will raise an error
return fromrecords(obj, dtype=dtype, shape=shape, **kwds)
##### Experiment ended. #####
Thanks