import numpy as np
import matplotlib.pyplot as plt
from matplotlib import pyplot as plt
plt.switch_backend('agg')
N = 5000
Ne = 4000
Ni = 1000
tmin = 9000
tmax = 1000
dtype = {"names": ["cellid", "time"], "formats": ["i4", "f8"]}
inh_cells = np.loadtxt("brunel_inh.txt", dtype=dtype)
exc_cells = np.loadtxt("brunel_exc.txt", dtype=dtype)
inh_cells["time"] = inh_cells["time"] * 1000 - tmin
exc_cells["time"] = exc_cells["time"] * 1000 - tmin
inh_cells["cellid"] += Ne
Nstp = 10
tick_size = 5
fig, axes = plt.subplots(2, 1, figsize=(8, 6), sharex=True)
axes[0].plot(exc_cells[::Nstp]["time"], exc_cells[::Nstp]["cellid"], ".", ms=tick_size)
axes[0].plot(inh_cells[::Nstp]["time"], inh_cells[::Nstp]["cellid"], ".", ms=tick_size)
xmax = 0.2
ymax = 0.2
X, Y = np.random.rand(2, N) * np.array([[xmax, ymax]]).T
dt = 0.1
npts = int(tmax / dt)
xe = xmax / 2
ye = ymax / 2
va = 200
lambda_ = 0.2
dur = 100
nlfp = int(dur / dt)
amp_e = 0.7
amp_i = -3.4
sig_i = 2.1
sig_e = 1.5 * sig_i
amp_e = 0.48
amp_i = 3
dist = np.sqrt((X - xe) ** 2 + (Y - ye) ** 2)
delay = 10.4 + dist / va
amp = np.exp(-dist / lambda_)
amp[:Ne] *= amp_i
amp[Ne:] *= amp_e
s_e = 2 * sig_e * sig_e
s_i = 2 * sig_i * sig_i
lfp_time = np.arange(npts) * dt
def f_temporal_kernel(t, tau):
"""function defining temporal part of the kernel"""
return np.exp(-(t ** 2) / tau)
def calc_lfp(cells):
"""Calculate LFP from cells"""
spt = inh_cells["time"]
cid = inh_cells["cellid"]
kernel_contribs = amp[None, cid] * f_temporal_kernel(
lfp_time[:, None] - delay[None, cid] - spt[None, :], s_i
)
lfp = kernel_contribs.sum(1)
return lfp
lfp_inh = calc_lfp(inh_cells)
lfp_exc = calc_lfp(exc_cells)
total_lfp = lfp_inh + lfp_exc
axes[1].plot(lfp_time, total_lfp)
axes[1].set_xlabel("time, ms")
axes[1].set_xlim(0, tmax)
axes[0].spines["top"].set_visible(False)
axes[0].spines["right"].set_visible(False)
axes[1].spines["top"].set_visible(False)
axes[1].spines["right"].set_visible(False)
plt.savefig("demo_lfp_kernel.pdf")
plt.show()