In [1]:
%%javascript
if($(IPython.toolbar.selector.concat(' > #kill-run-all')).length == 0){
  IPython.toolbar.add_buttons_group([
        {
             'label'   : 'kill and run-all',
             'icon'    : 'fa fa-angle-double-down',
             'callback': function(){
                 IPython.notebook.kernel.restart();
                 $(IPython.events).one('kernel_ready.Kernel',
                                       function(){IPython.notebook.execute_all_cells();});
             }
        }
    ], 'kill-run-all');
}



In [2]:
import seaborn as sns
from foof.util import create_psd
%matplotlib inline

In [3]:
# stim induced
%run ../bin/ping.py ../data/test/ -t 1 --stim 0.75 --rate 10 --I_e 0. 0. --I_i 0.8 0.8 --w_e 0.8 --w_ee 0.2 --w_ei 0.0 --w_ie 0.8


Starting simulation for duration 1. s
213.4 ms (21%) simulated in 10s, estimated 37s remaining.
0.4262 s (42%) simulated in 20s, estimated 27s remaining.
0.6377 s (63%) simulated in 30s, estimated 17s remaining.
0.8486 s (84%) simulated in 40s, estimated 7s remaining.
1. s (100%) simulated in 47s
WARNING  py.warnings: /home/ejp/anaconda/lib/python2.7/site-packages/scipy/signal/spectral.py:281: UserWarning: nperseg = 1024, is greater than x.shape[-1] = 921, using nperseg = x.shape[-1]
  % (nperseg, axis, x.shape[axis], axis))

WARNING:py.warnings:/home/ejp/anaconda/lib/python2.7/site-packages/scipy/signal/spectral.py:281: UserWarning: nperseg = 1024, is greater than x.shape[-1] = 921, using nperseg = x.shape[-1]
  % (nperseg, axis, x.shape[axis], axis))

WARNING  py.warnings: /home/ejp/anaconda/lib/python2.7/site-packages/brian2/groups/group.py:196: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if item is None or item == 'True':

WARNING:py.warnings:/home/ejp/anaconda/lib/python2.7/site-packages/brian2/groups/group.py:196: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if item is None or item == 'True':

WARNING  py.warnings: /home/ejp/anaconda/lib/python2.7/site-packages/numpy/lib/nanfunctions.py:675: RuntimeWarning: Mean of empty slice
  warnings.warn("Mean of empty slice", RuntimeWarning)

WARNING:py.warnings:/home/ejp/anaconda/lib/python2.7/site-packages/numpy/lib/nanfunctions.py:675: RuntimeWarning: Mean of empty slice
  warnings.warn("Mean of empty slice", RuntimeWarning)


In [4]:
# Unpack
spikes_e = result['spikes_e']
spikes_stim = result['spikes_stim']
spikes_i = result['spikes_i']
pop_e = result['pop_e']
pop_stim = result['pop_stim']
voltages_e = result['voltages_e']
voltages_i = result['voltages_i']
t = 2000

# ------------------------------------------------------------
# Raster full
figure(figsize=(14, 12))
subplot(311)
plot(spikes_stim.t/ms, spikes_stim.i, 'o', label='', color='k')
xlim(0,1000)
ylabel("Neuron #")
legend()

subplot(312)
plot(spikes_e.t/ms, spikes_e.i, 'o', label='E', color='k')
plot(spikes_i.t/ms, spikes_i.i, 'o', label='I', color='r')
xlim(0,1000)
ylabel("Neuron #")
legend()


# Raster zoom
figure(figsize=(10, 4))
subplot(211)
plot(spikes_e.t/ms, spikes_e.i, 'o', label='E', color='k')
ylabel("Neuron #")
ylim(0,200)
xlim(600,700)
legend()

subplot(212)
plot(spikes_i.t/ms, spikes_i.i, 'o', label='I', color='r')
xlabel("Time (ms)")
ylim(0,40)
xlim(600,700)

# ------------------------------------------------------------
# V 
tn = 2000
figure(figsize=(10,4))
subplot(211)
plot(voltages_e.t[tn:]/ms, voltages_e.V[:, tn:].T/mvolt, color='k')
# ylim(-90, -50)
ylabel("V")
legend()

subplot(212)
plot(voltages_i.t[tn:]/ms, voltages_i.V[:, tn:].T/mvolt, color='r')
xlabel("Time (ms)")
legend()

# V hist
figure(figsize=(6,6))
subplot(211)
hist(voltages_e.V[0][tn:]/mvolt, label='E (V)', color='k', bins=100, range=(-80, -50))
xlabel("V")
legend()

# ------------------------------------------------------------
# E rate
figure(figsize=(10,4))
plot(pop_e.t[tn:]/ms, pop_e.rate[tn:]/Hz, color='k', label='E rate')
ylabel('Rate (Hz)')
xlabel("Time (ms)")
legend()

figure(figsize=(10,4))
plot(pop_stim.t[tn:]/ms, pop_stim.rate[tn:]/Hz, color='k', label='Stim rate')
ylabel('Rate (Hz)')
xlabel("Time (ms)")
legend()

# ------------------------------------------------------------
figure(figsize=(12,10))
subplot(511)
plot(voltages_e.t[tn:]/ms, voltages_e.g_s.sum(0)[tn:], color='k', label='E (g_s)')
ylabel("g")
legend(loc='best')

subplot(512)
plot(voltages_e.t[tn:]/ms, voltages_e.g_e.sum(0)[tn:], color='k', label='E (g_e)')
legend(loc='best')

subplot(513)
plot(voltages_e.t[tn:]/ms, voltages_e.g_i.sum(0)[tn:], color='k', label='E (g_i)')
legend(loc='best')

subplot(514)
plot(voltages_i.t[tn:]/ms, voltages_i.g_i.sum(0)[tn:], color='k', label='I (g_i)')
legend(loc='best')

subplot(515)
plot(voltages_e.t[tn:]/ms, voltages_e.g_ee[1:20, tn:].T, label='E (g_ee)')
xlabel("Time (ms)")

# ------------------------------------------------------------
# Spectra
lfp = (np.abs(voltages_e.g_s.sum(0)) + np.abs(voltages_e.g_ee.sum(0)))
lfp = lfp[1000:]  # Drop initial spike

figure(figsize=(6,6))
subplot(211)
plot(voltages_i.t[1000:]/ms, lfp, color='k',  label='LFP')
xlabel("Time (ms)")
ylabel("Sim. LFP (msiemens)")

subplot(212)
fs, spec = create_psd(lfp, 10000)
plot(fs[:40], spec[:40], color='k')
xlabel("Freq (Hz)") 
ylabel("PSD")


WARNING  py.warnings: /home/ejp/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.py:475: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labelled objects found. "

WARNING:py.warnings:/home/ejp/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.py:475: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labelled objects found. "

Out[4]:
<matplotlib.text.Text at 0x7fd5a0cb5a50>

In [ ]: