Select subset of stimuli – nothing is displayed

URL of experiment: Sign in · GitLab

Description of the problem: I try to create individual stimulus lists for each participant. There are four different stimulus categories and all stimuli of each category should be divided into biased (14 items/category) and unbiased (3 items/category) sets.

Begin experiment – Python

exp_block = 0
myTrialCounter_baseline_size = -1

# create list with all stimuli
all_la_stim = ['Stimuli/bear.jpg', 'Stimuli/dog.jpg', 'Stimuli/donkey.jpg', 'Stimuli/elephant.jpg', 'Stimuli/alligatoa.jpg', 'Stimuli/goat.jpg', 'Stimuli/leopard.jpg', 'Stimuli/rhinoceros.jpg', 'Stimuli/buffalo.jpg', 'Stimuli/whale.jpg']
all_li_stim = ['Stimuli/house.jpg', 'Stimuli/church.jpg', 'Stimuli/barn.jpg', 'Stimuli/car.jpg', 'Stimuli/airplane.jpg', 'Stimuli/bed.jpg', 'Stimuli/sailboat.jpg', 'Stimuli/bus.jpg', 'Stimuli/bicycle.jpg', 'Stimuli/couch.jpg']
all_sa_stim = ['Stimuli/frog.jpg', 'Stimuli/fly.jpg', 'Stimuli/grashopper.jpg', 'Stimuli/snail.jpg', 'Stimuli/bee.jpg', 'Stimuli/butterfly.jpg', 'Stimuli/mouse.jpg', 'Stimuli/ant.jpg', 'Stimuli/bird.jpg', 'Stimuli/scorpion.jpg']
all_si_stim = ['Stimuli/key.jpg', 'Stimuli/whistle.jpg', 'Stimuli/comb.jpg', 'Stimuli/fork.jpg', 'Stimuli/glasses.jpg', 'Stimuli/button.jpg', 'Stimuli/clothespin.jpg', 'Stimuli/pencil.jpg', 'Stimuli/wineglas.jpg', 'Stimuli/lock.jpg']

# shuffle all_stim lists to generate random biased & unbiased sets
shuffle(all_la_stim)
shuffle(all_li_stim)
shuffle(all_sa_stim)
shuffle(all_si_stim)

# create unbiased lists (each stim shown once)
stim_unbiased_la = all_la_stim[0:3]
stim_unbiased_li = all_li_stim[0:3]
stim_unbiased_sa = all_sa_stim[0:3]
stim_unbiased_si = all_si_stim[0:3]
# create biased lists (basic list with each item just once)
## in each block 6 stimuli will randomly be selected to be shown twice
b_la_list = all_la_stim[3:10]
b_li_list = all_li_stim[3:10]
b_sa_list = all_sa_stim[3:10]
b_si_list = all_si_stim[3:10]

stim_biased_la = []
stim_biased_li = []
stim_biased_sa = []
stim_biased_si = []

Begin experiment – JS

exp_block = 0;
myTrialCounter_baseline_size = (- 1);
all_la_stim = ["Stimuli/bear.jpg", "Stimuli/dog.jpg", "Stimuli/donkey.jpg", "Stimuli/elephant.jpg", "Stimuli/alligatoa.jpg", "Stimuli/goat.jpg", "Stimuli/leopard.jpg", "Stimuli/rhinoceros.jpg", "Stimuli/buffalo.jpg", "Stimuli/whale.jpg"];
all_li_stim = ["Stimuli/house.jpg", "Stimuli/church.jpg", "Stimuli/barn.jpg", "Stimuli/car.jpg", "Stimuli/airplane.jpg", "Stimuli/bed.jpg", "Stimuli/sailboat.jpg", "Stimuli/bus.jpg", "Stimuli/bicycle.jpg", "Stimuli/couch.jpg"];
all_sa_stim = ["Stimuli/frog.jpg", "Stimuli/fly.jpg", "Stimuli/grashopper.jpg", "Stimuli/snail.jpg", "Stimuli/bee.jpg", "Stimuli/butterfly.jpg", "Stimuli/mouse.jpg", "Stimuli/ant.jpg", "Stimuli/bird.jpg", "Stimuli/scorpion.jpg"];
all_si_stim = ["Stimuli/key.jpg", "Stimuli/whistle.jpg", "Stimuli/comb.jpg", "Stimuli/fork.jpg", "Stimuli/glasses.jpg", "Stimuli/button.jpg", "Stimuli/clothespin.jpg", "Stimuli/pencil.jpg", "Stimuli/wineglas.jpg", "Stimuli/lock.jpg"];
util.shuffle(all_la_stim);
util.shuffle(all_li_stim);
util.shuffle(all_sa_stim);
util.shuffle(all_si_stim);
stim_unbiased_la = all_la_stim.slice(0, 3);
stim_unbiased_li = all_li_stim.slice(0, 3);
stim_unbiased_sa = all_sa_stim.slice(0, 3);
stim_unbiased_si = all_si_stim.slice(0, 3);
b_la_list = all_la_stim.slice(3, 10);
b_li_list = all_li_stim.slice(3, 10);
b_sa_list = all_sa_stim.slice(3, 10);
b_si_list = all_si_stim.slice(3, 10);
stim_biased_la = [];
stim_biased_li = [];
stim_biased_sa = [];
stim_biased_si = [];

