Esempio n. 1
0
        ec, np.tile(bgcolor[0], np.multiply([s, s, 1], img_buffer.shape)))
    bright = visual.RawImage(
        ec, np.tile([1.], np.multiply([s, s, 1], img_buffer.shape)))
    # Calculate stimulus size
    d_pix = -np.diff(ec._convert_units([[3., 0.], [3., 0.]], 'deg', 'pix'),
                     axis=-1)

    # do the drawing, then flip
    ec.set_visible(True)
    frametimes = []
    buttons = []
    ec.listen_presses()
    last_flip = -1

    # Create a fixation dot
    fix = visual.FixationDot(ec, colors=('k', 'k'))
    fix.set_radius(4, 0, 'pix')
    fix.draw()

    # Display instruction (7 seconds).
    # They will be different depending on the run number
    if int(ec.session) % 2:
        t = visual.Text(
            ec,
            text='Button press when the dot turns red - Ignore images',
            pos=[0, .1],
            font_size=40,
            color='k')
    else:
        t = visual.Text(ec,
                        text='Button press for fake word',
Esempio n. 2
0
movie_path = fetch_data_file('video/example-video.mp4')

ec_args = dict(exp_name='advanced video example',
               window_size=(720, 480),
               full_screen=False,
               participant='foo',
               session='foo',
               version='dev',
               output_dir=None)
colors = [x for x in 'rgbcmyk']

with ExperimentController(**ec_args) as ec:
    screen_period = 1. / ec.estimate_screen_fs()
    all_presses = list()
    fix = visual.FixationDot(ec)
    text = text = visual.Text(ec, "Running ...", (0, -0.1), 'k')
    screenshot = None  # don't have one yet
    ec.load_video(movie_path)
    ec.video.set_scale('fill')
    ec.screen_prompt('press 1 during video to toggle pause.', max_wait=1.)
    ec.listen_presses()  # to catch presses on first pass of while loop
    t_zero = ec.video.play(auto_draw=False)
    this_sec = 0.
    while not ec.video.finished:
        if ec.video.playing:
            ec.video.draw()
        else:
            ec.screen_text('paused!', color='y', font_size=32, wrap=False)
        text.draw()
        fix.draw()
Esempio n. 3
0
def test_visuals(hide_window):
    """Test EC visual methods."""
    with ExperimentController('test', **std_kwargs) as ec:
        pytest.raises(TypeError, visual.Circle, ec, n_edges=3.5)
        pytest.raises(ValueError, visual.Circle, ec, n_edges=3)
        circ = visual.Circle(ec)
        circ.draw()
        pytest.raises(ValueError, circ.set_radius, [1, 2, 3])
        pytest.raises(ValueError, circ.set_pos, [1])
        pytest.raises(ValueError, visual.Triangle, ec, [5, 6])
        tri = visual.Triangle(ec, [[-1, 0, 1], [-1, 1, -1]],
                              units='deg',
                              line_width=1.0)
        tri.draw()
        rect = visual.Rectangle(ec, [0, 0, 1, 1], line_width=1.0)
        rect.draw()
        diamond = visual.Diamond(ec, [0, 0, 1, 1], line_width=1.0)
        diamond.draw()
        pytest.raises(TypeError, visual.ConcentricCircles, ec, colors=dict())
        pytest.raises(TypeError,
                      visual.ConcentricCircles,
                      ec,
                      colors=np.array([]))
        pytest.raises(ValueError, visual.ConcentricCircles, ec, radii=[[1]])
        pytest.raises(ValueError, visual.ConcentricCircles, ec, radii=[1])
        fix = visual.ConcentricCircles(ec,
                                       radii=[1, 2, 3],
                                       colors=['w', 'k', 'y'])
        fix.set_pos([0.5, 0.5])
        fix.set_radius(0.1, 1)
        fix.set_radii([0.1, 0.2, 0.3])
        fix.set_color('w', 1)
        fix.set_colors(['w', 'k', 'k'])
        fix.set_colors(('w', 'k', 'k'))
        pytest.raises(IndexError, fix.set_color, 'w', 3)
        pytest.raises(ValueError, fix.set_colors, ['w', 'k'])
        pytest.raises(ValueError, fix.set_colors, np.array(['w', 'k', 'k']))
        pytest.raises(IndexError, fix.set_radius, 0.1, 3)
        pytest.raises(ValueError, fix.set_radii, [0.1, 0.2])
        fix.draw()
        fix_2 = visual.FixationDot(ec)
        fix_2.draw()
        pytest.raises(ValueError, rect.set_pos, [0, 1, 2])
        for shape in ((3, 3, 3), (3, 3, 4), (3, 3), (3, ), (3, ) * 4):
            data = np.ones(shape)
            if len(shape) not in (2, 3):
                pytest.raises(RuntimeError, visual.RawImage, ec, data)
            else:
                img = visual.RawImage(ec, data)
            print(img.bounds)  # test bounds
            assert_equal(img.scale, 1)
            # test get_rect
            imgrect = visual.Rectangle(ec, img.get_rect())
            assert_equal(imgrect._points['fill'][(0, 2, 0, 1), (0, 0, 1, 1)],
                         img.bounds)
            img.draw()
        line = visual.Line(ec, [[0, 1], [1, 0]])
        line.draw()
        pytest.raises(ValueError, line.set_line_width, 100)
        line.set_line_width(2)
        line.draw()
        pytest.raises(ValueError, line.set_coords, [0])
        line.set_coords([0, 1])
        ec.set_background_color('black')
        text = visual.Text(ec,
                           'Hello {color (255 0 0 255)}Everybody!',
                           pos=[0, 0],
                           color=[1, 1, 1],
                           wrap=False)
        text.draw()
        text.set_color(None)
        text.draw()
        text = visual.Text(ec,
                           'Thank you, come again.',
                           pos=[0, 0],
                           color='white',
                           attr=False)
        text.draw()
        text.set_color('red')
        text.draw()
        bar = visual.ProgressBar(ec, [0, 0, 1, .2])
        bar = visual.ProgressBar(ec, [0, 0, 1, 1], units='pix')
        bar.update_bar(.5)
        bar.draw()
        pytest.raises(ValueError,
                      visual.ProgressBar,
                      ec, [0, 0, 1, .1],
                      units='deg')
        pytest.raises(ValueError,
                      visual.ProgressBar,
                      ec, [0, 0, 1, .1],
                      colors=['w'])
        pytest.raises(ValueError, bar.update_bar, 500)
Esempio n. 4
0
v_off = 2.

with ExperimentController('standard_setup',
                          full_screen=False,
                          stim_db=75,
                          noise_db=45,
                          participant='s',
                          session='0',
                          output_dir=None,
                          suppress_resamp=True,
                          check_rms=None,
                          version='9c4bcea') as ec:
    square = visual.Rectangle(ec, [0, 0, 10, 10], units='deg')
    ec.screen_text('expy_standard_setup_test.', wrap=False)
    ec.set_background_color(bg_color)
    fix = visual.FixationDot(ec, colors=[fix_color, bg_color])
    circ = visual.Circle(ec,
                         radius=1,
                         units='deg',
                         line_color=fix_color,
                         fill_color=None)
    strs = ',   '.join(token.capitalize() for token in p['tokens'])
    targ_text = visual.Text(ec,
                            strs,
                            pos=[0, v_off],
                            units='deg',
                            color=fix_color)

    # actual experiment
    ec.set_visible(False)
    bi = get_keyboard_input('Enter block number (%s): ' % 1, 1, int) - 1
Esempio n. 5
0
def test_visuals():
    """Test EC visual methods
    """
    with ExperimentController('test', **std_kwargs) as ec:
        assert_raises(TypeError, visual.Circle, ec, n_edges=3.5)
        assert_raises(ValueError, visual.Circle, ec, n_edges=3)
        circ = visual.Circle(ec)
        circ.draw()
        assert_raises(ValueError, circ.set_radius, [1, 2, 3])
        assert_raises(ValueError, circ.set_pos, [1])
        assert_raises(ValueError, visual.Triangle, ec, [5, 6])
        tri = visual.Triangle(ec, [[-1, 0, 1], [-1, 1, -1]],
                              units='deg',
                              line_width=1.0)
        tri.draw()
        rect = visual.Rectangle(ec, [0, 0, 1, 1], line_width=1.0)
        rect.draw()
        diamond = visual.Diamond(ec, [0, 0, 1, 1], line_width=1.0)
        diamond.draw()
        assert_raises(TypeError, visual.ConcentricCircles, ec, colors=dict())
        assert_raises(TypeError,
                      visual.ConcentricCircles,
                      ec,
                      colors=np.array([]))
        assert_raises(ValueError, visual.ConcentricCircles, ec, radii=[[1]])
        assert_raises(ValueError, visual.ConcentricCircles, ec, radii=[1])
        fix = visual.ConcentricCircles(ec,
                                       radii=[1, 2, 3],
                                       colors=['w', 'k', 'y'])
        fix.set_pos([0.5, 0.5])
        fix.set_radius(0.1, 1)
        fix.set_radii([0.1, 0.2, 0.3])
        fix.set_color('w', 1)
        fix.set_colors(['w', 'k', 'k'])
        fix.set_colors(('w', 'k', 'k'))
        assert_raises(IndexError, fix.set_color, 'w', 3)
        assert_raises(ValueError, fix.set_colors, ['w', 'k'])
        assert_raises(ValueError, fix.set_colors, np.array(['w', 'k', 'k']))
        assert_raises(IndexError, fix.set_radius, 0.1, 3)
        assert_raises(ValueError, fix.set_radii, [0.1, 0.2])
        fix.draw()
        fix_2 = visual.FixationDot(ec)
        fix_2.draw()
        assert_raises(ValueError, rect.set_pos, [0, 1, 2])
        img = visual.RawImage(ec, np.ones((3, 3, 4)))
        print(img.bounds)  # test bounds
        assert_equal(img.scale, 1)
        img.draw()
        line = visual.Line(ec, [[0, 1], [1, 0]])
        line.draw()
        assert_raises(ValueError, line.set_line_width, 100)
        line.set_line_width(2)
        line.draw()
        assert_raises(ValueError, line.set_coords, [0])
        line.set_coords([0, 1])
        ec.set_background_color('black')
        text = visual.Text(ec,
                           'Hello {color (255 0 0 255)}Everybody!',
                           pos=[0, 0],
                           color=[1, 1, 1],
                           wrap=False)
        text.draw()
        text.set_color(None)
        text.draw()
        text = visual.Text(ec,
                           'Thank you, come again.',
                           pos=[0, 0],
                           color='white',
                           attr=False)
        text.draw()
        text.set_color('red')
        text.draw()

    # test video
    std_kwargs.update(dict(enable_video=True, window_size=(640, 480)))
    video_path = fetch_data_file('video/example-video.mp4')
    with ExperimentController('test', **std_kwargs) as ec:
        ec.load_video(video_path)
        ec.video.play()
        assert_raises(ValueError, ec.video.set_scale, 'foo')
        assert_raises(ValueError, ec.video.set_scale, -1)
        ec.video.set_scale('fill')
        ec.video.set_scale('fit')
        ec.video.set_scale(0.5)
        ec.video.set_pos(pos=(0.1, 0), units='norm')
        ec.wait_secs(0.2)
        ec.video.pause()
        ec.delete_video()
Esempio n. 6
0
        ec, np.tile(bgcolor[0], np.multiply([s, s, 1], img_buffer.shape)))
    # Calculate stimulus size
    d_pix = -np.diff(ec._convert_units([[3., 0.], [3., 0.]], 'deg', 'pix'),
                     axis=-1)

    # do the drawing, then flip
    ec.set_visible(True)
    frametimes = []
    buttons = []
    ec.listen_presses()
    last_flip = -1
    # Initiate a counter
    c = -1

    # Create a fixation dot
    fix = visual.FixationDot(ec, colors=('k', 'k'))

    # Show images
    for trial in imorder_shuf:
        # Insert a blank after waiting the desired image duration
        blank.draw(), fix.draw()
        last_flip = ec.flip(last_flip + imduration)
        # Draw a fixation dot of a random color a random portion of the time
        # through the ISI
        fix = visual.FixationDot(ec, colors=(dcolor[trial], dcolor[trial]))
        fix.draw()
        last_flip = ec.flip(last_flip + ISI[trial] * dotchange[trial])
        # Stamp a trigger when the image goes on
        ec.call_on_next_flip(ec.stamp_triggers,
                             imtype_shuf[trial],
                             check='int4')
