[solved] Referencing to image file pool in psychopy
Hi!
I'm using the following script for randomizing pictures in the file pool.
import copy
import random
# Create a list of 100 pictures and shuffle them
nr_of_pictures = 100
self.experiment.pictures = []
for i in range(nr_of_pictures):
self.experiment.pictures.append("MP%d.png" % i)
random.shuffle(self.experiment.pictures)
# Create some lists for bookkeeping, so we remember which pictures have been shown
self.experiment.unused_pictures = copy.deepcopy(self.experiment.pictures)
self.experiment.Memory_Target = copy.deepcopy(self.experiment.pictures)
self.experiment.Targets_Distractors = copy.deepcopy(self.experiment.pictures)
self.experiment.Memory = []
self.experiment.Target = []
During a trial I'm using the following script for selecting pictures
import random
from array import array
from psychopy import visual, core, event, sound
# Select 2 random pictures
pic1 = self.experiment.unused_pictures.pop()
pic2 = self.experiment.unused_pictures.pop()
# Save the pictures as experimental variables
self.experiment.set("pic1", pic1)
self.experiment.set("pic2", pic2)
# Remember that these pictures were targets
self.experiment.Memory_Target.append(pic1)
self.experiment.Memory_Target.append(pic2)
# Get pictures for Left and Right Polygon + Fixation dot
fixdot = visual.PatchStim(self.experiment.window, tex = None, size = 12, mask = "circle", color = "white")
ImRight = visual.ImageStim(win, image="pic1",pos=(250, 0.0), size=(350))
ImLeft = visual.ImageStim(win, image="pic2",pos=(-250, 0.0), size=(350))
As you can see in the last bit I'm using psychopy instead of the built-in canvas options. Psychopy requires a path for getting pictures and using the 'pic1'/ 'pic2' variables doesn't work
So, my question: Is there a way I can stil use the other script for randomizing and selecting pictures and make psychopy recognize the 'pic1' and 'pic2' variables?
at the moment I get the following error
Error: Inline script error
In: Congruent_Right (prepare phase)
File "dist\psychopy\visual.py", line 7419, in createTexture
Python traceback:
OSError: Couldn't find image file 'pic1'; check path? (tried: C:\Program Files\OpenSesame\pic1)
If anything is unclear or more information is needed please let me know. Thanks in advance!
Comments
Hi Michel,
You could use the experiment function
exp.get_file()
to find the path corresponding to a given file name. Do the variablespic1
andpic2
refer to the exact file names of the .png files? And are the .png files saved in the file pool or in the same folder as your .opensesame.tar.gz script? In that case finding the paths simply works like this:For more information, see:
Then, you use the paths instead of the filenames when calling the psychopy function
visual.ImageStim()
.Also, make sure you use the identifier name of the object (without quotes) for the keyword argument
image
. In your script, you wroteIn this case you accidentally make the
image
argument a literal constant (i.e., "pic1"), instead of variable (e.g. "MP1.png", or "MP2.png", etc., depending on the current cycle).Does this help? Please let us know if you still encounter any problems!
Cheers,
Lotje
Did you like my answer? Feel free to
Hi Lotje,
Adding the, <exp.get_file()>, function worked like a charm!
Also, I was aware of the quotes, I think it was a remnant of the trial and error testing I did to try and make the code work. My programming skills are not that advanced .
Thank you very much! If anything else comes up I won't hesitate to ask.
Greetings,
Michel
That's great! And yes, feel free to post any further questions!
Did you like my answer? Feel free to