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 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() 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) # 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)
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', line_width=3.0)
n_tr += 1 ec.start_noise() ec.flip() ec.screen_prompt(('You will now do a training block of trials.\n\n' + tr_instructions[bi] + continue_msg) % (tstr, dstr), color=fcolor) if bi < 2 and first_try: idx = p['targ_pos'][tr_trials[bi]].any(axis=-1).all(axis=-1) demo_trial(tr_trials[bi][np.random.choice(np.where(idx)[0])], titles[bi], tstr) first_try = False if not calibrated: # use one calibration for all training runs ec.system_beep() el.calibrate() calibrated = True ec.write_data_line('training', bi) fix.draw() ec.flip() ec.wait_for_presses(5.0) count_mask = np.ones(n_tr_trials[bi], bool) if tr_trials[bi] is not None: these_trials = np.random.choice(tr_trials[bi], n_tr_trials[bi], False) else: assert bi == 5 # special case, last condition assert n_tr_trials[bi] == 16 a = np.random.choice(tr_trials[0], 5, False) b = np.random.choice(tr_trials[1], 5, False) c = np.random.choice(tr_trials[3], 3, False)
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', line_width=3.0) targ_circ = visual.Circle(ec, targ_rad, (x_pos[0], y_pos[0]), units='deg', fill_color='red') fix_pos = (x_pos[0], y_pos[0])
max_wait=wait_keys[section_key]) # run block for b_ind in range(len(section[snum])): bnum = section[snum][b_ind] if (snum == 1): if (b_ind < inputBlock): continue ec.write_data_line('Block: ', str(bnum)) # show instructions if (snum != 2): block_key = 's' + str(snum) + '_' + 'start_block_' + str(b_ind) ec.screen_prompt( instr[(block_key)]) #start a new EDF file only in the middle section if (snum != 2): el.calibrate(prompt=True) assert el.recording for tnum in range(len(order[section[snum][b_ind]][0])): if (tnum < inputCondition): block_ind[bnum] += 1 continue ec.write_data_line('Trial: ', tnum) # introduce the conditions in first/last section if (snum != 1): trial_vars = getTrialInfo(block_ind, bnum) paradigm = trial_vars['paradigm'][0] condition_no = tnum trial_key = 's' + str(0) + '_' + 'start_trial_' \ + str(condition_no) ec.screen_prompt( instr[(trial_key)])