Esempio n. 7
0
def test_visuals():
    """Test EC visual methods."""
    with ExperimentController('test', **std_kwargs) as ec:
        assert_raises(TypeError, visual.Circle, ec, n_edges=3.5)
        assert_raises(ValueError, visual.Circle, ec, n_edges=3)
        circ = visual.Circle(ec)
        circ.draw()
        assert_raises(ValueError, circ.set_radius, [1, 2, 3])
        assert_raises(ValueError, circ.set_pos, [1])
        assert_raises(ValueError, visual.Triangle, ec, [5, 6])
        tri = visual.Triangle(ec, [[-1, 0, 1], [-1, 1, -1]], units='deg',
                              line_width=1.0)
        tri.draw()
        rect = visual.Rectangle(ec, [0, 0, 1, 1], line_width=1.0)
        rect.draw()
        diamond = visual.Diamond(ec, [0, 0, 1, 1], line_width=1.0)
        diamond.draw()
        assert_raises(TypeError, visual.ConcentricCircles, ec, colors=dict())
        assert_raises(TypeError, visual.ConcentricCircles, ec,
                      colors=np.array([]))
        assert_raises(ValueError, visual.ConcentricCircles, ec, radii=[[1]])
        assert_raises(ValueError, visual.ConcentricCircles, ec, radii=[1])
        fix = visual.ConcentricCircles(ec, radii=[1, 2, 3],
                                       colors=['w', 'k', 'y'])
        fix.set_pos([0.5, 0.5])
        fix.set_radius(0.1, 1)
        fix.set_radii([0.1, 0.2, 0.3])
        fix.set_color('w', 1)
        fix.set_colors(['w', 'k', 'k'])
        fix.set_colors(('w', 'k', 'k'))
        assert_raises(IndexError, fix.set_color, 'w', 3)
        assert_raises(ValueError, fix.set_colors, ['w', 'k'])
        assert_raises(ValueError, fix.set_colors, np.array(['w', 'k', 'k']))
        assert_raises(IndexError, fix.set_radius, 0.1, 3)
        assert_raises(ValueError, fix.set_radii, [0.1, 0.2])
        fix.draw()
        fix_2 = visual.FixationDot(ec)
        fix_2.draw()
        assert_raises(ValueError, rect.set_pos, [0, 1, 2])
        img = visual.RawImage(ec, np.ones((3, 3, 4)))
        print(img.bounds)  # test bounds
        assert_equal(img.scale, 1)
        img.draw()
        line = visual.Line(ec, [[0, 1], [1, 0]])
        line.draw()
        assert_raises(ValueError, line.set_line_width, 100)
        line.set_line_width(2)
        line.draw()
        assert_raises(ValueError, line.set_coords, [0])
        line.set_coords([0, 1])
        ec.set_background_color('black')
        text = visual.Text(ec, 'Hello {color (255 0 0 255)}Everybody!',
                           pos=[0, 0], color=[1, 1, 1], wrap=False)
        text.draw()
        text.set_color(None)
        text.draw()
        text = visual.Text(ec, 'Thank you, come again.', pos=[0, 0],
                           color='white', attr=False)
        text.draw()
        text.set_color('red')
        text.draw()
    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):
        """Run a trial, optionally with feedback"""
        samples = read_wav(op.join(stim_dir, p['stim_names'][ti]))[0]
        ec.load_buffer(samples)
        id_ = decimals_to_binary(p['cond_mat'][ti], [1, 2, 2, 1])
        ec.identify_trial(ec_id=id_, ttl_id=id_, el_id=id_)
        ec.listen_presses()