Run a very basic experimentΒΆ

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

basic experiment
exp_name: testExp
date: 2023-07-25 19_08_12.210900
file: /home/circleci/project/examples/basic_experiment.py
participant: foo
session: 001
2023-07-25 19:08:12,211 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2023-07-25 19:08:12,274 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2023-07-25 19:08:12,475 - 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.
2023-07-25 19:08:12,475 - INFO    - Expyfun: Setting up screen
2023-07-25 19:08:12,630 - EXP     - Expyfun: Set screen visibility True
2023-07-25 19:08:12,690 - INFO    - Initialized [1400  900] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f1a95b502b0>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2023-07-25 19:08:12,691 - INFO    - Expyfun: Initializing dummy triggering mode
2023-07-25 19:08:12,693 - INFO    - Expyfun: Initialization complete
2023-07-25 19:08:12,693 - EXP     - Expyfun: Participant: foo
2023-07-25 19:08:12,693 - EXP     - Expyfun: Session: 001
2023-07-25 19:08:12,862 - WARNING - Expyfun: Resampling 1.0 seconds of audio
2023-07-25 19:08:13,198 - EXP     - Expyfun: Loading 88200 samples to buffer
2023-07-25 19:08:13,314 - EXP     - Expyfun: Stamp trial ID to ec_id  : tone
2023-07-25 19:08:13,314 - EXP     - Expyfun: Stamp trial ID to ttl_id : [0, 0]
2023-07-25 19:08:13,314 - EXP     - Stamping TTL triggers: [4 4]
2023-07-25 19:08:13,355 - EXP     - Expyfun: Starting stimuli: flipping screen and playing audio
2023-07-25 19:08:13,357 - EXP     - Stamping TTL triggers: [1]
2023-07-25 19:08:13,367 - WARNING - ec.trial_ok called before stimulus had stopped
2023-07-25 19:08:13,367 - EXP     - Expyfun: Trial OK
Presses:
[]
2023-07-25 19:08:13,367 - INFO    - Expyfun: Exiting
2023-07-25 19:08:13,373 - 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.  # 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. if not building_doc else 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.)
    ec.trial_ok()
    print('Presses:\n{}'.format(presses))

analyze.plot_screen(screenshot)

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

Gallery generated by Sphinx-Gallery