Пример #1
0
def test_grating():
    gm = movie.GratingMovie(row_size=120, col_size=240, frame_rate=1000.0)

    # Default grating movie
    mv = gm.create_movie()
    assert (mv.data.shape == (1001, 60, 120))
    assert (mv.row_range[0] == 0.0)
    assert (mv.row_range[-1] == 120.0)
    assert (mv.col_range[0] == 0.0)
    assert (mv.col_range[-1] == 240.0)
    assert (mv.t_range[0] == 0)
    assert (mv.t_range[-1] == 1.0)

    # 2 second gratings with 0.5 second gray screen
    mv = gm.create_movie(t_max=2.0, gray_screen_dur=0.5)
    assert (mv.data.shape == (2001, 60, 120))
    assert (mv.t_range[0] == 0.0)
    assert (mv.t_range[-1] == 2.0)
    assert (np.sum(mv.data[0:500, :, :]) == 0)  # check 0.5 second grey screen
    assert (np.sum(mv.data[501, :, :]) > 0)  # movie starts

    # disable aliasing
    mv = gm.create_movie(cpd=0.1)
    assert (mv.data.shape == (1001, 120, 240))
    assert (mv.t_range[0] == 0.0)
    assert (mv.t_range[-1] == 1.0)
    assert (mv.row_range[-1] == 120)
    assert (mv.col_range[-1] == 240)
Пример #2
0
def plot_sfilter_params():
    gm = movie.GratingMovie(200, 200)
    mv = gm.create_movie(t_max=2.0)

    fig, axes = plt.subplots(2, 2, figsize=(7, 7))
    rotations = [0.0, 45.0]
    sigmas = [(30.0, 20.0), (20.0, 30.0)]

    for r, sigma in enumerate(sigmas):
        for c, rot in enumerate(rotations):
            gsf = GaussianSpatialFilter(translate=(0, 0),
                                        sigma=sigma,
                                        rotation=rot)
            axes[r, c].imshow(gsf.get_kernel(mv.row_range,
                                             mv.col_range).full(),
                              extent=(0, 200, 0, 200),
                              origin='lower')

            if r == 0:
                axes[r, c].title.set_text('spatial_rotation={}'.format(rot))

            if c == 0:
                axes[r, c].set_ylabel('spatial_size={}'.format(sigma))

    plt.show()
Пример #3
0
def test_offunit(cell_type, expected_val):
    gm = movie.GratingMovie(row_size=120, col_size=240, frame_rate=24.0)
    mv = gm.create_movie(t_max=1.0)

    cell = default_cell_loader(MockNode(), ('lgnmodel', cell_type), dynamics_params)
    assert(isinstance(cell, OffUnit))

    lgn = LGNModel([cell])
    results = lgn.evaluate(mv, downsample=5)  # Does the filtering + non-linearity on movie object m
    times = np.array(results[0][0], dtype=np.float64)
    rates = np.array(results[0][1], dtype=np.float64)

    assert(np.allclose(times, [0.0, 0.2083, 0.4167, 0.6250, 0.8333], atol=1.0e-3))
    assert(np.allclose(rates, expected_val, atol=1.0e-3))
Пример #4
0
def plot_tfilter_params():
    gm = movie.GratingMovie(120, 240)
    mv = gm.create_movie(t_max=2.0)
    #
    # tf = TemporalFilterCosineBump(weights=[33.328, -20.10059],
    #                               kpeaks=[59.0, 120.0],  # [9.67, 20.03],
    #                               delays=[0.0, 0.0])
    #
    # tf.get_kernel(t_range=mv.t_range, threshold=0.0, reverse=True)
    # tf.imshow(t_range=mv.t_range, reverse=True)

    fig, axes = plt.subplots(3, 3, figsize=(10, 7))
    ri = ci = 0

    weights = [(30.0, -20.0), (30.0, -1.0), (15.0, -20.0)]
    kpeaks = [(3.0, 5.0), (3.0, 30.0), (20.0, 40.0)]
    delays = [(0.0, 0.0), (0.0, 60.0), (20.0, 60.0)]

    # weights control the amplitude of the peaks
    for ci, w in enumerate(weights):
        tf = TemporalFilterCosineBump(weights=w,
                                      kpeaks=[9.67, 20.03],
                                      delays=[0.0, 1.0])
        linear_kernel = tf.get_kernel(t_range=mv.t_range, reverse=True)
        axes[ri, ci].plot(linear_kernel.t_range[linear_kernel.t_inds],
                          linear_kernel.kernel)
        axes[ri, ci].set_ylim([-3.5, 10.0])
        axes[ri, ci].text(0.05,
                          0.90,
                          'weights={}'.format(w),
                          horizontalalignment='left',
                          verticalalignment='top',
                          transform=axes[ri, ci].transAxes)

    axes[0, 0].set_ylabel('effect of weights')
    ri += 1

    # kpeaks parameters controll the spread of both peaks, the second peak must have a bigger spread
    for ci, kp in enumerate(kpeaks):
        tf = TemporalFilterCosineBump(weights=[30.0, -20.0],
                                      kpeaks=kp,
                                      delays=[0.0, 1.0])
        linear_kernel = tf.get_kernel(t_range=mv.t_range, reverse=True)
        axes[ri, ci].plot(linear_kernel.t_range[linear_kernel.t_inds],
                          linear_kernel.kernel)
        axes[ri, ci].set_xlim([-0.15, 0.005])
        axes[ri, ci].text(0.05,
                          0.90,
                          'kpeaks={}'.format(kp),
                          horizontalalignment='left',
                          verticalalignment='top',
                          transform=axes[ri, ci].transAxes)
    axes[1, 0].set_ylabel('effects of kpeaks')
    ri += 1

    for ci, d in enumerate(delays):
        tf = TemporalFilterCosineBump(weights=[30.0, -20.0],
                                      kpeaks=[9.67, 20.03],
                                      delays=d)
        linear_kernel = tf.get_kernel(t_range=mv.t_range, reverse=True)
        axes[ri, ci].plot(linear_kernel.t_range[linear_kernel.t_inds],
                          linear_kernel.kernel)
        axes[ri, ci].set_xlim([-0.125, 0.001])
        axes[ri, ci].text(0.05,
                          0.90,
                          'delays={}'.format(d),
                          horizontalalignment='left',
                          verticalalignment='top',
                          transform=axes[ri, ci].transAxes)

    axes[2, 0].set_ylabel('effects of delays')
    # plt.xlim()
    plt.show()