Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2009 Jan 15:2:10.
doi: 10.3389/neuro.11.010.2008. eCollection 2008.

Generating Stimuli for Neuroscience Using PsychoPy

Affiliations

Generating Stimuli for Neuroscience Using PsychoPy

Jonathan W Peirce. Front Neuroinform. .

Abstract

PsychoPy is a software library written in Python, using OpenGL to generate very precise visual stimuli on standard personal computers. It is designed to allow the construction of as wide a variety of neuroscience experiments as possible, with the least effort. By writing scripts in standard Python syntax users can generate an enormous variety of visual and auditory stimuli and can interact with a wide range of external hardware (enabling its use in fMRI, EEG, MEG etc.). The structure of scripts is simple and intuitive. As a result, new experiments can be written very quickly, and trying to understand a previously written script is easy, even with minimal code comments. PsychoPy can also generate movies and image sequences to be used in demos or simulated neuroscience experiments. This paper describes the range of tools and stimuli that it provides and the environment in which experiments are conducted.

Keywords: EEG; MEG; Python; fMRI; neuroscience; psychophysics; software; vision.

PubMed Disclaimer

Figures

Figure 1
Figure 1
The integrated development environment (IDE) running one of the demo scripts. Multiple scripts can be opened at once in the editor, appearing as tabs. There is a menu from which demos can be easily loaded for a quick view of how to use various aspects of the program. Output from the running script is displayed in the panel at the bottom of the window and scripts can be started and forced to quit directly from the editor. Although the OS X version is shown here, the editor runs on all platforms.
Figure 2
Figure 2
The structure of PsychoPy. PsychoPy comprises a number of sub-modules for controlling different aspects of an experimental setup, from stimulus presentation to analysis of data. In turn these use a number of dependent libraries, that typically have a very good degree of platform-independence.
Figure 3
Figure 3
A sample of PsychoPy components. Within the Window is a coloured Gabor from PatchStim, some rotated Unicode text from the TextStim and 500-dot DotStim. The central image is actually a MovieStim. All the stimuli are dynamic and being updated simultaneously at 60Hz, without any dropped frames. Also shown is a dialog (gui.DlgFromDict) to receive information about the current experiment.
Code SNIPPET 1
Code SNIPPET 1
Presenting stimuli under real-time control. This demo script controls a drifting grating in real-time according to input from the mouse. It demonstrates the use of the Window, PatchStim, TextStim and Mouse objects and how to get keyboard input from the participant. These objects have associated methods that allow them to have their attributes changed.
Code SNIPPET 2
Code SNIPPET 2
The use of serial and parallel ports to control hardware and synchronisation. The demo sends a command to the serial port (in this case the command would request information from a Cedrus box about its type and version) and reads the response after a 0.5-s pause. During this period pin 2 on the parallel port is set to high.

References

    1. Brainard D. H. (1997). The psychophysics toolbox. Spat. Vis. 10, 433–43610.1163/156856897X00357 - DOI - PubMed
    1. Derrington A. M., Krauskopf J., Lennie P. (1984). Chromatic mechanisms in lateral geniculate nucleus of macaque. J. Physiol. 357, 241–265 - PMC - PubMed
    1. MacLeod D. I., Boynton R. M. (1979). Chromaticity diagram showing cone excitation by stimuli of equal luminance. J. Opt. Soc. Am. 69, 1183–118610.1364/JOSA.69.001183 - DOI - PubMed
    1. Peirce J. W. (2007). PsychoPy-Psychophysics software in Python. J. Neurosci. Methods 162, 8–1310.1016/j.jneumeth.2006.11.017 - DOI - PMC - PubMed
    1. Pelli D. G. (1997). The VideoToolbox software for visual psychophysics: transforming numbers into movies. Spat. Vis. 10, 437–44210.1163/156856897X00366 - DOI - PubMed