psychopy.org | Reference | Downloads | Github

Problem with implementing an experiment using pictures

Dear community,

after some time I’m again planning to commit an experiment using psychopy again. One part of the experiment consists in a task similar to the stroop tasks but I want to use arrows instead of words to test the inhibition in children.
So I imagine it to be in two different conditions with the arrows being white in one case which suggests that the subject is supposed to press the correct direction of the arrow and with the arrow being black the subject is supposed to press the alternate direction.
The problem is that I can’t display the pictures as easy as words in the stroop test. I made my excel file with the conditions according to the normal stroop experiment, but is there a way to tell Psychopy that it should please open the picture named in the stimulus column?

If you have an idea I would be really greatful since my programming skills have become quiet rusty with the time.

I assume you’re using the builder interface? If I understand what you want, taking the “stroopExtended” demo as an example, if you look at the “trial” routine (click on the “trial” tab more towards the top of the window), it currently has a Text element called word (the icon has a red T and a black T). The only thing you would need to do is to use an Image component instead. So on the right, drag in an Image component. This will bring up the Image properties window so that you can set behavior for this element.

The important thing to make it change the image based on your conditions file, is that in the Image field, add something like $conditionName, and select “set every repeat” in the dropdown to the right.

Have you watched the tutorial @jon made a few years ago? https://youtu.be/VV6qhuQgsiI

I hope this has been helpful.

Thanks for your answer!
Yes I had watched the video before and tried it like that.
Now I succeded in actually displaying one of the arrow using the extended stroop task.
To change them randomly I inserted $arrow in the image column under image properties.
Sadly now two other problems came up. First, under image properties -> advanced-> color it says $[1,1,1], therefore I get a white picture and not the picture I actually want displayed.
If I just leave the column empty I get this error message:

Running: C:\Users\Johanna\Documents\Uni\Bachelorarbeit\Inhibition\stroop_lastrun.py
pyo version 0.8.0 (uses single precision)
C:\Program Files (x86)\PsychoPy2\lib\site-packages\openpyxl\reader\worksheet.py:322: UserWarning: Unknown extension is not supported and will be removed
warn(msg)
Traceback (most recent call last):
File “C:\Users\Johanna\Documents\Uni\Bachelorarbeit\Inhibition\stroop_lastrun.py”, line 287, in
win.flip()
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\window.py”, line 569, in flip
thisStim.draw()
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\image.py”, line 247, in draw
self.contrast)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\basevisual.py”, line 433, in _getDesiredRGB
desiredRGB = (rgb * contrast + 1) / 2.0
TypeError: unsupported operand type(s) for *: ‘NoneType’ and ‘float’

Is there something I can insert so Psychopy just displays the picture? I inserted $None but still get:

Running: C:\Users\Johanna\Documents\Uni\Bachelorarbeit\Inhibition\stroop_lastrun.py
pyo version 0.8.0 (uses single precision)
C:\Program Files (x86)\PsychoPy2\lib\site-packages\openpyxl\reader\worksheet.py:322: UserWarning: Unknown extension is not supported and will be removed
warn(msg)
Traceback (most recent call last):
File “C:\Users\Johanna\Documents\Uni\Bachelorarbeit\Inhibition\stroop_lastrun.py”, line 287, in
win.flip()
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\window.py”, line 569, in flip
thisStim.draw()
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\image.py”, line 247, in draw
self.contrast)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\basevisual.py”, line 433, in _getDesiredRGB
desiredRGB = (rgb * contrast + 1) / 2.0
TypeError: unsupported operand type(s) for *: ‘NoneType’ and ‘float’

Or is the problem something else?
The second problem which arises when I just leave $[1,1,1] for the advanced color I get an error message that he can not find some of the pictures. With others it works fine (just that the picture is displayed as completely white) but it stops working as soon as the experiment tries to call on one of the not working picture. But since they are all in the same folder and I already checked the names I don’t get the problem.
The error message I get is:
18.2117 ERROR Couldn’t find image file ‘downB’; check path?
C:\Program Files (x86)\PsychoPy2\lib\site-packages\openpyxl\reader\worksheet.py:322: UserWarning: Unknown extension is not supported and will be removed
warn(msg)
Traceback (most recent call last):
File “C:\Users\Johanna\Documents\Uni\Bachelorarbeit\Inhibition\stroop_lastrun.py”, line 225, in
image.setImage(arrow)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\image.py”, line 289, in setImage
setAttribute(self, ‘image’, value, log)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\tools\attributetools.py”, line 137, in setAttribute
setattr(self, attrib, value)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\tools\attributetools.py”, line 27, in set
newValue = self.func(obj, value)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\image.py”, line 276, in image
forcePOW2=False)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.0-py2.7.egg\psychopy\visual\basevisual.py”, line 790, in _createTexture
raise OSError, msg % (tex, os.path.abspath(tex))
OSError: Couldn’t find image ‘downB’; check path? (tried: C:\Users\Johanna\Documents\Uni\Bachelorarbeit\Inhibition\downB)

Does someone get what I did wrong and how I can solve this?

For your first question, regarding the color setting of $[1,1,1], that seems to be the default, and leaving it as is worked for me just now on a random image. (I didn’t get a white image, I saw the image no problem). Maybe you could send us a minimal example, (send your .psyexp file and your conditions file, and a problematic image or two, preferably in a zip file so that we can see how your folders are laid out).

There was a user who was seeing a white box instead of a photo, he found it was because his computer was too slow, and that trying it on a faster machine fixed the problem. You can see the thread here.

With the second problem, even though I know you checked, I would bet money that there’s simply a mistake in the conditions file, or the file isn’t where it’s supposed to be. If you look at the last line of the error, it’s looking for a file named ‘downB’ in that folder (C:\Users\Johanna\Documents\Uni\Bachelorarbeit\Inhibition\downB). You really have a photo file with no extension (.png, .jpg, etc) in that folder? If you’ve triple checked it, I would quadruple check it! (We’ve all been there).

After rechecking it a few times I found a very very stupid mistake in my conditions file.
So it actually works to a certain point.
A problem that is now arising and seems to explain the white pictures displayed before is that Psychopy somehow uses mor conditions than I gave it. Sadly it seems I can not upload anything except pictures and only one per post so I will try to show it to you using that.
So I have this conditions file with 8 conditions and 4 parameters looking like this:

But if I look in Psychopy in loop properties it says it has got 12 conditions and 4 parameters.
Now when running the experiment Psychopy displays in between the real stimuli blank pictures and my
result looks like this:

So it uses 4 conditions filling every row in the conditions file with none and uses them happily. Why I do not understand.
Any thoughts?

Now I added 4 new conditions (just use 2 of the black arrows and two white arrows twice) and I only get half of the blank pictures, but if I add more the number stays the same. Consider me confused.

My guess is that one of your cells contains something (like a space character), or you’ve left yourself a note in one of the lower rows, so the importer thinks all the rows must be conditions (some of which are blank). Just copy the grid of values that you actually need (A1:D9), paste it into a new file and use that.

1 Like

Thanks jon!!!
Must have been a space or something that I did not see, for notes and stuff I had already checked.
Pasting it in a new file solved the problem.

1 Like

It’s awesome it got sorted out! Please mark Jon’s response as the answer so that everyone knows the question is resolved.

1 Like