Begin routine – Python

myTrialCounter_baseline_size = myTrialCounter_baseline_size + 1

if myTrialCounter_baseline_size == 64:
    myTrialCounter_baseline_size = 0

if myTrialCounter_baseline_size == 0:
    exp_block = exp_block + 1
    # counters for items in shuffled lists
    ## to go through shuffled lists one by one
    u_la = 0
    u_li = 0
    u_sa = 0
    u_si = 0
    b_la = 0
    b_li = 0
    b_sa = 0
    b_si = 0
    # create stimulus lists for this block (length: 13 items/category)
    ## 6 stimuli shown twice, 1 shown once
    ## shuffle lists of biased items and extend lists each by 6 items
    # first – safety: clear stim_biased_la list
    stim_biased_la = []
    # second: add all items of basic list to current list
    stim_biased_la = b_la_list[0:7]
    # third: shuffle basic list again
    shuffle(b_la_list)
    # fourth: add another 6 items of basic list to current list
    stim_biased_la.extend(b_la_list[0:6])
    # last: shuffle current list again
    shuffle(stim_biased_la)
    
    stim_biased_li = []
    stim_biased_li = b_li_list[0:7]
    shuffle(b_li_list)
    stim_biased_li.extend(b_li_list[0:6])
    shuffle(stim_biased_li)

    stim_biased_sa = []
    stim_biased_sa = b_sa_list[0:7]
    shuffle(b_sa_list)
    stim_biased_sa.extend(b_sa_list[0:6])
    shuffle(stim_biased_sa)
    
    stim_biased_si = []
    stim_biased_si = b_si_list[0:7]
    shuffle(b_si_list)
    stim_biased_si.extend(b_si_list[0:6])
    shuffle(stim_biased_si)
    
    # also shuffle unbiased lists
    shuffle(stim_unbiased_la)
    shuffle(stim_unbiased_li)
    shuffle(stim_unbiased_sa)
    shuffle(stim_unbiased_si)

if stim_type == 'unbiased':
    if stim_category == 'LA':
        baselineSize_stim = stim_unbiased_la[u_la]
        u_la = u_la + 1
    elif stim_category == 'LI':
        baselineSize_stim = stim_unbiased_li[u_li]
        u_li = u_li + 1
    elif stim_category == 'SA':
        baselineSize_stim = stim_unbiased_sa[u_sa]
        u_sa = u_sa + 1
    elif stim_category == 'SI':
        baselineSize_stim = stim_unbiased_si[u_si]
        u_si = u_si + 1
elif stim_type == 'biased':
    if stim_category == 'LA':
        baselineSize_stim = stim_biased_la[b_la]
        b_la = b_la + 1
    elif stim_category == 'LI':
        baselineSize_stim = stim_biased_li[b_li]
        b_li = b_li + 1
    elif stim_category == 'SA':
        baselineSize_stim = stim_biased_sa[b_sa]
        b_sa = b_sa + 1
    elif stim_category == 'SI':
        baselineSize_stim = stim_biased_si[b_si]
        b_si = b_si + 1

Begin routine – JS

