psychopy.org | Reference | Downloads | Github

Stimulus display order after import (Ubuntu 16.04)

Hello,

I’m using ‘glob.glob(os.path.join…’ to import some image stimuli, I’m then sorting these stims into a list and displaying them sequentially. My issue is, Psychopy seems to be displaying the images in a random order on every run; I cannot detect any pattern at all. I’m using Ubuntu 16.04, I’m not sure if this is the issue or not.

Here is the code:

#import stims
stim_import = glob.glob(os.path.join('/home/jon/exp/stims/stims','*.png'))

set_one   = [visual.ImageStim(win, img, name='set_one-' + img)   for img in stim_import[:8]]
set_two   = [visual.ImageStim(win, img, name='set_two-' + img)   for img in stim_import[8:15]]

purp = [set_one[0], set_one[1], set_one[2], set_one[3], set_one[4], set_one[5], set_one[6], set_one[7]]

for i in purp:
    i.draw()
    win.flip()
    core.wait(2)

win.close()
core.quit()

I want the images to import in a particular order, does anyone know how Psychopy selects stimuli from a directory to import? how does it select which image to import first, and why would this change every time this process occurs?

Cheers,
Jon

I don’t think the results of glob.glob (which is part of the standard library, rather than part of Psychopy) are guaranteed to be returned in any particular order. How are your set of PNG files named?

Would you be able to suggest a better way to import stimuli, a more Psychopy-ish way? They’re named like this:

blue_circle.png
blue_square.png
blue_triangle.png
green_circle.png
green_square.png
green_triangle.png

etc…

If the order above is the order that you want them to be in the list, you could do something like:

stim_dir = "/home/jon/exp/stims/stims"

colours = ["blue", "green"]
shapes = ["circle", "square", "triangle"]

stim_import = [
    os.path.join(stim_dir, colour + "_" + shape + ".png")
    for colour in colours
    for shape in shapes
]
2 Likes

That method works much nicer, thank you!