Ejemplo n.º 1
0
def test_generate_coordinate_matrices():
    
    # set some dummy display parameters
    pixels_across = 100
    pixels_down = 100
    ppd = 1.0
    scale_factor = 1.0
    
    # generate coordinates
    deg_x, deg_y = generate_coordinate_matrices(pixels_across,pixels_down,ppd,scale_factor)
    
    # assert
    nt.assert_true(np.sum(deg_x[0,0:50]) == np.sum(deg_x[0,50::])*-1)
    nt.assert_true(np.sum(deg_y[0:50,0]) == np.sum(deg_y[50::,0])*-1)
    
    # try the same with an odd number of pixels
    pixels_across = 101
    pixels_down = 101
    
    # generate coordinates
    deg_x, deg_y = generate_coordinate_matrices(pixels_across,pixels_down,ppd,scale_factor)
    
    # assert
    nt.assert_true(np.sum(deg_x[0,0:50]) == np.sum(deg_x[0,50::])*-1)
    nt.assert_true(np.sum(deg_y[0:50,0]) == np.sum(deg_y[50::,0])*-1)
    
    # try with another rescaling factor
    scale_factor = 0.5
    
    # get the horizontal and vertical coordinate matrices
    deg_x, deg_y = generate_coordinate_matrices(pixels_across,pixels_down,ppd,scale_factor)
    
    # assert
    nt.assert_true(np.sum(deg_x[0,0:50]) == np.sum(deg_x[0,50::])*-1)
    nt.assert_true(np.sum(deg_y[0:50,0]) == np.sum(deg_y[50::,0])*-1)
Ejemplo n.º 2
0
def test_generate_og_receptive_field():
    xpixels = 500 # simulated screen width
    ypixels = 500 # simulated screen height
    ppd = 1 # simulated visual angle
    scale_factor = 1.0 # simulated stimulus resampling rate
    distance = 5 # standard deviations to compute gauss out to
    xcenter = 0 # x coordinate of the pRF center
    ycenter = 0 # y coordinate of the pRF center
    sigma = 1 # width of the pRF
    
    test_value = 6 # this is the sum of a gaussian given 1 ppd 
                   # and a 1 sigma prf centered on (0,0)
                   
    # generate the visuotopic coordinates
    dx,dy = generate_coordinate_matrices(xpixels,
                                         ypixels,
                                         ppd,
                                         scale_factor)
    
    # generate a pRF at (0,0) and 1 sigma wide
    rf = generate_og_receptive_field(xcenter, ycenter, sigma, dx, dy)
    
    # divide by integral
    rf /= 2 * np.pi * sigma ** 2
    
    # compare the volume of the pRF to a known value
    nt.assert_almost_equal(np.sum(rf),1)
Ejemplo n.º 3
0
def test_generate_og_timeseries():
    xpixels = 100 # simulated screen width
    ypixels = 100 # simulated screen height
    ppd = 1 # simulated visual angle
    scaleFactor = 1.0 # simulated stimulus resampling rate
    
    xcenter = 0 # x coordinate of the pRF center
    ycenter = 0 # y coordinate of the pRF center
    sigma = 10 # width of the pRF
    
    # generate the visuotopic coordinates
    dx,dy = generate_coordinate_matrices(xpixels,
                                         ypixels,
                                         ppd,
                                         scaleFactor)
    
    timeseries_length = 15 # number of frames to simulate our stimulus array
    
    # initialize the stimulus array
    stim_arr = np.zeros((xpixels, ypixels, timeseries_length)).astype('uint8')
    
    # make a circular mask appear for the first 5 frames
    xi,yi = np.nonzero(np.sqrt((dx-xcenter)**2 + (dy-ycenter)**2)<sigma)
    stim_arr[xi,yi,0:5] = 1
    
    # make an annulus appear for the next 5 frames
    xi,yi = np.nonzero(np.sqrt((dx-xcenter)**2 + (dy-ycenter)**2)>sigma)
    stim_arr[xi,yi,5:10] = 1
    
    # make a circular mask appear for the next 5 frames
    xi,yi = np.nonzero(np.sqrt((dx-xcenter)**2 + (dy-ycenter)**2)<sigma)
    stim_arr[xi,yi,10::] = 1
    
    
    # make the response prediction
    response = generate_og_timeseries(dx,
                                      dy,
                                      stim_arr,
                                      xcenter,
                                      ycenter,
                                      sigma)
                                
    # make sure the RSS is 0
    step = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0])
    rval = np.corrcoef(response, step)[0, 1]
    
    # The voxel responds when the stimulus covers its PRF, so it perfectly
    # correlates with a step function: 
    nt.assert_equal(round(rval, 3), 1)
Ejemplo n.º 4
0
def test_gaussian_2D():
    
    # set some dummy display parameters
    pixels_across = 101
    pixels_down = 101
    ppd = 1.0
    scale_factor = 1.0
    
    # generate coordinates
    deg_x, deg_y = generate_coordinate_matrices(pixels_across,pixels_down,ppd,scale_factor)
    
    # generate 2D case
    G = utils.gaussian_2D(deg_x,deg_y,0,0,10,10,0)
    
    # generate 1D case
    gx = np.exp(-((deg_x[0,:]-0)**2)/(2*10**2))
    gy = np.exp(-((deg_y[:,0]-0)**2)/(2*10**2))
    
    # assertions
    npt.assert_equal(np.round(G[:,50],5),np.round(gx,5))
    npt.assert_equal(np.round(G[50,:],5),np.round(gy,5))
Ejemplo n.º 5
0
def test_generate_og_receptive_field():
    xpixels = 100 # simulated screen width
    ypixels = 100 # simulated screen height
    ppd = 1 # simulated visual angle
    scale_factor = 1.0 # simulated stimulus resampling rate
    
    xcenter = 0 # x coordinate of the pRF center
    ycenter = 0 # y coordinate of the pRF center
    sigma = 1 # width of the pRF
    
    test_value = 6 # this is the sum of a gaussian given 1 ppd 
                   # and a 1 sigma prf centered on (0,0)
                   
    # generate the visuotopic coordinates
    dx,dy = generate_coordinate_matrices(xpixels,
                                         ypixels,
                                         ppd,
                                         scale_factor)
    
    # generate a pRF at (0,0) and 1 sigma wide
    rf = generate_og_receptive_field(dx, dy, xcenter, ycenter, sigma)
    
    # compare the volume of the pRF to a known value
    nt.assert_equal(np.round(np.sum(rf)), test_value)