Example #1
0
def test_ImageStimulus_center():
    # Create a horizontal bar:
    fname = 'test.png'
    shape = (5, 5)
    ndarray = np.zeros(shape, dtype=np.uint8)
    ndarray[2, :] = 255
    imsave(fname, ndarray)
    # Center phosphene:
    stim = ImageStimulus(fname)
    npt.assert_almost_equal(stim.data, stim.center().data)
    npt.assert_almost_equal(stim.data, stim.shift(0, 2).center().data)
    os.remove(fname)
Example #2
0
def test_ImageStimulus_shift():
    # Create a horizontal bar:
    fname = 'test.png'
    shape = (5, 5)
    ndarray = np.zeros(shape, dtype=np.uint8)
    ndarray[2, :] = 255
    imsave(fname, ndarray)
    stim = ImageStimulus(fname)
    # Top row:
    top = stim.shift(0, -2)
    npt.assert_almost_equal(top.data.reshape(stim.img_shape)[0, :], 1)
    npt.assert_almost_equal(top.data.reshape(stim.img_shape)[1:, :], 0)
    # Bottom row:
    bottom = stim.shift(0, 2)
    npt.assert_almost_equal(bottom.data.reshape(stim.img_shape)[:4, :], 0)
    npt.assert_almost_equal(bottom.data.reshape(stim.img_shape)[4, :], 1)
    # Bottom right pixel:
    bottom = stim.shift(4, 2)
    npt.assert_almost_equal(bottom.data.reshape(stim.img_shape)[4, 4], 1)
    npt.assert_almost_equal(bottom.data.reshape(stim.img_shape)[:4, :], 0)
    npt.assert_almost_equal(bottom.data.reshape(stim.img_shape)[:, :4], 0)
    os.remove(fname)