For my project I want to generate conditions files. I want to make a randomized sequence of 9 images from the set of 24 images and generate 150 files and use them with psychopy. Overall, I want the images equally distributed which will be in-between 55-56 times. I need help to know where I am making an error and once conditions file are ready how to integrate them with experiment file to avoid errors.
e.g
images = [1,2,3,-------24]
randomize set = [1,4,2,5,21,11,24,16,8]
I want 150 sets with equal distribution/count of 24 images.
I am adding scripts below.
‘’’
This script is used to generate condition files for 150 participants, where each participants is presented with 9 images
randomly drawn from a set of 24 images. Each of the images are eventually presented 50 times.
‘’’
import the libraries needed
import pandas as pd
from numpy.random import shuffle
from psychopy import core
list of images - currently with generic naming convention - researcher would need to change the names on line 14
researcher needs to change it to the appropriate file names (i.e. file name + extension)
if images are in a subfolder, the path must also be included/specified e.g. stimuli/image1.jpg where stimuli is the name of the subfolder and image1.jpg is within it
images = [‘im1’, ‘im2’, ‘im3’, ‘im4’, ‘im5’, ‘im6’, ‘im7’, ‘im8’, ‘im9’, ‘im10’, ‘im11’, ‘im12’, ‘im13’, ‘im14’, ‘im15’, ‘im16’, ‘im17’, ‘im18’,‘im19’,‘im20’,‘im21’,‘im22’,‘im23’,‘im24’]
parameters
ims_per_participant = 9 # since there are 24 images to use in total and each participant sees 9 randomly from this set
n_participants = 150 # and it is projected that there will be 150 participants, with each image presented at least 50 times
repeat the splitting and randomising process 50 times
for i in range(75):
shuffle(images) # randomise the images
p1 = {‘images’ : images[0:12]} # select the first 9 images
p2 = {‘images’ : images[13:24]} # select the last 9 images
ps = [p1, p2] # the resulting separated images
for pi, p in enumerate(ps): # save the separated images by numbering them
p = pd.DataFrame.from_dict(p)
p.to_excel(‘condition_file_’+str(i+1)+‘_part’+str(pi+1)+‘.xlsx’, index = False)
Option 2 I tried was
import random
#list of images
images = [‘im1’, ‘im2’, ‘im3’, ‘im4’, ‘im5’, ‘im6’, ‘im7’, ‘im8’, ‘im9’, ‘im10’, ‘im11’, ‘im12’, ‘im13’, ‘im14’, ‘im15’, ‘im16’, ‘im17’, ‘im18’,‘im19’,‘im20’,‘im21’,‘im22’,‘im23’,‘im24’]
#using the sample() method
for i in range(150):
sample_images = random.sample (images,k = 9)
#displaying random selections without
#repetitions
print(sample_images)
Thanks