psychopy.org | Reference | Downloads | Github

Possible to generate other types of element with ElementArrayStim?

This might sound like a beginner question, but is it possible to create other types of element (ie. a text or a .jpg image) other that the standard gabor (or dots) patches? For example, I want to have 50 random crosses or 50 random images to be generated on the screen.

The API at http://www.psychopy.org/api/visual/elementarraystim.html#psychopy.visual.ElementArrayStim doesn’t seem to elaborate much on this, or at least, it doesn’t seem like there is an option to do so.

Images will work as the type of element in ElementArrayStim; you can provide the filename as the elementTex option. For crosses, you can set elementTex=None and elementMask="cross".

Thanks! That worked. Just two follow up questions - 1) is there a list of possible other items that can be inserted apart from crosses? And also, 2) what about text in the form of words or digits in place of crosses and dots? How do you go about duplicating those?

  1. I’m not sure if it is actually documented anywhere, but the code that generates the textures is at psychopy.visual.basevisual.TextureMixin._createTexture (current) and the options can be seen there.

  2. You could perhaps use BufferImageStim to render a text stimulus and then use the result as the texture for an ElementArrayStim. But that gets a bit tricky with the alpha channel, so you are probably best to just implement the ElementArrayStim functionality manually (i.e. draw your text stimulus multiple times, updating its pos attribute each time), if that is feasible time-wise.

is there a way of using a list of filenames, one for each element? sorry to be so dense, but the list crashes with an elementTex. clearly i dont really understand what a texture is.

is there a way of using a list of filenames, one for each element?

I don’t think so, with ElementArrayStim - it is mostly for when you have a single ‘texture’ (pattern of pixels, or description that leads to the generation of such a pattern) and you want to show multiple instances of that pattern with a small set of variations (position, orientation, contrast, etc.).

If you have a list of filenames (stored in image_filenames, say), one potential way (if the number of images and their dimensions aren’t too large) would be to construct a list of ImageStim items:

image_stims = [
    psychopy.visual.ImageStim(win=win, image=image_filename)  # set other params as required
    for image_filename in image_filenames
]

and then draw each when required:

for image_stim in image_stims:
    image_stim.draw()