Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Referencing to image file pool in psychopy

edited October 2013 in OpenSesame

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

  • edited 4:19AM

    Hi Michel,

    You could use the experiment function exp.get_file() to find the path corresponding to a given file name. Do the variables pic1 and pic2 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:

    path1 = exp.get_file(pic1)
    path2 = exp.get_file(pic2)
    

    For more information, see:

    Then, you use the paths instead of the filenames when calling the psychopy function visual.ImageStim().

    ImRight = visual.ImageStim(win, image=path1,pos=(250, 0.0), size=(350))
    

    Also, make sure you use the identifier name of the object (without quotes) for the keyword argument image. In your script, you wrote

    ImRight = visual.ImageStim(win, image="pic1",pos=(250, 0.0), size=(350))
    

    In 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 Buy Me A Coffee :)

  • edited October 2013

    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

  • edited 4:19AM

    That's great! :) And yes, feel free to post any further questions!

    Did you like my answer? Feel free to Buy Me A Coffee :)

Sign In or Register to comment.