In [1]:
# import seaborn as snsf
from __future__ import print_function, division
from scipy.stats import circmean, circstd
from fakespikes.util import create_psd
from pykdf.kdf import load_kdf
from bw.util import fit_gaussian
from scipy.signal import welch
%matplotlib inline
from brian2 import *
In [2]:
%run ../ie.py ie -t 3 -p 1 -q 1 --sigma .01
In [3]:
res = load_kdf('ie.hdf5')
# -
t = res['t']
dt = res['dt']
times = np.linspace(0, t, t * int(1 / float(dt)))
# -
E = res['E']
I = res['I']
lfp = res['lfp']
# -
figure(figsize=(12, 10))
subplot(311)
plot(times, lfp, label='lfp', color='grey')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
xlim(0, 3)
subplot(312)
plot(times, E, label='E', color='k')
plot(times, I, label='I', color='r')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
xlim(0, 3)
# -
# Make and fit PSD
fs, psd = welch(lfp, int(1 / dt), scaling='density', nperseg=3000/2)
m = np.logical_and(fs > 20, fs < 40)
fs = fs[m]
psd = psd[m]
center, powers, stdevs, fit = fit_gaussian(fs, psd, 20, mph=1e-3)
print(stdevs*2.355)
# -
subplot(313)
plot(fs, psd, color='k', alpha=0.9, ls='--', label='data', lw=3)
plt.plot(center, powers, 'o', alpha=0.9)
plt.plot(fs, fit, color='blue', alpha=0.3, lw=3, label='model')
plt.xlabel("Freq (Hz)")
plt.ylabel("PSD (AU)")
plt.legend()
# plt.semilogy()
plt.tight_layout()
In [22]:
%run ../slidie.py slidie -t 2 --p0 0.3 --pn 1 --sigma .001
# -
res = load_kdf('slidie.hdf5')
# -
t = res['t']
dt = res['dt']
times = np.linspace(0, t, t * int(1 / float(dt)))
# -
E = res['E']
I = res['I']
lfp = res['lfp']
# -
figure(figsize=(12, 10))
subplot(311)
plot(times, lfp, label='lfp', color='grey')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
# xlim(8, 12)
subplot(312)
plot(times, E, label='E', color='k')
plot(times, I, label='I', color='r')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
# xlim(8, 12)
# -
# Make and fit PSD
fs, psd = welch(lfp, int(1 / dt), scaling='density', nperseg=20000)
m = np.logical_and(fs > 20, fs < 40)
fs = fs[m]
psd = psd[m]
center, powers, stdevs, fit = fit_gaussian(fs, psd, 20, mph=1e-3)
print(stdevs*2.355)
# -
subplot(313)
plot(fs, psd, color='k', alpha=0.9, ls='--', label='data', lw=3)
plt.plot(center, powers, 'o', alpha=0.9)
plt.plot(fs, fit, color='blue', alpha=0.3, lw=3, label='model')
plt.xlabel("Freq (Hz)")
plt.ylabel("PSD (AU)")
plt.legend()
# plt.semilogy()
plt.tight_layout()
In [20]:
%run ../mixie.py mixie -n 10 -p 2 -q 1 -s 0.5 --dt 1e-3 --seed 10 --sigma .01
In [21]:
res = load_kdf('mixie.hdf5')
# -
t = res['t']
dt = res['dt']
times = np.linspace(0, t, t * int(1 / float(dt)))
# -
E = res['E']
I = res['I']
lfp = res['lfp']
# -
figure(figsize=(12, 10))
subplot(311)
plot(times, lfp, label='lfp', color='grey')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
xlim(0, 3)
subplot(312)
plot(times, E, label='E', color='k')
plot(times, I, label='I', color='r')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
xlim(0, 3)
# -
fs, psd = welch(lfp, int(1 / dt), scaling='density', nperseg=3000)
m = np.logical_and(fs > 20, fs < 40)
fs = fs[m]
psd = psd[m]
center, powers, stdevs, fit = fit_gaussian(fs, psd, 20, mph=1e-5)
print(stdevs*2.355)
# -
subplot(313)
plot(fs, psd, color='k', alpha=0.9, ls='--', label='data', lw=3)
plt.plot(center, powers, 'o', alpha=0.5)
plt.plot(fs, fit, color='blue', alpha=0.3, lw=3, label='model')
plt.xlabel("Freq (Hz)")
plt.ylabel("PSD (AU)")
plt.legend()
plt.tight_layout()
In [19]:
%run ../burstie.py burstie -w 0.5 -s 1 --sigma 0.001
res = load_kdf('burstie.hdf5')
# -
t = res['t']
dt = res['dt']
times = np.linspace(0, t, t * int(1 / float(dt)))
# -
E = res['E']
I = res['I']
lfp = res['lfp']
# -
figure(figsize=(12, 10))
subplot(311)
plot(times, lfp, label='lfp', color='grey')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
xlim(0, 3)
subplot(312)
plot(times, E, label='E', color='k')
plot(times, I, label='I', color='r')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
xlim(0, 3)
# -
fs, psd = welch(lfp, int(1 / dt), scaling='density', nperseg=3000)
m = np.logical_and(fs > 20, fs < 40)
fs = fs[m]
psd = psd[m]
center, powers, stdevs, fit = fit_gaussian(fs, psd, 20, mph=1e-5)
print(stdevs*2.355)
# -
subplot(313)
plot(fs, psd, color='k', alpha=0.9, ls='--', label='data', lw=3)
plt.plot(center, powers, 'o', alpha=0.5)
plt.plot(fs, fit, color='blue', alpha=0.3, lw=3, label='model')
plt.xlabel("Freq (Hz)")
plt.ylabel("PSD (AU)")
plt.legend()
plt.tight_layout()
In [17]:
%run ../driftie.py driftie -t 3 -d .1 --min_P 0.5
res = load_kdf('driftie.hdf5')
In [18]:
# -
t = res['t']
dt = res['dt']
times = np.linspace(0, t, t * int(1 / float(dt)))
# -
E = res['E']
I = res['I']
lfp = res['lfp']
# -
figure(figsize=(12, 10))
subplot(311)
plot(times, lfp, label='lfp', color='grey')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
# xlim(0, 30)
subplot(312)
plot(times, E, label='E', color='k')
plot(times, I, label='I', color='r')
legend(loc='best')
xlabel("Time (s)")
ylabel("Rate (Hz)")
# xlim(0, 30)
# -
# Make and fit PSD
fs, psd = welch(lfp, int(1 / dt), scaling='density', nperseg=1000)
m = np.logical_and(fs > 20, fs < 40)
fs = fs[m]
psd = psd[m]
center, powers, stdevs, fit = fit_gaussian(fs, psd, 20, mph=1e-3)
# print(stdevs*2.355)
# -
subplot(313)
plot(fs, psd, color='k', alpha=0.9, ls='--', label='data', lw=3)
plt.plot(center, powers, 'o', alpha=0.5)
plt.plot(fs, fit, color='blue', alpha=0.3, lw=3, label='model')
plt.xlabel("Freq (Hz)")
plt.ylabel("PSD (AU)")
plt.legend()
plt.tight_layout()
In [2]:
%run ../kur.py kur -t 4 -n 50 -k 6 -o 30 -r 3 --sigma .1 -p 0.99 --dt 1e-3
In [3]:
res = load_kdf('kur.hdf5')
times = res['times']
thetas = res['thetas']
lfp = res['lfp']
waves = res['waves']
figure(figsize=(12, 3))
plot(times, thetas, color='k', alpha=0.1);
In [ ]:
mTheta = circmean(thetas[times > 3, :], axis=0)
r = np.ones_like(mTheta) # Unit vectors
figure(figsize=(6, 6))
ax = plt.subplot(111, polar=True)
ax.plot(mTheta, r, '.k')
ax.plot(circmean(mTheta), 1, '.r', markersize=30, alpha=0.5)
In [ ]:
# Now sample the avg theta and simulate sin waves with that property,
# each at freq range defined in the K model
# Use this to create a LFP, and PSD
In [ ]:
figure(figsize=(12, 3))
for n in range(res['N'])[:2]:
wave = waves[n, :]
if n == 0:
plt.plot(times, wave, color='k', alpha=0.2, label='Inv. osc.')
else:
plt.plot(times, wave, color='k', alpha=0.2)
plt.plot(times, lfp, 'r', alpha=0.6, label='Sim. LFP')
plt.xlabel("Time (s)")
plt.ylabel("LFP (AU)")
plt.legend()
# plt.xlim(2.8, 3)
print("The oscillator frequencies are", res['omegas'])
In [ ]:
# -
# Make and fit PSD
fs, psd = welch(lfp, int(1 / dt), scaling='density', nperseg=1000)
m = np.logical_and(fs > 20, fs < 40)
fs = fs[m]
psd = psd[m]
center, powers, stdevs, fit = fit_gaussian(fs, psd, 20, mph=1e-3)
print(stdevs*2.355)
# -
figure(figsize=(12, 3))
plot(fs, psd, color='k', alpha=0.9, ls='--', label='data', lw=3)
plt.plot(center, powers, 'o', alpha=0.5)
plt.plot(fs, fit, color='blue', alpha=0.3, lw=3, label='model')
plt.xlabel("Freq (Hz)")
plt.ylabel("PSD (AU)")
plt.legend()
plt.tight_layout()
In [ ]:
In [ ]: