Hello All,
I have a task in which participants are presented with one image followed by another image. Fairly simple aside from the fact that I have 3 conditions files with these images that I would like to pseudo-randomly select from.
Here are examples of the 3 conditions files with a sample of their respective parameters:
threat1.csv
image1.jpg image2.jpg
image3.jpg image4.jpg
image5.jpg image6.jpg
threat2.csv
image1.jpg image7.jpg
image3.jpg image8.jpg
image5.jpg image9.jpg
neutral.csv
image10.jpg image11.jpg
image12.jpg image13.jpg
image14.jpg image15.jpg
The 2 threat files contain 40 images and the neutral condition contains 20 images. In total, the whole neutral file should be used and twenty from each threat file, for a total of 60 trials. These should be presented randomly. In addition, my threat files contain the same image for the first image presentation (see sample above), but the second image is different in each file. I would like for experiment to not ever have the same initial image presentation, so if image1.jpg is presented from threat1.csv, the program does not select image1.jpg from threat2.csv. I hope this makes sense.
I have attempted to use and modify code that I found on the old google forum to at least randomly select images to start (see below post). However, I received a few error codes, and it does not work.
I am hoping that someone may help me 1) get the code to work for a PC using Psychopy v1.83.00 and 2) modify it so that the presentation of threat images do not repeat. I am aware that the version of psychopy is a bit out dated, but we are running a study that was programmed on this version and have decided to not update until that study is complete.
Please let me know if additional information is needed and thank you!
Danielle
import csv
newConditions = [] #define an initially empty list
for fileName in ['Neutral.csv', 'Threat1.csv', 'Threat2.csv']:
conditions = data.importConditions(fileName) #creat a list of dictionaries
shuffle(conditions) #randomize their order
conditions = conditions[0:20] #select just twenty of them
newConditions.extend(conditions)
#will end up as 60 randomly selected but balanced for consistency trials
#write out the conditions for this run of the experiment
header = newConditions[0].keys() # get the header labels as a list
output = csv.DictWriter(file, fieldnames = header) #arrange to write our dictionaries to it
output.writeheader()
output.writerows(newConditions)```