Merge branch 'master' of https://whale.am28.uni-tuebingen.de/git/jgrewe/gp_neurobio
This commit is contained in:
commit
244ed72f6a
@ -20,9 +20,18 @@ spikes = read_baseline_spikes(os.path.join(data_dir, dataset))
|
||||
# calculate interpike intervals and plot them
|
||||
interspikeintervals = np.diff(spikes)
|
||||
|
||||
fig, ax = plt.subplots(figsize=(12/inch_factor, 8/inch_factor))
|
||||
plt.hist(interspikeintervals, bins=np.arange(0, np.max(interspikeintervals), 0.0001))
|
||||
plt.show()
|
||||
fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor))
|
||||
plt.hist(interspikeintervals, bins=np.arange(0, np.max(interspikeintervals), 0.0001), color='darkblue')
|
||||
plt.xlabel("time [ms]", fontsize = 22)
|
||||
plt.xticks(fontsize = 18)
|
||||
plt.ylabel("number of \n interspikeintervals", fontsize = 22)
|
||||
plt.yticks(fontsize = 18)
|
||||
ax.spines["top"].set_visible(False)
|
||||
ax.spines["right"].set_visible(False)
|
||||
fig.tight_layout()
|
||||
#plt.show()
|
||||
plt.savefig('isis.pdf')
|
||||
|
||||
|
||||
# calculate coefficient of variation
|
||||
mu = np.mean(interspikeintervals)
|
||||
@ -64,21 +73,23 @@ std_eod = np.nanstd(eod_cuts, axis=0)*3
|
||||
time_axis = np.arange(max_cut)/sampling_rate*1000
|
||||
|
||||
# plot eod form and spike histogram
|
||||
fig, ax1 = plt.subplots(figsize=(12/inch_factor, 8/inch_factor))
|
||||
ax1.hist(spike_times, color='crimson')
|
||||
ax1.set_xlabel('time [ms]', fontsize=12)
|
||||
ax1.set_ylabel('number', fontsize=12)
|
||||
ax1.tick_params(axis='y', labelcolor='crimson')
|
||||
plt.yticks(fontsize=8)
|
||||
fig, ax1 = plt.subplots(figsize=(20/inch_factor, 10/inch_factor))
|
||||
ax1.hist(spike_times, color='firebrick')
|
||||
ax1.set_xlabel('time [ms]', fontsize=22)
|
||||
ax1.set_ylabel('number', fontsize=22)
|
||||
ax1.tick_params(axis='y', labelcolor='firebrick')
|
||||
plt.xticks(fontsize=18)
|
||||
plt.yticks(fontsize=18)
|
||||
ax1.spines['top'].set_visible(False)
|
||||
|
||||
ax2 = ax1.twinx()
|
||||
ax2.fill_between(time_axis, mu_eod+std_eod, mu_eod-std_eod, color='dodgerblue', alpha=0.5)
|
||||
ax2.fill_between(time_axis, mu_eod+std_eod, mu_eod-std_eod, color='royalblue', alpha=0.5)
|
||||
ax2.plot(time_axis, mu_eod, color='black', lw=2)
|
||||
ax2.set_ylabel('voltage [mV]', fontsize=12)
|
||||
ax2.tick_params(axis='y', labelcolor='dodgerblue')
|
||||
ax2.set_ylabel('voltage [mV]', fontsize=22)
|
||||
ax2.tick_params(axis='y', labelcolor='darkblue')
|
||||
ax2.spines['top'].set_visible(False)
|
||||
|
||||
plt.xticks(fontsize=8)
|
||||
plt.yticks(fontsize=8)
|
||||
plt.yticks(fontsize=18)
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
#plt.show()
|
||||
plt.savefig('eodform_spikehist.pdf')
|
@ -15,11 +15,19 @@ spikes = read_baseline_spikes(os.path.join(data_dir, dataset))
|
||||
# calculate interpike intervals and plot them
|
||||
interspikeintervals = np.diff(spikes)*1000
|
||||
|
||||
fig, ax = plt.subplots(figsize=(12/inch_factor, 8/inch_factor))
|
||||
plt.hist(interspikeintervals, bins=np.arange(0, np.max(interspikeintervals), 0.1))
|
||||
ax.set_xlabel('time [ms]', fontsize=14)
|
||||
ax.set_ylabel('number of interspikeintervals', fontsize=14)
|
||||
fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor))
|
||||
plt.hist(interspikeintervals, bins=np.arange(0, np.max(interspikeintervals), 0.0001), color='darkblue')
|
||||
plt.xlabel("time [ms]", fontsize = 22)
|
||||
plt.xticks(fontsize = 18)
|
||||
plt.ylabel("Number of \n Interspikeinterval", fontsize = 22)
|
||||
plt.yticks(fontsize = 18)
|
||||
ax.spines["top"].set_visible(False)
|
||||
ax.spines["right"].set_visible(False)
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
plt.show()
|
||||
#plt.savefig('isis.pdf')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
102
code/repetition_firingrate.py
Normal file
102
code/repetition_firingrate.py
Normal file
@ -0,0 +1,102 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import scipy.stats as ss
|
||||
from read_chirp_data import *
|
||||
from utility import *
|
||||
from IPython import embed
|
||||
|
||||
# define sampling rate and data path
|
||||
sampling_rate = 40 #kHz
|
||||
data_dir = "../data"
|
||||
dataset = "2018-11-09-ad-invivo-1"
|
||||
inch_factor = 2.54
|
||||
# parameters for binning, smoothing and plotting
|
||||
cut_window = 60
|
||||
chirp_size = 14 #ms
|
||||
neuronal_delay = 5 #ms
|
||||
chirp_start = int((-chirp_size/2+neuronal_delay+cut_window)*sampling_rate)
|
||||
chirp_end = int((chirp_size/2+neuronal_delay+cut_window+1)*sampling_rate)
|
||||
num_bin = 12
|
||||
window = 1 #ms
|
||||
time_axis = np.arange(-cut_window, cut_window, 1/sampling_rate) #steps
|
||||
spike_bins = np.arange(-cut_window, cut_window+1) #ms
|
||||
|
||||
# read data from files
|
||||
spikes = read_chirp_spikes(os.path.join(data_dir, dataset))
|
||||
eod = read_chirp_eod(os.path.join(data_dir, dataset))
|
||||
chirp_times = read_chirp_times(os.path.join(data_dir, dataset))
|
||||
|
||||
# make a delta f map for the quite more complicated keys
|
||||
df_map = map_keys(spikes)
|
||||
|
||||
# differentiate between phases
|
||||
phase_vec = np.arange(0, 1+1/num_bin, 1/num_bin)
|
||||
cut_range = np.arange(-cut_window*sampling_rate, cut_window*sampling_rate, 1)
|
||||
|
||||
# make dictionaries for spiketimes
|
||||
df_phase_time = {}
|
||||
df_phase_binary = {}
|
||||
|
||||
# iterate over delta f, repetition, phases and a single chirp
|
||||
for deltaf in df_map.keys():
|
||||
df_phase_time[deltaf] = {}
|
||||
df_phase_binary[deltaf] = {}
|
||||
for rep in df_map[deltaf]:
|
||||
for phase in spikes[rep]:
|
||||
for idx in np.arange(num_bin):
|
||||
# check the phase
|
||||
if phase[1] > phase_vec[idx] and phase[1] < phase_vec[idx+1]:
|
||||
|
||||
# get spikes between 50 ms befor and after the chirp
|
||||
spikes_to_cut = np.asarray(spikes[rep][phase])
|
||||
spikes_cut = spikes_to_cut[(spikes_to_cut > -cut_window) & (spikes_to_cut < cut_window)]
|
||||
spikes_idx = np.round(spikes_cut*sampling_rate)
|
||||
# also save as binary, 0 no spike, 1 spike
|
||||
binary_spikes = np.isin(cut_range, spikes_idx)*1
|
||||
|
||||
# add the spikes to the dictionaries with the correct df and phase
|
||||
if idx in df_phase_time[deltaf].keys():
|
||||
df_phase_time[deltaf][idx].append(spikes_cut)
|
||||
df_phase_binary[deltaf][idx] = np.vstack((df_phase_binary[deltaf][idx], binary_spikes))
|
||||
else:
|
||||
df_phase_time[deltaf][idx] = [spikes_cut]
|
||||
df_phase_binary[deltaf][idx] = binary_spikes
|
||||
|
||||
|
||||
# for plotting and calculating iterate over delta f and phases
|
||||
for df in df_phase_time.keys():
|
||||
for index_phase, phase in enumerate(df_phase_time[df].keys()):
|
||||
|
||||
# plot
|
||||
plot_trials = df_phase_time[df][phase]
|
||||
plot_trials_binary = np.mean(df_phase_binary[df][phase], axis=0)
|
||||
|
||||
# calculation
|
||||
#overall_spikerate = (np.sum(plot_trials_binary)/len(plot_trials_binary))*sampling_rate*1000
|
||||
|
||||
smoothed_spikes = smooth(plot_trials_binary, window, 1./sampling_rate)
|
||||
|
||||
fig, ax = plt.subplots(2, 1, sharex=True, figsize=(20/inch_factor, 15/inch_factor))
|
||||
for i, trial in enumerate(plot_trials):
|
||||
ax[0].scatter(trial, np.ones(len(trial))+i, marker='|', color='k')
|
||||
|
||||
ax[1].plot(time_axis, smoothed_spikes*1000, color='royalblue', lw = 2)
|
||||
|
||||
|
||||
|
||||
ax[0].set_title('df = %s Hz' %(df))
|
||||
ax[0].set_ylabel('repetition', fontsize=22)
|
||||
ax[0].yaxis.set_label_coords(-0.1, 0.5)
|
||||
ax[0].set_yticks(np.arange(1, len(plot_trials)+1,2))
|
||||
ax[0].set_yticklabels(np.arange(1, len(plot_trials)+1,2), fontsize=18)
|
||||
|
||||
ax[1].set_xlabel('time [ms]', fontsize=22)
|
||||
ax[1].yaxis.set_label_coords(-0.1, 0.5)
|
||||
ax[1].set_ylabel('firing rate [Hz]', fontsize=22)
|
||||
plt.xticks(fontsize=18)
|
||||
plt.yticks(fontsize=18)
|
||||
fig.tight_layout()
|
||||
#plt.show()
|
||||
#exit()
|
||||
namefigure = '../figures/%s_%i_%i_firingrate.pdf' %(dataset, df, index_phase)
|
||||
plt.savefig(namefigure)
|
Loading…
Reference in New Issue
Block a user