AttributeError: Couldn't make sense of requested image (builder view, code component)

Hi everyone,

I’m having a little difficulty with indexing an image from an array that I had previously stored from my encoding phase.

I am trying to randomise the set of 6 (randomly) presented images from the encoding phase and use one of the images for the retrieval phase.

In the end routine of my coding phase I have:

# store the presented shapes for the retrieval phase
encStoredShape1=[]
encStoredShape1.append(stimulus1.image)
encStoredShape2=[]
encStoredShape2.append(stimulus2.image)
encStoredShape3=[]
encStoredShape3.append(stimulus3.image)
encStoredShape4=[]
encStoredShape4.append(stimulus4.image)
encStoredShape5=[]
encStoredShape5.append(stimulus5.image)
encStoredShape6=[]
encStoredShape6.append(stimulus6.image)

In the begin routine of my retrieval phase, I have:

storedShapes = [encStoredShape1, encStoredShape2, encStoredShape3,
                encStoredShape4, encStoredShape5, encStoredShape6]
randShape=[]
retrievalShape=[]
for i in randShape:
    random.randint(0, len(storedShapes) -1)
retrievalShape.append(randShape)

And in the each frame tab I have:

shape_cue = visual.ImageStim(win, image = (retrievalShape))
shape_cue.colorSpace = "rgb"
shape_cue.color = [0.168,0.168,0.168]
shape_cue.size = 0.3
shape_cue.pos = (0, 0)

I have tried indexing it through: image = shapeValues[retrievalShape[0]] but it throws an indexing error (shapeValues being the array of original stimuli).

Any suggestions on what I could try?
Cheers everyone!

Why is this in Each Frame? This appears to be recreating an image component several times per second, which is a huge overhead…

Also, retrievalShape is an array – shouldn’t you be using just one value from it?

Also, what does this loop do? randShape = at that point and you aren’t doing anything with the random integer you are creating.

for i in randShape:
    random.randint(0, len(storedShapes) -1)

The code is in the Each Frame tab as it would refresh to a new image on each iteration of the component - would you suggest to put it in the Begin Routine tab?

Yes I would like to use one value from it - I have tried random.choice() to select from the array but that does not seem to work. Any suggestions?

In terms of the loop, I was hoping that it would randomise the order of storedShapes and assign to a new array randShapes. I have tried simply:

 random.randint(storedShapes)

and

random.random(storedShapes)

but neither worked on their own.

Please could you clarify what exactly you are wanting to achieve?

Could you have an image component with the image set to $storedShapes[0] every repeat?

where in code you shuffle storedShapes?

Where do the six storedShapes come from? Why do you need to check the image attribute of each stimulus rather than using whatever text or variable you are using to set the stimuli?

During the encoding phase, 6 shapes are randomly displayed from an array of 360 shapes. Each shape will be randomly assigned a colour from 360 CIELa*b colours, and the stimuli will be displayed on a imaginary circle. In the retrieval phase, the participant will be displayed either the colour, shape or location as a cue and will have to respond to the corresponding colour/shape/location by means of a colour wheel, shape wheel or location wheel, respectively.

In terms of the retrieval image, I would like it to be one of the 6 displayed images but in order to display the image, I would need to store the information of the presented stimuli (which I have done in the End Routine tab of the encoding phase).

I can share my experiment with you, if that helps at all?

Are the original 360 shapes and colours in a spreadsheet or a coded array?

Sure – share it with me if you like and I’ll take a quick look.

I tend to code in a way that works online, but you only need it to work locally, don’t you?

The original 360 shapes are in a coded array.
The experiment is coded for local debugging at the moment, but I would like it to eventually run online through Pavlovia.

Here is the link to my git: GitHub - dtgoldenhausmanning/Experiment-1. You will find a copy of my experiment, along with a zip file of my stimuli and a figure of the experimental procedure.

Thanks in advance for having a look at it!

This will take a lot of work to translate for online using your current approach.

If you are basically wanting to select 6 shapes out of 360 and 6 colours out of 360 I’d recommend that you do the following in Begin Experiment

