예제 #1
0
def oasis_function(signal, threshold=0.5):
  ''' apply OASIS function to a single calcium signal and binarize spike train 
  with threshold '''
  if signal.dtype != np.double:
    signal = signal.astype(np.double)
  _, train = oasisAR1(signal, g=0.95, s_min=.55)
  return np.where(train > threshold, 1.0, 0.0)
예제 #2
0
def AR1(constrained=False):
    g = .95
    sn = .3
    y, c, s = [a[0] for a in gen_data([g], sn, N=1)]
    result = constrained_oasisAR1(y, g, sn) if constrained else oasisAR1(y, g, lam=2.4)
    result_foopsi = constrained_foopsi(y, [g], sn) if constrained else foopsi(y, [g], lam=2.4)
    npt.assert_allclose(np.corrcoef(result[0], result_foopsi[0])[0, 1], 1)
    npt.assert_allclose(np.corrcoef(result[1], result_foopsi[1])[0, 1], 1)
    npt.assert_allclose(np.corrcoef(result[0], c)[0, 1], 1, .03)
    npt.assert_allclose(np.corrcoef(result[1], s)[0, 1], 1, .2)
예제 #3
0
def generate_spike_train(hparams, filename):
    print('processing file {}...'.format(filename))

    with open(filename, 'rb') as file:
        data = pickle.load(file)

    if 'oasis' in data:
        print('oasis spike train already existed in {}'.format(filename))
        if hparams.overwrite:
            print('overwriting...')
        else:
            return

    oasis = np.zeros((data['signals'].shape), dtype=data['signals'].dtype)
    for i in tqdm(range(len(data['signals']))):
        _, oasis[i] = oasisAR1(data['signals'][i], g=0.95, s_min=.55)
    oasis = np.where(oasis > 0.5, 1.0, 0.0)

    data['oasis'] = np.array(oasis, dtype=np.float32)

    with open(filename, 'wb') as file:
        pickle.dump(data, file)
예제 #4
0
 def AR1_model_deconvole(self, trace, smin=0.7):
     c, s = oasisAR1(trace, g=np.exp(-1 / (1.6 * 4.85)), s_min=smin)
     return (c, s)