PsychoPy Builder
Here is a guide to running explorepy
inside PsychoPy experiments. We will demonstrate how to record data, set markers, and push to lab streaming layer (LSL).
Install software
Download explorepy
- Download Anaconda.
- Open the Anaconda prompt and create a virtual environment:
conda create -n psychopyenv python=3.8
- Activate the virtual environment:
conda activate psychopyenv
- Download
explorepy
, and extract the files.
Edit explorepy
- Open the
explorepy-1.8.0\src\explorepy\stream_processor.py
script using a text editor (e.g. right-click → open with → Notepad). - Comment out line 215:
logger.info(f"Setting a marker with code: {code}")
. (To do this add a#
at the beginning of this line.) - Save your changes, the code should look like the figure.
- Navigate to the
explorepy-1.8.0
directory in your terminal:cd <PATH-TO-EXPLOREPY>
- Install
explorepy
:pip install .
Download PsychoPy
- Download the PsychoPy source code and extract the files.
- Navigate to the extracted folder (i.e. PsychoPy-2023.1.0) in your terminal:
cd <PATH-TO-PSYCHOPY>
- Install PsychoPy:
pip install .
- Run PsychoPy:
python psychopy\app\psychopyApp.py
1. Open Anaconda prompt
2. Navigate to the PsychoPy folder (step 11 above)
3. Run PsychoPy:
python psychopy\app\psychopyApp.py
(step 12 above)Use explorepy in PsychoPy builder
Initialize
In order to run explorepy
, you will need to add a Code component to your experiment. In the “Begin Experiment” section, setup and initialize streaming, recording (optional) or push to LSL (optional).
To do this, add the following code to your Code file:
from explorepy import Explore
explore = Explore()
explore.connect(device_name='Explore_XXXX')
explore.push2lsl()
explore.record_data(file_name='recorded_trial_02', file_type='csv', do_overwrite=False)
Explore_CA52
.Line 6: remember to set the filename; the file type can be
csv
or edf
(CSV recommended).
Set an event marker
To set an event marker in your recorded data, use the set_marker
method. For instance, if there is a loop and the beginning of each iteration should be marked, call set_marker
in the “Begin Routine” section of your Code component.
If instead you would like to mark multiple event types, you can assign specific codes to each type of marker using the following pattern:
if cond == 'left':
explore.set_marker(10)
elif cond == 'right':
explore.set_marker(11)
elif cond == 'up':
explore.set_marker(12)
elif cond == 'down':
explore.set_marker(13)
Example
Here, you find an PsychoPy experiment. The file iterates over 4 conditions (left, right, up and down) while recording the data. As each trial begins, a marker event is set in the recorded data. The data and event markers are pushed to LSL at the same time.
To change the name of the Mentalab Explore device and the recorded file:
- Click on “trial” in the Flow section
- Click “code” in the Routines section
- Change the relevant arguments in the script in the “Begin Experiment” tab
For more information or support, do not hesitate to get in contact at: support@mentalab.com