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

  1. Download Anaconda.
  2. Open the Anaconda prompt and create a virtual environment: conda create -n psychopyenv python=3.8
  3. Activate the virtual environment: conda activate psychopyenv
  4. Download explorepy, and extract the files.

Edit explorepy

How the explorepy code should look
Comment out line 215.
  1. Open the explorepy-1.8.0\src\explorepy\stream_processor.py script using a text editor (e.g. right-click → open with → Notepad).
  2. Comment out line 215: logger.info(f"Setting a marker with code: {code}"). (To do this add a # at the beginning of this line.)
  3. Save your changes, the code should look like the figure.
  4. Navigate to the explorepy-1.8.0 directory in your terminal: cd <PATH-TO-EXPLOREPY>
  5. Install explorepy: pip install .

Download PsychoPy

  1. Download the PsychoPy source code and extract the files.
  2. Navigate to the extracted folder (i.e. PsychoPy-2023.1.0) in your terminal: cd <PATH-TO-PSYCHOPY>
  3. Install PsychoPy: pip install .
  4. Run PsychoPy: python psychopy\app\psychopyApp.py

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).

PsychoPy add code screenshot
Look for add Code option.

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)

Set an event marker

Begin routine in PsychoPy
If you need a marker at the start of a loop,
use the "Begin Routine" tab.

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:

  1. Click on “trial” in the Flow section
  2. Click “code” in the Routines section
  3. 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

Copyright © 2024 Mentalab