Flicker paradigm images

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 1.85.2
Standard Standalone? (y/n) If not then what?: Yes
What are you trying to achieve?: I am creating a flicker paradigm where an image (image1) is displayed for 500 ms followed by a blank for 250ms and then another image (image2) for 500ms. Hence, I would like a continuous loop of image1, blank, image2, blank, etc. which stops until the spacebar is pressed.

What did you try to make it work?: I have put the two images in a .xlsx, used a $ to link them and ā€˜set every repeatā€™ is selected.

What specifically went wrong when you tried that?: When running the experiment, image1 appears for 500ms followed by the 250ms blank and then image1 is displayed again for 500ms immediately followed by image2 for 500ms, a 250ms blank and then image2.

I would greatly appreciate if someone could provide advice on how to display image1, blank, image2, blank, etc.
Also, is it possible to make this loop occur infinitely until the spacebar is pressed and how should I terminate this loop when the spacebar is pressed?

Thanking You

Will you ever be using other images than Band 1.jpg and 'Bridge .jpg?

Hi

Yes, I will be having around 20 trials (routines) that have to show a different pair of images each time. So in total, I will have 40 images. Is it possible to have all 40 images in one excel file and select which image I need from there in my Image Component?

I managed to display the images the way I want them to, but I had to use the root path i.e. C:\Usersā€¦ so my experiment is not portable. Could you please tell me how to select which images I want from my excel file using the $pictures?

I havenā€™t used Psychopy before so apologies in advance if I seem unfamiliar with its features.

Thank You

You probably really need to spend the few minutes it takes to watch Jon Peirceā€™s Youtube tutorial on the Stroop task. It doesnā€™t deal with images, but it will show you how to structure your conditions file. Hint:

  • You need two picture columns, not one, as the variables for each trial need to be on the same row of the file.

Re images, donā€™t use absolute paths. Instead specify a location relative to your .psyexp Builder file. e.g. if the images are in the same folder, just give the bare filenames. If they are tidied in a subfolder, prefix the file name with that folder name (with no / first) (e.g. images/Band 1.jpg). Finally, use proper forward slashes in your paths, not Windows-style back slashes, which can cause a world of hurt.

Once it is working, come back to us on how to use static periods to get better timing for loading your images.

1 Like

Hi Michael

Thank you for your advice on inserting the images. I managed to insert them using both the methods you mentioned and Jon Peirceā€™s video also makes more sense now.

However, I cannot find the setting for static periods. I am also unable to cycle my two images with a blank screen between the second and first and end the loop when the spacebar is pressed (in spite of having ā€˜Force end of Routineā€™ selected).

Hi Michael,

I was able to insert ā€˜blanksā€™ between my two images. However, is it possible to make this loop occur infinitely and end when the spacebar is pressed? I have set the nReps $ in the loop Properties to 100 so that the loop continues for a good amount of time.

As of now, when I use a keyboard component, it seems to have become a part of the loop. After showing image1, blank, image2, blank, I have to press the spacebar in order for the loop to start at image1 again, rather than the spacebar ending the loop even though I have ā€˜Force end of Routineā€™ selected.

Thanking You

That setting does just exactly what it says: immediately end the routine. It doesnā€™t end any loop(s) that might or might not encompass that routine. You could delete the keyboard and instead insert some code in the ā€œevery frameā€ tab of a code component, which would do what you want:

keys = event.getKeys()

if 'escape' in keys: # need to handle this manually now
    core.quit() 

if 'space' in keys:
    continueRoutine = False # immediately exit the current trial
    myloop.finished = True # but also exit the surrounding loop
2 Likes

Hi Michael

Thanks a lot for the code - it ends the loop as I want it to.
I would like to measure the time (reaction time) it took for participants to press the spacebar on each trial. Do I need to insert a keyboard component to obtain that in my output? My output now only shows the time it took to press the spacebar in the keyboard component of my Instructions routine.

Will I also be able to obtain the reaction time for my other trials/loops?

Thanks

Because we are handling the keypresses in code rather than using a keyboard component, we now need to do some things manually that we otherwise would get ā€œfor freeā€ by using the keyboard component. e.g. extend the code above as below, to explicitly record a reaction time in the data (i.e. this will add a new column to your data output file, with the specified name):

if 'space' in keys:
    thisExp.addData('my_reaction_time', t) # t = current trial time in seconds
    continueRoutine = False # immediately exit the current trial
    myloop.finished = True # but also exit the surrounding loop
