PsychoPy (PyHab)
Example from a Discrimination/HPP study using three screens (central fixation, right and left).
Last updated
Example from a Discrimination/HPP study using three screens (central fixation, right and left).
Last updated
Open the script:
Open PsychoPy and open the Coder Window. Open the “NewPyHabProject.py” or your project (e.g., “DiscriminationPyHabTestLauncer.py”).
Hit the green running man image. From here, you can run the experiment or open the builder to make edits.
Builder view will look like this (if nothing has been programmed):
First, select “HPP” from Exp Type:
It’s important to do this early, otherwise, PyHab has to make a bunch of changes when you click “HPP” and it may not do this successfully.
Next, create all the different trial types (Pre-Hab trials, HabTrials trials, PreTest trials, TestTrials):
PreHab trials: These trials depict the spinning pinwheel in silence. They are later used to draw infants’ attention to a side monitor before the stimulus starts to play. After the infant looks to the pinwheel for 2s, the actual habituation trial will start.
Click “New Trial Type”
Trial type name: “PreHabTrials”
Max duration: 60s
If the infant hasn’t looked at the pinwheel for 2s within a 60s time period, the habituation stimuli will start automatically (because if they don’t look within 60s, they’re likely fussing out).
Gaze-contingent trial type: OnOnly
This means that the pinwheel will start when the infant looks at it.
From the manual: “If it is set to “OnOnly”, the trial will run until the maximum duration or the “Minimum on-time” criterion has been met. In other words, this is for a trial you want to end after the infant has looked at it, but regardless of whether they look away.
Number of continuous seconds looking away to end trial: 2.0
This value is ignored when “OnOnly” is selected (as we do here)
From the manual: “The minimum-on and maximum-off criteria for the trial type are set in the next two lines. If the trial is not gaze-contingent, these values are ignored. If it is set to “OnOnly”, the first value is ignored.”
Minimum looking at screen before stimuli can be ended: 0.1
This is how much time looking at the screen the infant has to accumulate before look aways counts (and the trial ends 2s later). I have this set to a very low number, otherwise if the infant looks for < the min look time the trial just continues until they look back. This is not what we want, so set this time very low so that any time the infant looks away and doesn’t look back within 2s, the trial ends.
Audio-redo if minimum on-time criterion not met? NO
If this is set to YES, and the infant doesn’t look for the “Minimum looking at screen before stimuli can be ended” the trial will repeat. Currently, I have it set not to do this for the habituation trials. There are so many habituation trials, that this is maybe not necessary.
Deadline to meet on-time criterion (ignored if <=0): 60
This is something that will be edited in future versions of PyHab (by Jonathan Kominski). For now, he says to set it to the same value as the max trial duration.
Check to use total trial duration instead of gaze-on time for trial length calculation: NO
Didn’t check this because we want to only use time the infant is looking at the screen to decide when a trial ends and not just time stimuli is on the screen regardless of looking.
Auto-advance INTO trial without waiting for the experimenter: YES
Trial automatically starts after the attention-getter without the experimenter having to tell it to start.
Attention-getter for this trial type (Stim presentation mode only): LaughingBaby
Added attention-getter here before the infant looks to the side. But won’t have an attention-getter between the PreHab and Habituation trials.
Note: the laughing baby is a custom attention-getter we added (see instructions later).
Only end trial on end of movie repetition? (Only works when presenting stimuli): NO
If set to yes, the trial won’t end while the movie is still going. Left box unchecked because we want the trial to end exactly when the infant looks away for >2s.
Inter-stimulus interval on loops (pause between one loop and start of next): 0
Left at 0 because I don’t think we want to pause between trials, the length between trials should be infant-controlled.
When you add stimulus files (later), there will be an additional section called “Current movies in trial type…” that just tells you what options there are for stimuli of this type.
Here is what this will look like:
Now create the HabTrials trials: The stimuli for these trials are movie files with a spinning pinwheel and English or Spanish/French audio (depending on the familiarization condition).
Click “New Trial Type”
Trial type name: “HabTrials”
Max duration: 15s
Set to 15s because that’s the maximum length of the stimuli.
Gaze-contingent trial type: YES
Time trials play is contingent on infants’ gaze.
Number of continuous seconds looking away to end trial: 2.0
Minimum looking at screen before stimuli can be ended: 0.1
This is how much time looking at the screen the infant has to accumulate before look aways counts (and the trial ends 2s later). I have this set to a very low number, otherwise if the infant looks for < the min looking time the trial just continues until they look back. This is not what we want, so set this time very low so that any time the infant looks away and doesn’t look back within 2s, the trial ends.
Audio-redo if minimum on-time criterion not met? NO
If this is set to YES, and the infant doesn’t look for the “Minimum looking at screen before stimuli can be ended” the trial will repeat. Currently, I have it set not to do this for the habituation trials. There are so many habituation trials, that this is maybe not necessary.
Deadline to meet on-time criterion (ignored if <=0): 60
This is something that will be edited in future versions of PyHab (per Jonathan). For now, he says to set it to the same value as the max trial duration.
Check to use total trial duration instead of gaze-on time for trial length calculation: NO
Didn’t check this because we want to only use the time the infant is looking at the screen to decide when a trial ends.
Auto-advance INTO trial without waiting for the experimenter: YES
Checked this box because we want the audio to start when the infant looks to the side, no need to wait for the experimenter.
Attention-getter for this trial type (Stim presentation mode only): None
No attention-getter here because it would disrupt the flow of looking to the side and the stim starting.
Only end trial on end of movie repetition? (Only works when presenting stimuli): NO
If set to yes, the trial won’t end while the movie is still going. Left box unchecked because we want the trial to end exactly when the infant looks away for >2s.
Inter-stimulus interval on loops (pause between one loop and start of next): 0
Left at 0 because I don’t think we want to pause between trials, the length between trials should be infant-controlled.
Here is what this will look like:
Now create the PreTest trials: This is very similar to the PreHab trials. These trials depict the spinning pinwheel in silence. They are later used to draw infants’ attention to a side monitor before the stimulus starts to play.
Click “New Trial Type”
Trial type name: “PreTestTrials”
Max duration: 60s
See note in PreHab trials
Gaze-contingent trial type: OnOnly
This means that that pinwheel will start and only end once the infant looks at it and away for 2s.
Number of continuous seconds looking away to end trial: 2.0
This value is ignored when “OnOnly” is selected (as we do here)
From manual: “The minimum-on and maximum-off criteria for the trial type are set in the next two lines. If the trial is not gaze-contingent, these values are ignored. If it is set to “OnOnly”, the first value is ignored.”
Minimum looking at screen before stimuli can be ended: 0.1
This is how much time looking at the screen the infant has to accumulate before look aways counts (and the trial ends 2s later). I have this set to a very low number, otherwise if the infant looks for < the min look time the trial just continues until they look back. This is not what we want, so set this time very low so that any time the infant looks away and doesn’t look back within 2s, the trial ends.
Audio-redo if minimum on-time criterion not met? NO
Here we don’t do this, because it’s the Test trial we want to repeat, not the PreTest trial. For this to work you will need to add "Test Blocks".
Deadline to meet on-time criterion (ignored if <=0): 60
This is something that will be edited in future versions of PyHab (per Jonathan). For now, he says to set it to the same value as the max trial duration.
Check to use total trial duration instead of gaze-on time for trial length calculation: NO
Didn’t check this because we want to only use time the infant is looking at the screen to decide when a trial ends.
Auto-advance INTO trial without waiting for experimenter: YES
Checked so that trial starts immediately after attention-getter.
Attention-getter for this trial type (Stim presentation mode only): LaughingBaby
Added attention-getter here before the infant looks to the side. But won’t have an attention-getter between the PreTest and Test
Only end trial on end of movie repetition? (Only works when presenting stimuli): NO
If set to yes, the trial won’t end while the movie is still going. Left box unchecked because we want the trial to end exactly when the infant looks away for >2s.
Inter-stimulus interval on loops (pause between one loop and start of next): 0
Left at 0 because I don’t think we want to pause between trials, the length between trials should be infant-controlled.
Here is what this will look like:
Now create the Test trials: This is very similar to the HabTrials. The stimuli for these trials are movie files with a spinning pinwheel and English or Spanish audio.
Click “New Trial Type”
Trial type name: “TestTrials”
Max duration: 15s
Because this is the stimulus duration.
Gaze-contingent trial type: YES
For the Habit version, we had the habituation trials be gaze-contingent. Keeping it this way here.
Number of continuous seconds looking away to end trial: 2.0
Minimum looking at screen before stimuli can be ended: 0.1
This is how much time looking at the screen the infant has to accumulate before look aways counts (and the trial ends 2s later). I have this set to a very low number, otherwise if the infant looks for < the min look time the trial just continues until they look back. This is not what we want, so set this time very low so that any time the infant looks away and doesn’t look back within 2s, the trial ends.
Audio-redo if minimum on-time criterion not met? YES
We decided that we want to do this for the Test trials. However, I had to do some workarounds because usually the trial repeats if the “minimum looking at screen before stimuli can be ended” is not reached. Because we wanted to set that for such a small value (so we don’t have the issue of audio playing without the infant looking), I had to manually set this to 1s.
Instructions from Jonathan: “You're going to want to look at line 1012. This conditional statement controls whether a trial needs to be flagged for a redo as it ends. Currently, this line checks total on-time against self.minOn[localType], which is the minimum on-time that also controls when a trial is allowed to end at all. In short, you'll want to change that to something else.
Change self.minOn[localType] to a constant, in this case 1.0 (the decimal is important so it doesn't do integer math and round everything to the closest whole number). With that, every trial with the auto-redo option will trip the redo if the total on-time at the end (for the stimulus screen, if you're using that setting) is less than 1 second.”
I also had to go in and set it so that the trial repeats only once.
Instructions from Jonathan Kominski: “You just need to add a new check near the start of the doTrial function (before the while runTrial loop) that looks something like this:
dontRepeat = False
if len(self.badTrials) > 0: # Checks if any trials have been repeated/aborted
badTrialNumbers = [x['trial'] for x in self.badTrials] # Gets just trial numbers of previously aborted trials
if number in badTrialNumbers: # Checks if the current trial number is in the list of trials that have been repeated
dontRepeat = True