Run a very basic experiment#

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

basic experiment
exp_name: testExp
date: 2024-10-08 13_42_39.379831
file: /home/circleci/project/examples/basic_experiment.py
participant: foo
session: 001
2024-10-08 13:42:39,380 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2024-10-08 13:42:39,455 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2024-10-08 13:42:39,662 - WARNING - Expyfun: Mismatch between reported stim sample rate (24414) 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.
2024-10-08 13:42:39,662 - INFO    - Expyfun: Setting up screen
2024-10-08 13:42:39,814 - EXP     - Expyfun: Set screen visibility True
2024-10-08 13:42:39,868 - INFO    - Initialized [1400  900] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f392c363f10>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2024-10-08 13:42:39,868 - INFO    - Expyfun: Initializing dummy triggering mode
2024-10-08 13:42:39,870 - INFO    - Expyfun: Initialization complete
2024-10-08 13:42:39,870 - EXP     - Expyfun: Participant: foo
2024-10-08 13:42:39,870 - EXP     - Expyfun: Session: 001
2024-10-08 13:42:40,044 - WARNING - Expyfun: Resampling 1.0 seconds of audio
2024-10-08 13:42:40,171 - EXP     - Expyfun: Loading 88200 samples to buffer
2024-10-08 13:42:40,278 - EXP     - Expyfun: Stamp trial ID to ec_id  : tone
2024-10-08 13:42:40,279 - EXP     - Expyfun: Stamp trial ID to ttl_id : [0, 0]
2024-10-08 13:42:40,279 - EXP     - Stamping TTL triggers: [4 4]
2024-10-08 13:42:40,320 - EXP     - Expyfun: Starting stimuli: flipping screen and playing audio
2024-10-08 13:42:40,322 - EXP     - Stamping TTL triggers: [1]
2024-10-08 13:42:40,332 - WARNING - ec.trial_ok called before stimulus had stopped
2024-10-08 13:42:40,332 - EXP     - Expyfun: Trial OK
Presses:
[]
2024-10-08 13:42:40,332 - INFO    - Expyfun: Exiting
2024-10-08 13:42:40,338 - 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.048 seconds)

Gallery generated by Sphinx-Gallery