def test_eyelink_methods():
    """Test EL methods."""
    with ExperimentController(*std_args, **std_kwargs) as ec:
        assert_raises(ValueError, EyelinkController, ec, fs=999)
        el = EyelinkController(ec)
        assert_raises(RuntimeError, EyelinkController, ec)  # can't have 2 open
        assert_raises(ValueError, el.custom_calibration, ctype='hey')
        el.custom_calibration('H3')
        el.custom_calibration('HV9')
        el.custom_calibration('HV13')
        assert_raises(ValueError, el.custom_calibration, ctype='custom',
                      coordinates='foo')
        assert_raises(ValueError, el.custom_calibration, ctype='custom',
                      coordinates=[[0, 1], 0])
        assert_raises(ValueError, el.custom_calibration, ctype='custom',
                      coordinates=[[0, 1], [0]])
        el._open_file()
        assert_raises(RuntimeError, el._open_file)
        el._start_recording()
        el.get_eye_position()
        assert_raises(ValueError, el.wait_for_fix, [1])
        x = el.wait_for_fix([-10000, -10000], max_wait=0.1)
        assert_true(x is False)
        assert el.eye_used
        print(el.file_list)
        assert_true(len(el.file_list) > 0)
        print(el.fs)
        x = el.maintain_fix([-10000, -10000], 0.1, period=0.01)
        assert_true(x is False)
        # run much of the calibration code, but don't *actually* do it
        el._fake_calibration = True
        el.calibrate(beep=False, prompt=False)
        el._fake_calibration = False
        # missing el_id
        assert_raises(KeyError, ec.identify_trial, ec_id='foo', ttl_id=[0])
        ec.identify_trial(ec_id='foo', ttl_id=[0], el_id=[1])
        ec.start_stimulus()
        ec.stop()
        ec.trial_ok()
        ec.identify_trial(ec_id='foo', ttl_id=[0], el_id=[1, 1])
        ec.start_stimulus()
        ec.stop()
        ec.trial_ok()
        assert_raises(ValueError, ec.identify_trial, ec_id='foo', ttl_id=[0],
                      el_id=[1, dict()])
        assert_raises(ValueError, ec.identify_trial, ec_id='foo', ttl_id=[0],
                      el_id=[0] * 13)
        assert_raises(TypeError, ec.identify_trial, ec_id='foo', ttl_id=[0],
                      el_id=dict())
        assert_raises(TypeError, el._message, 1)
        el.stop()
        el.transfer_remote_file(el.file_list[0])
        assert_true(not el._closed)
    # ec.close() auto-calls el.close()
    assert_true(el._closed)
Example #2
0
import numpy as np
import matplotlib.pyplot as plt

from expyfun import ExperimentController, EyelinkController, visual
import expyfun.analyze as ea

print(__doc__)

