This is an old revision of the document!
Table of Contents
PsychoPy is an open-source application to allow the presentation of stimuli and collection of data for a wide range of neuroscience, psychology and psychophysics experiments. It’s a free, powerful alternative to Presentation™ or e-Prime™, written in Python (a free alternative to Matlab™ ).
I have chosen PsychoPy as the primary stimulus presentation software for the lab for a number of reasons:
- It is free
- It is open-source
- Experiments can be developed in two environments
Builder
a nice GUI interface for quick and easy development of experimentsCoder
a programming environment for exploiting the power of Python programming to develop more complex paradigms and/or for greater customization an experiment.
- There is an active and friendly user group for getting help and addressing issues.
Below are notes and tips for building experiments for use in the EEG lab. Many of these tips include using a custom code componet in Builder
. This is a way of inserting short pieces of Python code into your Builder experiment. In other words, you can leverage some of the power of Coder
without leaving the Builder
GUI environment. An alternative would be to start by building your experiment in Builder
and then compiling the code to be further modified in Coder
.
Moving between Builder
and Coder
is a one-way street. You can move from Builder
to Coder
, but not from Coder
to Builder
.
Sending digital event codes
It is critical that we acquire stimulus-locked digital codes so that we can bin the data according to stimulus type during analysis. This is also essential for creating event-related averages of psychophysiological data (e.g. creating ERPs from EEG data) as it gives us the precise onset time of each stimulus. Below is a description of the hardware, software, and steps necessary for sending and acquiring such codes with PsychoPy and the BioSemi ActiveTwo system.
Setting the default LabJack address
- PsychoPy has a built-in python library to drive the LabJack DAQ device. By default, PsychoPy uses the address for the “EI0” DB15 pins (address = 6008). We use the “FIO” terminal blocks so we need to specify the correct address (
6000
). In order to use the “FIO” terminal we need to add the following custom code component to the beginning our Builder experiment. PsychoPy users thread.
def mySetData(self, byte, endian='big', address=6000): if endian=='big': byteStr = '{0:08b}'.format(byte)[-1::-1] else: byteStr = '{0:08b}'.format(byte) [self.writeRegister(address+pin, int(entry)) for (pin, entry) in enumerate(byteStr)] labjacks.U3.setData = mySetData
Initializing the LabJack
Status attribute
- There seems to be a bug in Builder that results in an attribute of the p_port not being initialized (see psychopy users thread). Running a Builder-built experiment with LabJack digital codes will give the following error.
AttributeError:'U3' object has no attribute 'status'
This can be fixed by adding the following code to the start of the script (anywhere after the code that imports the LabJacks module)
p_port.status = NOT_STARTED
Alternatively, you should be able to fix this problem by using the custom code
component, selecting the Begin Routine
tab, and adding the following“
p_port.status = []
- The LabJacks will initialize with all bits set to hight (i.e. sending a
255
code). So you should also add the following code to your script (it can be added right after the code shown above).
win.callOnFlip(p_port.setData, int(1), address=6000)