OS Win 11
PsychoPy version 2023.2.1
**Standard Standalone? y
I am brand new to PsychoPy and coding–I first built my study routines with both an image and text component. Before I had code added to correctly select 3 images from each of two folders for each block, both my images and text were appearing (the images just were not constrained to particular blocks, instead it was cycling through my entire list of images). I added the following code before the first study routine to set the images; I have a loop around each block w/nReps set to “block1” (etc) and then an outer loop with a conditions file with headers “block1” Block2" etc. The images are correctly randomized but the text has disappeared. Can anyone see what in this code might be causing the text component to be ignored? (I also tried separating the text into a separate routine within the loop).
import pandas as pd
import random
fileName = [‘Nameable_Group.csv’, ‘Unnameable_Group.csv’]
conditionFile = pd.DataFrame(columns=[‘ImageName’]) # where ‘ImageName’ is the column name for your images
for files in fileName:
myDat = pd.read_csv(files) # Get conditions file
myDat = myDat.sample(frac=1).reset_index(drop=True) # Shuffle the dataframe
myDat = myDat.head(6) # Take first 6 rows from sheet
conditionFile = conditionFile.append(myDat) # Append to new conditions file variable
conditionFile.to_csv(“randImageName.csv”, index=False) # Save to new csv file for use in the loop handler.
nam_files = [“Objects_and_lures/inanimate{}.jpg”.format(format(image_number, “02d”)) for image_number in range(1, 43)]
unn_files = [“NOUN_and_lures_2/abstract{}.jpg”.format(format(image_number, “02d”)) for image_number in range(1, 43)]
Shuffle the order of blocks if needed
block_order = list(range(14))
random.shuffle(block_order)
Loop to create the lists for each block
block_images_list =
for block_num in block_order:
# Ensure that the same image does not appear in consecutive blocks
nam_selection = random.sample(nam_files, 3)
unn_selection = random.sample(unn_files, 3)
# Randomize the order of presentation within the block
block = random.sample(nam_selection + unn_selection, 6)
block_images_list.append(block)
Flatten the list of lists into a single list
block_files = [item for sublist in block_images_list for item in sublist]
Save the list of images for each block to a file
image_list_df = pd.DataFrame({‘ImageName’: block_files})
image_list_df.to_csv(“block_images_list.csv”, index=False)