def __init__(self, **kwargs): # Set default values of keyword arguments self.tau_gcl = 0.42 / 1000 self.tau_inl = 18.0 / 1000 self.tau_ca = 45.25 / 1000 self.tau_slow = 26.25 / 1000 self.scale_ca = 42.1 self.scale_slow = 1150.0 self.lweight = 0.636 self.aweight = 0.5 self.slope = 3.0 self.shift = 15.0 # Overwrite any given keyword arguments, print warning message (True) # if attempting to set an unrecognized keyword self.set_kwargs(True, **kwargs) # perform one-time setup calculations _, self.gamma_inl = utils.gamma(1, self.tau_inl, self.tsample) _, self.gamma_gcl = utils.gamma(1, self.tau_gcl, self.tsample) # gamma_ca is used to calculate charge accumulation _, self.gamma_ca = utils.gamma(1, self.tau_ca, self.tsample) # gamma_slow is used to calculate the slow response _, self.gamma_slow = utils.gamma(3, self.tau_slow, self.tsample)
def __init__(self, **kwargs): self.tsample = 0.01 / 1000 self.tau1 = 0.42 / 1000 self.tau2 = 45.25 / 1000 self.tau3 = 26.25 / 1000 self.epsilon = 2.25 self.beta = 3.43 # Overwrite any given keyword arguments, print warning message (True) # if attempting to set an unrecognized keyword self.set_kwargs(True, **kwargs) _, self.gamma1 = utils.gamma(1, self.tau1, self.tsample) _, self.gamma2 = utils.gamma(1, self.tau2, self.tsample) _, self.gamma3 = utils.gamma(3, self.tau3, self.tsample)
def test_conv(mode, method): reload(convolution) # time vector for stimulus (long) stim_dur = 0.5 # seconds tsample = 0.001 / 1000 t = np.arange(0, stim_dur, tsample) # stimulus (10 Hz anondic and cathodic pulse train) stim = np.zeros_like(t) stim[::1000] = 1 stim[100::1000] = -1 # kernel _, gg = gamma(1, 0.005, tsample) # make sure conv returns the same result as np.convolve for all modes: npconv = np.convolve(stim, gg, mode=mode) conv = convolution.conv(stim, gg, mode=mode, method=method) npt.assert_equal(conv.shape, npconv.shape) npt.assert_almost_equal(conv, npconv) with pytest.raises(ValueError): convolution.conv(gg, stim, mode="invalid") with pytest.raises(ValueError): convolution.conv(gg, stim, method="invalid")
def test_conv(mode, method, use_jit): reload(convolution) # time vector for stimulus (long) stim_dur = 0.5 # seconds tsample = 0.001 / 1000 t = np.arange(0, stim_dur, tsample) # stimulus (10 Hz anondic and cathodic pulse train) stim = np.zeros_like(t) stim[::1000] = 1 stim[100::1000] = -1 # kernel _, gg = gamma(1, 0.005, tsample) # make sure conv returns the same result as np.convolve for all modes: npconv = np.convolve(stim, gg, mode=mode) conv = convolution.conv(stim, gg, mode=mode, method=method, use_jit=use_jit) npt.assert_equal(conv.shape, npconv.shape) npt.assert_almost_equal(conv, npconv) with pytest.raises(ValueError): convolution.conv(gg, stim, mode="invalid", use_jit=use_jit) with pytest.raises(ValueError): convolution.conv(gg, stim, method="invalid", use_jit=use_jit) with mock.patch.dict("sys.modules", {"numba": {}}): with pytest.raises(ImportError): reload(convolution) convolution.conv(stim, gg, mode='full', method='sparse', use_jit=True)
def __init__(self, **kwargs): # Set default values of keyword arguments self.tau1 = 0.42 / 1000 self.tau2 = 45.25 / 1000 self.tau3 = 26.25 / 1000 self.eps = 8.73 self.asymptote = 14.0 self.slope = 3.0 self.shift = 16.0 # Overwrite any given keyword arguments, print warning message (True) # if attempting to set an unrecognized keyword self.set_kwargs(True, **kwargs) # perform one-time setup calculations # gamma1 is used for the fast response _, self.gamma1 = utils.gamma(1, self.tau1, self.tsample) # gamma2 is used to calculate charge accumulation _, self.gamma2 = utils.gamma(1, self.tau2, self.tsample) # gamma3 is used to calculate the slow response _, self.gamma3 = utils.gamma(3, self.tau3, self.tsample)
def test_gamma(): tsample = 0.005 / 1000 with pytest.raises(ValueError): t, g = gamma(0, 0.1, tsample) with pytest.raises(ValueError): t, g = gamma(2, -0.1, tsample) with pytest.raises(ValueError): t, g = gamma(2, 0.1, -tsample) for tau in [0.001, 0.01, 0.1]: for n in [1, 2, 5]: t, g = gamma(n, tau, tsample) npt.assert_equal(np.arange(0, t[-1] + tsample / 2.0, tsample), t) if n > 1: npt.assert_equal(g[0], 0.0) # Make sure area under the curve is normalized npt.assert_almost_equal(np.trapz(np.abs(g), dx=tsample), 1.0, decimal=2) # Make sure peak sits correctly npt.assert_almost_equal(g.argmax() * tsample, tau * (n - 1))
def test_conv(): reload(utils) # time vector for stimulus (long) stim_dur = 0.5 # seconds tsample = 0.001 / 1000 t = np.arange(0, stim_dur, tsample) # stimulus (10 Hz anondic and cathodic pulse train) stim = np.zeros_like(t) stim[::1000] = 1 stim[100::1000] = -1 # kernel _, gg = utils.gamma(1, 0.005, tsample) # make sure conv returns the same result as # make sure sparseconv returns the same result as np.convolve # for all modes methods = ["fft", "sparse"] modes = ["full", "valid", "same"] for mode in modes: # np.convolve npconv = np.convolve(stim, gg, mode=mode) for method in methods: conv = utils.conv(stim, gg, mode=mode, method=method) npt.assert_equal(conv.shape, npconv.shape) npt.assert_almost_equal(conv, npconv) with pytest.raises(ValueError): utils.conv(gg, stim, mode="invalid") with pytest.raises(ValueError): utils.conv(gg, stim, method="invalid") with mock.patch.dict("sys.modules", {"numba": {}}): with pytest.raises(ImportError): reload(utils) utils.conv(stim, gg, mode='full', method='sparse', use_jit=True)