<commit_before>"""
=======================
Run a simple experiment
=======================

This example demonstrates much of the basic functionality built into
the ExperimentController class.
"""
# Author: <NAME> <<EMAIL>>
#
# License: BSD (3-clause)

print(__doc__)

from os import path as op
import numpy as np
from scipy import io as sio

from expyfun import ExperimentController
from expyfun._utils import set_log_level, get_config
import expyfun.analyze as ea


set_log_level('INFO')

# set configuration
ac = get_config('AUDIO_CONTROLLER', 'pyglet')
fs = 44100
noise_db = 45  # dB for background noise
stim_db = 65  # dB for stimuli
min_resp_time = 0.1
max_resp_time = 2.0
feedback_dur = 0.5
isi = 0.2
running_total = 0

# if the stimuli have not been made, let's make them in examples dir
stimulus_file = 'equally_spaced_sinewaves.mat'
if not op.isfile(stimulus_file):
    from generate_stimuli import generate_stimuli
    generate_stimuli(output_dir='.', fs=fs)

# load stimuli (from a call to generate_stimuli() from generate_stimuli.py)
stims = sio.loadmat('equally_spaced_sinewaves.mat')
orig_rms = stims['rms'][0]
freqs = stims['freqs'][0]
fs = stims['fs'][0][0]
trial_order = stims['trial_order'][0]
num_trials = len(trial_order)
num_freqs = len(freqs)

if num_freqs > 8:
    raise RuntimeError('Too many frequencies, not enough buttons.')

# keep only sinusoids, make stereo, order low-high, convert to list of arrays
wavs = {k: np.r_[stims[k], stims[k]].T for k in stims if 'stim_' in k}
wavs = [np.ascontiguousarray(v) for _, v in sorted(wavs.items())]

# instructions
instructions = ('You will hear tones at {0} different frequencies. Your job is'
                ' to press the button corresponding to that frequency. Please '
                'press buttons 1-{0} now to hear each tone.').format(num_freqs)

instr_finished = ('Okay, now press any of those buttons to start the real '
                  'thing. There will be background noise.')

# select audio controller
if ac == 'tdt':
    ac = dict(TYPE=ac, TDT_MODEL=get_config('TDT_MODEL'))

with ExperimentController('testExp', ac, screen_num=0,
                          window_size=[800, 600], full_screen=False,
                          stim_db=stim_db, noise_db=noise_db, stim_fs=fs,
                          participant='foo', session='001',
                          verbose=True) as ec:

    # define usable buttons / keys
    live_keys = [x + 1 for x in range(num_freqs)]
    not_yet_pressed = live_keys[:]

    # show instructions until all buttons have been pressed at least once
    ec.screen_text(instructions)
    screenshot = ec.screenshot()<commit_msg>removed explicit audio controller definition entirely<commit_after>"""
=======================
Run a simple experiment
=======================

This example demonstrates much of the basic functionality built into
the ExperimentController class.
"""
# Author: <NAME> <<EMAIL>>
#
# License: BSD (3-clause)

print(__doc__)

from os import path as op
import numpy as np
from scipy import io as sio

from expyfun import ExperimentController
from expyfun._utils import set_log_level
import expyfun.analyze as ea


set_log_level('INFO')

# set configuration
fs = 44100
noise_db = 45  # dB for background noise
stim_db = 65  # dB for stimuli
min_resp_time = 0.1
max_resp_time = 2.0
feedback_dur = 0.5
isi = 0.2
running_total = 0

# if the stimuli have not been made, let's make them in examples dir
stimulus_file = 'equally_spaced_sinewaves.mat'
if not op.isfile(stimulus_file):
    from generate_stimuli import generate_stimuli
    generate_stimuli(output_dir='.', fs=fs)

# load stimuli (from a call to generate_stimuli() from generate_stimuli.py)
stims = sio.loadmat('equally_spaced_sinewaves.mat')
orig_rms = stims['rms'][0]
freqs = stims['freqs'][0]
fs = stims['fs'][0][0]
trial_order = stims['trial_order'][0]
num_trials = len(trial_order)
num_freqs = len(freqs)

if num_freqs > 8:
    raise RuntimeError('Too many frequencies, not enough buttons.')

# keep only sinusoids, make stereo, order low-high, convert to list of arrays
wavs = {k: np.r_[stims[k], stims[k]].T for k in stims if 'stim_' in k}
wavs = [np.ascontiguousarray(v) for _, v in sorted(wavs.items())]

# instructions
instructions = ('You will hear tones at {0} different frequencies. Your job is'
                ' to press the button corresponding to that frequency. Please '
                'press buttons 1-{0} now to hear each tone.').format(num_freqs)

instr_finished = ('Okay, now press any of those buttons to start the real '
                  'thing. There will be background noise.')

with ExperimentController('testExp', verbose=True, screen_num=0,
                          window_size=[800, 600], full_screen=False,
                          stim_db=stim_db, noise_db=noise_db, stim_fs=fs,
                          participant='foo', session='001') as ec:

    # define usable buttons / keys
    live_keys = [x + 1 for x in range(num_freqs)]
    not_yet_pressed = live_keys[:]

    # show instructions until all buttons have been pressed at least once
    ec.screen_text(instructions)
    screenshot = ec.screenshot()
{'fraction_non_alphanumeric': 0.11485302705859451, 'fraction_numerical': 0.015183959509441309, 'mean_word_length': 3.7706592386258126, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3195125', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1613, 'n_words': 528}