import numpy as np import matplotlib.pyplot as plt from plotstyle import * rate = 20.0 trials = 10 duration = 2.0 dt = 0.001 drate = 50.0 tau = 0.1; def hompoisson(rate, trials, duration) : spikes = [] for k in range(trials) : times = [] t = 0.0 while t < duration : t += np.random.exponential(1/rate) times.append(t) spikes.append(times) return spikes def inhompoisson(rate, trials, dt) : spikes = [] p = rate*dt for k in range(trials) : x = np.random.rand(len(rate)) times = dt*np.nonzero(x= vthresh : v = vreset times.append(k*dt) spikes.append(times) return spikes def oupifspikes(rate, trials, duration, dt, D, drate, tau): # OU noise: rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt) + rate for k in range(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 spikes = pifspikes(x, trials, dt, D) return spikes def plot_homogeneous_spikes(ax): homspikes = hompoisson(rate, trials, duration) ax.set_title('stationary') ax.set_xlim(0.0, duration) ax.set_ylim(-0.5, trials-0.5) ax.set_xticks([0, 1, 2]) ax.set_yticks(np.arange(0, trials+1, 5)) ax.set_xlabel('Time', 's') ax.set_ylabel('Trial') ax.eventplot(homspikes, colors=[lsA['color']], linelength=0.8, lw=1) def plot_inhomogeneous_spikes(ax): inhspikes = oupifspikes(rate, trials, duration, dt, 0.3, drate, tau) ax.set_title('non-stationary') ax.set_xlim(0.0, duration) ax.set_ylim(-0.5, trials-0.5) ax.set_xticks([0, 1, 2]) ax.set_yticks(np.arange(0, trials+1, 5)) ax.set_xlabel('Time', 's') #ax.set_ylabel('Trial') ax.eventplot(inhspikes, colors=[lsA['color']], linelength=0.8, lw=1) if __name__ == "__main__": fig, (ax1, ax2) = plt.subplots(1, 2) fig.subplots_adjust(**adjust_fs(fig, left=5.0, right=1.0, top=1.2)) plot_homogeneous_spikes(ax1) plot_inhomogeneous_spikes(ax2) plt.savefig('rasterexamples.pdf') plt.close()