Session 5 - PsychoPy Flashcards
Neuroscientists often want to present stimuli to subjects. These can be
pictures, words, sounds or more complex things like pulses of pain, electric shocks, smells or vibrations.
There are many computer programmes that can help you make and present stimuli on a computer screen such as
Psychopy
There are many computer programmes that can help you make and present stimuli on a computer screen. Here are some that we have used in the past:
ePrime
Presentation
Psychtoolbox
Psykinematix
Unity
They all have strengths and weaknesses. Many of them are
expensive, some require significant understanding of a particular programming language (Psychtoolbox = MATLAB, Unity = C#)
Psychopy is piece of software developed in Python by
scientists at Nottingham.
Why we teach Psychopy? - (3)
1: It is free. This means that lots of labs can use it and that you can personally have a copy on your own machine at no cost. In fact we encourage you to download it here: https://www.psychopy.org/download.html. You can get all the older versions (useful for compatibility) here: https://github.com/psychopy/psychopy/releases
2: It uses Python. And Python is the language that we are using for this course.
3: It is ‘careful’. Psychopy is written by vision scientists (among others) and these people need to know lots of details about the screen and the computer. They care about tiny timing errors of tens of milliseconds and how big something looks on the screen. Some of the other packages are a little more ‘loosey-goosey’.
Diagram of Builder view of Psychopy:
In Builder view, This is a way to build experiments
without coding
Why is it good to use psychopy to build experiments without using code? - (2)
or one thing, you need to know what experiments look like before writing one yourself - a ‘high level’ view is important.
But also, the Psychopy builder is a great way to make stimuli! The people who make Psychopy ensure that it runs more or less without bugs and that it does all the right things. And you can inspect and edit the code that it generates later anyway.
Diagram of Psychopy builder view labelled
What does ‘components’ section do?
The things we can add to a routine e.g., a text, picture, key or mouse responses
What does ‘flow’ section do? - (2)
Shows timeline of the experiment
Shows order in which things occur and if they repeat in a loop
What does ‘routine’ seciton do? - (2)
What happens in a single routine e.g., show some text, wait for a key press
Several routines can be added to the flow
What is a routine?
basic building block of Psychopy experiments
What does this blue box represent in flow?
A trial ‘routine’
What will this experiment do?
Show a blank screen for a certain duration
There are many different components in Psychopy such as - (8)
‘T’ = present text stimuli like for instructions and ‘get ready’
Sound: Play recorded files
Keyboard: Respond with keypress
Mouse: Respond with mouse press
Images: Images to display during experiment
Slider: Use sliders during the experiment to get participants rating
Can also get a range of stimuli like gratings, movies etc also range of response devices
In custom zone there is also ‘code’ which allows you to slot python code in experiment to control experiment and produce variables
What does clicking text from components show?
The ‘text’ has certain properties
You can edit the properities of the ‘text’ stimuli by
double clicking
What do these text properities show? - (3)
Name: name the text stimuli so far its named as ‘text’ which will show inside the routine
Start set to 0.0 meaning as soon as the routine ‘trial’ is run, the text will appear and last for 1.0s duration
The text which is displayed is ‘hello world’
When we press ‘run the experiment’ button with our text - (3)
Psychopy asks us to save the experiment
You should always make a note of where it is
At this time, we will name it as ‘hello.psyexp’ (leave extensionas it is)
When running the text the output will be - (2)
It will first pop up with box saying to input participant and session to help you keep track of participant and session, gives you a randomised participant ID - assumes running psychopy as part of experiment
Press ‘okay, the screen will go blank and some text will appear for 1.0s
You can also add a a shape (polygon) in your experiment (alongside the ‘hello world’ text) in your trial routine by selecting ‘polygon’ from components:
When double clicking on polygon, these properities show up - (basic) - (3)
It is asking you to name the polygon stimuli in trial routine so far it is set as ‘polygon’
Asking for start and end time
The shape of the polygon is going to a triangle but can alter it at the drop down menu
You can also choose a hexagon in polygon properities box by
from shape menu select regular polygon with 6 sides - making it a hexagon
Now we have in our ‘trial routine’ - (2)
a ‘text’ saying hello world for 1.0
a hexagon for 1.0s
“In PsychoPy, if both text and polygon stimuli have the same duration, what determines their order of appearance?” - (2)
“The order in which stimuli are stacked in the routine determines their presentation order.
Since both text and polygon stimuli have the same duration value (1.0), the polygon stimulus will appear ontop of the text stimulus
If we run the experiment with this
polygon appears over the text and since polygon is so big, we can’t see the text
What does the appearence section of polygon properities box show you? - (5)
Fill colour: The colour with which the polygon is filled.
Border colour: The colour of the polygon’s border.
Colour space format for the specified colours.
Opacity of the stimulus: A value of 1 indicates it’s opaque, 0 means fully transparent, and 0.5 represents translucency.
Contrast of the stimulus and width of the shape.”
How to change colour of the polygon? - (3)
Next to ‘Fill Colour,’ select ‘Specify Colour.’
Choose one of Python’s colors listed on the right or changing values of RGB channels
For example, to change the polygon’s fill color to ‘salmon,’ select it from the list.”
How to change the opacity of our ‘salmon’ colour polygon to be semi-transparent? - (2)
Navigate to the ‘Appearance’ section in the Polygon Properties box.
Adjust the opacity value to be 0.5 (or 50%) to make it semi-transparent.”
When we run our code with text stimuli (still unchanged- saying ‘hello world’) and semi-transparent salmon polygon with both duration values of 1.0s, we get when we run the experiment:
Semi-transparent salmon polygon appearing over the text saying ‘hello world,’ - both polygon and text lasting for 1.0s
You can also alter more properities of the text such as in formatting section of text properities, you can - (3)
change the font of text by changing font name (e.g., Open Sans to Comic Sans)
Specificy size of text via letter height
Specificy if the text is read from left to right (set to LTR at the moment) or RTL (right to left)
You can also alter more properities of the text such as in formatting section of text properities, you can in appearence again as well as layout tab
change the colour of the text, opacity, contrast etc.. as well as its layout like position of stimulus (set at centre at position 0,0), orientation of stimulus in degrees
The order in which stimuli are stacked in the routine determines their presentation order - (3)
“How do you change the presentation order of stimuli in PsychoPy so that text appears on top of other stimuli?” (both have a duration of 1.0s)
“To change the presentation order so that text appears on top of other stimuli:
Right-click on the polygon stimulus.
Select ‘Move to Top.’”
How to remove stimuli from Psychopy for instance? - (2)
Right click on stimuli in the routine (in this example, in trial routine right click polygon)
Should be option saying remove (polygon)