How to access trial number of routine (or, how to create catch trials within routine)

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2021.2.3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:

I want to make sure 25% of my trials are catch trials, within a routine.

What did you try to make it work?:

I’ve created a 100x1 array, with 75 slots filled with 1’s, and 25 slots with 0’s.
I shuffle this array.

Now, I want to access the index of each array, such that if array(N) is 1, I call for a regular trial, if array(N) is 0, I call for a catch trial.

More technically, in the “Begin Experiment” tab, I have written:

onesArray = [ ]
onesArray[:25] == 0
onesArray[51:100] == 1
shuffle(onesArray)

In the “Begin Routine” tab, I have written:

for trialNum in range(100)
checkCatch = onesArray[trialNum]

if checkCatch == 1:
contrastVal = level #the level variable comes from staircasing.
else:
contrastVal = 0

What went wrong when you tried that?:
I think the problem is: I don’t know how to correctly call for the index of each trial.
Most often, I get this error:

TypeError: ‘list’ object is not callable

I have tried calling for the array in a multitude of ways, including trial number of the current routine, creating a for loop of some specific range, etc. None seem to work.

Thank you so much!

Hi There,

I have a suspicion this might be more complicated than it needs to be. Is there a reason that you can’t just have a spreadsheet where 25% of the rows correspond to “catch” trials?

How does a catch trial differ from your other trials?

Thanks,
Becca

1 Like

Hi Becca, thanks for your reply! I wanted the catch trials to come up in a unique randomized order each time. Also, because these are catch trials within a staircase, I wasn’t sure how to convert between the QUEST staircase conditions file and regular catch trials.
Maybe the QUEST algorithm in PsychoPy already covers this, if there is no simple fix, I’ll go look at their GitHub page for insight! If you have any ideas, I’d appreciate them also. Thank you so much.

Hello ah5005

is the code you posted above the code you used in your experiment?

onesArray[:25] == 0
onesArray[51:100] == 1

I think the code does not what you want it to do, at least as I understand it. In PsychoPy you would write something such as

onesArray = []
for i in range(100):
    if i < 25:
        onesArray.append(0)
    else:
        onesArray.append(1)

shuffle(onesArray)

to fill the array(list) in a Begin Experiment tab.

Then in the Begin Routine tab:

checkCatch = onesArray.pop()

if checkCatch == 1:
    contrastVal  = level
else: 
    contrastVal = 0

BTW, if you follow Becca’s advice and put the 0s and 1s in an Excel-file, loop over this file and set it to randomize, you’ll get a unique randomized order each time the loop is called.

Best wishes Jens

2 Likes

That worked, thank you so much Jens and Becca!