gp_neurobio/code/base_spikes.py
2018-11-22 15:11:31 +01:00

84 lines
2.6 KiB
Python

from read_baseline_data import *
from read_chirp_data import *
from utility import *
#import nix_helpers as nh
import matplotlib.pyplot as plt
import numpy as np
from IPython import embed #Funktionen imposrtieren
data_dir = "../data"
dataset = "2018-11-13-ad-invivo-1"
#data = ("2018-11-09-ad-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ad-invivo-1", "2018-11-09-af-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-ah-invivo-1", "2018-11-13-ai-invivo-1", "2018-11-13-aj-invivo-1", "2018-11-13-ak-invivo-1", "2018-11-13-al-invivo-1", "2018-11-14-aa-invivo-1", "2018-11-14-ab-invivo-1", "2018-11-14-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-ae-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-aj-invivo-1", "2018-11-14-ak-invivo-1", "2018-11-14-al-invivo-1", "2018-11-14-am-invivo-1", "2018-11-14-an-invivo-1", "2018-11-20-aa-invivo-1", "2018-11-20-ab-invivo-1", "2018-11-20-ac-invivo-1", "2018-11-20-ad-invivo-1"," 2018-11-20-ae-invivo-1", "2018-11-20-af-invivo-1", "2018-11-20-ag-invivo-1", "2018-11-20-ah-invivo-1", "2018-11-20-ai-invivo-1")
spike_times = read_baseline_spikes(os.path.join(data_dir, dataset))
#inst_frequency = 1. / np.diff(spike_times)
spike_rate = np.diff(spike_times)
x = np.arange(0.001, 0.01, 0.0001)
plt.hist(spike_rate,x)
mu = np.mean(spike_rate)
sigma = np.std(spike_rate)
cv = sigma/mu
plt.title('A.lepto ISI Histogramm', fontsize = 14)
plt.xlabel('duration ISI[ms]', fontsize = 12)
plt.ylabel('number of ISI', fontsize = 12)
plt.xticks(fontsize = 12)
plt.yticks(fontsize = 12)
plt.show()
#Nyquist-Theorem Plot:
chirp_spikes = read_chirp_spikes(os.path.join(data_dir, dataset))
df_map = map_keys(chirp_spikes)
sort_df = sorted(df_map.keys())
plt.figure()
dct_rate = {}
for i in sort_df:
freq = list(df_map[i])
dct_rate[i] = []
for k in freq:
for phase in chirp_spikes[k]:
spikes = chirp_spikes[k][phase]
rate = len(spikes)/ 1.2
dct_rate[i].append(rate)
for h in sort_df:
plt.plot(np.arange(0,len(dct_rate[h]),1),dct_rate[h], label = h)
#plt.vlines(10, ymin = 190, ymax = 310)
plt.legend()
plt.title('Firing rate of the cell for all trials, sorted by df')
plt.xlabel('# of trials')
plt.ylabel('Instant firing rate of the cell')
plt.show()
#mittlere Feuerrate einer Frequenz auf Frequenz
plt.figure()
ls_mean = []
for d in sort_df:
mean = np.mean(dct_rate[d])
ls_mean.append(mean)
plt.plot(np.arange(0,len(ls_mean),1),ls_mean)
plt.title('Mean firing rate of a cell for a range of frequency differences')
plt. xticks(np.arange(len(sort_df)), (sort_df))
plt.xlabel('Range of frequency differences [Hz]')
plt.ylabel('Mean firing rate of the cell')
plt.show()