1 Like

Hi Michael

Thank you once again for the code. I have looped (nested) my ā€˜crossā€™, ā€˜trialsā€™ and Responseā€™ routines since I want them to be repeated 20 times.
However, the timing for ā€˜my_reaction_timeā€™ that I get in my output file doesnā€™t seem to reflect the actual time I took to press the spacebar. Could you please tell me the format that PsychoPy displays it in? I timed myself with a stopwatch and the timings for the 4 conditions should have approximately been (in order of display): 12, 12, 20 and 22 seconds.

I have attached the conditions file (Demo.xlsx) and output file for your reference.

I greatly appreciate the help that you have provided me.


Demo.xlsx (8.0 KB)
Demo_5_2017_Aug_05.csv (5.2 KB)

Iā€™m not sure I really understand the question, but Iā€™m guessing that the issue is that the code is currently reporting the reaction time as the Builder variable t, which represents the time in seconds since the start of the current routine. This resets to zero on every iteration of the loop surrounding that routine, whereas your trials are based on multiple repetitions of that routine, and so I guess you want the cumulative time elapsed since the start of the first routine in the current trial?

If so, you need to insert something like this in the Begin routine tab to set an absolute anchor in time:

if myloop.thisN == 0: # only on the first routine of each trial,
    # get the current overall experiment time:
    trial_start_time = globalClock.getTime()

then change the line given above to be:

thisExp.addData('my_reaction_time',  globalClock.getTime() - trial_start_time )

i.e. calculate the reaction time to be relative to the start of the first routine in the trial, rather than the start of current repetition of the routine.

1 Like

Hi Michael

It worked! Thank You very much for your help. I am truly grateful to you for taking your time to help me understand PsychoPy and build this experiment :smiley:
Sorry if I have not been clear when explaining my difficulties.

Best Wishes,

Charlie

Hi There,

Iā€™m also trying to build a similiar experiment and this thread has been an extremely valuable resource, however I am encountering one key issue:

When trying to call my first image from the condition file ā€˜picture1ā€™, the whole image row is run (including values from column two ā€˜picture2ā€™).

Below I have included an image of the experiment design & an example stimulus condition file

image of experiment design

Iā€™d greatly appreciate any advice on how to only display a single column using a condition call, for instance $picture1

Kind Regards,
Maxwell

Can you please explain more precisely what you mean by this? What is the exact sequence of events during your trial?

Hi Michael,

Apologies for the lack of clarity:


In my trial the sequence of events is:

i) Presentation of an image containing an array of faces
(located using the condition $picture1)

ii) Presentation of a masking blank image

iii) presentation of an edited version of the first image
(located using the condition $picture2)

iv) presentation of a masking blank image

v) The trial then loops, until the participant presses a key to indicate that they have detected the change.

vi) Once the key has been pressed, the participants reaction time is recorded, then the next trial commences


The issue I am encountering is as follows:

i) Presentation of image one (called by $picture1), then instead of simply displaying image one, it goes on to present an image from $picture2 as well.

ii) Presentation of a masking blank image

iii) presentation of an edited version of the first image
(located using the condition $picture2)

iv) Presentation of a masking blank image

v) The trial then loops, until the participant presses a key to indicate that they have detected the change.


So essentially, the trial is showing an image from each condition column, when it should only display one.

The experiment runs four blocks, each with four trials, containing an image and an edited version of the image.

I hope this clarifies the problem!

The image components can only show what you tell them to show. I note that the T1 routine is surrounded by a loop, so it will run multiple times per trial. I suspect that you are just seeing the images from picture1 and picture2 in their proper sequence (i.e. shown by their respective image components) but that performance problems might be causing delays. Try inspecting your log files to see what events happen and when.

It would be a good idea for you to pre-load your images. It takes quite some time for images to be loaded from disk, so in a flicker-type paradigm, you need them prepared prior to the time you want them to start displaying. Try shifting your blanking images to come before rather than after your images (this will seem the same in a loop-like arrangement), and insert a ā€œstatic periodā€ component to coincide with each. Then in your image components, select that the image updates occur during the associated static period prior to each image component. That option appears only when a static period has been inserted. i.e. the images will load during the mask period, ideally so that they are loaded and ready prior to the start time of each image component.

1 Like

Thank you for the prompt reply Michael, Iā€™ll give this a shot, much appreciated!

Hi Michael,

Tried that fix this morning and it worked perfectly, really appreciate the help with that!