Esempio n. 1
0
def test_estfr():

    T = 100
    dt = 1e-2

    # test an empty array
    bspk = np.zeros(T,)
    time = np.arange(0, 1, dt)
    fr = spk.estfr(bspk, time, sigma=0.01)
    assert np.allclose(fr, bspk)

    # test a single spike
    bspk[T // 2] = 1.
    fr = spk.estfr(bspk, time, sigma=0.01)
    assert (fr.sum() * dt) == bspk.sum()
Esempio n. 2
0
def create_default_fake_rates():
    """Return the default firing rates."""
    spikes = np.arange(10)
    time = np.linspace(0, 10, 100)
    binned = spiketools.binspikes(spikes, time)
    rate = spiketools.estfr(binned, time)
    return rate
Esempio n. 3
0
def create_default_fake_rates():
    """Return the default firing rates."""
    spikes = np.arange(10)
    time = np.linspace(0, 10, 100)
    binned = spiketools.binspikes(spikes, time)
    rate = spiketools.estfr(binned, time)
    return rate
Esempio n. 4
0
def test_play_rates():
    """Test playing firing rates for cells as a movie."""
    nx, ny, nt = 10, 10, 50
    sta = utils.create_spatiotemporal_filter(nx, ny, nt)[-1]
    time = np.linspace(0, 10, 100)
    spikes = np.arange(10)
    binned_spikes = spiketools.binspikes(spikes, time)
    rate = spiketools.estfr(binned_spikes, time)

    # Plot cell
    fig, axes = viz.ellipse(sta)
    patch = plt.findobj(axes, Ellipse)[0]
    anim = viz.play_rates(rate, patch)
    filename = os.path.join(IMG_DIR, 'test-rates-movie.png')
    frame = 10
    anim._func(frame)
    plt.savefig(filename)
    assert not compare_images(
        os.path.join(IMG_DIR, 'baseline-rates-movie-frame.png'), filename, 1)
    os.remove(filename)
    plt.close('all')
Esempio n. 5
0
all_nrepeats = []
for test_stim in stim_types:
    full_path = data_dir + expt + '/'
    f = h5py.File(full_path + test_stim, 'r')
    bspk = np.array(f['train/response/binned'])
    tax = np.array(f['train/time'])
    ncells = bspk.shape[0]

    # estimate firing rate with 1 second Gaussian filter
    frs = np.zeros_like(bspk)
    # estimate the cross-correlogram between trials
    nrepeats = np.array(f['test/repeats/cell01']).shape[0]
    correlations = np.zeros((ncells, nrepeats, nrepeats))
    for c in range(ncells):
        # estimate firing rate with 2 second Gaussian
        frs[c,:] = spktools.estfr(tax, bspk[c,:], 2.0)

        cell_label = 'cell%02i' %(c+1)
        repeats = np.array(f['test/repeats/' + cell_label])
        for i in range(nrepeats):
            for j in range(i+1): #(i, nrepeats):
                correlations[c,i,j] = cc(repeats[i,:], repeats[j,:])

    all_ccs.append(correlations)
    all_frs.append(frs)
    all_nrepeats.append(nrepeats)


# generate plots
for c in range(ncells):
    cell_label = 'cell%02i' %(c+1)