357 lines
16 KiB
Python
357 lines
16 KiB
Python
from IPython import embed
|
|
from matplotlib import gridspec as gridspec, pyplot as plt
|
|
import numpy as np
|
|
|
|
from threefish.RAM.values import start_name, version_final
|
|
from threefish.RAM.plot_subplots import plt_specific_cells, scatter_with_marginals_colorcoded
|
|
from threefish.RAM.plot_grid import get_grid_4
|
|
from threefish.defaults import default_figsize
|
|
from threefish.RAM.plot_colors import colors_overview
|
|
from threefish.reformat import exclude_nans_for_corr
|
|
from threefish.RAM.reformat_population import load_overview_susept, update_cell_names_to_unify_invivo_nomenclature
|
|
from threefish.load import save_visualization
|
|
from threefish.RAM.calc_bursts import setting_overview_score
|
|
from threefish.RAM.plot_labels import basename_small, label_NLI_scorename2_small, label_pearson, label_stimname_small, \
|
|
make_log_ticks
|
|
from scipy import stats
|
|
try:
|
|
from plotstyle import plot_style, spines_params
|
|
except:
|
|
a = 5
|
|
|
|
|
|
def data_overview3():
|
|
|
|
plot_style()
|
|
default_figsize(column=2, length=6.2) #65.5
|
|
|
|
var_it = 'Response Modulation [Hz]'
|
|
var_it2 = ''
|
|
right = 0.85
|
|
ws = 0.75
|
|
#print(right)
|
|
grid0 = gridspec.GridSpec(3, 2, wspace=ws, bottom=0.06,
|
|
hspace=0.45, left=0.1, right=right, top=0.95)
|
|
|
|
##########################
|
|
# Auswahl: wir nehmen den mean um nicht Stimulus abhängigen Noise rauszumitteln
|
|
save_names = ['calc_RAM_overview-_simplified_noise_data12_nfft0.5sec_original__StimPreSaved4__direct_']
|
|
|
|
#####################################################
|
|
#grid_lower_lower = gridspec.GridSpecFromSubplotSpec(1, 2, grid0[1], wspace = 0.5, hspace=0.55)#, height_ratios = [1,3]
|
|
cell_types = [' P-unit',' Ampullary', ]#, ' P-unit',]#' P-unit',
|
|
cell_types_name = ['P-units','Ampullary cells',]
|
|
species = ' Apteronotus leptorhynchus'
|
|
burst_corr_reset = 'response_modulation'
|
|
burst_fraction = [1000, 1000]# 50, # ,1,1]
|
|
burst_fraction = [1, 1] # ,1,1]
|
|
burst_corr_reset = 'burst_fraction_burst_corr_individual_stim'
|
|
redo = False
|
|
#embed()
|
|
counter = 0
|
|
tags = []
|
|
frame_load_sp = load_overview_susept(save_names[0], redo=redo, redo_class=redo)
|
|
scores = ['max(diag5Hz)/med_diagonal_proj_fr','max(diag5Hz)/med_diagonal_proj_fr',
|
|
'max(diag5Hz)/med_diagonal_proj_fr_base_w_burstcorr'] # + '_diagonal_proj'
|
|
scores = ['max(diag5Hz)/med_diagonal_proj_fr','max(diag5Hz)/med_diagonal_proj_fr',
|
|
] # + '_diagonal_proj'
|
|
printing = False # print values for paper
|
|
max_xs = [[[],[],[]],[[],[],[]]]
|
|
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)
|
|
#embed()
|
|
test = False
|
|
# ok das schließe ich aus weil da irgendwas in der Detektion ist, das betrifft jetzt genau 3 Zellen, also nicht so schlimm
|
|
#63 2018-08-14-af-invivo-1
|
|
#241 2018-09-05-aj-invivo-1
|
|
#252 2022-01-08-ah-invivo-1
|
|
frame_file = frame_file[frame_file.cv_stim <5]
|
|
|
|
|
|
##############################################
|
|
# modulatoin comparison for both cell_types
|
|
################################
|
|
# Modulation, cell type comparison
|
|
|
|
|
|
x_axis = ['cv_base','cv_stim','response_modulation']#,'fr_base']#
|
|
var_item_names = [var_it,var_it,var_it2]#,var_it2]#['Response Modulation [Hz]',]
|
|
var_types = ['response_modulation','response_modulation','']#,'']#'response_modulation'
|
|
max_x = max_xs[c]
|
|
x_axis_names = ['CV$' + basename_small() +'$','CV$' + label_stimname_small() + '$', 'Response modulation [Hz]']#$'+basename()+'$,'Fr$'+basename()+'$',]
|
|
#score = scores[0]
|
|
score_n = ['Perc99/Med', 'Perc99/Med', 'Perc99/Med']
|
|
score = scores[c]
|
|
scores_here = [score,score,score]#,score]
|
|
score_name = ['max(diag5Hz)/med_diagonal_proj_fr','max(diag5Hz)/med_diagonal_proj_fr']#,'max(diag5Hz)/med_diagonal_proj_fr']#'Perc99/Med'
|
|
score_name = ['Fr/Med', 'Fr/Med']#'Fr/Med'] # 'Perc99/Med'
|
|
score_name = [label_NLI_scorename2_small(), label_NLI_scorename2_small(), label_NLI_scorename2_small()]#NLI_scorename()] # 'Fr/Med''Perc99/Med'
|
|
ax_j = []
|
|
axls = []
|
|
axss = []
|
|
#embed()
|
|
#frame_max = frame_file[frame_file[score]>5]
|
|
cv_name = "cv_base"
|
|
max_val = 1.5
|
|
log = ''#'logall'#''#'logy','logall'True#False
|
|
|
|
|
|
marker = ['o']
|
|
for v, var_type in enumerate(var_types):
|
|
# ax = plt.subplot(grid0[1+v])#grid_lower[0, v]
|
|
|
|
axx, axy, axs, axls, axss, ax_j = get_grid_4(ax_j, axls, axss, grid0[v,counter])
|
|
|
|
|
|
if log == 'logy':
|
|
ymin = 'no'
|
|
else:
|
|
ymin = 0
|
|
xmin = 0
|
|
|
|
xlimk = None
|
|
|
|
labelpad = 0.5#-1
|
|
cmap, _, y_axis = scatter_with_marginals_colorcoded(var_item_names[v], axs, cell_type_here, x_axis[v],
|
|
frame_file, scores_here[v], axy, axx, ymin=ymin,
|
|
xmin=xmin, burst_fraction_reset=burst_corr_reset,
|
|
var_item=var_type, labelpad=labelpad, max_x=max_x[v],
|
|
xlim=xlimk, x_pos=1, burst_fraction=burst_fraction[c],
|
|
ha='right')
|
|
|
|
if printing:
|
|
print(cell_type_here + ' median '+scores_here[v]+''+str(np.nanmedian(frame_file[scores_here[v]])))
|
|
print(cell_type_here + ' max ' + x_axis[v] + '' + str(np.nanmax(frame_file[x_axis[v]])))
|
|
|
|
if v == 0:
|
|
colors = colors_overview()
|
|
axx.set_title(cell_types_name[c], color = colors[cell_type_here])
|
|
|
|
axx.show_spines('')
|
|
axy.show_spines('')
|
|
axs.set_ylabel(score_name[v])
|
|
axs.set_xlabel(x_axis_names[v], labelpad = labelpad)
|
|
extra_lim = False
|
|
if extra_lim:
|
|
if (' P-unit' in cell_type_here) & ('cv' in x_axis[v]):
|
|
axs.set_xlim(xlimk)
|
|
axx.set_xlim(xlimk)
|
|
#embed()
|
|
#remove_yticks(axl)
|
|
|
|
if log == 'logy':
|
|
axy.set_yscale('log')
|
|
axs.set_yscale('log')
|
|
make_log_ticks([axs])
|
|
axy.minorticks_off()
|
|
elif log == 'logall':
|
|
axy.set_yscale('log')
|
|
axs.set_yscale('log')
|
|
make_log_ticks([axs])
|
|
axy.minorticks_off()
|
|
|
|
axx.set_xscale('log')
|
|
axs.set_xscale('log')
|
|
make_log_ticks([axs])
|
|
axx.minorticks_off()
|
|
axy.set_yticks_blank()
|
|
|
|
|
|
plt_specific_cells(axs, cell_type_here, x_axis[v], frame_file, scores_here[v], marker = ['o',"s"])
|
|
tags.append(axx)
|
|
#plt.show()
|
|
counter += 1
|
|
#plt.show()
|
|
|
|
|
|
if printing:
|
|
printing_values_data_overview(cell_types, frame_load_sp, scores, species, x_axis, y_axis)
|
|
|
|
show = False#True
|
|
fig = plt.gcf()
|
|
#embed()
|
|
tags_final = np.concatenate([tags[0::3],tags[1::3],tags[2::3]])#,tags[2::3]
|
|
fig.tag(tags_final, xoffs=-4.2, yoffs=1.12)
|
|
save_visualization(pdf = True, show = show)
|
|
|
|
|
|
def printing_values_data_overview(cell_types, frame_load_sp, scores, species, x_axis, y_axis):
|
|
############################
|
|
# 1 Print scores
|
|
print('\n')
|
|
speciess = [' Apteronotus leptorhynchus', ' Eigenmannia virescens']
|
|
# for species in speciess:
|
|
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)
|
|
print(cell_type_here + str(len(frame_file.cell.unique())))
|
|
# embed()
|
|
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_to_unify_invivo_nomenclature(cells_amp)
|
|
frame_amps = frame_file[frame_file.cell.isin(cells_amp)]
|
|
frame_amps.cell.unique()
|
|
#################################################################
|
|
# print the corrs
|
|
score = scores[c] # 'ser_base',
|
|
score_print = [score]
|
|
score_print = [scores[c], scores[c], scores[c], scores[c], scores[c],
|
|
'burst_fraction_burst_corr_individual_base']
|
|
corr_vars = ['cv_base', 'response_modulation', 'fr_base', 'ser_first_base',
|
|
'burst_fraction_burst_corr_individual_stim', 'cv_base']
|
|
# for score in score_print:
|
|
for c_nr, corr_var in enumerate(corr_vars): # ,'ser_sum_corr'
|
|
score = score_print[c_nr]
|
|
x = frame_file['fr_base']
|
|
y = frame_file['ser_first']
|
|
c = frame_file['cv_base']
|
|
|
|
c_axis, x_axis, y_axis, exclude_here = exclude_nans_for_corr(frame_file, corr_var, cv_name=corr_var,
|
|
score=score)
|
|
|
|
corr, p_value = stats.pearsonr(x_axis, y_axis)
|
|
pears_l = label_pearson(corr, p_value, y_axis, n=True)
|
|
print(start_name(cell_type_here, species) + ' ' + corr_var + ' to ' + str(score) + pears_l)
|
|
|
|
print('\n')
|
|
################################
|
|
# cv to fr correlation
|
|
c_axis, x_axis, y_axis, exclude_here = exclude_nans_for_corr(frame_file, 'fr_base', cv_name='fr_base',
|
|
score='cv_base')
|
|
corr, p_value = stats.pearsonr(x_axis, y_axis)
|
|
pears_l = label_pearson(corr, p_value, y_axis, n=True)
|
|
|
|
print(start_name(cell_type_here, species) + ' ' + 'fr_base' + ' to ' + 'cv_base' + pears_l)
|
|
|
|
################################
|
|
# cv to fr correlation
|
|
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='range', species=species)
|
|
c_axis, x_axis, y_axis, exclude_here = exclude_nans_for_corr(frame_file,
|
|
'burst_fraction_burst_corr_individual_base',
|
|
cv_name='burst_fraction_burst_corr_individual_base',
|
|
score='cv_base')
|
|
corr, p_value = stats.pearsonr(x_axis, y_axis)
|
|
pears_l = label_pearson(corr, p_value, y_axis, n=True)
|
|
print(start_name(cell_type_here,
|
|
species) + ' amprange: ' + 'burst_fraction_individual_base' + ' to ' + 'cv_base' + pears_l)
|
|
###############################
|
|
# fr to nonline but for both modulations
|
|
|
|
c_axis, x_axis, y_axis, exclude_here = exclude_nans_for_corr(frame_file, 'fr_base', cv_name='fr_base',
|
|
score=score)
|
|
corr, p_value = stats.pearsonr(x_axis, y_axis)
|
|
pears_l = label_pearson(corr, p_value, y_axis, n=True)
|
|
print(start_name(cell_type_here, species) + ' amprange: ' + ' ' + 'fr_base' + ' to score' + pears_l)
|
|
##################################
|
|
print('\n')
|
|
# embed()
|
|
# todo: hier noch die Werte für die Methodik printen
|
|
test = False
|
|
# embed()
|
|
|
|
if test:
|
|
plt.hist(frame_file['lim_individual'])
|
|
# print(frame_file['lim_individual'])
|
|
############################################
|
|
############################
|
|
# 2 Print names
|
|
# printe um welchen Zeitraum es sich handelt
|
|
frame_file = setting_overview_score(frame_load_sp, cell_type_here='', f_exclude=False, snippet=None, min_amp='min',
|
|
species='')
|
|
print('\n')
|
|
print('From ' + str(np.sort(frame_file.cell)[0]) + ' to ' + str(np.sort(frame_file.cell)[-1]) + ' nr ' + str(
|
|
len(frame_file.cell)))
|
|
# embed()
|
|
# embed()
|
|
#####################################################################
|
|
############################
|
|
# 3 Print , EODF
|
|
print('\n')
|
|
speciess = [' Apteronotus leptorhynchus', ' Eigenmannia virescens']
|
|
for species in speciess:
|
|
fish = []
|
|
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)
|
|
|
|
if len(frame_file) > 0:
|
|
# ja der fisch hatte halt eine ziemlich niedriege EODf
|
|
frame_here = frame_file[frame_file.cell != '2022-01-05-af-invivo-1']
|
|
|
|
print(start_name(cell_type_here,
|
|
species) + ' eodf_min ' + str(
|
|
int(np.round(np.nanmin(frame_here.eod_fr)))) + ' eodf_max ' + str(
|
|
int(np.round(np.nanmax(frame_here.eod_fr)))) + ' n ' + str(len(frame_here)))
|
|
|
|
my_list = np.unique(frame_here.cell)
|
|
new_list = [item[0:10] for item in my_list]
|
|
fish.extend(new_list)
|
|
|
|
print(species[0:7] + ' n_fish ' + str(len(np.unique(fish))))
|
|
#####################################################################
|
|
# Burst corr limits
|
|
print('\n')
|
|
for species in speciess:
|
|
fish = []
|
|
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)
|
|
|
|
lims = np.unique(frame_file['lim_individual'])
|
|
lims_name = ''
|
|
for lim in lims:
|
|
lims_name = lims_name + str(lim) + ': ' + str(np.sum(frame_file['lim_individual'] == lim)) + ','
|
|
print(start_name(cell_type_here, species) + ' ' + lims_name)
|
|
#####################################################################
|
|
############################
|
|
# 3 Print , EODF
|
|
# Amplituden
|
|
print('\n')
|
|
speciess = [' Apteronotus leptorhynchus', ' Eigenmannia virescens']
|
|
for species in speciess:
|
|
for c, cell_type_here in enumerate(cell_types):
|
|
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='', species=species)
|
|
|
|
if len(frame_file) > 0:
|
|
# embed()
|
|
print(start_name(cell_type_here, species) + ' amp_min ' + str(
|
|
np.nanmin(frame_file.amp)) + ' amp_max ' + str(
|
|
np.nanmax(frame_file[~np.isinf(frame_file.amp)].amp)))
|
|
############################
|
|
# CVs min max
|
|
for species in speciess:
|
|
for c, cell_type_here in enumerate(cell_types):
|
|
frame_file = setting_overview_score(frame_load_sp, cell_type_here, min_amp='', species=species)
|
|
|
|
if len(frame_file) > 0:
|
|
|
|
print(start_name(cell_type_here, species) + ' CV_min ' + str(
|
|
np.round(np.nanmin(frame_file.cv_base), 2)) + ' CV max ' + str(
|
|
np.round(np.nanmax(frame_file.cv_base), 2)) + ' FR max ' + str(
|
|
np.round(np.nanmin(frame_file.fr_base))) + ' FR max ' + str(
|
|
np.round(np.nanmax(frame_file.fr_base))))
|
|
|
|
############################################
|
|
#######
|
|
# N
|
|
print('\n N')
|
|
speciess = [' Apteronotus leptorhynchus', ' Eigenmannia virescens']
|
|
for species in speciess:
|
|
for c, cell_type_here in enumerate(cell_types):
|
|
##################
|
|
# printe wie viele Zellen es am Anfang gab
|
|
frame_file = setting_overview_score(frame_load_sp, cell_type_here, f_exclude=False, snippet=None,
|
|
min_amp='min', species=species)
|
|
print(start_name(cell_type_here, species) + ' nr ' + str(len(frame_file)))
|
|
|
|
|
|
############################################
|
|
# printe um welchen Zeitraum es sich handelt
|
|
frame_file = setting_overview_score(frame_load_sp, cell_type_here='', f_exclude=False, snippet=None, min_amp='min',
|
|
species='')
|
|
print('\n sampling' + str(frame_file.sampling.unique()))
|
|
print('P-units Fr: 50-450 Hz CV: 0.15 - 1.35')
|
|
print('Ampullary Fr: 80-200 Hz, CV: 0.08 - 0.22')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
data_overview3() |