Add oddball to image presentation

Hello again to all,

With the help of the forum I reached my code of the experiment to work perfectly well. And now I have this code for image presentation in a specific order (below). So in total there are 480 trials with 96 sequences of all categories. Now I would like to add an oddball component to this but I am not sure how. In the total of 96 sequences I would like only in 10 of them to have an oddball inside. The oddball should replace one image in the sequence. So for example in sequence face,body,scrambled,scene,tool…, face would be replaced with a different picture or some other category in these 10 sequences.
I am trying to work my mind around it and I am thinking to maybe specify a second oddball sequence that could alternate with the regular sequence? So if regular go through the regular pattern but if oddball present the oddball sequence. Anyone has ever done something similar? thank you in advance for all the help!


Faces = [f’Face_{i}.png’ for i in range(21,44)] * 4
Scenes = [f’Scene_{i}.png’ for i in range(21,44)] * 4
Bodies = [f’Body_{i}.png’ for i in range(21,44)]* 4
Tools = [f’tool_{i}.png’ for i in range(21,44)]* 4
Scrambled = [f’scrambled_{i}.tif’ for i in range(21,44)] * 4


Sequence == ‘F’:
image_file = Faces.pop()
elif Sequence == ‘S’:
image_file = Scenes.pop()
elif Sequence == ‘B’:
image_file = Bodies.pop()
elif Sequence == ‘Sr’:
image_file = Scrambled.pop()
elif Sequence == ‘T’:
image_file = Tools.pop()

thisExp.addData(‘image_file’, image_file)

Hi Anastasia,

Two solutions I can think of.

  • If it doesn’t need to be completely random, you could define an ‘O’ explicitly in the excel file you are getting your images from
  • Alternatively you could try something such as the following:
oddball_indices = []
while len(odball_indices) < 10:
   new_index = random.randint(len(Faces))
   if new_index not in odball_indices:
      Faces[new_index] = 'oddball_image.jpg'

This will generate 10 random indices in your Faces list, taking care not to select the same index twice, and update the image at that location.

Thank you for your response. I got an error for the randint for some reason.
I did it in a more “naive” way by defining all the conditions in the excel file and adding the oddball conditions in specific trials so something like F B S Sr Odd x 100 times. Maybe too silly but it worked