shuffle(colorValues)
shuffle(shapeValues)

Then when you want to pick 6 (e.g. in Begin Routine)

theseColors=[]
theseShapes=[]
for Idx in rand(set_size):
     theseColors.append(colorValues.pop())
     theseShapes.append(shapeValues.pop())

Please do look at my crib sheet. If you want something to work online then it’s work writing the offline code in a way that might work online.

Thanks for the advice, but I am still getting a “can’t make sense of requested image” error code. Any other thoughts on what I could try?

Your experiment needs a fair amount of attention. I just had a look at encoding_code and found the following in Each Frame. It might get totally ignored because there are no components in that routine.

from numpy.random import rand, shuffle
import math as math
import psychopy.tools.colorspacetools as cst
from psychopy import core, visual

cielabColor = (70, 20, 38)          # CIE*L*a*b colour space
rgbColor=cst.cielab2rgb(cielabColor)


win = visual.Window([1000, 1000], 
    monitor="testMonitor", color=[0.168,0.168,0.168])
print("FRAME")
# locations of the stimuli
distFromFix = 6
stim1POS = [0, 0.4]
stim2POS = [0, -0.4]
stim3POS = [0.4, 0.2]
stim4POS = [-0.4, 0.2]
stim5POS = [-0.4, -0.2]
stim6POS = [0.4, -0.2]

colorTrials, shapeTrials, locationTrials = generate_stimuli(set_size)
#print(colorTrials)
#print(shapeTrials)
#print(locationTrials)

# encoding stimuli parameters 
stimulus1 = visual.ImageStim(win, image = shapeValues[shapeTrials[0]])
stimulus1.colorSpace = "rgb"
stimulus1.color = [x / 255 for x in colorValues[colorTrials[0]]]
stimulus1.size = 0.3
stimulus1.pos = stim1POS
print(stimulus1.color)

stimulus2 = visual.ImageStim(win, image = shapeValues[shapeTrials[1]])
stimulus1.colorSpace = "rgb"
stimulus2.color = [x / 255 for x in colorValues[colorTrials[1]]]
stimulus2.size = 0.3
stimulus2.pos = stim2POS

stimulus3 = visual.ImageStim(win, image = shapeValues[shapeTrials[2]])
stimulus1.colorSpace = "rgb"
stimulus3.color = [x / 255 for x in colorValues[colorTrials[2]]]
stimulus3.size = 0.3
stimulus3.pos = stim3POS

stimulus4 = visual.ImageStim(win, image = shapeValues[shapeTrials[3]])
stimulus1.colorSpace = "rgb"
stimulus4.color = [x / 255 for x in colorValues[colorTrials[3]]]
stimulus4.size = 0.3
stimulus4.pos = stim4POS

stimulus5 = visual.ImageStim(win, image = shapeValues[shapeTrials[4]])
stimulus1.colorSpace = "rgb"
stimulus5.color = [x / 255 for x in colorValues[colorTrials[4]]]
stimulus5.size = 0.3
stimulus5.pos = stim5POS

stimulus6 = visual.ImageStim(win, image = shapeValues[shapeTrials[5]])
stimulus1.colorSpace = "rgb"
stimulus6.color = [x / 255 for x in colorValues[colorTrials[5]]]
stimulus6.size = 0.3
stimulus6.pos = stim6POS

stimulus1.draw()
stimulus2.draw()
stimulus3.draw()
stimulus4.draw()
stimulus5.draw()
stimulus6.draw()
core.wait(1.0, hogCPUperiod=0.2)
win.flip()

core.wait and win.flip are not code that should appear in Builder based experiments at all.

Thanks for the feedback, I’ll make the adjustments. Is there an alternative way to specify the duration of the stimuli presentation?

What I do for a routines where I want a duration but don’t have any non-code components is add a text box displaying a single space either for the desired duration or without a duration if I want to end the routine in code.

In theory I think that you might be able to use wait and flip if you only put code into Begin Routine and have no other components.