susceptibility1/data_overview.py
2024-02-19 15:46:02 +01:00

918 lines
44 KiB
Python

#sys.path.insert(0, '..')
#from plt_RAM import plt_RAM_overview_nice
#from utils_susept import
from IPython import embed
from matplotlib import gridspec as gridspec, pyplot as plt
import numpy as np
#embed()
from utils_all_down import default_settings, resave_small_files,update_cell_names
from utils_suseptibility import default_figsize, NLI_scorename, kernel_scatter, plt_burst_modulation_hists, \
plt_model_overview2, version_final
from utils_all import colors_overview, cv_base_name, load_overview_susept, make_log_ticks, p_units_to_show, \
save_visualization, \
setting_overview_score, update_ssh_file, load_folder_name
#import lstat
try:
from plotstyle import plot_style, spines_params
except:
a = 5
from heterogeneity import plt_fr_cv_base, get_grids_for_cv_fr, get_frame_for_base_plot
def data_overview2():
# calcdf_RAM_overview()
save_name = 'calc_RAM_overview-noise_data8_nfft1sec_original__LocalEOD_CutatBeginning_0.05_s_NeurDelay_0.005_s_burst_corr'
save_name = 'calc_RAM_overview-noise_data8_nfft1sec_original__LocalEOD_CutatBeginning_0.05_s_NeurDelay_0.005_s'
save_name = 'calc_RAM_overview-noise_data9_nfft1sec_original__StimPreSaved4__CutatBeginning_0.05_s_NeurDelay_0.005_s'
save_name = 'calc_RAM_overview-noise_data9_nfft1sec_original__StimPreSaved4__mean5__CutatBeginning_0.05_s_NeurDelay_0.005_s'
col = 4
row = 2 # sharex=True,
plot_style()
default_figsize(column=2, length=7.35)
#fig, ax = plt.subplots(4, 2) # , figsize=(14, 7.5) constrained_layout=True,
three = True
if three:
top = True
grid00 = gridspec.GridSpec(2, 1, wspace=0.37, bottom=0.15,
hspace=0.25, left=0.085, right=0.95, top=0.94, height_ratios = [1,2.7])
else:
grid00 = gridspec.GridSpec(4, 2, wspace=0.75, bottom=0.04,
hspace=0.6, left=0.15, right=0.99, top=0.95)
top = False
#grid0 = gridspec.GridSpec(3, 3, wspace=0.35, bottom=0.2,
# hspace=1, left=0.085, right=0.95, top=0.94)
grid0 = gridspec.GridSpecFromSubplotSpec(1, 5, grid00[0],width_ratios = [1,0.4, 1,0.55,1], hspace=0.35,wspace=0)
grid1 = gridspec.GridSpecFromSubplotSpec(2, 5, grid00[1],width_ratios = [1,0.4, 1,0.55,1], hspace=1.1, wspace=0)
###################################
###############################
# Das ist der Finale Score
scoreall = 'perc99/med'
###################################
#scores = [scoreall+'_diagonal_proj']
#score = scores[0]
##########################
# Auswahl: wir nehmen den mean um nicht Stimulus abhängigen Noise rauszumitteln
#save_names = []
save_names = ['calc_RAM_overview-_simplified_'+version_final()]#'calc_RAM_overview-_simplified_noise_data9_nfft1sec_original__StimPreSaved4__mean5__CutatBeginning_0.05_s_NeurDelay_0.005_s__burstIndividual_','calc_RAM_overview-noise_data9_nfft1sec_original__StimPreSaved4__mean5__CutatBeginning_0.05_s_NeurDelay_0.005_s__burstIndividual_',
save_names = [version_final_overview()]#_abs_
#save_names = ['calc_RAM_overview-_simplified_noise_data12_nfft0.5sec_original__StimPreSaved4__abs_']
counter = 0
colors = colors_overview()
ax_j = []
axls = []
axss = []
cell_types = [' Ampullary', ' P-unit', ]
counter = 0
tags = []
log = False
counterplus = 2
max_val = 1.5
score_burst_corr = 'max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr'#scores[0]
score_n_burst_corr= 'max(diag5Hz)/med \n diagonal_proj \n fr_base_w_burstcorr' # , 'max(diag5Hz)/med \n diagonal_proj \n fr_base_w_burstcorr']
score_n_burst_corr = 'Fr$_{BurstCorr}$/Median' # , 'max(diag5Hz)/med \n diagonal_proj \n fr_base_w_burstcorr']
score_n_burst_corr = NLI_burstcorr_name()
score = 'max(diag5Hz)/med_diagonal_proj_fr'
score_n = 'max(diag5Hz)\n/med_diagonal_proj_fr'
score_n = 'Fr/Median' # , 'max(diag5Hz)/med \n diagonal_proj \n fr_base_w_burstcorr']
score_n = NLI_scorename()
#score = 'max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr' # scores[0]
redo = False#True#True
frame_load_sp = load_overview_susept(save_names[0], redo=redo, redo_class=redo)
#embed()
test_amps = False
if test_amps:
cells_amp = ['2011-09-21-ab', '2010-06-21-am', '2012-05-15-ac', '2012-04-26-ae', '2012-05-07-ac', '2010-06-21-ac']
cells_amp = update_cell_names(cells_amp)
frame_amps = frame_load_sp[frame_load_sp.cell.isin(cells_amp)]
fish_plot = False
if fish_plot:
axls, axss, counter, frame_load_sp, max_val, score_burst_corr = fish_plt_false(ax_j, axls, axss, cell_types,
colors, counter, grid0, log,
max_val, save_names,
score_burst_corr)
alpha = 0.3
####################################################################
# base plots
# cells = p_units_to_show()
# cell_type_type, frame_load, frame_spikes = get_frame_for_base_plot(cells)
burst_choice = ['', '_burst_corr_individual']
xmax_burst = [[1.5,'no'],[0.8,'no']]
for gg in range(len(burst_choice)):
cells = p_units_to_show()
species = ' Apteronotus leptorhynchus'
cell_type_type, frame_load, frame_spikes = get_frame_for_base_plot(cells, save_names = save_names, species = species)
ax0, ax_cv, ax_fr = get_grids_for_cv_fr(gg, grid0[counter])#counter
if gg == 0:
#ax_cv.text(1.5, 2, r'\bf{A} \textit{Apteronotus leptorhynchus}', ha = 'center', va = 'center', transform=ax_cv.transAxes)
text_punits(ax_cv, colors)
ax_cv.text(0.35, 0.45, r'Ampullary cells', ha='left', va='center',
transform=ax_cv.transAxes, color = colors[' Ampullary'])#' Ampullary',
species_letter(ax_cv)
print(species)
x_axis, y_axis = plt_fr_cv_base(ax0, ax_cv, ax_fr, burst_choice,
frame_load, gg, alpha = alpha, xmax = xmax_burst[gg], species = species)
ax0.set_xticks_delta(0.5)
tags.append(ax_cv)
counter += 2
#frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='min', species=species)
####################################################################
# base plots
# cells = p_units_to_show()
# cell_type_type, frame_load, frame_spikes = get_frame_for_base_plot(cells)
burst_choice = ['']#, '_burst_corr_individual']
#counter += 1
nrs = [1,3]
for gg in range(len(burst_choice)):
cells = p_units_to_show()
species = ' Eigenmannia virescens'
cell_type_type, frame_load, frame_spikes = get_frame_for_base_plot(cells,save_names = save_names, species = species)
ax0, ax_cv, ax_fr = get_grids_for_cv_fr(gg, grid0[counter])#counter
#ax_cv.set_title('Eigenmannia virescens')
#ax_cv.text(0.5, 2, B, ha='center', va='center', transform=ax_cv.transAxes)
species_letter(ax_cv, letter='B', species=r'\textit{Eigenmannia virescens}')
print(species)
x_axis, y_axis = plt_fr_cv_base(ax0, ax_cv, ax_fr, burst_choice,
frame_load, gg, alpha = alpha, xmax = ['no','no'], species = species)
ax0.set_xticks_delta(0.5)
tags.append(ax_cv)
counter += 2
#embed()
###########################
###########################
###########################
# counterreset!
counter = 0
#grid0 = grid1
# base ready
####################################################################
####################################################################
####################################################################
####################################################################
#grid_lower = gridspec.GridSpecFromSubplotSpec(2, 2, grid0[2],hspace = 0.55, wspace = 0.5)
#
cv_name = "cv_base"
species = ' Apteronotus leptorhynchus'
cell_type_here = ' P-unit'
#for c, cell_type_here in enumerate(cell_types):
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='min', species=species)
#embed()
#setting_overview_score(frame_load_sp, cell_type_here, min_amp='min', species=species)
x_axis = ['cv_base',score]#,'burst_fraction_burst_corr_individual_stim']#, 'cv_base']#,'cv_base',]
x_axis_names = [cv_base_name(), score_n] # ,'Burst Fraction$_{Stim}$' 'CV$_{Base}$']#,'Burst Fraction$_{Base}$',]
y_axis = ['burst_fraction_burst_corr_individual_base', score_burst_corr] # , 'coherence_', ]
y_axis_name = ['Burst Fraction$_{Base}$', score_n_burst_corr]
#
var_item_names = ['Response Modulation [Hz]']#,'Response Modulation [Hz]']#,'Burst Fraction$_{Base}$']#'Response Modulation',]#,score_n_burst_corr,'Response Modulation [Hz]']#'Burst Fraction$_{Stim}$',['Modulation']#,
#'Response Modulation [Hz]',
var_types = ['response_modulation']#,'response_modulation']#,'burst_fraction_burst_corr_individual_base']#'response_modulation']#,score_burst_corr,'response_modulation']#,'burst_fraction_burst_corr_individual_stim','cv_base''response_modulation'] # [ 'response_modulation']#,'cv_base''response_modulation']#,'burst_fraction_burst_corr_individual_base', ]
logs = [False,False]#,False]
xmins = [0,0]#,'no']
#'response_modulation',
#var_item_names = ['burst_diff']#['Modulation [Hz]']#,
#var_types = ['burst_diff'] # [ 'response_modulation']#,'cv_base''response_modulation']#,'burst_fraction_burst_corr_individual_base', ]
#['burst_fraction_burst_corr_individual_stim']
#score_name = ['Burst Fraction$_{Stim}$']# 'CV$_{Base}$']#,'Burst Fraction', ]
frame_file['burst_diff'] = np.abs(frame_file['burst_fraction_burst_corr_individual_stim']-frame_file['burst_fraction_burst_corr_individual_base'])
burst_fraction = [1,1,1]#, 0.5, 1, 1]#05burst_fraction_burst_corr_individual_base
#score_n = ['Perc99/Med','Perc99/Med']
#score = ['max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr','max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr']
n = False
xlim_here0 = [0,1.5]
ax_j, axls, axs, axss, counter = plt_var_axis([], axls, axss,y_axis_name, burst_fraction, cell_type_here, counter, cv_name,
frame_file, grid1, max_val, score_burst_corr, y_axis, var_item_names,
var_types, x_axis, x_axis_names, counterplus = counterplus, n = n, xlim = xlim_here0, log = logs, top = top, xmins = xmins, extra_cells = False)
text_punits(ax_j[0], colors, xpos = 0.65, ypos = 0.9)
#plt.show()
#hier beide anhängen
tags.append(ax_j[-1])
#tags.extend(ax_j)
xlim_here = axss[-1].get_xlim()
ylim_here = axss[-1].get_ylim()
axss[-1].set_xlim(xlim_here0)
ax_j[-1].set_xlim(xlim_here0)
start = np.max([xlim_here[0],ylim_here[0]])
end = np.min([xlim_here[1], ylim_here[1]])
#axss[-1].plot([start, end], [start, end], color='grey', linewidth=0.5)
#plt.show()
####################################################################
#grid_lower = gridspec.GridSpecFromSubplotSpec(2, 2, grid0[2],hspace = 0.55, wspace = 0.5)
#
cv_name = "cv_base"
species = ' Apteronotus leptorhynchus'
cell_type_here = ' P-unit'
#for c, cell_type_here in enumerate(cell_types):
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='min', species=species)
x_axis = ['burst_fraction_burst_corr_individual_base','cv_base',score]#,'burst_fraction_burst_corr_individual_stim']#, 'cv_base']#,'cv_base',]
x_axis_names = ['Burst Fraction$_{Base}$', 'CV$_{Base}$',score_n] # ,'Burst Fraction$_{Stim}$' 'CV$_{Base}$']#,'Burst Fraction$_{Base}$',]
y_axis = [score_burst_corr, 'burst_fraction_burst_corr_individual_base', score_burst_corr] # , 'coherence_', ]
y_axis_name = [score_n_burst_corr, 'Burst Fraction$_{Base}$', score_n_burst_corr]
#
var_item_names = ['Response Modulation [Hz]']#,'Response Modulation [Hz]']#,'Burst Fraction$_{Base}$']#'Response Modulation',]#,score_n_burst_corr,'Response Modulation [Hz]']#'Burst Fraction$_{Stim}$',['Modulation']#,
#'Response Modulation [Hz]',
var_types = ['response_modulation']#,'response_modulation']#,'burst_fraction_burst_corr_individual_base']#'response_modulation']#,score_burst_corr,'response_modulation']#,'burst_fraction_burst_corr_individual_stim','cv_base''response_modulation'] # [ 'response_modulation']#,'cv_base''response_modulation']#,'burst_fraction_burst_corr_individual_base', ]
logs = [False,False]#,False]
xmins = [0,0]#,'no']
#'response_modulation',
#var_item_names = ['burst_diff']#['Modulation [Hz]']#,
#var_types = ['burst_diff'] # [ 'response_modulation']#,'cv_base''response_modulation']#,'burst_fraction_burst_corr_individual_base', ]
#['burst_fraction_burst_corr_individual_stim']
#score_name = ['Burst Fraction$_{Stim}$']# 'CV$_{Base}$']#,'Burst Fraction', ]
frame_file['burst_diff'] = np.abs(frame_file['burst_fraction_burst_corr_individual_stim']-frame_file['burst_fraction_burst_corr_individual_base'])
burst_fraction = [1,1,1]#, 0.5, 1, 1]#05burst_fraction_burst_corr_individual_base
#score_n = ['Perc99/Med','Perc99/Med']
#score = ['max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr','max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr']
xmax = 6
ax_j, axls, axs, axss, counter = plt_var_axis([], axls, axss,y_axis_name, burst_fraction, cell_type_here, counter, cv_name,
frame_file, grid1, max_val, score_burst_corr, y_axis, var_item_names,
var_types, x_axis, x_axis_names, counterplus = counterplus, n = n, log = logs, top = top, xmins = xmins, ymaxs = [xmax], extra_cells = True)
#text_punits(axs, colors)
#hier beide anhängen
reset_xlims(axls, axss, xmax)
tags.append(ax_j[-1])
#tags.extend(ax_j)
xlim_here = axss[-1].get_xlim()
ylim_here = axss[-1].get_ylim()
start = np.max([xlim_here[0],ylim_here[0]])
end = np.min([xlim_here[1], ylim_here[1]])
#axss[-1].plot([start, end], [start, end], color='grey', linewidth=0.5)
#plt.show()
########################################################################
#####################################################################
# Eigemania Zellen
ylim_eigen = [0, 6]
cell_types = [' P-unit',' Ampullary'] # ,' P-unit',' Ampullary', ]
x_axis = ["cv_base"] # , "cv_base_w_burstcorr","cv_base", ]
cv_name_title = [cv_base_name()] # ,'CV$_{BurstCorr}$','CV']
species_all = [' Eigenmannia virescens'] # ,' Apteronotus leptorhynchus',' Eigenmannia virescens']
#counter += counterplus
ax_j, axls, axss, cell_types, _, max_val, _ = species_with_both_cells(grid1[counter], cell_types, ax_j,
axls, axss, colors,
cv_name_title,
save_names, score,
species_all, x_axis,ylim = ylim_eigen,
max_val=max_val,n = n, alpha = alpha, log = False, score_n = score_n)
tags.append(ax_j[-1])
axss[-1].set_title('')
ax_j[-1].set_title('')
counter += 1
####################################################################
# grid_lower = gridspec.GridSpecFromSubplotSpec(2, 2, grid0[2],hspace = 0.55, wspace = 0.5)
#
cv_name = "cv_base"
species = ' Apteronotus leptorhynchus'
cell_type_here = ' P-unit'
# for c, cell_type_here in enumerate(cell_types):
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='min', species=species)
x_axis = [
score] # 'burst_fraction_burst_corr_individual_base','cv_base']#,score]#,'burst_fraction_burst_corr_individual_stim']#, 'cv_base']#,'cv_base',]
x_axis_names = [
score_n] # ,'Burst Fraction$_{Base}$', 'CV$_{Base}$']#,score_n] # ,'Burst Fraction$_{Stim}$' 'CV$_{Base}$']#,'Burst Fraction$_{Base}$',]
y_axis = [
score_burst_corr] # , 'burst_fraction_burst_corr_individual_base']#, score_burst_corr] # , 'coherence_', ]
y_axis_name = [score_n_burst_corr] # , 'Burst Fraction$_{Base}$']#, score_n_burst_corr]
#
var_item_names = [
'Burst Fraction$_{Base}$'] # 'Response Modulation',]#,score_n_burst_corr,'Response Modulation [Hz]']#'Burst Fraction$_{Stim}$',['Modulation']#,
# 'Response Modulation [Hz]',
var_types = [
'burst_fraction_burst_corr_individual_base'] # 'response_modulation']#,score_burst_corr,'response_modulation']#,'burst_fraction_burst_corr_individual_stim','cv_base''response_modulation'] # [ 'response_modulation']#,'cv_base''response_modulation']#,'burst_fraction_burst_corr_individual_base', ]
logs = [False]
xmins = ['no']
ymins = ['no']
# 'response_modulation',
# var_item_names = ['burst_diff']#['Modulation [Hz]']#,
# var_types = ['burst_diff'] # [ 'response_modulation']#,'cv_base''response_modulation']#,'burst_fraction_burst_corr_individual_base', ]
# ['burst_fraction_burst_corr_individual_stim']
# score_name = ['Burst Fraction$_{Stim}$']# 'CV$_{Base}$']#,'Burst Fraction', ]
frame_file['burst_diff'] = np.abs(frame_file['burst_fraction_burst_corr_individual_stim'] - frame_file[
'burst_fraction_burst_corr_individual_base'])
burst_fraction = [1, 1, 1] # , 0.5, 1, 1]#05burst_fraction_burst_corr_individual_base
# score_n = ['Perc99/Med','Perc99/Med']
# score = ['max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr','max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr']
xmax = 7
ax_j, axls, axs, axss, counter = plt_var_axis(ax_j, axls, axss, y_axis_name, burst_fraction, cell_type_here,
counter, cv_name,
frame_file, grid1, max_val, score_burst_corr, y_axis, var_item_names,
var_types, x_axis, x_axis_names, counterplus = counterplus,n = n, log=logs, top=top, xmins=xmins, ymaxs = [xmax], extra_cells= False)
reset_xlims(axls, axss, xmax)
axss[-1].set_xticks_delta(2)
axss[-1].set_yticks_delta(2)
axss[-1].set_xlim(0.5, xmax)
ax_j[-1].get_shared_x_axes().join(*[axss[-1], ax_j[-1]])
#text_punits(axs, colors)
# embed()
tags.append(ax_j[-1])
xlim_here = axss[-1].get_xlim()
ylim_here = axss[-1].get_ylim()
start = np.max([xlim_here[0], ylim_here[0]])
end = np.min([xlim_here[1], ylim_here[1]])
axss[-1].plot([start, end], [start, end], color='grey', linewidth=0.5)
# embed()
####################################################################
cv_name = "cv_base"
species = ' Apteronotus leptorhynchus'
cell_type_here = ' P-unit'
# for c, cell_type_here in enumerate(cell_types):
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='range', species=species)
var_types = ['response_modulation']#,'response_modulation']
x_axis = ['burst_fraction_burst_corr_individual_base']#,score]
var_item_names = ['Response Modulation [Hz]']#,'Response Modulation [Hz]']#'Modulatoin'
x_axis_names = ['Burst Fraction$_{Base}$']#,score_n]
burst_fraction = [1, 1, 1, 1] # burst_fraction_burst_corr_individual_base
y_axis = ['burst_fraction_burst_corr_individual_stim']#,score_burst_corr]
y_axis_name = ['Burst Fraction$_{Stim}$']#,score_n_burst_corr]
#embed()
test = False
if test:
burst_fraction, var_item_names, var_types, x_axis, x_axis_names, y_axis, y_axis_name = test_eodfr(
burst_fraction, var_item_names, var_types, x_axis, x_axis_names, y_axis, y_axis_name)
#embed()
for v, var_type in enumerate(var_types):
# ax = plt.subplot(grid0[1+v])#grid_lower[0, v]
axk, axl, axs, axls, axss, ax_j = get_grid_4(ax_j, axls, axss, grid1[counter])
cmap, _, _ = plt_burst_modulation_hists(axk, axl, var_item_names[v], axs, cell_type_here,
x_axis[v], frame_file, max_val, y_axis[v],
burst_fraction=burst_fraction[v], n = n,top = top, var_item=var_type)
axs.set_ylabel(y_axis_name[v])
axs.set_xlabel(x_axis_names[v])
#text_punits(axs, colors)
plot_extra_cells(axs, frame_file, y_axis, v, x_axis, type_here = 'contrasts')
#if v == 1:
if test == False:
axs.plot([0, 1.01], [0, 1.01], color='grey', linewidth=0.5)
tags.append(axk)
counter += counterplus
####################################################################
#grid_lower = gridspec.GridSpecFromSubplotSpec(2, 2, grid0[2],hspace = 0.55, wspace = 0.5)
#
mutual_information = False
if mutual_information:
cv_name = "cv_base"
species = ' Apteronotus leptorhynchus'
cell_type_here = ' P-unit'
#for c, cell_type_here in enumerate(cell_types):
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='min', species=species)
x_axis = ['burst_fraction_burst_corr_individual_base','cv_base',score]#,'burst_fraction_burst_corr_individual_stim']#, 'cv_base']#,'cv_base',]
x_axis_names = ['Burst Fraction$_{Base}$', 'CV$_{Base}$',score_n] # ,'Burst Fraction$_{Stim}$' 'CV$_{Base}$']#,'Burst Fraction$_{Base}$',]
y_axis = ['contrast_integral', 'burst_fraction_burst_corr_individual_base', score_burst_corr] # , 'coherence_', ]
y_axis_name = ['(MI$_{R}$-MI$_{C}$)/MI$_{C}$', 'Burst Fraction$_{Base}$', score_n_burst_corr]
#
var_item_names = ['Response Modulation [Hz]']#,'Response Modulation [Hz]']#,'Burst Fraction$_{Base}$']#'Response Modulation',]#,score_n_burst_corr,'Response Modulation [Hz]']#'Burst Fraction$_{Stim}$',['Modulation']#,
#'Response Modulation [Hz]',
var_types = ['response_modulation']#,'response_modulation']#,'burst_fraction_burst_corr_individual_base']#'response_modulation']#,score_burst_corr,'response_modulation']#,'burst_fraction_burst_corr_individual_stim','cv_base''response_modulation'] # [ 'response_modulation']#,'cv_base''response_modulation']#,'burst_fraction_burst_corr_individual_base', ]
logs = [False,False]#,False]
xmins = [0,0]#,'no']
#'response_modulation',
#var_item_names = ['burst_diff']#['Modulation [Hz]']#,
#var_types = ['burst_diff'] # [ 'response_modulation']#,'cv_base''response_modulation']#,'burst_fraction_burst_corr_individual_base', ]
#['burst_fraction_burst_corr_individual_stim']
#score_name = ['Burst Fraction$_{Stim}$']# 'CV$_{Base}$']#,'Burst Fraction', ]
frame_file['burst_diff'] = np.abs(frame_file['burst_fraction_burst_corr_individual_stim']-frame_file['burst_fraction_burst_corr_individual_base'])
burst_fraction = [1,1,1]#, 0.5, 1, 1]#05burst_fraction_burst_corr_individual_base
#score_n = ['Perc99/Med','Perc99/Med']
#score = ['max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr','max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr']
ax_j, axls, axs, axss, counter = plt_var_axis([], axls, axss,y_axis_name, burst_fraction, cell_type_here, counter, cv_name,
frame_file, grid0, max_val, score_burst_corr, y_axis, var_item_names,
var_types, x_axis, x_axis_names,counterplus = coutnerplus, n = n, extra_cells = True, log = logs, top = top, xmins = xmins)
#hier beide anhängen
tags.append(ax_j[-1])
#tags.extend(ax_j)
xlim_here = axss[-1].get_xlim()
ylim_here = axss[-1].get_ylim()
start = np.max([xlim_here[0],ylim_here[0]])
end = np.min([xlim_here[1], ylim_here[1]])
#axss[-1].plot([start, end], [start, end], color='grey', linewidth=0.5)
#####################################################################
# Eigemania Zellen
cell_types = [' P-unit',' Ampullary'] # ,' P-unit',' Ampullary', ]
x_axis = ["response_modulation"] # , "cv_base_w_burstcorr","cv_base", ]
cv_name_title = ['Response Modulation [Hz]'] # ,'CV$_{BurstCorr}$','CV']
species_all = [' Eigenmannia virescens'] # ,' Apteronotus leptorhynchus',' Eigenmannia virescens']
#counter += 1
ax_j, axls, axss, cell_types, frame_load_sp, max_val, score_burst_corr = species_with_both_cells(grid1[counter], cell_types, ax_j,
axls, axss, colors,
cv_name_title,
save_names, score,
species_all, x_axis, alpha = alpha,
max_val=max_val, n = n, ylim = ylim_eigen, log = False, score_n = score_n)
tags.append(ax_j[-1])
axss[-1].set_title('')
ax_j[-1].set_title('')
counter+= 1#counterplus
#####################################################
#grid_lower_lower = gridspec.GridSpecFromSubplotSpec(1, 2, grid0[1], wspace = 0.5, hspace=0.55)#, height_ratios = [1,3]
cell_types = [' P-unit']#,' P-unit',' Ampullary', ]
restrict = False
if restrict:
ax_j, axls, axss, counter = modulation_restrict(ax_j, axls, axs, axss, cell_types, counter, cv_name,
frame_load_sp, grid0, log, max_val, score_burst_corr, score_n,
species, tags, top)
################################
# coherence
coherence_plot = False
if coherence_plot:
coherence_plot_modulation(ax_j, axls, axss, counter, frame_load_sp, grid0, max_val, tags, top)
##############################################
# jetzt kommen die extra P-unit Eigen statistiken
#species = ' Eigenmannia virescens'
#cv_name = 'cv_base'
#ax = plt.subplot(grid[4, 0])
#for c, cell_type_here in enumerate(cell_types):
# frame_file = setting_overview_score(cell_type_here, frame_load_sp, species=species)
# plt_eigen(cv_name, ax, c, cell_type_here, cells_extra, colors, frame_file, max_val, score,
# species, x_axis, y_axis)
########################
# modell
model_plot = False
if model_plot:
model_overview_plot(grid0, scoreall)
#ax_j[0].get_shared_y_axes().join(*[ax_j[0],ax_j[2],ax_j[3]])
#ax_j[0].get_shared_y_axes().join(*[ax_j[1], ax_j[3], ax_j[5], axls[0], axls[1], axls[2]])
#ax_j[0].get_shared_x_axes().join(*ax_j)
#ax_j[0].get_shared_x_axes().join(*[ax_j[0],ax_j[1]])
#ax_j[2].get_shared_x_axes().join(*[ax_j[2], ax_j[3]])
#ax_j[4].get_shared_x_axes().join(*[ax_j[4], ax_j[5]])
#plt.show()
fig = plt.gcf()
fig.tag([[tags[0], tags[1], tags[3], tags[4], tags[6], tags[7]],[tags[2], tags[5], tags[8]]], xoffs=-4.2, yoffs=1.12)
show = False#True
save_visualization(pdf = True, show = show)
def reset_xlims(axls, axss, xmax):
axss[-1].set_ylim(0.5, xmax)
axls[-1].get_shared_y_axes().join(*[axss[-1], axls[-1]])
def species_letter(ax_cv, letter = 'A', species = r'\textit{Apteronotus leptorhynchus}'):
ax_cv.text(-0.26, 1.8, letter, ha='left',
transform=ax_cv.transAxes, fontsize=13.5)
ax_cv.text(-0.1, 1.8, species, ha='left',
transform=ax_cv.transAxes) # va='center',
def text_punits(ax_cv, colors, xpos = 0.35, ypos = 0.85):
ax_cv.text(xpos, ypos, r'P-units', ha='left', va='center',
transform=ax_cv.transAxes, color=colors[' P-unit'])
def fish_plt_false(ax_j, axls, axss, cell_types, colors, counter, grid0, log, max_val, save_names, score_burst_corr):
#####################################################################
x_axis = ["cv_base"] # , "cv_base_w_burstcorr","cv_base", ]
cv_name_title = ['CV'] # ,'CV$_{BurstCorr}$','CV']
species_all = [' Apteronotus leptorhynchus'] # ,' Apteronotus leptorhynchus',' Eigenmannia virescens']
ax_j, axls, axss, cell_types, frame_load_sp, max_val, score_burst_corr = species_with_both_cells(grid0[counter],
cell_types, ax_j,
axls, axss, colors,
cv_name_title,
save_names,
score_burst_corr,
species_all,
x_axis, log=log,
max_val=max_val)
counter += 1
#####################################################################
x_axis = ["cv_base"] # , "cv_base_w_burstcorr","cv_base", ]
cv_name_title = ['CV'] # ,'CV$_{BurstCorr}$','CV']
# embed()
species_all = [' Apteronotus albifrons'] # ,' Apteronotus leptorhynchus',' Eigenmannia virescens']
ax_j, axls, axss, cell_types, frame_load_sp, max_val, score_burst_corr = species_with_both_cells(grid0[-2],
cell_types, ax_j,
axls, axss, colors,
cv_name_title,
save_names,
score_burst_corr,
species_all,
x_axis,
max_val=max_val)
return axls, axss, counter, frame_load_sp, max_val, score_burst_corr
def version_final_overview():
return 'calc_RAM_overview-_simplified_noise_data12_nfft0.5sec_original__StimPreSaved4__direct_'
def NLI_burstcorr_name():
return 'NLI$(f_{BaseCorrected})$'#f_{BaseCorr}
def test_eodfr(burst_fraction, var_item_names, var_types, x_axis, x_axis_names, y_axis, y_axis_name):
########################################
# test
var_types = ['response_modulation']
x_axis = ['burst_fraction_burst_corr_individual_base']
var_item_names = ['Response Modulation [Hz]'] # 'Modulatoin'
x_axis_names = ['Burst Fraction$_{Base}$']
burst_fraction = [1, 1, 1, 1] # burst_fraction_burst_corr_individual_base
y_axis = ['eod_fr']
y_axis_name = ['EOD Fr']
return burst_fraction, var_item_names, var_types, x_axis, x_axis_names, y_axis, y_axis_name
def model_overview_plot(grid0, scoreall):
model = resave_small_files("models_big_fit_d_right.csv", load_folder='calc_model_core')
cells = model.cell.unique()
axm = plt.subplot(grid0[-3])
plt_model_overview2(axm, cells, scores=[scoreall + '_'])
plt.subplots_adjust(left=0.07, right=0.95, top=0.98, bottom=0.05, wspace=0.45, hspace=0.55)
def coherence_plot_modulation(ax_j, axls, axss, counter, frame_load_sp, grid0, max_val, tags, top):
cv_name = "cv_base"
species = ' Apteronotus leptorhynchus'
cell_type_here = ' P-unit'
# for c, cell_type_here in enumerate(cell_types):
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='min', species=species)
var_types = ['burst_fraction_burst_corr_individual_base'] # ,'response_modulation']
x_axis = ['cv_base'] # ,'burst_fraction_burst_corr_individual_base']
var_item_names = ['Burst Fraction'] # , 'Modulatoin' ]
x_axis_names = ['Burst Fraction$_{Base}$'] # ,'Burst Fraction$_{Base}$']
burst_fraction = [1] # , 1, 1, 1]#burst_fraction_burst_corr_individual_base
y_axis = ['mutual_informaiton_'] # , 'coherence_''burst_fraction_burst_corr_individual_stim']
y_axis_name = ['Mutual Information'] # , 'coherence''Burst Fraction$_{Stim}$']
# embed()
for v, var_type in enumerate(var_types):
# ax = plt.subplot(grid0[1+v])#grid_lower[0, v]
axk, axl, axs, axls, axss, ax_j = get_grid_4(ax_j, axls, axss, grid0[counter])
cmap, _, y_axis = plt_burst_modulation_hists(axk, axl, var_item_names[v], axs, cell_type_here,
x_axis[v], frame_file, max_val, y_axis[v],
burst_fraction=burst_fraction[v], xmin=0, ymin=0, top=top,
var_item=var_type)
axs.set_ylabel(y_axis_name[v])
axs.set_xlabel(x_axis_names[v])
# if v == 1:
# axs.plot([0, 1], [0, 1], color='grey', linewidth=0.5)
tags.append(axk)
counter += 1
# ax_j
def modulation_restrict(ax_j, axls, axs, axss, cell_types, counter, cv_name, frame_load_sp, grid0, log, max_val,
score_burst_corr, score_n, species, tags, top):
burst_corr_reset = 'response_modulation'
burst_fraction = [50] # , 1000, 1000] # ,1,1]
burst_fraction = [0.01] # , 1, 1] # ,1,1]
burst_corr_reset = 'burst_fraction_burst_corr_individual_stim'
for c, cell_type_here in enumerate(cell_types):
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='range', species=species)
##############################################
# modulatoin comparison for both cell_types
################################
# Modulation, cell type comparison
# todo: hier die diff werte über die zellen
# ax_here = []
# axd = plt.subplot(grid_lower_lower[0, c])
# embed()
# kernel_histogram(axk, colors[str(cell_type_here)], np.array(x_axis), norm=True, step=0.03, alpha=0.5)
# embed()
# axk.show_spines('lb')
# axs = plt.subplot(grid0[6+c])
var_types = ['response_modulation']
x_axis = ['cv_base']
var_item_names = ['Response Modulation [Hz]', ] # 'Modulatoin'
x_axis_names = ['CV$_{Base}$']
y_axis = [score_burst_corr]
y_axis_name = [score_n]
for v, var_type in enumerate(var_types):
# ax = plt.subplot(grid0[1+v])#grid_lower[0, v]
axk, axl, axs, axls, axss, ax_j = get_grid_4(ax_j, axls, axss, grid0[counter])
cmap, _, y_axis = plt_burst_modulation_hists(axk, axl, var_item_names[v], axs, cell_type_here,
x_axis[v], frame_file, max_val, y_axis[v],
burst_fraction=burst_fraction[c], top=top,
burst_fraction_reset=burst_corr_reset, var_item=var_type)
axs.set_ylabel(y_axis_name[v])
axs.set_xlabel(x_axis_names[v])
# remove_yticks(axl)
if log:
axl.set_yscale('log')
axs.set_yscale('log')
axl.minorticks_off()
axl.set_yticks_blank()
tags.append(axk)
counter += 1
if c in [0, 2]:
######################################################
# hier kommen die kontrast Punkte dazu
# für die Zellen spielt Burst correctin ja keine Rolle
# if cv_n == 0:
if cell_type_here == ' P-unit':
cells_plot2 = p_units_to_show(type_here='contrasts')[0:2]
else:
cells_plot2 = [p_units_to_show(type_here='contrasts')[-1]]
# for cell_plt in cells_plot2:
cells_extra = frame_file[frame_file['cell'].isin(cells_plot2)].index
# ax = plt.subplot(grid[1, cv_n])
# todo: hier nur noch die kleinste und größte Amplitude nehmen
# embed()
axs.scatter(frame_file[cv_name].loc[cells_extra], frame_file[score_burst_corr].loc[cells_extra],
s=5, color='white', edgecolor='black', alpha=0.5, clip_on=False) # colors[str(cell_type_here)]
# cmap, _, y_axis = plt_modulation_overview(axs, c, cell_type_here,
# cv_name, frame_file, max_val, score,
# species)
# axs.set_ylabel(score)
# embed()#frame_file[(frame_file.cv_base < 0.65) & (frame_file.response_modulation > 200)].response_modulation
# axs.set_xlabel(cv_name)
# axs.get_shared_x_axes().join(*[axs, axd])
# elif species == ' Apteronotus albifrons':
# plt_albi(ax[4, 1], cell_type_here, colors, max_val, species, x_axis, y_axis)
# ax[1,cv_n].set_xlim(0, max_val)
# set_same_ylim(np.concatenate(ax[1::, :]))
# set_same_ylim(np.concatenate(ax[1::, :]),ylim_type ='xlim')
# set_same_ylim(ax[0, :], ylim_type='xlim')
# set_ylim_same()
# ax[1, 1].get_shared_y_axes().join(*ax[1, 1::])
# embed()
# counter += 1
# embed()
return ax_j, axls, axss, counter
def plt_var_axis(ax_j, axls, axss,score_name, burst_fraction, cell_type_here, counter, cv_name, frame_file, grid0, max_val, score,
scores_here, var_item_names, var_types, x_axis, x_axis_names, ymaxs = ['no'], n = True,counterplus = 1, extra_cells_false = False, extra_cells = True, ymins = ['no'], xmins = [], xlim = None, log = [False], top = False):
for v, var_type in enumerate(var_types):
# ax = plt.subplot(grid0[1+v])#grid_lower[0, v]
axk, axl, axs, axls, axss, ax_j = get_grid_4(ax_j, axls, axss, grid0[counter])
counter += counterplus
try:
cmap, _, y_axis = plt_burst_modulation_hists(axk, axl, var_item_names[v], axs, cell_type_here,
x_axis[v], frame_file, max_val, scores_here[v],
ymax = ymaxs[v], burst_fraction=burst_fraction[v], n = n, xlim = xlim, xmin = xmins[v],ymin =ymins[v], var_item=var_type, top = top)
except:
print('burst thing')
embed()
axk.show_spines('')
axl.show_spines('')
axs.set_ylabel(score_name[v])
axs.set_xlabel(x_axis_names[v])
if v in [0, 1]:
if log[v]:
axl.set_yscale('log')
axs.set_yscale('log')
axes = [axl, axs]
make_log_ticks(axes)
axl.set_yticks_blank()
# remove_yticks(axl)
axl.minorticks_off()
if extra_cells:
plot_extra_cells(axs, frame_file, scores_here, v, x_axis)
return ax_j, axls, axs, axss, counter
def plot_extra_cells(axs, frame_file, scores_here, v, x_axis, type_here = 'bursts'):
############################
# extra Zellen Scatter
# todo: diese Zellen müssen noch runter konvertiert werden
# todo: extra funktion für Zellen über 9 Snippets schreiben und die nochmal extra machen
cells_plot2 = p_units_to_show(type_here=type_here)
# for cell_plt in cells_plot2:
cells_extra = frame_file[frame_file['cell'].isin(cells_plot2)].index
# ax = plt.subplot(grid[1, cv_n])
#embed()
test_amps = False
if test_amps:
cells_here = frame_file.cell.unique()
cells_amp = ['2011-09-21-ab', '2010-06-21-am', '2012-05-15-ac', '2012-04-26-ae', '2012-05-07-ac',
'2010-06-21-ac']
cells_amp = update_cell_names(cells_amp)
# frame_amps = frame_file[frame_file.cell.isin(cells_amp)]
for cell_amp in cells_amp:
if cell_amp in cells_here:
print(cell_amp)
# cells_plot = update_cell_names(cells_search)
try:
axs.scatter(frame_file[x_axis[v]].loc[cells_extra], frame_file[scores_here[v]].loc[cells_extra],
s=5, color='white', edgecolor='black', alpha=0.5,
clip_on=False) # colors[str(cell_type_here)]
except:
print('small things')
embed()
def species_with_both_cells(grid0, cell_types, ax_j, axls, axss, colors, cv_name_title, save_names, score, species_all, x_axis, log = True, n = True,ylim = None, alpha = 1, max_val = 1.5, score_n ='Perc(99)/Median'):
for cv_n, cv_name in enumerate(x_axis):
if cv_n == 0:
redo = False
else:
redo = False
redo = False
frame_load_sp = load_overview_susept(save_names[0], redo=redo, redo_class=redo)
if len(frame_load_sp.cell.unique()) <470:
# double check if the file is the newest
#hostname, password, root, username = credencials0()
dated_up = update_ssh_file(load_folder_name('calc_RAM') + '/' + save_names[0] + '.csv')
if dated_up == 'yes':
frame_load_sp = load_overview_susept(save_names[0], redo=True, redo_class=redo)
#res = pysftp.put(filepath, destination)
#ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd_to_execute)
#ssh
#embed()
# frame_file = setting_overview_score(cell_type_here, frame_load_sp, min_amp=True, species=species)
# print(np.isnan(species))
for c, cell_type_here in enumerate(cell_types):
#if c == 1:
# embed()
species = species_all[cv_n]
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='min', species=species)
##################################
# modulation and species comparison
# x_axis, y_axis = get_axis(cv_name, frame_file, score)
# if cv_n == 0:
###############################
#######################
# Kernel Histogram
# plot the histograms of the values above the according vals
# grid = gridspec.GridSpecFromSubplotSpec(1, 1, grid0[0],hspace=0, wspace = 0.15)#grid[0, cv_n]
#
if c == 0:
axk, axl, axs, axls, axss, ax_j = get_grid_4(ax_j, axls, axss, grid0)
if c in [0, 2]:
axk.set_title(species)
# embed()
if len(frame_file) > 0:
if log:
ymin = 'no'
else:
ymin = 0
xmin = 0
if ylim:
axs.set_ylim(ylim)
axs, x_axis = kernel_scatter(axl, cell_types, axk, axs, ax_j, c, cell_type_here, colors, cv_n, cv_name,
frame_file, grid0, max_val,
score, log = log,alpha = alpha, n = n,xmin = xmin, ymin = ymin)
if log:
axl.set_yscale('log')
make_log_ticks([axs])
axl.set_yticks_blank()
axl.minorticks_off()
axs.set_xlabel(cv_name_title[cv_n])
if cv_n == 0:
axs.set_ylabel(score_n)
axl.show_spines('')
axk.show_spines('')
if cv_n == 0:
axm = [axs]
return ax_j, axls, axss, cell_types, frame_load_sp, max_val, score
def get_grid_4(ax_j, axls, axss, grid0):
grid_k = gridspec.GridSpecFromSubplotSpec(2, 2, grid0,
hspace=0.1, wspace=0.1, height_ratios=[0.35, 3], width_ratios=[3, 0.5])
axk = plt.subplot(grid_k[0, 0])
ax_j.append(axk)
axs = plt.subplot(grid_k[1, 0])
axss.append(axs)
axl = plt.subplot(grid_k[1, 1])
axls.append(axl)
return axk, axl, axs, axls, axss, ax_j
if __name__ == '__main__':
data_overview2()