Run a very basic experiment#

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

basic experiment
exp_name: testExp
date: 2024-07-22 22_14_39.792344
file: /home/circleci/project/examples/basic_experiment.py
participant: foo
session: 001
2024-07-22 22:14:39,792 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2024-07-22 22:14:39,847 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2024-07-22 22:14:40,035 - 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-07-22 22:14:40,036 - INFO    - Expyfun: Setting up screen
2024-07-22 22:14:40,179 - EXP     - Expyfun: Set screen visibility True
2024-07-22 22:14:40,228 - INFO    - Initialized [1400  900] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f019f79fd90>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2024-07-22 22:14:40,228 - INFO    - Expyfun: Initializing dummy triggering mode
2024-07-22 22:14:40,230 - INFO    - Expyfun: Initialization complete
2024-07-22 22:14:40,230 - EXP     - Expyfun: Participant: foo
2024-07-22 22:14:40,230 - EXP     - Expyfun: Session: 001
2024-07-22 22:14:40,384 - WARNING - Expyfun: Resampling 1.0 seconds of audio
2024-07-22 22:14:40,503 - EXP     - Expyfun: Loading 88200 samples to buffer
2024-07-22 22:14:40,605 - EXP     - Expyfun: Stamp trial ID to ec_id  : tone
2024-07-22 22:14:40,605 - EXP     - Expyfun: Stamp trial ID to ttl_id : [0, 0]
2024-07-22 22:14:40,605 - EXP     - Stamping TTL triggers: [4 4]
2024-07-22 22:14:40,646 - EXP     - Expyfun: Starting stimuli: flipping screen and playing audio
2024-07-22 22:14:40,648 - EXP     - Stamping TTL triggers: [1]
2024-07-22 22:14:40,658 - WARNING - ec.trial_ok called before stimulus had stopped
2024-07-22 22:14:40,658 - EXP     - Expyfun: Trial OK
Presses:
[]
2024-07-22 22:14:40,658 - INFO    - Expyfun: Exiting
2024-07-22 22:14:40,663 - 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 0.955 seconds)

Gallery generated by Sphinx-Gallery