with ExperimentController('testExp',
                          full_screen=True,
                          participant='foo',
                          session='001',
                          output_dir=None,
                          version='dev') as ec:
    el = EyelinkController(ec)
    ec.screen_prompt('Welcome to the experiment!\n\nFirst, we will '
                     'perform a screen calibration.\n\nPress a button '
                     'to continue.')
    el.calibrate()  # by default this starts recording EyeLink data
    ec.screen_prompt('Excellent! Now, follow the red circle around the edge '
                     'of the big white circle.\n\nPress a button to '
                     'continue')

    # make some circles to be drawn
    radius = 7.5  # degrees
    targ_rad = 0.2  # degrees
    theta = np.linspace(np.pi / 2., 2.5 * np.pi, 200)
    x_pos, y_pos = radius * np.cos(theta), radius * np.sin(theta)
    big_circ = visual.Circle(ec,
                             radius, (0, 0),
import numpy as np
import matplotlib.pyplot as plt

from expyfun import ExperimentController, EyelinkController
from expyfun.codeblocks import (find_pupil_dynamic_range,
                                find_pupil_tone_impulse_response)

print(__doc__)

with ExperimentController('pupilExp',
                          full_screen=True,
                          participant='foo',
                          session='001',
                          output_dir=None,
                          version='dev') as ec:
    el = EyelinkController(ec)
    bgcolor, fcolor, lev, resp = find_pupil_dynamic_range(ec, el)
    prf, t_srf, e_prf = find_pupil_tone_impulse_response(
        ec, el, bgcolor, fcolor)

uni_lev = np.unique(lev)
uni_lev_label = (255 * uni_lev).astype(int)
uni_lev[uni_lev == 0] = np.sort(uni_lev)[1] / 2.
r = resp.reshape((len(lev) // len(uni_lev), len(uni_lev)))
r_span = [r.min(), r.max()]
# Grayscale responses
ax = plt.subplot(2, 1, 1, xlabel='Screen level', ylabel='Pupil dilation (AU)')
ax.plot([bgcolor, bgcolor], r_span, linestyle='--', color='r')
ax.fill_between(uni_lev,
                np.min(r, 0),
                np.max(r, 0),
Example #4
0
def test_eyelink_methods():
    """Test EL methods."""
    with ExperimentController(*std_args, **std_kwargs) as ec:
        assert_raises(ValueError, EyelinkController, ec, fs=999)
        el = EyelinkController(ec)
        assert_raises(RuntimeError, EyelinkController, ec)  # can't have 2 open
        assert_raises(ValueError, el.custom_calibration, ctype='hey')
        el.custom_calibration('H3')
        el.custom_calibration('HV9')
        el.custom_calibration('HV13')
        assert_raises(ValueError,
                      el.custom_calibration,
                      ctype='custom',
                      coordinates='foo')
        assert_raises(ValueError,
                      el.custom_calibration,
                      ctype='custom',
                      coordinates=[[0, 1], 0])
        assert_raises(ValueError,
                      el.custom_calibration,
                      ctype='custom',
                      coordinates=[[0, 1], [0]])
        el._open_file()
        assert_raises(RuntimeError, el._open_file)
        el._start_recording()
        el.get_eye_position()
        assert_raises(ValueError, el.wait_for_fix, [1])
        x = el.wait_for_fix([-10000, -10000], max_wait=0.1)
        assert_true(x is False)
        assert el.eye_used
        print(el.file_list)
        assert_true(len(el.file_list) > 0)
        print(el.fs)
        x = el.maintain_fix([-10000, -10000], 0.1, period=0.01)
        assert_true(x is False)
        # run much of the calibration code, but don't *actually* do it
        el._fake_calibration = True
        el.calibrate(beep=False, prompt=False)
        el._fake_calibration = False
        # missing el_id
        assert_raises(KeyError, ec.identify_trial, ec_id='foo', ttl_id=[0])
        ec.identify_trial(ec_id='foo', ttl_id=[0], el_id=[1])
        ec.start_stimulus()
        ec.stop()
        ec.trial_ok()
        ec.identify_trial(ec_id='foo', ttl_id=[0], el_id=[1, 1])
        ec.start_stimulus()
        ec.stop()
        ec.trial_ok()
        assert_raises(ValueError,
                      ec.identify_trial,
                      ec_id='foo',
                      ttl_id=[0],
                      el_id=[1, dict()])
        assert_raises(ValueError,
                      ec.identify_trial,
                      ec_id='foo',
                      ttl_id=[0],
                      el_id=[0] * 13)
        assert_raises(TypeError,
                      ec.identify_trial,
                      ec_id='foo',
                      ttl_id=[0],
                      el_id=dict())
        assert_raises(TypeError, el._message, 1)
        el.stop()
        el.transfer_remote_file(el.file_list[0])
        assert_true(not el._closed)
    # ec.close() auto-calls el.close()
    assert_true(el._closed)

def _get_strs(type_):
    """Helper to convert block type to strings"""
    assert len(type_) == 3
    assert type_[0] in 'LR'
    assert type_[1] in 'MF'
    dstr = 'left' if type_[0] == 'L' else 'right'
    tstr = 'male' if type_[1] == 'M' else 'female'
    return tstr, dstr


with ExperimentController('capd', stim_db=65, noise_db=45,
                          check_rms=None) as ec:
    # Pupil parameters ######################################################
    el = EyelinkController(ec)
    bgcolor, fcolor = find_pupil_dynamic_range(ec, el)[:2]
    ec.write_data_line('bgcolor', bgcolor)
    ec.write_data_line('fcolor', fcolor)
    print('Using colors: %s, %s\n' % (bgcolor, fcolor))
    ec.set_background_color(bgcolor)
    fix = visual.FixationDot(ec, colors=[fcolor, 'k'])

    session = int(ec.session) if ec.session != '' else 0
    assert 0 <= session <= len(p['blocks'])
    n_blocks = p['n_blocks']

    # Trial running #########################################################


    def run_trial(ti, feedback=False):
"""
# Author: Eric Larson <*****@*****.**>
#
# License: BSD (3-clause)

import numpy as np

from expyfun import ExperimentController, EyelinkController, visual
import expyfun.analyze as ea

print(__doc__)


with ExperimentController('testExp', full_screen=True, participant='foo',
                          session='001', output_dir=None, version='dev') as ec:
    el = EyelinkController(ec)
    ec.screen_prompt('Welcome to the experiment!\n\nFirst, we will '
                     'perform a screen calibration.\n\nPress a button '
                     'to continue.')
    el.calibrate()  # by default this starts recording EyeLink data
    ec.screen_prompt('Excellent! Now, follow the red circle around the edge '
                     'of the big white circle.\n\nPress a button to '
                     'continue')

    # make some circles to be drawn
    radius = 7.5  # degrees
    targ_rad = 0.2  # degrees
    theta = np.linspace(np.pi / 2., 2.5 * np.pi, 200)
    x_pos, y_pos = radius * np.cos(theta), radius * np.sin(theta)
    big_circ = visual.Circle(ec, radius, (0, 0), units='deg',
                             fill_color=None, line_color='white',
Example #7
0
# run experiment
inputSection = input('Start from section (0,1,2)? ')
if (inputSection == 1):
    inputBlock = input('Start from block (0,1, ...8) ')
else:
    inputBlock = 0
if (inputSection == 2):
    inputCondition = input('Start from condition (0,1,2)? ')
else:
    inputCondition = 0
startInfo = dict()
startInfo['inputSection'] = inputSection
startInfo['inputBlock'] = inputBlock
with ef.ExperimentController(*std_args, **std_kwargs) as ec:
    el = EyelinkController(ec)  # create el instance
    stimdir = op.join(PATH, 'Stims', str(ec.stim_fs))

    assert os.path.isdir(stimdir), 'Can not find Stim directory. \
    Have you runCreateStims.m yet?'
    final_datadir = op.join( datadir, 'Params')
    assert os.path.isdir(final_datadir), 'Can not find Data directory. \
    Have you runCreateStims.m yet?'
    # read in particpant session variables from mat file
    global_vars = sio.loadmat(op.join(final_datadir, 'global_vars.mat'))
    global_vars['vPrimerLen'] = vPrimerLen
    global_vars['postblock'] = postblock
    sio.savemat(op.join(final_datadir, 'global_vars.mat'), global_vars)
    version_code = global_vars['version_code'][0][0]
    print "Using stimuli of version_code: " + str(version_code) + "\n"
    assert version_code == stim_version_code, """Version code specified