30 Using input files
Information in an input file can have different purposes. For example, you can use this information to:
- Change a component property from one trial to the next.
- Determine if a participant responded correctly.
- Add additional information to the PsychoPy output file (we will discuss output files in more detail in a future lab).
Let’s look at these use cases in turn.
30.1 Changing component properties
30.1.1 The basic idea
How do you tell PsychoPy that you want to change a component property (e.g., a piece of text, an image or a stimulus location) from one trial to the next? You tell PsychoPy that the property is variable.
How do you tell PsychoPy that the component property is variable? You provide PsychoPy with a variable name and set the component property to “set every repeat”.
Frequently, the variable name will come from the header row in your input file.1 It is probably most instructive to have a look at a more detailed example of this idea. We will use the Text property of the Text component for explaining the basic idea in more detail. Other properties will then be dealt with more briefly.
30.1.2 Changing text
If your aim is to change a piece of text from one trial to the next, you must update the Text property of the Text component. For this to work, you need:
- A variable name in the Text property field that is preceded by a
$
sign.2 - An input file that has a column header that matches this variable name exactly.
- To select “set every repeat”.
These requirements are illustrated here:
As this is such a common mistake, let us reiterate that the variable name in the Text field and the header in the input file need to match exactly. For example, the experiment will not run if you have stim
in the Text field and Stim
in the input file!
A frequent error that can be hard to spot is a space after the column header in Excel, e.g., stim
. The most straightforward way to identify this issue is to open the input file in Excel and to right-align the contents of the columns.
Note that sometimes you might need more than one column in the input file to update stimulus properties. For example, to udpate the Stroop stimulus RED, you need to get information about the word as well as the colour from the input file. Thus, your input file needs separate columns for defining word and colour (see my Stroop experiment in Chapter 28). The same is true when you would like to change, say, the stimulus and its location from trial to trial.
30.1.3 Changing images
If your experiment uses images that change from trial to trial, you will need to use an Image component and tell PsychoPy that the image should be updated on every repeat. The basic idea is the same as before: You provide PsychoPy with a variable name preceded by a $
sign and select “set every repeat”:
Again, the variable name needs to match a column header in the input file:
Note that the file name needs to include the extension of the file (.png
in this example). Also, when defined without a path, the images must be located in the same folder as the .psyexp
file.
30.1.4 Changing locations
If your experiment requires the location of stimuli to change from trial to trial, you will need to use the Position property of your component. The basic idea is the same as before: You provide PsychoPy with a variable name and select “set every repeat”. For example, if you would like to change the stimulus position along the y-axis, you could achieve this in the following way:
Again, the variable name needs to match a column header in the input file:
You might have noticed a difference to before though: We did not include the $
sign. Why is this? Note that next to “Position [x,y]” there already is a $
sign. This indicates that you should not add a $
sign here.3
What is the logic behind this? You do not need to add the $
sign when it does not make sense to enter text into a given field. For example, the position along one of the axes can only be a number. If you enter text, it is clear that this is meant to be a variable name. On the other hand, other properties can be represented by text (e.g., colours or file names). In these cases, you need to add the $
sign to indicate that you would like PsychoPy to interpret the input as a variable name.
30.1.5 Changing other properties
All other properties that can be changed from trial to trial (e.g., size, colour or orientation) work analogously to the examples illustrated above.
30.2 Determining a correct response
Information in the input file can also be used to determine if the participant gave a correct response. Here is the Keyboard component from our flanker task:
The orange arrow illustrates how the column called corrAns
in our input file is linked with our Keyboard component. Note that you need to tick “Store correct” for the field “Correct answer” to appear. Also note that the “Allowed keys” can be constant as these are the same on every trial.
If “Store correct” is ticked and a variable name for “Correct answer” is provided, PsychoPy will automatically write information about the accuracy of responses to the output file it produces. However, this information is not just useful for the output file. It can also be used to give participants online feedback about their performance. This is something we will have a closer look at next week.
30.3 Adding further information to the output file
What happens to information in the input file that is not used in one of the components? For example, the information about the congruency in our flanker task? Like the other information in the input file, it will automatically be written to the output file that PsychoPy creates. When you analyse your data, it will be helpful to have this information readily available.
30.4 Using input files quiz
You want this Image component to present images in your experiment:
Your images are inside a folder called “images” in the main experiment folder. The images are called left.png and right.png.
What is the correct setup for the input file?:
The correct option is:
Variable names in the Excel file header row must not use the dollar sign. The Image component uses “stim” as variable name, so the corresponding column in the Excel file must use “stim” as well. The images are in a subfolder, so the path to that subfolder must be added. The subfolder is called “images”, not “image”.
You want to present the letter K on half of your trials. The other half of the trials should present the letter G. These are your Text component properties:
Will this work?
This will not work because the Text field is not using a variable. Using “set every repeat” is necessary, but not sufficient. Adding a second Text component will not solve the problem either (it would simply present an additional letter). Using “$K” will also not help as the relevant part is to use a dollar sign and a variable name, not to prepend the actual stimulus with a dollar sign.
To modify the text presented by a Text component from one trial to the next, you must do the following:
- The variable name in the Text field must be preceded by:
- The variable name in the Text field must match:
- You should select the following option:
The variable name in the Text field must be immediately preceded by a $ sign, with no space in between. The variable name must match the relevant column header in the input file. “Set every repeat” should be selected. While “Set every frame” would also work, it is a poor choice if a stimulus only needs to be updated only once at the beginning of the trial.
When you learn how to give feedback, you will see that you can also use Python code to create variable names.↩︎
Why is there a
$
sign before the variable name? This tells PsychoPy that you don’t mean to literally presentstim
on the screen, but thatstim
should be interpreted as a variable name.↩︎In fact, doing so would stop the experiment from running.↩︎