psychopy.org | Reference | Downloads | Github

Preloading stimuli from conditions file with builder

OS: macOS Catalina
PsychoPy version: 2021.1.4
Standard Standalone: Yes

What are you trying to achieve?:

I have an experiment that needs to load a unique set of images and text for every trial. I have it set up like this:

With the conditions set in an excel file:


I don’t want to add an ISI between trials, as this will interrupt the narrative (with the exception of specific trials, for which I have an ISI set to 12 - reaction time on the prior trial). Unfortunately, I am running into some timing inconsistencies on the order of 1 second, which is not ideal for an fMRI experiment. I am hoping to preload all of the image stimuli before the experiment.

What did you try to make it work?:

I tried adding a code component for “before experiment” with:

import glob
import os
filenames = glob.glob(os.path.join('/stim/','*.png'))

images = []
images.append(visual.ImageStim(win=win, image=file))

And then setting the image in the component by using $images[Image_Character], where “Image_Character” is the column in the excel file containing the name if the image file (not sure if this is the correct way to do this?).

What specifically went wrong when you tried that?:
There must be something wrong with my code, because I get the following error:

Alert 4210:JavaScript Syntax Error in ‘Before JS Experiment’ tab. See ‘Line 1: Unexpected token’ in the ‘Before JS Experiment’ tab.
For further info see 4210: Probable syntax error detected in your JavaScript code — PsychoPy v2021.2

I am very new to java script so I’m not sure exactly what the issue is, any advice would be greatly appreciated!

The syntax error is probably just that you’re missing ; at the end of each line, but it also looks like you’re using append as if it’s a list when you need push as it’s a dict. I also can’t see where file is defined. Try this:

import glob
import os
filenames = glob.glob(os.path.join('/stim/','*.png'));

var images = [];
for (file of filenames) {
    images.push({key: file, value: visual.ImageStim(win=win, image=file)});
}

Hello,

do you plan to run the fMRI-experiment on-line? Because only then the JS-part is interesting.

Unfortunately, I am running into some timing inconsistencies on the order of 1 second, which is not ideal for an fMRI experiment.

I cannot recommend running a fMRI-experiment on-line. Is there any reason why you don’t run if locally?

All images that constant in an experiment are preloaded at the beginning of the experiment. Perhaps, there are some images that you could make constant?

Best wishes Jens