def test_short_spiketrain(self): # this spike train has the same length as anasig0 s1, f1 = sta.spike_field_coherence( self.anasig0, self.bst3, window='boxcar') # this spike train has the same spikes as above, but is shorter than # anasig0 s2, f2 = sta.spike_field_coherence( self.anasig0, self.bst4, window='boxcar') # the results above should be the same, nevertheless assert_array_equal(s1.magnitude, s2.magnitude) assert_array_equal(f1.magnitude, f2.magnitude)
def test_non_binned_spiketrain_input(self): s, f = sta.spike_field_coherence(self.anasig0, self.st0) f_ind = np.where(f >= 19.)[0][0] max_ind = np.argmax(s[1:]) + 1 self.assertEqual(f_ind, max_ind) self.assertAlmostEqual(s[f_ind], 1., delta=0.01)
def test_spike_field_coherence_perfect_coherence(self): # check for detection of 20Hz peak in anasig0/bst0 s, f = sta.spike_field_coherence( self.anasig0, self.bst0, window='boxcar') f_ind = np.where(f >= 19.)[0][0] max_ind = np.argmax(s[1:]) + 1 self.assertEqual(f_ind, max_ind) self.assertAlmostEqual(s[f_ind], 1., delta=0.01)
def test_signal_dimensions(self): # single analogsignal trace and single spike train s_single, f_single = sta.spike_field_coherence(self.anasig0, self.bst0) self.assertEqual(len(f_single.shape), 1) self.assertEqual(len(s_single.shape), 2) # multiple analogsignal traces and single spike train s_multi, f_multi = sta.spike_field_coherence(self.anasig4, self.bst0) self.assertEqual(len(f_multi.shape), 1) self.assertEqual(len(s_multi.shape), 2) # frequencies are identical since same sampling frequency was used # in both cases and data length is the same assert_array_equal(f_single, f_multi) # coherences of s_single and first signal in s_multi are identical, # since first analogsignal trace in anasig4 is same as in anasig0 assert_array_equal(s_single[:, 0], s_multi[:, 0])
def test_output_frequencies(self): nfft = 256 _, f = sta.spike_field_coherence(self.anasig3, self.bst1, nfft=nfft) # check number of frequency samples self.assertEqual(len(f), nfft / 2 + 1) # check values of frequency samples assert_array_almost_equal( f, np.linspace( 0, self.anasig3.sampling_rate.rescale('Hz').magnitude / 2, nfft / 2 + 1) * pq.Hz)
def test_output_frequencies(self): nfft = 256 _, f = sta.spike_field_coherence(self.anasig3, self.bst1, nfft=nfft) # check number of frequency samples self.assertEqual(len(f), nfft / 2 + 1) f_max = self.anasig3.sampling_rate.rescale('Hz').magnitude / 2 f_ground_truth = np.linspace(start=0, stop=f_max, num=nfft // 2 + 1) * pq.Hz # check values of frequency samples assert_array_almost_equal(f, f_ground_truth)
def test_spike_field_coherence_perfect_coherence(self): # check for detection of 20Hz peak in anasig0/bst0 with warnings.catch_warnings(): warnings.simplefilter("ignore") """ When the spiketrain is a vector with zero values, ignore the warning RuntimeWarning: invalid value encountered in true_divide Cxy = np.abs(Pxy)**2 / Pxx / Pyy. """ s, f = sta.spike_field_coherence( self.anasig0, self.bst0, window='boxcar') f_ind = np.where(f >= 19.)[0][0] max_ind = np.argmax(s[1:]) + 1 self.assertEqual(f_ind, max_ind) self.assertAlmostEqual(s[f_ind], 1., delta=0.01)