myTrialCounter_baseline_size = (myTrialCounter_baseline_size + 1);
if ((myTrialCounter_baseline_size === 64)) {
    myTrialCounter_baseline_size = 0;
}
if ((myTrialCounter_baseline_size === 0)) {
    exp_block = (exp_block + 1);
    u_la = 0;
    u_li = 0;
    u_sa = 0;
    u_si = 0;
    b_la = 0;
    b_li = 0;
    b_sa = 0;
    b_si = 0;
    stim_biased_la = [];
    stim_biased_la = b_la_list.slice(0, 7);
    util.shuffle(b_la_list);
    stim_biased_la.concat(b_la_list.slice(0, 6));
    util.shuffle(stim_biased_la);
    stim_biased_li = [];
    stim_biased_li = b_li_list.slice(0, 7);
    util.shuffle(b_li_list);
    stim_biased_li.concat(b_li_list.slice(0, 6));
    util.shuffle(stim_biased_li);
    stim_biased_sa = [];
    stim_biased_sa = b_sa_list.slice(0, 7);
    util.shuffle(b_sa_list);
    stim_biased_sa.concat(b_sa_list.slice(0, 6));
    util.shuffle(stim_biased_sa);
    stim_biased_si = [];
    stim_biased_si = b_si_list.slice(0, 7);
    util.shuffle(b_si_list);
    stim_biased_si.concat(b_si_list.slice(0, 6));
    util.shuffle(stim_biased_si);
    util.shuffle(stim_unbiased_la);
    util.shuffle(stim_unbiased_li);
    util.shuffle(stim_unbiased_sa);
    util.shuffle(stim_unbiased_si);
}
if ((stim_type === "unbiased")) {
    if ((stim_category === "LA")) {
        baselineSize_stim = stim_unbiased_la[u_la];
        u_la = (u_la + 1);
    } else {
        if ((stim_category === "LI")) {
            baselineSize_stim = stim_unbiased_li[u_li];
            u_li = (u_li + 1);
        } else {
            if ((stim_category === "SA")) {
                baselineSize_stim = stim_unbiased_sa[u_sa];
                u_sa = (u_sa + 1);
            } else {
                if ((stim_category === "SI")) {
                    baselineSize_stim = stim_unbiased_si[u_si];
                    u_si = (u_si + 1);
                }
            }
        }
    }
} else {
    if ((stim_type === "biased")) {
        if ((stim_category === "LA")) {
            baselineSize_stim = stim_biased_la[b_la];
            b_la = (b_la + 1);
        } else {
            if ((stim_category === "LI")) {
                baselineSize_stim = stim_biased_li[b_li];
                b_li = (b_li + 1);
            } else {
                if ((stim_category === "SA")) {
                    baselineSize_stim = stim_biased_sa[b_sa];
                    b_sa = (b_sa + 1);
                } else {
                    if ((stim_category === "SI")) {
                        baselineSize_stim = stim_biased_si[b_si];
                        b_si = (b_si + 1);
                    }
                }
            }
        }
    }
}

Offline this works perfectly fine. But when running it online, the selected stimulus is always empty and nothing is displayed.

The error message in the console when running it online returns:
log4javascript.js:148 WARN 10:29:48.598 ImageStim._setAttribute psychojs-2022.1.2.js:1049 | setting the value of attribute: image in PsychObject: baseline_size_image as: undefined

AND

log4javascript.js:148 WARN 10:30:30.320 ImageStim.draw psychojs-2022.1.2.js:1260 | the Pixi.js representation of this stimulus is undefined.

I found that there might be a problem with .slice() in JS which I tried to solve with the crib sheet to x:y but this didn’t work.

Does anyone have any thoughts on this? Thanks in advance!

If .slice() is a problem, could you try the .concat command instead? e.g. for this line:

stim_unbiased_la = all_la_stim.slice(0, 3);

try:

stim_unbiased_la =stim_unbiased_la.concat(all_la_stim[0], all_la_stim[1], all_la_stim[2]);

Also, I am not sure you are using the util.shuffle command correctly. As far as I understand, that should be at the beginning of the experiment in an only JS code and then you can use shuffle in the JS code. See this related post:

Hope that helps!

Hi dbryce,
Thanks for your suggestion! In the meantime, I had tried several other things and you were right! The concat works as does the slice but only if I assign it to a variable:

stim_unbiased_la = stim_unbiased_la.concat(all_la_stim.slice(0, 3))

So, the line above works.

And in the later versions of PsychoPy the shuffle command is already integrated in the auto translation. This means you don’t have to go the extra mile of putting shuffle = util.shuffle()in the begin experiment code. Writing shuffle() in the python box automatically translates to util.shuffle() in the JS box.

Thanks a lot!