In [1]:
import os
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import pickle
from Experiment import Experiment
from LIF import LIF
from Filter_Rect_LogSpaced import Filter_Rect_LogSpaced
plt.style.use('ggplot')
mpl.rcParams['font.size'] = 12
mpl.rcParams['axes.facecolor'] = 'white'
root_path = './full_dataset/article_4_data/grouped_ephys/'
figures_path = './results/figures/raw_data/full_dataset'
expm_path = './results/experiments/'
dirs = sorted(os.listdir(root_path))
animalset = np.arange(0,len(dirs))
In [2]:
def open_filterd_list(filtername):
with open('/home/andrej/Dropbox/Arbeit/MKP/gif_fitting/BlueBrain/' + filtername + '_infos.pkl', 'rb') as f:
filtered_list = pickle.load(f)
return filtered_list
soms = open_filterd_list('som_animals')
vips = open_filterd_list('vip_animals')
pvs = open_filterd_list('pv_animals')
In [3]:
cell_names = list(vips.keys())
expms = []
for i in range(len(vips)):
current_expm_name = 'Experiment_Cell_' + cell_names[i] + '_merged_idrest_traces.pkl'
current_expm_path = os.path.join(expm_path,current_expm_name)
try:
current_expm = Experiment.load(current_expm_path)
expms.append(current_expm)
except:
pass
In [4]:
len(expms)
In [5]:
my_expm = expms[0]
mylif = LIF(my_expm.dt)
mylif.Tref = 4.0
my_expm.detectSpikes_cython()
mylif.fitVoltageReset(my_expm,4.0)
tr = my_expm.trainingset_traces[0]
In [6]:
for expm in expms:
mylif = LIF(expm.dt)
mylif.Tref = 4.0
expm.detectSpikes_cython()
print(expm.name)
mylif.fitVoltageReset(expm,4.0)
In [20]:
for expm in expms:
tr = expm.trainingset_traces[0]
plt.figure(figsize=(12,12))
for i in range(tr.getSpikeNb()):
plt.plot(tr.spike_waveforms[i,:], label='V')
spike_diff = np.diff(tr.spike_waveforms[i,:])
#plt.plot(spike_diff, label='dV')
plt.plot(tr.relative_threshold_times[i], tr.threshold_values[i],'*r')
#peak_time = tr.peaks_t[i]-(tr.spks[i]-40)
plt.plot(tr.relative_peak_times[i], tr.spike_waveforms[i,tr.relative_peak_times[i]], 'ob')
plt.plot(tr.relative_max_dV_times[i], tr.max_dV_values[i], '*k')
plt.title(expm.name)
#plt.legend()
#plt.xlim([5,45])
#plt.ylim([-60,-30])
plt.show()
In [27]:
lifs = []
for expm in expms:
# Create a new object GIF
myLIF = LIF(expm.dt)
# Define parameters
myLIF.Tref = 5.0
# detect Spikes
expm.detectSpikes_cython()
# Perform the fit
myLIF.fit(expm, DT_beforeSpike=5.0)
lifs.append(myLIF)
In [33]:
tr.plot()
In [28]:
a = lifs[0]
In [29]:
plt.figure()
for a in lifs:
plt.plot(a.avg_spike_shape_support, a.avg_spike_shape, 'black')
Tref_ind = np.where(a.avg_spike_shape_support >= a.Tref)[0][0]
plt.plot([a.avg_spike_shape_support[Tref_ind]], [a.Vr], '.', color='red')
plt.show()
In [30]:
params_dict = {}
params_dict['taus'] = np.array([lif.C/lif.gl for lif in lifs])
params_dict['Rs'] = np.array([1/lif.gl for lif in lifs])
params_dict['Cs'] = np.array([lif.C for lif in lifs])
params_dict['Els'] = np.array([lif.El for lif in lifs])
params_dict['Vrs'] = np.array([lif.Vr for lif in lifs])
params_dict['Vt'] = np.array([lif.Vt for lif in lifs])
import pandas as pd
df = pd.DataFrame(params_dict)
In [31]:
df.describe(percentiles=[])
Out[31]:
In [32]:
df
Out[32]:
In [19]:
a.Vt
Out[19]: