Пример #1
0
def test_filterpeak():
    """Test finding the maximal point in a 3D filter"""
    arr = np.zeros((5, 2, 2))
    true_index = 7
    arr.flat[true_index] = -1
    true_indices = np.unravel_index(true_index, arr.shape)

    idx, sidx, tidx = flt.filterpeak(arr)
    assert true_index == idx
    assert true_indices[0] == tidx
    assert np.all(true_indices[1:] == sidx)
Пример #2
0
def test_filterpeak():
    """Test finding the maximal point in a 3D filter"""
    arr = np.zeros((5, 2, 2))
    true_index = 7
    arr.flat[true_index] = -1
    true_indices = np.unravel_index(true_index, arr.shape)

    idx, sidx, tidx  = flt.filterpeak(arr)
    assert true_index == idx
    assert true_indices[0] == tidx
    assert np.all(true_indices[1:] == sidx)
Пример #3
0
def stimcut(data, expt, ci, width=11):
    """Cuts out a stimulus around the whitenoise receptive field"""

    # get the white noise STA for this cell
    wn = _loadexpt_h5(expt, 'whitenoise')
    sta = np.array(wn[f'train/stas/cell{ci+1:02d}']).copy()

    # find the peak of the sta
    xc, yc = ft.filterpeak(sta)[1]

    # cutout stimulus
    X, y = data
    Xc = ft.cutout(X, idx=(yc, xc), width=width)
    yc = y[:, ci].reshape(-1, 1)
    return Exptdata(Xc, yc)
Пример #4
0
def loadexpt(expt, cells, filename, train_or_test, history, nskip, cutout_width=None):
    """Loads an experiment from an h5 file on disk

    Parameters
    ----------
    expt : str
        The date of the experiment to load in YY-MM-DD format (e.g. '15-10-07')

    cells : list of ints
        Indices of the cells to load from the experiment

    filename : string
        Name of the hdf5 file to load (e.g. 'whitenoise' or 'naturalscene')

    train_or_test : string
        The key in the hdf5 file to load ('train' or 'test')

    history : int
        Number of samples of history to include in the toeplitz stimulus

    nskip : float, optional
        Number of samples to skip at the beginning of each repeat

    cutout_width : int, optional
        If not None, cuts out the stimulus around the STA (assumes cells is a scalar)
    """
    assert history > 0 and type(history) is int, "Temporal history must be a positive integer"
    assert train_or_test in ('train', 'test'), "train_or_test must be 'train' or 'test'"

    with notify('Loading {}ing data for {}/{}'.format(train_or_test, expt, filename)):

        # get whitenoise STA for cutout stimulus
        if cutout_width is not None:
            assert len(cells) == 1, "cutout must be used with single cells"
            wn = _loadexpt_h5(expt, 'whitenoise')
            sta = np.array(wn[f'train/stas/cell{cells[0]+1:02d}']).copy()
            py, px = ft.filterpeak(sta)[1]

        # load the hdf5 file
        with _loadexpt_h5(expt, filename) as f:

            expt_length = f[train_or_test]['time'].size

            # load the stimulus into memory as a numpy array, and z-score it
            if cutout_width is None:
                stim = zscore(np.array(f[train_or_test]['stimulus']).astype('float32'))
            else:
                stim = zscore(ft.cutout(np.array(f[train_or_test]['stimulus']), idx=(px, py), width=cutout_width).astype('float32'))

            # apply clipping to remove the stimulus just after transitions
            num_blocks = NUM_BLOCKS[expt] if train_or_test == 'train' and nskip > 0 else 1
            valid_indices = np.arange(expt_length).reshape(num_blocks, -1)[:, nskip:].ravel()

            # reshape into the Toeplitz matrix (nsamples, history, *stim_dims)
            stim_reshaped = rolling_window(stim[valid_indices], history, time_axis=0)

            # get the response for this cell (nsamples, ncells)
            resp = np.array(f[train_or_test]['response/firing_rate_10ms'][cells]).T[valid_indices]
            resp = resp[history:]

            # get the spike history counts for this cell (nsamples, ncells)
            binned = np.array(f[train_or_test]['response/binned'][cells]).T[valid_indices]
            spk_hist = rolling_window(binned, history, time_axis=0)

    return Exptdata(stim_reshaped, resp, spk_hist)
Пример #5
0

# In[6]:

spk = f['spikes/cell01']


# In[8]:

time = np.array(f['train/time'])
sta, tax = ft.getsta(time, whitenoise_train.X, spk, 35)


# In[11]:

Xcut = ft.cutout(whitenoise_train.X, idx=np.flipud(ft.filterpeak(sta)[1]), width=5)


# In[113]:

stc = np.zeros((35*11*11, 35*11*11))
for idx, s in enumerate(ft.getste(time, Xcut, spk, 35)):
    sr = s.astype('float').ravel()
    if sr.size == (35*11*11):
        stc += np.outer(sr, sr)
        
    if idx % 500 == 0:
        print('{}'.format(100.*idx/len(spk)))


# In[ ]: