def test_basic(self): file_contents = np.load( os.path.join(os.path.dirname(__file__), 'test_data/tiny_spikes.npz')) spikes = Spikes(file_contents[file_contents.keys()[0]]) self.assertEqual(spikes._spikes.sum(), 9) self.assertEqual(spikes.rasterize(stop=5).sum(), 7) spikes.rasterize(save_png_name=os.path.join(self.TMP_PATH, 'spikes')) self.assertTrue( os.path.exists(os.path.join(self.TMP_PATH, 'spikes.png'))) file_contents = np.load( os.path.join(os.path.dirname(__file__), 'test_data/spikes_trials.npz')) spikes = Spikes(file_contents[file_contents.keys()[0]]) spikes.rasterize(save_png_name=os.path.join(self.TMP_PATH, 'spikes')) self.assertTrue( os.path.exists(os.path.join(self.TMP_PATH, 'spikes.png'))) file_contents = np.load( os.path.join(os.path.dirname(__file__), 'test_data/spikes_trials.npz')) spikes = Spikes(file_contents[file_contents.keys()[0]]) spikes.restrict_to_most_active_neurons(top_neurons=2) self.assertEqual(spikes._N, 2)
def test_basic(self): file_contents = np.load(os.path.join(os.path.dirname(__file__), 'test_data/tiny_spikes.npz')) spikes = Spikes(file_contents[file_contents.keys()[0]]) self.assertEqual(spikes._spikes.sum(), 9) self.assertEqual(spikes.rasterize(stop=5).sum(), 7) spikes.rasterize(save_png_name=os.path.join(self.TMP_PATH, 'spikes')) self.assertTrue(os.path.exists(os.path.join(self.TMP_PATH, 'spikes.png'))) file_contents = np.load(os.path.join(os.path.dirname(__file__), 'test_data/spikes_trials.npz')) spikes = Spikes(file_contents[file_contents.keys()[0]]) spikes.rasterize(save_png_name=os.path.join(self.TMP_PATH, 'spikes')) self.assertTrue(os.path.exists(os.path.join(self.TMP_PATH, 'spikes.png'))) file_contents = np.load(os.path.join(os.path.dirname(__file__), 'test_data/spikes_trials.npz')) spikes = Spikes(file_contents[file_contents.keys()[0]]) spikes.restrict_to_most_active_neurons(top_neurons=2) self.assertEqual(spikes._N, 2)
import numpy as np import matplotlib.pyplot as plt from hdnet.stimulus import Stimulus from hdnet.spikes import Spikes from hdnet.spikes_model import SpikeModel, BernoulliHomogeneous, DichotomizedGaussian # Let's first make up some simuilated spikes: 2 trials spikes = (np.random.random((2, 10, 200)) < .05).astype(int) spikes[0, [1, 5], ::5] = 1 # insert correlations spikes[1, [2, 3, 6], ::11] = 1 # insert correlations spikes = Spikes(spikes=spikes) # let's look at them: quick save as PNG or make PSTH pyplot plt.matshow(spikes.rasterize(), cmap='gray') plt.title('Raw spikes') plt.show() buff = input('Press a key to continue!') plt.close() #spikes.rasterize(save_png_name='raster') plt.matshow(spikes.covariance().reshape((2 * 10, 10)), cmap='gray') plt.title('Raw spikes covariance') plt.show() buff = input('Press a key to continue!') plt.close() #spikes.covariance(save_png_name='simul_cov_matrices') # let's examine the structure in spikes using a spike modeler spikes_model = BernoulliHomogeneous(spikes=spikes) BH_sample_spikes = spikes_model.sample_from_model()
import numpy as np import matplotlib.pyplot as plt from hdnet.stimulus import Stimulus from hdnet.spikes import Spikes from hdnet.spikes_model import SpikeModel, BernoulliHomogeneous, DichotomizedGaussian # Let's first make up some simuilated spikes: 2 trials spikes = (np.random.random((2, 10, 200)) < .05).astype(int) spikes[0, [1, 5], ::5] = 1 # insert correlations spikes[1, [2, 3, 6], ::11] = 1 # insert correlations spikes = Spikes(spikes=spikes) # let's look at them: quick save as PNG or make PSTH pyplot plt.matshow(spikes.rasterize(), cmap='gray') plt.title('Raw spikes') #spikes.rasterize(save_png_name='raster') plt.matshow(spikes.covariance().reshape((2 * 10, 10)), cmap='gray') plt.title('Raw spikes covariance') #spikes.covariance(save_png_name='simul_cov_matrices') # let's examine the structure in spikes using a spike modeler spikes_model = BernoulliHomogeneous(spikes=spikes) BH_sample_spikes = spikes_model.sample_from_model() plt.matshow(BH_sample_spikes.rasterize(), cmap='gray') plt.title('BernoulliHomogeneous sample') print "%1.4f means" % BH_sample_spikes.spikes.mean() plt.matshow(BH_sample_spikes.covariance().reshape((2 * 10, 10)), cmap='gray') plt.title('BernoulliHomogeneous covariance')