Run a very basic experiment#

This example demonstrates an (almost) minimum working example of the ExperimentController class.

basic experiment
exp_name: testExp
date: 2026-01-12 20_35_13.485853
file: /home/circleci/project/examples/basic_experiment.py
participant: foo
session: 001
2026-01-12 20:35:13,486 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2026-01-12 20:35:13,837 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2026-01-12 20:35:13,930 - WARNING - Expyfun: Mismatch between reported stim sample rate (48000.0) and device sample rate (44100.0). Experiment Controller will resample for you, but this takes a non-trivial amount of processing time and may compromise your experimental timing and/or cause artifacts.
2026-01-12 20:35:13,931 - INFO    - Expyfun: Setting up screen
2026-01-12 20:35:14,082 - EXP     - Expyfun: Set screen visibility True
2026-01-12 20:35:14,092 - INFO    - Initialized [1400  900] window on screen XlibScreenXrandr(display=<pyglet.display.xlib.XlibDisplay object at 0x7f3cf5d06380>, x=0, y=0, width=1400, height=900) with DPI 69.73
2026-01-12 20:35:14,093 - INFO    - Expyfun: Initializing dummy triggering mode
2026-01-12 20:35:14,095 - INFO    - Expyfun: Initialization complete
2026-01-12 20:35:14,095 - EXP     - Expyfun: Participant: foo
2026-01-12 20:35:14,095 - EXP     - Expyfun: Session: 001
2026-01-12 20:35:14,337 - WARNING - Expyfun: Resampling 0.51 seconds of audio
2026-01-12 20:35:14,572 - EXP     - Expyfun: Loading 44860 samples to buffer
2026-01-12 20:35:14,652 - EXP     - Expyfun: Stamp trial ID to ec_id  : tone
2026-01-12 20:35:14,652 - EXP     - Expyfun: Stamp trial ID to ttl_id : [0, 0]
2026-01-12 20:35:14,653 - EXP     - Stamping TTL triggers: [4 4]
2026-01-12 20:35:14,694 - EXP     - Expyfun: Starting stimuli: flipping screen and playing audio
2026-01-12 20:35:14,697 - EXP     - Stamping TTL triggers: [1]
2026-01-12 20:35:14,708 - WARNING - ec.trial_ok called before stimulus had stopped
2026-01-12 20:35:14,708 - EXP     - Expyfun: Trial OK
Presses:
[]
2026-01-12 20:35:14,708 - INFO    - Expyfun: Exiting
2026-01-12 20:35:14,714 - EXP     - Expyfun: Audio stopped and reset.

# Author: Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD (3-clause)

import numpy as np

from expyfun import ExperimentController, analyze, building_doc
from expyfun.visual import FixationDot

print(__doc__)

# set configuration
fs = 24414.0  # default for ExperimentController
dur = 1.0
tone = np.sin(2 * np.pi * 1000 * np.arange(int(fs * dur)) / float(fs))
tone *= 0.01 * np.sqrt(2)  # Set RMS to 0.01
max_wait = 1.0 if not building_doc else 0.0

with ExperimentController(
    "testExp", participant="foo", session="001", output_dir=None, version="dev"
) as ec:
    ec.screen_prompt("Press a button when you hear the tone", max_wait=max_wait)

    dot = FixationDot(ec)
    ec.load_buffer(tone)
    dot.draw()
    screenshot = ec.screenshot()  # only because we want to show it in the docs

    ec.identify_trial(ec_id="tone", ttl_id=[0, 0])
    ec.start_stimulus()
    presses = ec.wait_for_presses(dur if not building_doc else 0.0)
    ec.trial_ok()
    print(f"Presses:\n{presses}")

analyze.plot_screen(screenshot)

Total running time of the script: (0 minutes 1.322 seconds)

Gallery generated by Sphinx-Gallery