Help with a block + randomization issue

PsychoPy 2024.2.3, standalone, on MacOS Sonoma

I’m running a shadowing task that presents sentences for participants to repeat. I seem to have bungled some part of setting up my blocking in the experimental portion (although the familiarization blocks run correctly). I’m soliciting help in diagnosing and correcting the issue.

chooseBlocks is set up this way, and references either “m_blocs.csv” or “f_blocks.csv” where they shadow either a male or female voice. Screenshot of one of the referenced CSVs below:


image

trialsLoops is set up as here, and references the proper rows (corresponding to “set” == “fam” | “dis”) in the appropriate CSV (again, screenshot below).


My intention is to present each “audioStim” from each respective CSV (m_… or f_…) once, in blocks of 23. That appears to not be what’s happening. I’m suspecting that I’ve goofed in creating the breaks and number of blocks, but I’m struggling to get my head around it again. I’m getting different amounts of each audioStim presented by participant when I look at the CSVs after.

.psyexp attached; I could also link share the full folder with files if anyone wants to look. I’d appreciate any insight.
drtHelp.psyexp (94.7 KB)

From your screenshots you are presenting 4 x 46 x 4 = 736 trials, e.g 164m, 164f, 164m, 164f.

Selected rows 0:46 doesn’t do anything if your spreadsheet has 46 conditions.

Num. repeats 4 means present 46 trials 4 times.

Might this tip help?

Oh, I’m starting to see what I’ve done. I built this a while ago and have gained some dexterity in setting these things up in the first place since then, so it’s a little wonky getting my head back around this one that’s already set up.

So it is queued up to the present each inner loop 4x, and I’m using a code chunk to take breaks every 23 trials and to end the loops when I thought it had concluded (even though if it were configured correctly, it would do that on its own). The 0:46 just represents the subset of the conditions referenced that correspond to experimental items; the other items are familiarization and administered in a prior block.

I don’t believe I mentioned this clearly before, but I’m looking for alternating blocks 23m, 23f, 23m, 23f (or f-m; set by a variable at the start). I think what’s got my brain tripped up at the moment is alternately drawing m or f items appropriately between the blocks and setting up the num. repeats for each loop.

Those links did help, and I finally had a chance to take a crack at re-working this. I stripped it down to just the experimental trials and the loop for that, but I’m running into a problem.

I am down to one spreadsheet (attached) with stimuli in rows 0:93 (including header).

I inserted this in the first routine in the “Before Experiment” tab:

useRows = []

m_trials = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46]
shuffle(m_trials)

f_trials = [47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93]
shuffle(f_trials)

voice_order = [m_trials, f_trials]
shuffle(voice_order)

useRows.append((voice_order[0])[:23])
useRows.append((voice_order[1])[:23])
useRows.append((voice_order[0])[23:])
useRows.append((voice_order[1])[23:])

print(useRows)

The plan is to run it in one loop (sequential) with a break routine every 23, which will coincide with alternating the loops drawn from either m o fvoiced rows.

I print useRows to the console, and it seems to print each row once (as desired):

[[66, 90, 74, 70, 93, 78, 57, 60, 61, 55, 87, 89, 59, 54, 67, 68, 47, 79, 86, 83, 77, 51, 71], [12, 19, 29, 40, 34, 33, 39, 46, 10, 17, 18, 38, 21, 32, 20, 31, 9, 28, 41, 24, 23, 6, 30], [64, 75, 65, 53, 73, 62, 92, 58, 91, 88, 84, 49, 69, 52, 72, 63, 56, 50, 48, 81, 76, 82, 85, 80], [15, 1, 25, 2, 8, 22, 11, 14, 45, 44, 37, 13, 42, 36, 26, 43, 16, 7, 3, 35, 27, 4, 5]]

Here’s the problem: PsychoPy launches the experiment, prints useRows to console, and then freezes prior to proceeding. No error or warn, it just freezes. ESC won’t close the window. Instead I have to force quite the whole thing and restart PsychoPy, so I haven’t been able to test further. Any ideas?

Try Begin Experiment not Before.

I tried that – just moved it from ‘Before’ to ‘Begin Experiment’. Now it won’t even print to console before it freezes as before.

The closest I can get to making anything happen is by disabling all other routines, commenting out any other code in the above-referenced routine, and zero-ing out the loop seen here. The code above is in a chunk in routine ‘s’ at at 'Begin Experiment:

That gets it to print useRows to console but it still freezes before it can proceed. Is there anything in that code that would gum something up moving forward?

I note you are on a Mac. Have you tested your installation? It might also be worth upgrading to 2024.2.5.

That may have helped – either upgrading or restarting or the two together.

I’ve tweaked the code a bit, and the issue seems to be that “Selected Rows” is unhappy with useRows (and $useRows) as a list. Is that typical?

The code (nb. commenting out shuffle() for the moment just to look at slicing)

useRows = []

m_trials = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46]
#shuffle(m_trials)

f_trials = [47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93]
#shuffle(f_trials)

voice_order = [m_trials, f_trials]
shuffle(voice_order)

useRows.extend((voice_order[0])[:23])
useRows.extend((voice_order[1])[:23])
useRows.extend((voice_order[0])[23:])
useRows.extend((voice_order[1])[23:])

produces a list like (nb. I switched .append to .extend to see if it liked a flatter list any better–it did not)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93]

I’m just getting this error: trialList.append(allConds[int(ii)])
IndexError: list index out of range

Hello @dwbatten

You $condsFile is 46 rows long, isn’t it (see posting above)? But useRows has 94 elements.

Best wishes Jens

I am worried I hadn’t gotten those quite right at the start, but I have dropped all the stimuli into a single conditions file. That has 93 rows including header.

Excel rows 2:47 contain stimuli in condition “m” voice, and 48:93 contain stimuli in “f” voice.

I’m using voice_order to draw stimuli from the (at least hopefully) correct ranges within that single conditions file.

Ignoring what’s here, I was able to play all and only “m” voice stimuli by hard entering 0:46 for selected rows, and all and only “f” stimuli by entering 46:93 in selected rows.

I have gotten things to at least advanced to the trial and run by creating an outer loop referencing the conditions file:

I have both set to sequential, but I’m not sure if that’s right. My hope would be that it would advance through the sequence already drawn for useRows, but it’s just proceeding in the order of the Excel sheet even when I’ve shuffled both m_trials and f_trials.

Edit – attached conditions file
allExpDis.xlsx (9.9 KB)

Hi @dwbatten

I have made a simple toy version of your experiment. It shows the index from 0 to 91 from a condition file. This gives 92 trials.

Begin experiment tab

useRows = []

m_trials = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46]
shuffle(m_trials)

f_trials = [47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91]
shuffle(f_trials)

voice_order = [m_trials, f_trials].
shuffle(voice_order)

useRows.extend((voice_order[0])[:23])
useRows.extend((voice_order[1])[:23])
useRows.extend((voice_order[0])[23:])
useRows.extend((voice_order[1])[23:])

So m_trials go from 0 to 46 and f_trials from 47 to 91. You might want to use 0 to 45 as that gives you 46 trials and 46 to 91 as that gives you the remaing 46 trials. When using an index it is often best to turn off randomisation as a sequence is easier to control.

When I uncomment the shuffle commands as I have done above I get a randomised order.

Best wishes Jens

This looks like it works. I’ll keep tinkering with it, but so far so good. I appreciate all the help here; I’ll end up with a much more tidy design than I began with :slight_smile: