From 23675241f03a29dc51020f9e4a7143341b43201b Mon Sep 17 00:00:00 2001 From: efish Date: Wed, 28 Nov 2018 17:30:08 +0100 Subject: [PATCH 1/9] fertig --- code/base_chirps.py | 52 ++++++++++++++------------ code/base_spikes.py | 87 ++++++++++++++++++++++---------------------- code/func_chirp.py | 40 +++++++++++--------- code/vector_phase.py | 3 -- 4 files changed, 94 insertions(+), 88 deletions(-) diff --git a/code/base_chirps.py b/code/base_chirps.py index f19b18e..1b26e6c 100644 --- a/code/base_chirps.py +++ b/code/base_chirps.py @@ -8,45 +8,48 @@ from IPython import embed data_dir = "../data" -data = ("2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ac-invivo-1", "2018-11-13-ad-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-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-ai-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") +dataset = "2018-11-13-ah-invivo-1" +data = ["2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ac-invivo-1", "2018-11-13-ad-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-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-ai-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"] +#for dataset in data: -for dataset in data: - print(dataset) - eod = read_chirp_eod(os.path.join(data_dir, dataset)) - times = read_chirp_times(os.path.join(data_dir, dataset)) - df_map = map_keys(eod) - sort_df = sorted(df_map.keys()) +eod = read_chirp_eod(os.path.join(data_dir, dataset)) +times = read_chirp_times(os.path.join(data_dir, dataset)) +df_map = map_keys(eod) +sort_df = sorted(df_map.keys()) - chirp_eod_plot(df_map, eod, times) +eods = chirp_eod_plot(df_map, eod, times) +plt.show() +plt.close('all') - chirp_mods = [] - beat_mods = [] - for i in sort_df: - freq = list(df_map[i]) - ls_mod, beat_mod = cut_chirps(freq, eod, times) - chirp_mods.append(ls_mod) - beat_mods.append(beat_mod) - +chirp_mods = {} +beat_mods = [] +for i in sort_df: + chirp_mods[i] = [] + freq = list(df_map[i]) + ls_mod, beat_mod = cut_chirps(freq, eod, times) + chirp_mods[i].append(ls_mod) + beat_mods.append(beat_mod) #Chirps einer Phase zuordnen - zusammen plotten - chirp_spikes = read_chirp_spikes(os.path.join(data_dir, dataset)) - df_map = map_keys(chirp_spikes) - sort_df = sorted(df_map.keys()) - - #plot_std_chirp(sort_df, df_map, chirp_spikes, chirp_mods) - - +chirp_spikes = read_chirp_spikes(os.path.join(data_dir, dataset)) +df_map = map_keys(chirp_spikes) +sort_df = sorted(df_map.keys()) +dct_phase = plot_std_chirp(sort_df, df_map, chirp_spikes, chirp_mods) +plt.show() +plt.close('all') +''' #Vatriablen speichern, die man für die Übersicht aller Zellen braucht - name = str(dataset.strip('invivo-1')) + name = str(dataset.replace('-invivo-1', '')) + print('saving ../results/Chirpcut/Cc_' + name + '.dat') f = open('../results/Chirpcut/Cc_' + name + '.dat' , 'w') f.write(str(sort_df)) f.write(str(df_map)) @@ -56,3 +59,4 @@ for dataset in data: #f.write(str(chirp_mods)) #f.write(str(beat_mods)) f.close() +''' diff --git a/code/base_spikes.py b/code/base_spikes.py index 9f8bbc2..754df12 100644 --- a/code/base_spikes.py +++ b/code/base_spikes.py @@ -3,7 +3,7 @@ from read_chirp_data import * from func_spike import * import matplotlib.pyplot as plt import numpy as np -from IPython import embed #Funktionen imposrtieren +from IPython import embed #Funktionen importieren @@ -11,77 +11,77 @@ data_dir = "../data" data_base = ("2018-11-09-ab-invivo-1", "2018-11-09-ad-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ab-invivo-1", "2018-11-13-ad-invivo-1", "2018-11-13-af-invivo-1", "2018-11-13-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-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-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-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") data_chirps = ("2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ac-invivo-1", "2018-11-13-ad-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-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-ai-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") +dataset = "2018-11-14-al-invivo-1" -''' -for dataset in data_base: +#for dataset in data_base: - print(dataset) - spike_times = read_baseline_spikes(os.path.join(data_dir, dataset)) - spike_iv = np.diff(spike_times) - x = np.arange(0.001, 0.01, 0.0001) - plt.hist(spike_iv,x) +spike_times = read_baseline_spikes(os.path.join(data_dir, dataset)) +spike_iv = np.diff(spike_times) +x = np.arange(0.001, 0.01, 0.0001) +plt.hist(spike_iv,x) - mu = np.mean(spike_iv) - sigma = np.std(spike_iv) - cv = sigma/mu +mu = np.mean(spike_iv) +sigma = np.std(spike_iv) +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.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.xticks(fontsize = 12) +plt.yticks(fontsize = 12) +plt.show() -for dataset in data_chirps: +#for dataset in data_chirps: #Nyquist-Theorem Plot: - print(dataset) - chirp_spikes = read_chirp_spikes(os.path.join(data_dir, dataset)) - times = read_chirp_times(os.path.join(data_dir, dataset)) - eod = read_chirp_eod(os.path.join(data_dir, dataset)) - df_map = map_keys(chirp_spikes) - sort_df = sorted(df_map.keys()) - - dct_rate, over_r = spike_rates(sort_df, df_map, chirp_spikes) +chirp_spikes = read_chirp_spikes(os.path.join(data_dir, dataset)) +times = read_chirp_times(os.path.join(data_dir, dataset)) +eod = read_chirp_eod(os.path.join(data_dir, dataset)) +df_map = map_keys(chirp_spikes) +sort_df = sorted(df_map.keys()) - plt.figure() - ls_mean = plot_df_spikes(sort_df, dct_rate) +dct_rate, over_r = spike_rates(sort_df, df_map, chirp_spikes) +plt.figure() +ls_mean = plot_df_spikes(sort_df, dct_rate) +plt.show() #mittlere Feuerrate einer Frequenz auf Frequenz: - plt.figure() - plt.plot(np.arange(0,len(ls_mean),1),ls_mean) - plt.scatter(np.arange(0,len(ls_mean),1), np.ones(len(ls_mean))*over_r) - plt.title('Mean firing rate of a cell for a range of frequency differences') - plt.xticks(np.arange(1,len(sort_df),1), (sort_df)) - plt.xlabel('Range of frequency differences [Hz]') - plt.ylabel('Mean firing rate of the cell') - +plt.figure() +plt.plot(np.arange(0,len(ls_mean),1),ls_mean) +plt.scatter(np.arange(0,len(ls_mean),1), np.ones(len(ls_mean))*over_r) +plt.title('Mean firing rate of a cell for a range of frequency differences') +plt.xticks(np.arange(1,len(sort_df),1), (sort_df)) +plt.xlabel('Range of frequency differences [Hz]') +plt.ylabel('Mean firing rate of the cell') +plt.show() #Adaption der Zellen: #wie viel Prozent der Anfangsrate macht die Adaption von Zellen aus? - adapt = adaptation_df(sort_df, dct_rate) - plt.figure() - plt.boxplot(adapt) - plt.title('Adaptation of cell firing rate during a trial') - plt.xlabel('Cell') - plt.ylabel('Adaptation size [Hz]') +adapt = adaptation_df(sort_df, dct_rate) +plt.figure() +plt.boxplot(adapt) +plt.title('Adaptation of cell firing rate during a trial') +plt.xlabel('Cell') +plt.ylabel('Adaptation size [Hz]') +plt.show() +''' #Vatriablen speichern, die man für die Übersicht aller Zellen braucht - name = str(dataset.strip('invivo-1')) + name = str(dataset.replace('-invivo-1', '')) f = open('../results/Nyquist/Ny_' + name + '.txt' , 'w') f.write(str(sort_df)) f.write(str(df_map)) @@ -91,3 +91,4 @@ for dataset in data_chirps: f.write(str(over_r)) f.write(str(adapt)) f.close() +''' diff --git a/code/func_chirp.py b/code/func_chirp.py index 836b52d..b358e3a 100644 --- a/code/func_chirp.py +++ b/code/func_chirp.py @@ -21,23 +21,21 @@ def chirp_eod_plot(df_map, eod, times): if idx <= 3: axs[0, 0].plot(zeit, eods, color= 'blue', linewidth = 0.25) - axs[0, 0].scatter(np.asarray(ct), np.ones(len(ct))*3, color = 'green', s= 22) + axs[0, 0].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) elif 4<= idx <= 7: axs[0, 1].plot(zeit, eods, color= 'blue', linewidth = 0.25) - axs[0, 1].scatter(np.asarray(ct), np.ones(len(ct))*3, color = 'green', s= 22) + axs[0, 1].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) elif 8<= idx <= 11: axs[1, 0].plot(zeit, eods, color= 'blue', linewidth = 0.25) - axs[1, 0].scatter(np.asarray(ct), np.ones(len(ct))*3, color = 'green', s= 22) + axs[1, 0].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) else: axs[1, 1].plot(zeit, eods, color= 'blue', linewidth = 0.25) - axs[1, 1].scatter(np.asarray(ct), np.ones(len(ct))*3, color = 'green', s= 22) + axs[1, 1].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) + axs[0,1].set_ylabel('Amplitude [mV]') + axs[1,0].set_xlabel('Time [ms]') fig.suptitle('EOD for chirps', fontsize = 16) - axs[0,0].set_ylabel('Amplitude [mV]') - axs[0,1].set_xlabel('Amplitude [mV]') - axs[1,0].set_xlabel('Time [ms]') - axs[1,1].set_xlabel('Time [ms]') - plt.close() + @@ -60,15 +58,17 @@ def cut_chirps(freq, eod, times): ls_beat.extend(beat_cut) beat_mod = np.std(ls_beat) #Std vom Bereich vor dem Chirp - plt.figure() - plt.scatter(np.arange(0,len(ls_mod),1), ls_mod) - plt.scatter(np.arange(0,len(ls_mod),1), np.ones(len(ls_mod))*beat_mod, color = 'violet') - plt.close() + #plt.figure() + #plt.scatter(np.arange(0,len(ls_mod),1), ls_mod) + #plt.scatter(np.arange(0,len(ls_mod),1), np.ones(len(ls_mod))*beat_mod, color = 'violet') return(ls_mod, beat_mod) -def plot_std_chirp(sort_df, df_map, chirp_spikes, ls_mod): + + +def plot_std_chirp(sort_df, df_map, chirp_spikes, chirp_mods): + plt.figure() dct_phase = {} num_bin = 12 @@ -80,8 +80,12 @@ def plot_std_chirp(sort_df, df_map, chirp_spikes, ls_mod): for k in freq: for phase in chirp_spikes[k]: dct_phase[i].append(phase[1]) - - plt.scatter(dct_phase[i], ls_mod[i]) - plt.title('Change of std depending on the phase where the chirp occured') - plt.close() + + for i in sort_df: + plt.scatter(dct_phase[i], chirp_mods[i], label = i) + plt.title('Change of std depending on the phase where the chirp occured') + plt.xlabel('Phase') + plt.ylabel('Standard deviation of the amplitude modulation') + plt.legend() + return(dct_phase) diff --git a/code/vector_phase.py b/code/vector_phase.py index c902e6e..7828c2c 100644 --- a/code/vector_phase.py +++ b/code/vector_phase.py @@ -18,8 +18,5 @@ eod_durations = np.diff(eod_times) print(len(spike_times)) print(len(eod_durations)) -#for st in spike_times: - #et = eod_times[eod_times < st] - #dt = st - et #vs = vector_strength(spike_times, eod_durations) From e7e8206100c8254a5f3bd339a3296485a0b33597 Mon Sep 17 00:00:00 2001 From: efish Date: Thu, 29 Nov 2018 09:30:10 +0100 Subject: [PATCH 2/9] huhu --- code/plot_eodform_spikehist.py | 6 ++---- code/stimulus_chirp.py | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/code/plot_eodform_spikehist.py b/code/plot_eodform_spikehist.py index 7c6be52..1983d46 100644 --- a/code/plot_eodform_spikehist.py +++ b/code/plot_eodform_spikehist.py @@ -14,21 +14,19 @@ dataset = '2018-11-14-al-invivo-1' # read eod and time of baseline time, eod = read_baseline_eod(os.path.join(data_dir, dataset)) -<<<<<<< HEAD + eod_norm = eod - np.mean(eod) # calculate eod times and indices by zero crossings threshold = 0 shift_eod = np.roll(eod_norm, 1) -eod_times = time[(eod_norm >= threshold) & (shift_eod < threshold)] +eod_times = time[(eod_norm >= threshold) & (shift_eod < threshold)]*40000 eod_duration = eod_times[2]- eod_times[1] -======= ->>>>>>> 5cd62554fa5af12a6a50661f0a60cd2b0457e702 # read spikes during baseline activity spikes = read_baseline_spikes(os.path.join(data_dir, dataset)) # calculate interpike intervals and plot them diff --git a/code/stimulus_chirp.py b/code/stimulus_chirp.py index f45827c..ad9336b 100644 --- a/code/stimulus_chirp.py +++ b/code/stimulus_chirp.py @@ -40,8 +40,8 @@ ax1 = fig.add_subplot(211) plt.yticks(fontsize=18) ax2 = fig.add_subplot(212, sharex=ax1) plt.setp(ax1.get_xticklabels(), visible=False) -ax1.plot(time*1000, signal, color = 'midnightblue', lw = 1) -ax2.plot(time*1000, freq, color = 'midnightblue', lw = 3) +ax1.plot(time*1000, signal, color = 'royalblue', lw = 1) +ax2.plot(time*1000, freq, color = 'royalblue', lw = 3) ax1.set_ylabel("field [mV]", fontsize = 22) From 68670cd9b28ee968ed1bcbd2eff928e60cec9d76 Mon Sep 17 00:00:00 2001 From: efish Date: Thu, 29 Nov 2018 10:12:38 +0100 Subject: [PATCH 3/9] huhu --- code/plot_eodform_spikehist.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/code/plot_eodform_spikehist.py b/code/plot_eodform_spikehist.py index 1e5ada4..e2e1f3e 100644 --- a/code/plot_eodform_spikehist.py +++ b/code/plot_eodform_spikehist.py @@ -14,27 +14,22 @@ dataset = '2018-11-09-ad-invivo-1' # read eod and time of baseline time, eod = read_baseline_eod(os.path.join(data_dir, dataset)) -<<<<<<< HEAD -======= ->>>>>>> d77d377849b65effc29e550f25a9107463c2120b + eod_norm = eod - np.mean(eod) # calculate eod times and indices by zero crossings threshold = 0 shift_eod = np.roll(eod_norm, 1) -eod_times = time[(eod_norm >= threshold) & (shift_eod < threshold)]*40000 +eod_times = time[(eod_norm >= threshold) & (shift_eod < threshold)] eod_duration = eod_times[2]- eod_times[1] #time in s -<<<<<<< HEAD - eod_duration = eod_times[2]- eod_times[1] -======= ->>>>>>> d77d377849b65effc29e550f25a9107463c2120b + # read spikes during baseline activity spikes = read_baseline_spikes(os.path.join(data_dir, dataset)) #spikes in s # calculate interpike intervals and plot them @@ -49,9 +44,8 @@ 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') -exit() plt.savefig('isis.png') @@ -105,10 +99,10 @@ 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='navy', 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=22) -ax2.tick_params(axis='y', labelcolor='navy') +ax2.tick_params(axis='y', labelcolor='royalblue') ax2.spines['top'].set_visible(False) plt.yticks(fontsize=18) From 33634d23848add88a588b0ba5d76596905994779 Mon Sep 17 00:00:00 2001 From: efish Date: Thu, 29 Nov 2018 10:45:53 +0100 Subject: [PATCH 4/9] los --- code/base_eod.py | 12 +++++++----- code/base_spikes.py | 28 +++++++++++++++------------- code/func_spike.py | 7 ++++--- code/order_eff.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ code/vector_phase.py | 22 ---------------------- 5 files changed, 70 insertions(+), 43 deletions(-) create mode 100644 code/order_eff.py delete mode 100644 code/vector_phase.py diff --git a/code/base_eod.py b/code/base_eod.py index bf1e757..86a5ec2 100644 --- a/code/base_eod.py +++ b/code/base_eod.py @@ -8,14 +8,16 @@ from IPython import embed #Funktionen importieren data_dir = "../data" dataset = "2018-11-09-aa-invivo-1" #data = ("2018-11-09-aa-invivo-1", "2018-11-09-ab-invivo-1", "2018-11-09-ac-invivo-1", "2018-11-09-ad-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ab-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-aa-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") + + time,eod = read_baseline_eod(os.path.join(data_dir, dataset)) zeit = np.asarray(time) plt.plot(zeit[0:1000], eod[0:1000]) -plt.title('A.lepto EOD')#Plottitelk -plt.xlabel('time [ms]', fontsize = 12)#Achsentitel -plt.ylabel('amplitude[mv]', fontsize = 12)#Achsentitel -plt.xticks(fontsize = 12) -plt.yticks(fontsize = 12) +plt.title('A.lepto EOD', fontsize = 18)#Plottitelk +plt.xlabel('time [ms]', fontsize = 16)#Achsentitel +plt.ylabel('amplitude[mv]', fontsize = 16)#Achsentitel +plt.xticks(fontsize = 14) +plt.yticks(fontsize = 14) plt.show() diff --git a/code/base_spikes.py b/code/base_spikes.py index 754df12..32ffd68 100644 --- a/code/base_spikes.py +++ b/code/base_spikes.py @@ -11,7 +11,7 @@ data_dir = "../data" data_base = ("2018-11-09-ab-invivo-1", "2018-11-09-ad-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ab-invivo-1", "2018-11-13-ad-invivo-1", "2018-11-13-af-invivo-1", "2018-11-13-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-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-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-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") data_chirps = ("2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ac-invivo-1", "2018-11-13-ad-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-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-ai-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") -dataset = "2018-11-14-al-invivo-1" +dataset = "2018-11-13-ad-invivo-1" #for dataset in data_base: @@ -25,12 +25,12 @@ mu = np.mean(spike_iv) sigma = np.std(spike_iv) 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.title('A.lepto ISI Histogramm', fontsize = 18) +plt.xlabel('duration ISI[ms]', fontsize = 16) +plt.ylabel('number of ISI', fontsize = 16) -plt.xticks(fontsize = 12) -plt.yticks(fontsize = 12) +plt.xticks(fontsize = 14) +plt.yticks(fontsize = 14) plt.show() @@ -56,11 +56,12 @@ plt.show() plt.figure() plt.plot(np.arange(0,len(ls_mean),1),ls_mean) -plt.scatter(np.arange(0,len(ls_mean),1), np.ones(len(ls_mean))*over_r) -plt.title('Mean firing rate of a cell for a range of frequency differences') +plt.scatter(np.arange(0,len(ls_mean),1), np.ones(len(ls_mean))*over_r, color = 'green') +plt.title('Mean firing rate of a cell for a range of frequency differences', fontsize = 18) plt.xticks(np.arange(1,len(sort_df),1), (sort_df)) -plt.xlabel('Range of frequency differences [Hz]') -plt.ylabel('Mean firing rate of the cell') +plt.xlabel('Range of frequency differences [Hz]', fontsize = 16) +plt.ylabel('Mean firing rate of the cell', fontsize = 16) +plt.tick_params(axis='both', which='major', labelsize = 14) plt.show() @@ -71,9 +72,10 @@ plt.show() adapt = adaptation_df(sort_df, dct_rate) plt.figure() plt.boxplot(adapt) -plt.title('Adaptation of cell firing rate during a trial') -plt.xlabel('Cell') -plt.ylabel('Adaptation size [Hz]') +plt.title('Adaptation of cell firing rate during a trial', fontsize = 18) +plt.xlabel('Cell', fontsize = 16) +plt.ylabel('Adaptation size [Hz]', fontsize = 16) +plt.tick_params(axis='both', which='major', labelsize = 14) plt.show() diff --git a/code/func_spike.py b/code/func_spike.py index d512986..ac47c8f 100644 --- a/code/func_spike.py +++ b/code/func_spike.py @@ -50,9 +50,10 @@ def plot_df_spikes(sort_df, dct_rate): plt.plot(np.arange(0,len(dct_rate[h]),1),dct_rate[h], label = h) 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.title('Firing rate of the cell for all trials, sorted by df', fontsize = 18) + plt.xlabel('# of trials', fontsize = 16) + plt.ylabel('Instant firing rate of the cell', fontsize = 16) + plt.tick_params(axis='both', which='major', labelsize = 14) return(ls_mean) diff --git a/code/order_eff.py b/code/order_eff.py new file mode 100644 index 0000000..35f14e1 --- /dev/null +++ b/code/order_eff.py @@ -0,0 +1,44 @@ +from read_chirp_data import * +from func_spike import * +import matplotlib.pyplot as plt +import numpy as np +from IPython import embed #Funktionen importieren + + + + +data_dir = "../data" +data_chirps = ("2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ac-invivo-1", "2018-11-13-ad-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-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-ai-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") + + + +data_rate_dict = {} +for dataset in data_chirps: + + data_rate_dict[dataset] = [] + chirp_spikes = read_chirp_spikes(os.path.join(data_dir, dataset)) + times = read_chirp_times(os.path.join(data_dir, dataset)) + eod = read_chirp_eod(os.path.join(data_dir, dataset)) + df_map = map_keys(chirp_spikes) + + + for i in df_map.keys(): + freq = list(df_map[i]) + k = freq[0] + phase = list(chirp_spikes[k].keys())[0] + + spikes = chirp_spikes[k][phase] + rate = len(spikes)/ 1.2 + data_rate_dict[dataset].append(rate) + + +for dataset in data_rate_dict: + plt.plot(data_rate_dict[dataset]) +plt.title('Test for sequence effects', fontsize = 20) +plt.xlabel('Number of stimulus presentations', fontsize = 18) +plt.ylabel('Firing rates of cells', fontsize = 18) +plt.tick_params(axis='both', which='major', labelsize = 16) + +plt.show() + + diff --git a/code/vector_phase.py b/code/vector_phase.py deleted file mode 100644 index 7828c2c..0000000 --- a/code/vector_phase.py +++ /dev/null @@ -1,22 +0,0 @@ -from read_baseline_data import * -from utility import * -#import nix_helpers as nh -import matplotlib.pyplot as plt -import numpy as np -from IPython import embed #Funktionen importieren - - -#Zeitpunkte einer EOD über Zero-crossings finden, die in einer Steigung liegen -data_dir = "../data" -dataset = "2018-11-09-ad-invivo-1" -time,eod = read_baseline_eod(os.path.join(data_dir, dataset)) -spike_times = read_baseline_spikes(os.path.join(data_dir, dataset)) -print(len(spike_times)) - -eod_times = zero_crossing(eod,time) -eod_durations = np.diff(eod_times) -print(len(spike_times)) -print(len(eod_durations)) - - -#vs = vector_strength(spike_times, eod_durations) From 0d2ea250afd6d87eb91d5bc401db0c1f05a7fcfe Mon Sep 17 00:00:00 2001 From: efish Date: Thu, 29 Nov 2018 14:00:47 +0100 Subject: [PATCH 5/9] huhu --- code/eod_freq_beat.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/code/eod_freq_beat.py b/code/eod_freq_beat.py index 8dab8e7..31f6be1 100644 --- a/code/eod_freq_beat.py +++ b/code/eod_freq_beat.py @@ -2,38 +2,38 @@ from read_baseline_data import * from IPython import embed import matplotlib.pyplot as plt import numpy as np +from IPython import embed ## beat data_dir = '../data' dataset = '2018-11-09-ad-invivo-1' +inch_factor = 2.54 time, eod = read_baseline_eod(os.path.join(data_dir, dataset)) eod_norm = eod - np.mean(eod) +eod_norm = eod_norm[1000:2000] -# calculate eod times and indices by zero crossings -threshold = 0 -shift_eod = np.roll(eod_norm, 1) -eod_times = time[(eod_norm >= threshold) & (shift_eod < threshold)] - -#x = eod_times*40000 -x = np.arange(0., len(eod_times)-1) -y = np.sin(x*2*np.pi*600) -eod_freq_beat = 1/(np.diff(eod_times) + y) +x = np.arange(0., len(eod_norm)) +y = np.sin(x*2*np.pi*550) +ampl = eod_norm + y -# glätten -kernel = np.ones(7)/7 -smooth_eod_freq_beat = np.convolve(eod_freq_beat, kernel, mode = 'valid') -time_axis = np.arange(len(smooth_eod_freq_beat)) +time_axis = np.arange(len(ampl)) -plt.plot(time_axis, smooth_eod_freq_beat) -plt.show() +fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) +plt.plot(time_axis, ampl) +ax.set_xlabel("time [ms]", fontsize = 22) +plt.xticks(fontsize = 18) +ax.set_ylabel("eod amplitude [mV]", fontsize = 22) +plt.yticks(fontsize = 18) +ax.spines["top"].set_visible(False) +ax.spines["right"].set_visible(False) +fig.tight_layout() -#eod_freq_beat = eod_freq_normal + y -#smooth_eod_freq_beat = np.convolve(eod_freq_beat, kernel, mode = 'valid') -#fig = plt.plot(time_axis,smooth_eod_freq_beat) -#plt.xlabel("time [ms]") -#plt.ylabel("eod frequency [mV]") #plt.show() +plt.savefig('beat.png') + + + From 13ac3e1a6e9136bb70890e317503d654233cd374 Mon Sep 17 00:00:00 2001 From: efish Date: Thu, 29 Nov 2018 16:40:52 +0100 Subject: [PATCH 6/9] buh --- code/eod_freq_beat.py | 15 ++++++++++----- code/stimulus_chirp.py | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/code/eod_freq_beat.py b/code/eod_freq_beat.py index 31f6be1..04ed6e7 100644 --- a/code/eod_freq_beat.py +++ b/code/eod_freq_beat.py @@ -2,6 +2,7 @@ from read_baseline_data import * from IPython import embed import matplotlib.pyplot as plt import numpy as np +import thunderfish.peakdetection as pd from IPython import embed ## beat @@ -12,17 +13,21 @@ inch_factor = 2.54 time, eod = read_baseline_eod(os.path.join(data_dir, dataset)) eod_norm = eod - np.mean(eod) -eod_norm = eod_norm[1000:2000] +eod_norm = eod_norm[10000:20000] x = np.arange(0., len(eod_norm)) -y = np.sin(x*2*np.pi*550) + +y = np.sin(time[10000:20000]*2*np.pi*600)*0.5 ampl = eod_norm + y +p, t = pd.detect_peaks(ampl, 0.1) time_axis = np.arange(len(ampl)) fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) -plt.plot(time_axis, ampl) +plt.plot(time[10000:20000], ampl) +plt.plot(time[10000:20000][p], ampl[p], lw=2, color='k') +plt.plot(time[10000:20000][t], ampl[t], lw=2, color='k') ax.set_xlabel("time [ms]", fontsize = 22) plt.xticks(fontsize = 18) ax.set_ylabel("eod amplitude [mV]", fontsize = 22) @@ -31,8 +36,8 @@ ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) fig.tight_layout() -#plt.show() -plt.savefig('beat.png') +plt.show() +#plt.savefig('beat.png') diff --git a/code/stimulus_chirp.py b/code/stimulus_chirp.py index cf56727..0e01894 100644 --- a/code/stimulus_chirp.py +++ b/code/stimulus_chirp.py @@ -53,5 +53,5 @@ ax2.yaxis.set_label_coords(-0.1, 0.5) plt.xticks(fontsize=18) plt.yticks(fontsize=18) fig.tight_layout() -#plt.show() -plt.savefig('stimulus_chirp.png') +plt.show() +#plt.savefig('stimulus_chirp.png') From 28242c59d47b8acd1230f063d07217542de66d9f Mon Sep 17 00:00:00 2001 From: efish Date: Thu, 29 Nov 2018 16:41:48 +0100 Subject: [PATCH 7/9] buh --- code/eod_chirp_beat.py | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 code/eod_chirp_beat.py diff --git a/code/eod_chirp_beat.py b/code/eod_chirp_beat.py new file mode 100644 index 0000000..7f825df --- /dev/null +++ b/code/eod_chirp_beat.py @@ -0,0 +1,96 @@ +import numpy as np +import matplotlib.pyplot as plt +import thunderfish.peakdetection as pd + + +def create_chirp(eodf): + stimulusrate = eodf # the eod frequency of the fake fish + currentchirptimes = [0.0] + chirpwidth = 0.014 # ms + chirpsize = 100. + chirpampl = 0.02 + chirpkurtosis = 1. + p = 0. + stepsize = 0.00001 + + + time = np.arange(-0.05, 0.05, stepsize) + signal = np.zeros(time.shape) + ampl = np.ones(time.shape) + freq = np.ones(time.shape) + + ck = 0 + csig = 0.5 * chirpwidth / np.power(2.0*np.log(10.0), 0.5/chirpkurtosis) + + for k, t in enumerate(time): + a = 1. + f = stimulusrate + if ck < len(currentchirptimes): + if np.abs(t - currentchirptimes[ck]) < 2.0 * chirpwidth: + x = t - currentchirptimes[ck] + g = np.exp(-0.5 * (x/csig)**2) + f = chirpsize * g + stimulusrate + a *= 1.0 - chirpampl * g + elif t > currentchirptimes[ck] + 2.0 * chirpwidth: + ck += 1 + freq[k] = f + ampl[k] = a + p += f * stepsize + signal[k] = a * np.sin(6.28318530717959 * p) + + return time, signal + + +def plot_chirp(eodf, eodf1, phase, axis): + time, chirp_eod = create_chirp(eodf) + eod = np.sin(time * 2 * np.pi * eodf1 + phase) + + y = chirp_eod * 0.4 + eod + p, t = pd.detect_peaks(y, 0.1) + axis.plot(time*1000, y) + axis.plot(time[p]*1000, (y)[p], lw=2, color='k') + axis.plot(time[t]*1000, (y)[t], lw=2, color='k') + axis.spines["top"].set_visible(False) + axis.spines["right"].set_visible(False) + + + +inch_factor = 2.54 + +fig = plt.figure(figsize=(20 / inch_factor, 10 / inch_factor)) +ax1 = fig.add_subplot(221) +ax2 = fig.add_subplot(222) +ax3 = fig.add_subplot(223) +ax4 = fig.add_subplot(224) + +plot_chirp(600, 650, 0, ax1) +plot_chirp(600, 650, np.pi, ax3) + +plot_chirp(600, 620, 0, ax2) +plot_chirp(600, 620, np.pi, ax4) + +ax1.set_ylabel('EOD [mV]', fontsize=22) +ax1.set_title('$\Delta$f = 50 Hz', fontsize = 18) +ax1.yaxis.set_tick_params(labelsize=18) +ax1.set_xticklabels([]) + +ax2.set_title('$\Delta$f = 20 Hz', fontsize = 18) +ax2.set_xticklabels([]) +ax2.set_yticklabels([]) +ax3.set_ylabel('EOD [mV]', fontsize=22) +ax3.xaxis.set_tick_params(labelsize=18) +ax3.yaxis.set_tick_params(labelsize=18) + +ax3.set_xlabel('time [ms]', fontsize=22) +ax4.set_xlabel('time [ms]', fontsize=22) +ax4.xaxis.set_tick_params(labelsize=18) +ax4.set_yticklabels([]) + + + + + + +fig.tight_layout() +#plt.show() +plt.savefig('chirps_while_beat.png') From 3db401a3ea219c38e6bac972ef05bc6f497ba0a4 Mon Sep 17 00:00:00 2001 From: efish Date: Thu, 29 Nov 2018 16:45:59 +0100 Subject: [PATCH 8/9] buh --- code/eod_chirp_beat.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/eod_chirp_beat.py b/code/eod_chirp_beat.py index 7f825df..072cca7 100644 --- a/code/eod_chirp_beat.py +++ b/code/eod_chirp_beat.py @@ -47,7 +47,7 @@ def plot_chirp(eodf, eodf1, phase, axis): y = chirp_eod * 0.4 + eod p, t = pd.detect_peaks(y, 0.1) - axis.plot(time*1000, y) + axis.plot(time*1000, y, color = 'royalblue') axis.plot(time[p]*1000, (y)[p], lw=2, color='k') axis.plot(time[t]*1000, (y)[t], lw=2, color='k') axis.spines["top"].set_visible(False) @@ -63,18 +63,18 @@ ax2 = fig.add_subplot(222) ax3 = fig.add_subplot(223) ax4 = fig.add_subplot(224) -plot_chirp(600, 650, 0, ax1) -plot_chirp(600, 650, np.pi, ax3) +plot_chirp(600, 650, 0, ax2) +plot_chirp(600, 650, np.pi, ax4) -plot_chirp(600, 620, 0, ax2) -plot_chirp(600, 620, np.pi, ax4) +plot_chirp(600, 620, 0, ax1) +plot_chirp(600, 620, np.pi, ax3) ax1.set_ylabel('EOD [mV]', fontsize=22) -ax1.set_title('$\Delta$f = 50 Hz', fontsize = 18) +ax1.set_title('$\Delta$f = 20 Hz', fontsize = 18) ax1.yaxis.set_tick_params(labelsize=18) ax1.set_xticklabels([]) -ax2.set_title('$\Delta$f = 20 Hz', fontsize = 18) +ax2.set_title('$\Delta$f = 50 Hz', fontsize = 18) ax2.set_xticklabels([]) ax2.set_yticklabels([]) ax3.set_ylabel('EOD [mV]', fontsize=22) From b618c2d9cab5ca62e8955a353ff966aed30560ee Mon Sep 17 00:00:00 2001 From: efish Date: Thu, 29 Nov 2018 16:47:30 +0100 Subject: [PATCH 9/9] zwischendrin --- code/base_chirps.py | 6 ++- code/base_eod.py | 18 +++++--- code/base_spikes.py | 48 ++++++++++++-------- code/func_chirp.py | 53 ++++++++++++++--------- code/func_spike.py | 13 ++++-- code/order_eff.py | 14 +++--- code/plot_spikesduringbaselineactivity.py | 1 + 7 files changed, 96 insertions(+), 57 deletions(-) diff --git a/code/base_chirps.py b/code/base_chirps.py index 1b26e6c..9ead914 100644 --- a/code/base_chirps.py +++ b/code/base_chirps.py @@ -8,7 +8,7 @@ from IPython import embed data_dir = "../data" -dataset = "2018-11-13-ah-invivo-1" +dataset = "2018-11-13-ad-invivo-1" data = ["2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ac-invivo-1", "2018-11-13-ad-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-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-ai-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"] @@ -41,7 +41,9 @@ for i in sort_df: chirp_spikes = read_chirp_spikes(os.path.join(data_dir, dataset)) df_map = map_keys(chirp_spikes) sort_df = sorted(df_map.keys()) -dct_phase = plot_std_chirp(sort_df, df_map, chirp_spikes, chirp_mods) +example = [-50, 200, 400] + +dct_phase = plot_std_chirp(example, df_map, chirp_spikes, chirp_mods) plt.show() plt.close('all') diff --git a/code/base_eod.py b/code/base_eod.py index 86a5ec2..8789b9e 100644 --- a/code/base_eod.py +++ b/code/base_eod.py @@ -14,10 +14,16 @@ time,eod = read_baseline_eod(os.path.join(data_dir, dataset)) zeit = np.asarray(time) -plt.plot(zeit[0:1000], eod[0:1000]) -plt.title('A.lepto EOD', fontsize = 18)#Plottitelk -plt.xlabel('time [ms]', fontsize = 16)#Achsentitel -plt.ylabel('amplitude[mv]', fontsize = 16)#Achsentitel -plt.xticks(fontsize = 14) -plt.yticks(fontsize = 14) + +inch_factor = 2.54 +fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) + +plt.plot(zeit[0:1000], eod[0:1000], color = 'darkblue') +plt.title('A.lepto EOD', fontsize = 24)#Plottitel +plt.xlabel('time [ms]', fontsize = 22)#Achsentitel +plt.ylabel('amplitude[mv]', fontsize = 22)#Achsentitel +plt.tick_params(axis='both', which='major', labelsize = 22) +ax.spines['right'].set_visible(False) +ax.spines['top'].set_visible(False) +fig.tight_layout() plt.show() diff --git a/code/base_spikes.py b/code/base_spikes.py index 32ffd68..014b7b8 100644 --- a/code/base_spikes.py +++ b/code/base_spikes.py @@ -12,25 +12,28 @@ data_base = ("2018-11-09-ab-invivo-1", "2018-11-09-ad-invivo-1", "2018-11-13-aa- data_chirps = ("2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-ag-invivo-1", "2018-11-13-aa-invivo-1", "2018-11-13-ac-invivo-1", "2018-11-13-ad-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-ac-invivo-1", "2018-11-14-ad-invivo-1", "2018-11-14-af-invivo-1", "2018-11-14-ag-invivo-1", "2018-11-14-ah-invivo-1", "2018-11-14-ai-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") dataset = "2018-11-13-ad-invivo-1" - +inch_factor = 2.54 #for dataset in data_base: spike_times = read_baseline_spikes(os.path.join(data_dir, dataset)) spike_iv = np.diff(spike_times) x = np.arange(0.001, 0.01, 0.0001) -plt.hist(spike_iv,x) + +fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) +plt.hist(spike_iv,x, color = 'darkblue') mu = np.mean(spike_iv) sigma = np.std(spike_iv) cv = sigma/mu -plt.title('A.lepto ISI Histogramm', fontsize = 18) -plt.xlabel('duration ISI[ms]', fontsize = 16) -plt.ylabel('number of ISI', fontsize = 16) - -plt.xticks(fontsize = 14) -plt.yticks(fontsize = 14) +plt.title('A.lepto ISI Histogramm', fontsize = 24) +plt.xlabel('duration ISI[ms]', fontsize = 22) +plt.ylabel('number of ISI', fontsize = 22) +plt.tick_params(axis='both', which='major', labelsize = 22) +ax.spines['right'].set_visible(False) +ax.spines['top'].set_visible(False) +plt.tight_layout() plt.show() @@ -47,6 +50,7 @@ sort_df = sorted(df_map.keys()) dct_rate, over_r = spike_rates(sort_df, df_map, chirp_spikes) plt.figure() +fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) ls_mean = plot_df_spikes(sort_df, dct_rate) plt.show() @@ -54,14 +58,17 @@ plt.show() #mittlere Feuerrate einer Frequenz auf Frequenz: -plt.figure() -plt.plot(np.arange(0,len(ls_mean),1),ls_mean) +fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) +plt.plot(np.arange(0,len(ls_mean),1),ls_mean, color = 'darkblue') plt.scatter(np.arange(0,len(ls_mean),1), np.ones(len(ls_mean))*over_r, color = 'green') -plt.title('Mean firing rate of a cell for a range of frequency differences', fontsize = 18) +plt.title('Mean firing rate of a cell for a range of frequency differences', fontsize = 24) plt.xticks(np.arange(1,len(sort_df),1), (sort_df)) -plt.xlabel('Range of frequency differences [Hz]', fontsize = 16) -plt.ylabel('Mean firing rate of the cell', fontsize = 16) -plt.tick_params(axis='both', which='major', labelsize = 14) +plt.xlabel('Range of frequency differences [Hz]', fontsize = 22) +plt.ylabel('Mean firing rate of the cell', fontsize = 22) +plt.tick_params(axis='both', which='major', labelsize = 18) +ax.spines['right'].set_visible(False) +ax.spines['top'].set_visible(False) +plt.tight_layout() plt.show() @@ -70,12 +77,15 @@ plt.show() #wie viel Prozent der Anfangsrate macht die Adaption von Zellen aus? adapt = adaptation_df(sort_df, dct_rate) -plt.figure() +fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) plt.boxplot(adapt) -plt.title('Adaptation of cell firing rate during a trial', fontsize = 18) -plt.xlabel('Cell', fontsize = 16) -plt.ylabel('Adaptation size [Hz]', fontsize = 16) -plt.tick_params(axis='both', which='major', labelsize = 14) +plt.title('Adaptation of cell firing rate during a trial', fontsize = 24) +plt.xlabel('Cell', fontsize = 22) +plt.ylabel('Adaptation size [Hz]', fontsize = 22) +plt.tick_params(axis='both', which='major', labelsize = 18) +ax.spines['right'].set_visible(False) +ax.spines['top'].set_visible(False) +plt.tight_layout() plt.show() diff --git a/code/func_chirp.py b/code/func_chirp.py index b358e3a..5e2bddb 100644 --- a/code/func_chirp.py +++ b/code/func_chirp.py @@ -2,8 +2,10 @@ from read_baseline_data import * from read_chirp_data import * from utility import * import matplotlib.pyplot as plt +import math import numpy as np +inch_factor = 2.54 def chirp_eod_plot(df_map, eod, times): #die äußere Schleife geht für alle Keys durch und somit durch alle dfs @@ -11,7 +13,7 @@ def chirp_eod_plot(df_map, eod, times): for i in df_map.keys(): freq = list(df_map[i]) - fig,axs = plt.subplots(2, 2, sharex = True, sharey = True) + fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) for idx, k in enumerate(freq): ct = times[k] @@ -19,22 +21,28 @@ def chirp_eod_plot(df_map, eod, times): zeit = e1[0] eods = e1[1] - if idx <= 3: - axs[0, 0].plot(zeit, eods, color= 'blue', linewidth = 0.25) - axs[0, 0].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) - elif 4<= idx <= 7: - axs[0, 1].plot(zeit, eods, color= 'blue', linewidth = 0.25) - axs[0, 1].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) - elif 8<= idx <= 11: - axs[1, 0].plot(zeit, eods, color= 'blue', linewidth = 0.25) - axs[1, 0].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) - else: - axs[1, 1].plot(zeit, eods, color= 'blue', linewidth = 0.25) - axs[1, 1].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) + if idx <= 1: + ax.plot(zeit, eods, color= 'darkblue') + ax.scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) + #elif 4<= idx <= 7: + # axs[0, 1].plot(zeit, eods, color= 'blue', linewidth = 0.25) + # axs[0, 1].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) + #elif 8<= idx <= 11: + # axs[1, 0].plot(zeit, eods, color= 'blue', linewidth = 0.25) + # axs[1, 0].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) + else: + continue + #axs[1, 1].plot(zeit, eods, color= 'blue', linewidth = 0.25) + #axs[1, 1].scatter(np.asarray(ct), np.ones(len(ct))*np.mean(eods), color = 'green', s= 22) + + ax.set_ylabel('Amplitude [mV]', fontsize = 22) + ax.set_xlabel('Time [ms]', fontsize = 22) + ax.tick_params(axis='both', which='major', labelsize = 18) + ax.spines['right'].set_visible(False) + ax.spines['top'].set_visible(False) + fig.suptitle('EOD for chirps', fontsize = 24) + fig.tight_layout() - axs[0,1].set_ylabel('Amplitude [mV]') - axs[1,0].set_xlabel('Time [ms]') - fig.suptitle('EOD for chirps', fontsize = 16) @@ -69,7 +77,7 @@ def cut_chirps(freq, eod, times): def plot_std_chirp(sort_df, df_map, chirp_spikes, chirp_mods): - plt.figure() + fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) dct_phase = {} num_bin = 12 phase_vec = np.arange(0, 1+1/num_bin, 1/num_bin) @@ -82,10 +90,13 @@ def plot_std_chirp(sort_df, df_map, chirp_spikes, chirp_mods): dct_phase[i].append(phase[1]) for i in sort_df: - plt.scatter(dct_phase[i], chirp_mods[i], label = i) - plt.title('Change of std depending on the phase where the chirp occured') - plt.xlabel('Phase') - plt.ylabel('Standard deviation of the amplitude modulation') + norm = np.asarray(dct_phase[i]) *2*math.pi + plt.scatter(norm, chirp_mods[i], label = i, s = 22) + plt.title('Change of std depending on the phase where the chirp occured', fontsize = 24) + plt.xlabel('Phase', fontsize = 22) + plt.ylabel('Standard deviation of the amplitude modulation', fontsize = 22) + plt.xticks([0, math.pi/2, math.pi, math.pi*1.5, math.pi*2], ('0', '$\pi$ /2', '$\pi$', '1.5 $\pi$', '2$\pi$')) + plt.tick_params(axis='both', which='major', labelsize = 18) plt.legend() return(dct_phase) diff --git a/code/func_spike.py b/code/func_spike.py index ac47c8f..458f9d5 100644 --- a/code/func_spike.py +++ b/code/func_spike.py @@ -43,6 +43,8 @@ def spike_rates(sort_df, df_map, chirp_spikes): def plot_df_spikes(sort_df, dct_rate): #gibt die Feuerrate gegen die Frequenz aufgetragen + inch_factor = 2.54 + fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) ls_mean = [] for h in sort_df: mean = np.mean(dct_rate[h]) @@ -50,10 +52,13 @@ def plot_df_spikes(sort_df, dct_rate): plt.plot(np.arange(0,len(dct_rate[h]),1),dct_rate[h], label = h) plt.legend() - plt.title('Firing rate of the cell for all trials, sorted by df', fontsize = 18) - plt.xlabel('# of trials', fontsize = 16) - plt.ylabel('Instant firing rate of the cell', fontsize = 16) - plt.tick_params(axis='both', which='major', labelsize = 14) + plt.title('Firing rate of the cell for all trials, sorted by df', fontsize = 24) + plt.xlabel('# of trials', fontsize = 22) + plt.ylabel('Instant firing rate of the cell', fontsize = 22) + plt.tick_params(axis='both', which='major', labelsize = 18) + ax.spines['right'].set_visible(False) + ax.spines['top'].set_visible(False) + plt.tight_layout() return(ls_mean) diff --git a/code/order_eff.py b/code/order_eff.py index 35f14e1..1657ef3 100644 --- a/code/order_eff.py +++ b/code/order_eff.py @@ -12,6 +12,7 @@ data_chirps = ("2018-11-09-ad-invivo-1", "2018-11-09-ae-invivo-1", "2018-11-09-a +inch_factor = 2.54 data_rate_dict = {} for dataset in data_chirps: @@ -31,14 +32,17 @@ for dataset in data_chirps: rate = len(spikes)/ 1.2 data_rate_dict[dataset].append(rate) - +fig, ax = plt.subplots(figsize=(20/inch_factor, 10/inch_factor)) for dataset in data_rate_dict: plt.plot(data_rate_dict[dataset]) -plt.title('Test for sequence effects', fontsize = 20) -plt.xlabel('Number of stimulus presentations', fontsize = 18) -plt.ylabel('Firing rates of cells', fontsize = 18) -plt.tick_params(axis='both', which='major', labelsize = 16) +plt.title('Test for sequence effects', fontsize = 24) +plt.xlabel('Number of stimulus presentations', fontsize = 22) +plt.ylabel('Firing rates of cells', fontsize = 22) +plt.tick_params(axis='both', which='major', labelsize = 22) +ax.spines['right'].set_visible(False) +ax.spines['top'].set_visible(False) +fig.tight_layout() plt.show() diff --git a/code/plot_spikesduringbaselineactivity.py b/code/plot_spikesduringbaselineactivity.py index a13c16a..d9c2e49 100644 --- a/code/plot_spikesduringbaselineactivity.py +++ b/code/plot_spikesduringbaselineactivity.py @@ -17,6 +17,7 @@ interspikeintervals = np.diff(spikes)*1000 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') +#Titel fehlt!! plt.xlabel("time [ms]", fontsize = 22) plt.xticks(fontsize = 18) plt.ylabel("Number of \n Interspikeinterval", fontsize = 22)