Run a very basic experiment#

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

basic experiment
exp_name: testExp
date: 2024-11-19 15_32_12.039285
file: /home/circleci/project/examples/basic_experiment.py
participant: foo
session: 001
2024-11-19 15:32:12,039 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2024-11-19 15:32:12,098 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2024-11-19 15:32:12,302 - 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-11-19 15:32:12,302 - INFO    - Expyfun: Setting up screen
2024-11-19 15:32:12,457 - EXP     - Expyfun: Set screen visibility True
2024-11-19 15:32:12,508 - INFO    - Initialized [1400  900] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f25553adba0>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2024-11-19 15:32:12,508 - INFO    - Expyfun: Initializing dummy triggering mode
2024-11-19 15:32:12,510 - INFO    - Expyfun: Initialization complete
2024-11-19 15:32:12,510 - EXP     - Expyfun: Participant: foo
2024-11-19 15:32:12,510 - EXP     - Expyfun: Session: 001
2024-11-19 15:32:12,678 - WARNING - Expyfun: Resampling 1.0 seconds of audio
2024-11-19 15:32:12,806 - EXP     - Expyfun: Loading 88200 samples to buffer
2024-11-19 15:32:12,918 - EXP     - Expyfun: Stamp trial ID to ec_id  : tone
2024-11-19 15:32:12,918 - EXP     - Expyfun: Stamp trial ID to ttl_id : [0, 0]
2024-11-19 15:32:12,918 - EXP     - Stamping TTL triggers: [4 4]
2024-11-19 15:32:12,959 - EXP     - Expyfun: Starting stimuli: flipping screen and playing audio
2024-11-19 15:32:12,962 - EXP     - Stamping TTL triggers: [1]
2024-11-19 15:32:12,972 - WARNING - ec.trial_ok called before stimulus had stopped
2024-11-19 15:32:12,972 - EXP     - Expyfun: Trial OK
Presses:
[]
2024-11-19 15:32:12,972 - INFO    - Expyfun: Exiting
2024-11-19 15:32:12,978 - 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.028 seconds)

Gallery generated by Sphinx-Gallery