def test_empty_sta(): """Test that an empty with no spikes returns an array of nans""" np.random.seed(0) time = np.arange(100) spikes = np.array(()) stimulus = np.random.randn(100, ) filter_length = 5 sta, _ = flt.sta(time, stimulus, spikes, filter_length) assert np.all(np.isnan(sta))
def test_empty_sta(): """Test that an empty with no spikes returns an array of nans""" np.random.seed(0) time = np.arange(100) spikes = np.array(()) stimulus = np.random.randn(100,) filter_length = 5 sta, _ = flt.sta(time, stimulus, spikes, filter_length) assert np.all(np.isnan(sta))
def test_sta(): """Test computing a spike-triggered average.""" np.random.seed(0) time = np.arange(100) spikes = np.array((0, 30, 70)) stimulus = np.random.randn(100,) filter_length = 5 sta, tax = flt.sta(time, stimulus, spikes, filter_length) tmp = np.zeros(sta.shape) for ix in spikes[1:]: # Should ignore first spike, comes before filter_length frames tmp += stimulus[ix - filter_length : ix] tmp /= len(spikes) assert np.allclose(tmp, sta) assert np.allclose(tax, np.arange(-filter_length + 1, 1))
def test_sta(): """Test computing a spike-triggered average.""" np.random.seed(0) time = np.arange(100) spikes = np.array((0, 30, 70)) stimulus = np.random.randn(100,) filter_length = 5 sta, tax = flt.sta(time, stimulus, spikes, filter_length) tmp = np.zeros(sta.shape) for ix in spikes[1:]: # Should ignore first spike, comes before filter_length frames tmp += stimulus[ix - filter_length : ix] tmp /= len(spikes) assert np.allclose(tmp, sta) assert np.allclose(tax, np.arange(-filter_length + 1, 1))
def test_sta_acausal(): """Test computing a spike-triggered average with points before and after the time of the spike. """ np.random.seed(0) time = np.arange(100) spikes = np.array((0, 30, 70)) stimulus = np.random.randn(100,) nbefore, nafter = 5, 2 sta, tax = flt.sta(time, stimulus, spikes, nbefore, nafter) tmp = np.zeros(sta.shape) for ix in spikes[1:]: # Should ignore first spike, comes before filter_length frames tmp += stimulus[ix - nbefore : ix + nafter] tmp /= len(spikes) assert np.allclose(tmp, sta) assert np.allclose(tax, np.arange(-nbefore + 1, nafter + 1))
def test_sta_acausal(): """Test computing a spike-triggered average with points before and after the time of the spike. """ np.random.seed(0) time = np.arange(100) spikes = np.array((0, 30, 70)) stimulus = np.random.randn(100,) nbefore, nafter = 5, 2 sta, tax = flt.sta(time, stimulus, spikes, nbefore, nafter) tmp = np.zeros(sta.shape) for ix in spikes[1:]: # Should ignore first spike, comes before filter_length frames tmp += stimulus[ix - nbefore : ix + nafter] tmp /= len(spikes) assert np.allclose(tmp, sta) assert np.allclose(tax, np.arange(-nbefore + 1, nafter + 1))