634 lines
34 KiB
Python
634 lines
34 KiB
Python
##from update_project import **
|
|
import sys
|
|
|
|
import numpy as np
|
|
from IPython import embed
|
|
from matplotlib import gridspec, pyplot as plt
|
|
|
|
from threefish.RAM.calc_fft import create_full_matrix2
|
|
from threefish.reformat import chose_mat_max_value, get_axis_on_full_matrix, get_psds_ROC, \
|
|
load_b_public
|
|
from threefish.RAM.reformat import check_var_substract_method, chose_certain_group, extract_waves, \
|
|
get_transfer_from_model, load_cells_three, predefine_grouping_frame, restrict_cell_type, save_arrays_susept
|
|
from threefish.RAM.save import get_transfer_for_model_full
|
|
from threefish.RAM.reformat_matrix import convert_csv_str_to_float, load_stack_data_susept
|
|
from threefish.RAM.plot_subplots import colors_suscept_paper_dots, letters_for_full_model, \
|
|
plt_model_big, \
|
|
plt_model_full_model2, \
|
|
plt_model_letters, \
|
|
plt_psds_ROC, plt_RAM_perc, recalc_fr_to_DF1
|
|
from threefish.load import resave_small_files, save_visualization
|
|
from threefish.RAM.values import find_all_dir_cells, perc_model_full, vals_model_full, version_final
|
|
from threefish.core import find_code_vs_not, info
|
|
from plotstyle import plot_style
|
|
import time
|
|
from threefish.defaults import default_diagonal_points, default_figsize
|
|
from threefish.plot.colorbar import colorbar_outside, rescale_colorbar_and_values
|
|
from threefish.RAM.plot_labels import label_deltaf1, label_deltaf2, label_diff, label_sum, \
|
|
nonlin_title, remove_xticks, set_xlabel_arrow, set_ylabel_arrow, title_motivation, label_two_deltaf1, \
|
|
label_two_deltaf2, \
|
|
xlabel_transfer_hz
|
|
from threefish.plot.limits import set_clim_same
|
|
from threefish.values import values_nfft_full_model, values_stimuluslength_model_full
|
|
|
|
|
|
#from utils_test import test_spikes_clusters
|
|
|
|
|
|
def model_full():
|
|
|
|
|
|
|
|
plot_style()
|
|
default_figsize(column=2, length=3.5)#2.7
|
|
grid = gridspec.GridSpec(2, 2, wspace=0.55, bottom = 0.15, height_ratios = [2, 5], width_ratios = [1.2, 1], hspace=0.7, top=0.88, left=0.06, right=0.98)#hspace=0.25,top=0.92
|
|
|
|
|
|
axes = []
|
|
a_size = 0.02#6#0.0095#0.01#15#0.0095#0.0065#0.0065und 0.0005 für das lineare das ist vielleicht für das nichtlienare 0.0065#0.0085#0.01#0.0085#125 # 0.0025# 0.01 0.005 und davor 0.025, funktioniert gut 0.0085
|
|
adjust_factor_outside = 1#adjust_factor_outside_nonlin()
|
|
|
|
|
|
|
|
##################################
|
|
# model part
|
|
ls = '--'
|
|
lw = 0.5
|
|
axm = plt.subplot(grid[:,0])
|
|
|
|
axes.append(axm)
|
|
|
|
cell = '2012-07-03-ak-invivo-1'
|
|
cell = "2013-01-08-aa-invivo-1"
|
|
#'calc_RAM_model-2__nfft_whole_power_1_RAM_additiv_cv_adapt_factor_scaled_cNoise_0.1_cSig_0.9_cutoff1_300_cutoff2_300no_sinz_length1_TrialsStim_4000000_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV'
|
|
tr = 500000
|
|
save_name_given = 'calc_RAM_model-3__nfft_whole_power_1_RAM_additiv_cv_adapt_factor_scaled_cNoise_0.1_cSig_0.9_cutoff1_300_cutoff2_300no_sinz_length1_TrialsStim_'+str(tr) + '_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV_old_fit_'
|
|
save_name_given = 'calc_RAM_model-2__nfft_whole_power_1_RAM_additiv_cv_adapt_factor_scaled_cNoise_0.1_cSig_0.9_cutoff1_300_cutoff2_300no_sinz_length1_TrialsStim_1000000_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV'
|
|
#save_name_given = 'calc_RAM_model-2__nfft_whole_power_1_RAM_additiv_cv_adapt_factor_scaled_cNoise_0.1_cSig_0.9_cutoff1_300_cutoff2_300no_sinz_length1_TrialsStim_4000000_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV'
|
|
perc, im, stack_final, stack_saved = plt_model_big(axm, ls = ls, pos_rel=-0.12, lw = 0.75, cell = cell, lines = True,
|
|
save_name_given = save_name_given)
|
|
#embed()
|
|
fr_waves = 139
|
|
color01, color012, color01_2, color02, color0_burst, color0 = colors_suscept_paper_dots()
|
|
DF1_frmult, DF2_frmult = vals_model_full(val=0.30833333333333335)
|
|
|
|
models_name = "models_big_fit_d_right.csv"#_big_fit
|
|
#############################################
|
|
# plot coherence
|
|
#embed()
|
|
do_transfer = False
|
|
if do_transfer:
|
|
loaded_from_calc_RAM_model = False
|
|
if loaded_from_calc_RAM_model:
|
|
cross = get_transfer_from_model(stack_saved)
|
|
axc = plt.subplot(grid[0, 1])
|
|
axc.plot(stack_saved.index, cross, color = 'black')
|
|
axc.set_xlabel('Frequency [Hz]')
|
|
axc.set_ylabel(xlabel_transfer_hz())
|
|
else:
|
|
############################################################
|
|
#calculate the noise induced tranferfunction
|
|
# start_eod_emitter -- the lowest frequency of the emmiter fish, default 20
|
|
|
|
# frequently used value
|
|
# so harmonic is the right one since p-change and wave is some relict so take just harmonic
|
|
|
|
models = resave_small_files(models_name,
|
|
load_folder='calc_model_core')
|
|
#flowchart_cell = '2012-07-03-ak-invivo-1'
|
|
|
|
model_params = models[models['cell'] == cell].iloc[0]
|
|
print('cell=' + str(cell))
|
|
model_params = models[models['cell'] == cell].iloc[0]
|
|
print('cell=' + str(cell))
|
|
# amp_frame = pd.read_csv('peak_amplitudes_power.csv')
|
|
model_params.pop('cell') # .iloc[0]# Werte für das Paper nachschauen
|
|
eod_fr = model_params['EODf'] # .iloc[0]
|
|
deltat = model_params.pop("deltat") # .iloc[0]
|
|
v_offset = model_params.pop("v_offset") # .iloc[0]
|
|
stimulus_length = 1
|
|
|
|
power = 1
|
|
xlim = [0,300]
|
|
c_sigs = [0.9] # '',0,
|
|
var_types = [
|
|
] # ''#'additiv_cv_adapt_factor_scaled'
|
|
# 'additiv_visual_d_4_scaled', '']
|
|
#a_f = 0.009 # 2
|
|
a_fes = [a_size, a_size, 0] # alpha\alpha0.1,
|
|
trials_nr = 100 # 100
|
|
|
|
|
|
frame = get_transfer_for_model_full([a_size], 0,cell, deltat,eod_fr,
|
|
model_params,
|
|
stimulus_length,
|
|
trials_nr,
|
|
v_offset,
|
|
c_sig = 0.9,redo =False,
|
|
var_type='additiv_cv_adapt_factor_scaled')
|
|
|
|
axc = plt.subplot(grid[0, 1])
|
|
f_same = frame.index
|
|
#embed()
|
|
try:
|
|
transfer = frame['0']
|
|
except:
|
|
transfer = frame[0]
|
|
axc.plot(f_same[f_same< xlim[-1]], np.abs(transfer[f_same< xlim[-1]])**power, color = 'black', zorder = 100)
|
|
|
|
axc.set_xlim(xlim)
|
|
ylim_here = axc.get_ylim()
|
|
#if c == 0:
|
|
axc.set_ylabel(r'$|\chi_1|^2$')
|
|
else:
|
|
f_same = False
|
|
transfer = []
|
|
|
|
|
|
#################
|
|
# power spectra data
|
|
log = 'log'#'log'#log'log'#'log'#'log'#'log'#'log'
|
|
ylim_log = (-14.2, 3)#(-14.2, 3)
|
|
nfft = values_nfft_full_model()#length = values_stimuluslength_model_full()
|
|
xlim_psd = [0, 300]
|
|
|
|
DF1_desired_orig = [133, 166]#33
|
|
DF2_desired_orig = [-33, 53]#166
|
|
|
|
#grid0 = gridspec.GridSpecFromSubplotSpec(len(DF1_desired_orig), 1, wspace=0.15, hspace=0.35,
|
|
# subplot_spec=grid[1])
|
|
|
|
markers = ['s', 'o']
|
|
ms = 14
|
|
|
|
markers = ['o', 'o', 'o', 'o', ]
|
|
|
|
#0.16666666666666666
|
|
grid0 = gridspec.GridSpecFromSubplotSpec(2, 2, wspace=0.15, hspace=0.4,
|
|
subplot_spec=grid[:,1])
|
|
|
|
|
|
|
|
#################
|
|
#################
|
|
# power spectra model
|
|
ylim_log = (-38, 28) #
|
|
|
|
# punkte die zur zweiten Reihe gehören
|
|
|
|
combis = default_diagonal_points()
|
|
diagonal = 'diagonal1'
|
|
diagonal = ''
|
|
plus_q = 'plus' # 'minus'#'plus'##'minus'
|
|
length = values_stimuluslength_model_full()
|
|
reshuffled = '' # ,
|
|
array_len = 2
|
|
alphas = [1,0.5]
|
|
#a_size = 0.0065#0.0125#25#0.04#0.015
|
|
|
|
#embed()
|
|
# ATTENTION: Diese Zelle ('2012-07-03-ak-invivo-1') braucht längere Abschnitte, mindsetesn 5 Sekunden damit das Powerspectrum nicht so niosy ist!
|
|
#print('started')
|
|
fr_noise, eod_fr_mm, axes2 = plt_model_full_model2(grid0, stack_final = stack_final, reshuffled=reshuffled, dev=0.0005, a_f1s=[a_size], af_2 = a_size,
|
|
stimulus_length=length, plus_q=plus_q, stack_saved = stack_saved,
|
|
diagonal=diagonal, runs=1, nfft = nfft, xlim_psd = xlim_psd,
|
|
cells=[cell], dev_spikes ='original', markers = markers, DF1_frmult = DF1_frmult, DF2_frmult = DF2_frmult,
|
|
log = log, ms = ms, models_name = models_name, adjust_factor_outside = adjust_factor_outside, array_len = array_len, f_same = f_same, transfer = transfer, clip_on = False, trials_nr_all= [1, 1, 1, 1, 1]) #arrays_len a_f1s=[0.02]"2012-12-13-an-invivo-1"'2013-01-08-aa-invivo-1'
|
|
|
|
|
|
|
|
|
|
|
|
# letters for the matrix
|
|
plt_model_letters(DF1_frmult, DF2_frmult, axm, color012, color01_2, fr_noise, markers)
|
|
|
|
# letters for the transfer function
|
|
if do_transfer:
|
|
transferletters(DF1_frmult, DF2_frmult, array_len, axc, color01, color02, f_same, fr_noise, transfer)
|
|
|
|
fig = plt.gcf()#[axes[0], axes[3], axes[4]]
|
|
fig.tag([axes[0], axes2[0], axes2[1], axes2[2], axes2[3]], xoffs=-4.5, yoffs=1.35) # ax_ams[3],
|
|
#plt.show()
|
|
save_visualization()
|
|
|
|
|
|
def transferletters(DF1_frmult, DF2_frmult, array_len, axc, color01, color02, f_same, fr_noise, transfer):
|
|
letters = letters_for_full_model()
|
|
for f in range(len(letters)):
|
|
df1_recalc = recalc_fr_to_DF1(DF1_frmult, f, fr_noise)
|
|
df2_recalc = recalc_fr_to_DF1(DF2_frmult, f, fr_noise)
|
|
|
|
pos_df1 = np.argmin(np.abs(f_same - np.abs(df1_recalc)))
|
|
pos_df2 = np.argmin(np.abs(f_same - np.abs(df2_recalc)))
|
|
if letters[f] == 'C':
|
|
axc.text(df1_recalc, np.max(transfer[pos_df1 - array_len:pos_df1 + array_len]) + 5000,
|
|
'C,D', color=color01, ha='center',
|
|
va='center', zorder=100) # , alpha = alphas[f]
|
|
if (letters[f] not in ['C', 'D']):
|
|
axc.text(df1_recalc, np.max(transfer[pos_df1 - array_len:pos_df1 + array_len]) + 3500,
|
|
letters[f], color=color01, ha='center',
|
|
va='center', zorder=100) # , alpha = alphas[f]
|
|
axc.text(df2_recalc, np.max(transfer[pos_df2 - array_len:pos_df2 + array_len]) + 2500,
|
|
letters[f], color=color02, ha='center',
|
|
va='center', zorder=100) # , alpha = alphas[f]
|
|
|
|
|
|
def plt_data_matrix(axes, grid, ls, lw, perc):
|
|
ax = plt.subplot(grid[0])
|
|
axes.append(ax)
|
|
cell = '2012-07-03-ak-invivo-1'
|
|
mat_rev, stack_final_rev = load_stack_data_susept(cell, redo=True, save_name=version_final(), end='_revQuadrant_')
|
|
mat, stack = load_stack_data_susept(cell, save_name=version_final(), end='')
|
|
new_keys, stack_plot = convert_csv_str_to_float(stack)
|
|
# mat = RAM_norm_data(stack['isf'].iloc[0], stack_plot,
|
|
# stack['snippets'].unique()[0], stack_here=stack) #
|
|
new_keys, stack_plot = convert_csv_str_to_float(stack_final_rev)
|
|
# mat_rev = RAM_norm_data(stack_final_rev['isf'].iloc[0], stack_plot,
|
|
# stack_final_rev['snippets'].unique()[0], stack_here=stack_final_rev) #
|
|
mat, add_nonlin_title, resize_val = rescale_colorbar_and_values(mat)
|
|
mat_rev, add_nonlin_title, resize_val = rescale_colorbar_and_values(mat_rev, resize_val=resize_val)
|
|
# try:
|
|
full_matrix = create_full_matrix2(np.array(mat), np.array(mat_rev))
|
|
# except:
|
|
# print('full matrix something')
|
|
# embed()
|
|
stack_final = get_axis_on_full_matrix(full_matrix, mat)
|
|
abs_matrix = np.abs(stack_final)
|
|
abs_matrix, add_nonlin_title, resize_val = rescale_colorbar_and_values(abs_matrix, add_nonlin_title='k')
|
|
ax.axhline(0, color='white', linestyle=ls, linewidth=lw)
|
|
ax.axvline(0, color='white', linestyle=ls, linewidth=lw)
|
|
im = plt_RAM_perc(ax, perc, abs_matrix)
|
|
cbar, left, bottom, width, height = colorbar_outside(ax, im, add=5, width=0.01)
|
|
set_clim_same([im], mats=[abs_matrix], lim_type='up', nr_clim='perc', clims='', percnr=perc_model_full())
|
|
# clim = im.get_clim()
|
|
# if clim[1]> 1000:
|
|
# todo: change clim values with different Hz values
|
|
# embed()
|
|
cbar.set_label(nonlin_title(add_nonlin_title=' [' + add_nonlin_title), rotation=90, labelpad=8)
|
|
offset = -0.35
|
|
set_ylabel_arrow(ax, xpos=offset, ypos=0.97)
|
|
set_xlabel_arrow(ax, xpos=1, ypos=offset)
|
|
''' eod_fr, stack_spikes = plt_data_suscept_single(ax, cbar_label, cell, cells, f, fig, file_names_exclude, lp, title,
|
|
width)'''
|
|
cbar, left, bottom, width, height = colorbar_outside(ax, im, add=5, width=0.01)
|
|
return ax, cell, stack_final
|
|
|
|
|
|
def plt_data_peaks_letters(DF1_desired, DF2_desired, ax, color012, color01_2, eod_fr, fr_noise, fr_waves, markers):
|
|
DF2_hz = np.abs(np.array(DF1_desired) * eod_fr - eod_fr)
|
|
DF1_hz = np.abs(np.array(DF2_desired) * eod_fr - eod_fr)
|
|
for f in range(len(DF1_hz)):
|
|
ax.plot(fr_noise * DF1_hz[f] / fr_waves, fr_noise * DF2_hz[f] / fr_waves, markers[f], ms=5,
|
|
markeredgecolor=color012,
|
|
markerfacecolor="None") # , alpha = alphas[f]
|
|
ax.plot(-fr_noise * DF1_hz[f] / fr_waves, fr_noise * DF2_hz[f] / fr_waves, markers[f], ms=5,
|
|
markeredgecolor=color01_2,
|
|
markerfacecolor="None") # , alpha = alphas[f]
|
|
|
|
|
|
def plt_data_peaks(DF1_desired_orig, DF2_desired_orig, c1, chose_score, detections, devs, dfs, end, grid, log, ms,
|
|
mult_type, nfft, sorted_on, xlim_psd, ylim_log):
|
|
DF1_desired, DF2_desired, fr, eod_fr, arrays_len = plt_data_full_model(c1, chose_score, detections, devs, dfs, end,
|
|
grid[3], mult_type, sorted_on, ms=ms,
|
|
markers=['s', 'o'], clip_on=True,
|
|
DF2_desired=DF2_desired_orig,
|
|
DF1_desired=DF1_desired_orig, alpha=[1, 1],
|
|
log=log, ylim_log=ylim_log, nfft=nfft,
|
|
xlim_psd=xlim_psd)
|
|
fr_mult = fr / eod_fr
|
|
multwise = False
|
|
if multwise:
|
|
DF1_frmult = np.abs((np.array(DF1_desired) - 1) / fr_mult)
|
|
DF2_frmult = np.abs((np.array(DF2_desired) - 1) / fr_mult)
|
|
else:
|
|
DF1_frmult = np.array(DF1_desired_orig) / fr
|
|
DF2_frmult = np.array(DF2_desired_orig) / fr
|
|
# embed()
|
|
DF1_frmult[0] = 1
|
|
DF2_frmult[1] = 0.32339256 # 1.06949369
|
|
print(DF1_frmult)
|
|
print(DF2_frmult)
|
|
grid0 = gridspec.GridSpecFromSubplotSpec(len(DF1_desired), 1, wspace=0.15, hspace=0.35,
|
|
subplot_spec=grid[2])
|
|
return DF1_desired, DF1_frmult, DF2_desired, DF2_frmult, eod_fr, grid0
|
|
|
|
|
|
def plt_data_full_model(c1, chose_score, detections, devs, dfs, end, grid, mult_type, sorted_on, ms = 14, log = 'log', markers = ['s', 'o'],
|
|
clip_on = False, alpha = [], DF2_desired = [-33, -100], DF1_desired = [133, 66], ylim_log = (-15, 3), nfft =2 ** 13, xlim_psd = [0, 235]):
|
|
# mean_type = '_MeanTrialsIndexPhaseSort_Min0.25sExcluded_'
|
|
extract = ''
|
|
datasets, data_dir = find_all_dir_cells()
|
|
cells = ['2022-01-28-ah-invivo-1'] # , '2022-01-28-af-invivo-1', '2022-01-28-ab-invivo-1',
|
|
# '2022-01-27-ab-invivo-1', ] # ,'2022-01-28-ah-invivo-1', '2022-01-28-af-invivo-1', ]
|
|
append_others = 'apend_others' # '#'apend_others'#'apend_others'#'apend_others'##'apend_others'
|
|
autodefine = '_DFdesired_'
|
|
autodefine = 'triangle_diagonal_fr' # ['triangle_fr', 'triangle_diagonal_fr', 'triangle_df2_fr','triangle_df2_eodf''triangle_df1_eodf', ] # ,'triangle_df2_fr''triangle_df1_fr','_triangle_diagonal__fr',]
|
|
# 167(167, 133) (166, 249)
|
|
# (133, 265)167, -33) das ist ein komischer Punkt: (166,83)
|
|
#(66 / 166
|
|
autodefine = '_dfchosen_closest_'
|
|
autodefine = '_dfchosen_closest_first_'
|
|
cells = ['2021-08-03-ac-invivo-1'] ##'2021-08-03-ad-invivo-1',,[10, ][5 ]
|
|
# c1s = [10] # 1, 10,
|
|
# c2s = [10]
|
|
minsetting = 'Min0.25sExcluded'
|
|
c2 = 10
|
|
# detections = ['MeanTrialsIndexPhaseSort'] # ['AllTrialsIndex'] # ,'MeanTrialsIndexPhaseSort''DetectionAnalysis''_MeanTrialsPhaseSort'
|
|
# detections = ['AllTrialsIndex'] # ['_MeanTrialsIndexPhaseSort_Min0.25sExcluded_extended_eod_loc_synch']
|
|
extend_trials = '' # 'extended'#''#'extended'#''#'extended'#''#'extended'#''#'extended'#''#'extended'# ok kein Plan was das hier ist
|
|
# phase_sorting = ''#'PhaseSort'
|
|
eodftype = '_psdEOD_'
|
|
concat = '' # 'TrialsConcat'
|
|
indices = ['_allindices_']
|
|
chirps = [
|
|
''] # '_ChirpsDelete3_',,'_ChirpsDelete3_'','','',''#'_ChirpsDelete3_'#''#'_ChirpsDelete3_'#'#'_ChirpsDelete2_'#''#'_ChirpsDelete_'#''#'_ChirpsDelete_'#''#'_ChirpsDelete_'#''#'_ChirpsCache_'
|
|
extract = '' # '_globalmax_'
|
|
devs_savename = ['original', '05'] # ['05']#####################
|
|
# control = pd.read_pickle(
|
|
# load_folder_name(
|
|
# 'calc_model') + '/modell_all_cell_no_sinz3_afe0.1__afr1__afj0.1__length1.5_adaptoffsetallall2___stepefish' + step + 'Hz_ratecorrrisidual35__modelbigfit_nfft4096.pkl')
|
|
if len(cells) < 1:
|
|
data_dir, cells = load_cells_three(end, data_dir=data_dir, datasets=datasets)
|
|
cells, p_units_cells, pyramidals = restrict_cell_type(cells, 'p-units')
|
|
# default_settings(fs=8)
|
|
start = 'min' #
|
|
cells = ['2021-08-03-ac-invivo-1']
|
|
tag_cells = []
|
|
fr = float('nan')
|
|
eod_fr = float('nan')
|
|
arrays_len = []
|
|
for c, cell in enumerate(cells):
|
|
counter_pic = 0
|
|
contrasts = [c2]
|
|
tag_cell = []
|
|
for c, contrast in enumerate(contrasts):
|
|
contrast_small = 'c2'
|
|
contrast_big = 'c1'
|
|
contrasts1 = [c1]
|
|
for contrast1 in contrasts1:
|
|
for devname_orig in devs:
|
|
datapoints = [1000]
|
|
for d in datapoints:
|
|
################################
|
|
# prepare DF1 desired
|
|
|
|
# chose_score = 'auci02_012-auci_base_01'
|
|
|
|
# hier muss das halt stimmen mit der auswahl
|
|
# hier wollen wir eigntlich kein autodefine
|
|
# sondern wir wollen so ein diagonal ding haben
|
|
df1 = []
|
|
df2 = []
|
|
for df in range(len(DF1_desired)):
|
|
divergnce, fr, pivot_chosen, max_val, max_x, max_y, mult, DF1, DF2, min_y, min_x, min_val, diff_cut = chose_mat_max_value(
|
|
DF1_desired[df], DF2_desired[df], '', mult_type, eodftype, indices, cell,
|
|
contrast_small,
|
|
contrast_big, contrast1, dfs, start, devname_orig, contrast, autodefine=autodefine,
|
|
cut_matrix='cut', chose_score=chose_score) # chose_score = 'auci02_012-auci_base_01'
|
|
df1.append(DF1[0])
|
|
df2.append(DF2[0])
|
|
|
|
DF1_desired = df1 # [::-1]
|
|
DF2_desired = df2 # [::-1]
|
|
|
|
|
|
#######################################
|
|
# ROC part
|
|
# fr, celltype = get_fr_from_info(cell, data_dir[c])
|
|
|
|
version_comp, subfolder, mod_name_slash, mod_name, subfolder_path = find_code_vs_not()
|
|
b = load_b_public(c, cell, data_dir)
|
|
|
|
mt_sorted = predefine_grouping_frame(b, eodftype=eodftype, cell_name=cell)
|
|
|
|
counter_waves = 0
|
|
|
|
mt_sorted = mt_sorted[(mt_sorted['c2'] == c2) & (mt_sorted['c1'] == c1)]
|
|
|
|
test = False
|
|
if test:
|
|
mt_sorted[['DF1, DF2', 'm1, m2']]
|
|
mt_sorted['DF1, DF2']
|
|
ax00s = []
|
|
p_means_all_all = {}
|
|
choices = [[[0, 1, 2,3, 6]] * 6, [[0, 1, 2, 3, 4]] * 6]
|
|
for gg in range(len(DF1_desired)):
|
|
|
|
|
|
# try:
|
|
grid0 = gridspec.GridSpecFromSubplotSpec(len(DF1_desired), 1, wspace=0.15, hspace=0.35,
|
|
subplot_spec=grid)
|
|
t3 = time.time()
|
|
# except:
|
|
# print('time thing')
|
|
# embed()
|
|
ax_w = []
|
|
|
|
###################
|
|
# all trials in one
|
|
grouped = mt_sorted.groupby(
|
|
['c1', 'c2', 'm1, m2'],
|
|
as_index=False)
|
|
# try:
|
|
grouped_mean = chose_certain_group(DF1_desired[gg],
|
|
DF2_desired[gg], grouped,
|
|
several=True, emb=False,
|
|
concat=True)
|
|
# mt_sorted['m1, m2']
|
|
|
|
|
|
# except:
|
|
# print('grouped thing')
|
|
# embed()
|
|
###################
|
|
# groups sorted by repro tag
|
|
# todo: evnetuell die tuples gleich hier umspeichern vom csv ''
|
|
|
|
grouped = mt_sorted.groupby(
|
|
['c1', 'c2', 'm1, m2', 'repro_tag_id'],
|
|
as_index=False)
|
|
grouped_orig = chose_certain_group(DF1_desired[gg],
|
|
DF2_desired[gg],
|
|
grouped,
|
|
several=True)
|
|
gr_trials = len(grouped_orig)
|
|
###################
|
|
|
|
groups_variants = [grouped_mean]
|
|
group_mean = [grouped_orig[0][0], grouped_mean]
|
|
|
|
for d, detection in enumerate(detections):
|
|
mean_type = '_' + detection # + '_' + minsetting + '_' + extend_trials + concat
|
|
|
|
##############################################################
|
|
# load plotting arrays
|
|
arrays, arrays_original, spikes_pure = save_arrays_susept(
|
|
data_dir, cell, c, chirps, devs, extract, group_mean, mean_type, plot_group=0,
|
|
rocextra=False, sorted_on=sorted_on)
|
|
####################################################
|
|
|
|
####################################################
|
|
# hier checken wir ob für diesen einen Punkt das funkioniert mit der standardabweichung
|
|
|
|
try:
|
|
check_var_substract_method(spikes_pure)
|
|
except:
|
|
print('var checking not possible')
|
|
# fig = plt.figure()
|
|
# grid = gridspec.GridSpec(2, 1, wspace=0.7, left=0.05, top=0.95, bottom=0.15,
|
|
# right=0.98)
|
|
|
|
##########################################################################
|
|
# part with the power spectra
|
|
|
|
xlim = [0, 100]
|
|
|
|
# plt.savefig(r'C:\Users\alexi\OneDrive - bwedu\Präsentations\latex\experimental_protocol.pdf')
|
|
|
|
# fr_end = divergence_title_add_on(group_mean, fr[gg], autodefine)
|
|
|
|
###########################################
|
|
stimulus_length = 0.3
|
|
deltat = 1 / 40000
|
|
eodf = np.mean(group_mean[1].eodf)
|
|
eod_fr = eodf
|
|
|
|
a_fr = 1
|
|
|
|
eod_fe = eodf + np.mean(
|
|
group_mean[1].DF2) # data.eodf.iloc[0] + 10 # cell_model.eode.iloc[0]
|
|
a_fe = group_mean[0][1] / 100
|
|
eod_fj = eodf + np.mean(
|
|
group_mean[1].DF1) # data.eodf.iloc[0] + 50 # cell_model.eodj.iloc[0]
|
|
a_fj = group_mean[0][0] / 100
|
|
variant_cell = 'no' # 'receiver_emitter_jammer'
|
|
print('f0' + str(eod_fr))
|
|
print('f1' + str(eod_fe))
|
|
print('f2' + str(eod_fj))
|
|
eod_fish_j, time_array, time_fish_r, eod_fish_r, time_fish_e, eod_fish_e, time_fish_sam, eod_fish_sam, stimulus_am, stimulus_sam = extract_waves(
|
|
variant_cell, '',
|
|
stimulus_length, deltat, eod_fr, a_fr, a_fe, [eod_fe], 0, eod_fj, a_fj)
|
|
|
|
jammer_name = 'female'
|
|
cocktail_names = False
|
|
if cocktail_names:
|
|
titles = ['receiver ',
|
|
'+' + 'intruder ',
|
|
'+' + jammer_name,
|
|
|
|
'+' + jammer_name + '+intruder',
|
|
[]] ##'receiver + ' + 'receiver + receiver
|
|
else:
|
|
titles = title_motivation()
|
|
gs = [0, 1, 2, 3, 4]
|
|
waves_presents = [['receiver', '', '', 'all'],
|
|
['receiver', 'emitter', '', 'all'],
|
|
['receiver', '', 'jammer', 'all'],
|
|
|
|
['receiver', 'emitter', 'jammer', 'all'],
|
|
] # ['', '', '', ''],['receiver', '', '', 'all'],
|
|
# ['receiver', '', 'jammer', 'all'],
|
|
# ['receiver', 'emitter', '', 'all'],'receiver', 'emitter', 'jammer',
|
|
symbols = [''] # '$+$', '$-$', '$-$', '$=$',
|
|
symbols = ['', '', '', '', '']
|
|
|
|
time_array = time_array * 1000
|
|
|
|
color0 = 'green'
|
|
color0_burst = 'darkgreen'
|
|
color01 = 'green'
|
|
color02 = 'red'
|
|
color012 = 'orange'
|
|
color01_2 = 'purple'
|
|
color01, color012, color01_2, color02, color0_burst, color0 = colors_suscept_paper_dots()
|
|
colors_am = ['black', 'black', 'black', 'black'] # color01, color02, color012]
|
|
extracted = [False, True, True, True]
|
|
extracted2 = [False, False, False, False]
|
|
|
|
printing = True
|
|
if printing:
|
|
print(time.time() - t3)
|
|
|
|
|
|
|
|
##########################################
|
|
# spike response
|
|
array_chosen = 1
|
|
if d == 0: #
|
|
|
|
# plot the psds
|
|
|
|
p_means_all = {}
|
|
names = ['0', '02', '01',
|
|
'012'] ## names = ['012']#'0', '02', '01',
|
|
for j in range(len(arrays)): # [arrays[-1]]
|
|
########################################
|
|
# get the corresponding psds
|
|
# hier kann man aussuchen welches power spektrum machen haben will
|
|
f, nfft = get_psds_ROC(array_chosen, arrays, arrays_original, j,
|
|
mean_type,
|
|
names, p_means_all, nfft = nfft)
|
|
# f, nfft = get_psds_ROC(array_chosen, [arrays[-1]], [arrays_original[-1]], j, mean_type,
|
|
# names, p_means_all)
|
|
# ax_as.append(ax_a)
|
|
ps = {}
|
|
p_means = {}
|
|
ax_ps = []
|
|
|
|
#color012_minus = 'purple' # ,
|
|
names = ['0', '02', '01', '012'] #
|
|
|
|
colors_p = [color0, color02, color01, color012, color02, color01, color01_2,
|
|
color0_burst, color0_burst,
|
|
color0, color0]
|
|
ax00 = plt.subplot(grid0[gg])
|
|
ax00s.append(ax00)
|
|
if gg == 0:
|
|
ax00.text(1, 1, 'Data', ha='right', va = 'top', transform=ax00.transAxes)
|
|
# todo: da nicht alle vier über einander plotten das ist das problem!
|
|
#embed()
|
|
choice = choices[gg]
|
|
arrays_len.append(len(spikes_pure['012']))
|
|
|
|
#labels = labels_all_motivation(DF1, DF2, fr_isi)
|
|
|
|
labels = ['$f_{base}$',
|
|
label_deltaf1(),
|
|
label_deltaf2(),
|
|
label_sum(),
|
|
label_two_deltaf1(),
|
|
label_two_deltaf2(),
|
|
label_diff(),
|
|
'fr_bc',
|
|
'fr_given_burst_corr_individual', 'highest_fr_burst_corr_individual',
|
|
'fr', 'fr_given',
|
|
'highest_fr'] # '$|$DF1-DF2$|$=' + str(np.abs(np.abs(DF1) - np.abs(DF2))) + 'Hz',
|
|
#freqs = [fr_isi, np.abs(DF2), np.abs(DF1),
|
|
# np.abs(DF1) + np.abs(DF2), 2 * np.abs(DF2), 2 * np.abs(DF1),
|
|
# np.abs(np.abs(DF1) - np.abs(DF2)), ]
|
|
if len(alpha)> 0:
|
|
alphas = [alpha[gg]]*len(labels)
|
|
else:
|
|
alphas = []
|
|
#embed()
|
|
ax00, fr_isi = plt_psds_ROC(arrays, ax00, ax_ps, cell, colors_p, f, grid0,
|
|
group_mean, nfft, p_means, p_means_all, ps, 4,
|
|
spikes_pure, range_plot=[3], names=names,
|
|
ax01=ax00, ms = ms, clip_on = clip_on, xlim_psd=xlim_psd, alphas = alphas, marker = markers[gg], choice = choice, labels = labels, ylim_log=ylim_log, log=log, text_extra=False)
|
|
# [arrays[-1]]arrays, ax00, ax_ps, cell, colors_p, f, [-1]grid0, group_mean, nfft, p_means, p_means_all, ps, row,spikes_pure, time_array,
|
|
ax00.show_spines('b')
|
|
if gg == 0:
|
|
ax00.legend(ncol=6, loc=(-1.16, 1.1))
|
|
if gg != len(DF1_desired) - 1:
|
|
remove_xticks(ax00)
|
|
ax00.set_xlabel('')
|
|
|
|
axes = []
|
|
axes.append(ax_w)
|
|
return DF1_desired, DF2_desired, fr, eod_fr, arrays_len
|
|
|
|
|
|
if __name__ == '__main__':
|
|
#embed()
|
|
sys.excepthook = info
|
|
model_full() |