267 lines
10 KiB
Python
267 lines
10 KiB
Python
import os
|
|
|
|
import numpy as np
|
|
import pandas as pd
|
|
from IPython import embed
|
|
from matplotlib import pyplot as plt
|
|
from plotstyle import plot_style
|
|
from threefish.RAM.plot_labels import title_find_cell_add
|
|
from threefish.defaults import default_figsize, default_settings
|
|
from threefish.RAM.values import overlap_cells
|
|
from threefish.load import resave_small_files, save_visualization
|
|
from threefish.RAM.reformat_matrix import get_stack, load_model_susept
|
|
from threefish.core import find_folder_name
|
|
from threefish.RAM.calc_model import trial_nrs_ram_model
|
|
|
|
|
|
##from update_project import *
|
|
|
|
|
|
def table_printen(table):
|
|
print(table.keys())
|
|
for l in range(len(table)):
|
|
list_here = np.array(table.iloc[l])
|
|
l1 = "& ".join(list_here)
|
|
print(l1)
|
|
|
|
|
|
def trialnr(nffts=['whole'], powers=[1], contrasts=[0], noises_added=[''], D_extraction_method=['additiv_cv_adapt_factor_scaled'],
|
|
internal_noise=['RAM'], external_noise=['RAM'], level_extraction=[''], receiver_contrast=[1],
|
|
dendrids=[''], ref_types=[''], adapt_types=[''], c_noises=[0.1], c_signal=[0.9], cut_offs1=[300]): # ['eRAM']
|
|
# plot_style()#['_RAMscaled']'_RAMscaled'
|
|
|
|
duration_noise = '_short',
|
|
formula = 'code' ##'formula'
|
|
# ,int(2 ** 16) int(2 ** 16), int(2 ** 15),
|
|
stimulus_length = 1 # 20#550 # 30 # 15#45#0.5#1.5 15 45 100
|
|
trials_nrs = [1] # [100, 500, 1000, 3000, 10000, 100000, 1000000] # 500
|
|
stimulus_type = '_StimulusOrig_' # ,#
|
|
# ,3]#, 3, 1, 1.5, 0.5, ] # ,1,1.5, 0.5] #[1,1.5, 0.5] # 1.5,0.5]3, 1,
|
|
variant = 'sinz'
|
|
mimick = 'no'
|
|
cell_recording_save_name = ''
|
|
trans = 1 # 5
|
|
rep = 1000000 # 500000#0
|
|
repeats = [20, rep] # 250000
|
|
aa = 0
|
|
good_data, remaining = overlap_cells()
|
|
cells_all = [good_data[0]]
|
|
|
|
plot_style()
|
|
default_figsize(column=2, length=3.1) #.254.75 0.75
|
|
#grid = gridspec.GridSpec(1, 1, wspace=0.95, bottom=0.09,
|
|
# hspace=0.25, width_ratios = [1,0,1,1,1], left=0.09, right=0.93, top=0.9)
|
|
|
|
a = 0
|
|
maxs = []
|
|
mins = []
|
|
mats = []
|
|
ims = []
|
|
perc05 = []
|
|
perc95 = []
|
|
iternames = [D_extraction_method, external_noise,
|
|
internal_noise, powers, nffts, dendrids, cut_offs1, trials_nrs, c_signal,
|
|
c_noises,
|
|
ref_types, adapt_types, noises_added, level_extraction, receiver_contrast, contrasts, ]
|
|
|
|
nr = '2'
|
|
|
|
# cell_contrasts = ["2013-01-08-aa-invivo-1"]
|
|
# cells_triangl_contrast = np.concatenate([cells_all,cell_contrasts])
|
|
# cells_triangl_contrast = 1
|
|
# cell_contrasts = 1
|
|
|
|
rows = len(cells_all) # len(good_data)+len(cell_contrasts)
|
|
perc = 'perc'
|
|
lp = 2
|
|
label_model = r'Nonlinearity $\frac{1}{S}$'
|
|
|
|
fig = plt.figure()
|
|
|
|
hs = 0.45
|
|
|
|
|
|
##################################
|
|
# model part
|
|
|
|
trial_nr = 500000
|
|
|
|
|
|
cell = '2013-01-08-aa-invivo-1'
|
|
#cell = '2012-07-03-ak-invivo-1'
|
|
#print('cell'+str(cell))
|
|
cells_given = [cell]
|
|
save_name_rev = find_folder_name(
|
|
'calc_model') + '/' + '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_' + str(
|
|
trial_nr) + '_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV_revQuadrant_'
|
|
# for trial in trials:#.009
|
|
trial_nr = 1000000#1000000
|
|
trial_nrs_here = trial_nrs_ram_model()
|
|
|
|
|
|
|
|
# '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_5000000_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV'
|
|
# 'calc_RAM_model-2__nfft_whole_power_1_afe_0.009_RAM_RAM_additiv_cv_adapt_factor_scaled_cNoise_0.1_cSig_0.9_cutoff1_300_cutoff2_300no_sinz_length1_TrialsStim_11_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV',
|
|
# 'calc_RAM_model-2__nfft_whole_power_1_afe_0.009_RAM_RAM_additiv_cv_adapt_factor_scaled_cNoise_0.1_cSig_0.9_cutoff1_300_cutoff2_300no_sinz_length1_TrialsStim_500000_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV',
|
|
|
|
fig, ax = plt.subplots(1, 1)
|
|
ax = [ax]
|
|
alphas = [0.5]#, 1, 1]
|
|
colors = ['black']#, 'black','red']
|
|
for s in range(len(colors)):
|
|
stacks = []
|
|
perc95 = []
|
|
perc90 = []
|
|
vars = []
|
|
cv_stims = []
|
|
fr_stims = []
|
|
perc05 = []
|
|
median = []
|
|
stacks_wo_norm = []
|
|
perc95_wo_norm = []
|
|
perc05_wo_norm = []
|
|
median_wo_norm = []
|
|
counter = []
|
|
for tr in trial_nrs_here:
|
|
save_names = [
|
|
'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','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_' + str(
|
|
tr) + '_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV',
|
|
'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_names = ['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_'+str(tr) + '_a_fr_1__trans1s__TrialsNr_1_fft_o_forward_fft_i_forward_Hz_mV']
|
|
nrs_s = [3, 4, 8, 9]#, 10, 11
|
|
save_name = save_names[s]
|
|
tr_name = trial_nr/1000000
|
|
if tr_name == 1:
|
|
|
|
|
|
save_name = find_folder_name('calc_model') + '/' + save_name
|
|
|
|
cell_add, cells_save = title_find_cell_add(cells_given)
|
|
perc = 'perc'
|
|
|
|
path = save_name + '.pkl' # '../'+
|
|
|
|
#embed()
|
|
stack = load_model_susept(path, cells_save, save_name.split(r'/')[-1] + cell_add)
|
|
|
|
if len(stack)> 0:
|
|
model_show, stack_plot, stack_plot_wo_norm = get_stack(cell, stack)
|
|
stacks.append(stack_plot)
|
|
if 'counter_validate' in stack.keys():
|
|
counter.append(stack['counter_validate'].iloc[0])
|
|
else:
|
|
counter.append(float('nan'))
|
|
cv_stims.append(stack['cv_stim_mean'].iloc[0])
|
|
fr_stims.append(stack['fr_stim_mean'].iloc[0])
|
|
vars.append(stack['var_RAM'].iloc[0])
|
|
|
|
perc95.append(np.percentile(stack_plot,99.9))#99.99
|
|
perc90.append(np.percentile(stack_plot, 90))
|
|
perc05.append(np.percentile(stack_plot, 10))
|
|
median.append(np.percentile(stack_plot, 50))
|
|
stacks_wo_norm.append(stack_plot_wo_norm)
|
|
perc95_wo_norm.append(np.percentile(stack_plot_wo_norm,99.99))
|
|
perc05_wo_norm.append(np.percentile(stack_plot_wo_norm, 10))
|
|
median_wo_norm.append(np.percentile(stack_plot_wo_norm, 50))
|
|
|
|
else:
|
|
vars.append(float('nan'))
|
|
cv_stims.append(float('nan'))
|
|
fr_stims.append(float('nan'))
|
|
stacks.append([])
|
|
perc95.append(float('nan'))
|
|
perc90.append(float('nan'))
|
|
perc05.append(float('nan'))
|
|
median.append(float('nan'))
|
|
|
|
stacks_wo_norm.append([])
|
|
perc95_wo_norm.append(float('nan'))
|
|
perc05_wo_norm.append(float('nan'))
|
|
median_wo_norm.append(float('nan'))
|
|
counter.append(float('nan'))
|
|
|
|
#if s == 0:
|
|
|
|
ax[0].plot(trial_nrs_here, perc95, color = colors[s], clip_on = False, label = '99.99th percentile', alpha = alphas[s])
|
|
ax[0].scatter(trial_nrs_here, perc95, color = colors[s], clip_on = False, alpha = alphas[s])
|
|
#embed()
|
|
ax[0].set_xscale('log')#colors[s]
|
|
ax[0].set_yscale('log')
|
|
ax[0].set_xlabel('Trials [$N$]')
|
|
ax[0].set_ylabel('$\chi_{2}$\,[Hz]')
|
|
|
|
|
|
############################################
|
|
if s == 0:
|
|
ax[0].plot(trial_nrs_here, perc05, color='lightgrey', clip_on=False, label = '10th percentile', alpha = alphas[s])
|
|
ax[0].scatter(trial_nrs_here, perc05, color='lightgrey', clip_on=False, alpha = alphas[s])
|
|
ax[0].plot(trial_nrs_here, perc90, color='grey', clip_on=False, label='90th percentile', alpha = alphas[s])
|
|
ax[0].scatter(trial_nrs_here, perc90, color='grey', clip_on=False, alpha = alphas[s])
|
|
ax[0].legend()
|
|
|
|
|
|
#ax[1].plot(trial_nrs_here,cv_stims/ trial_nrs_here, color = colors[s])
|
|
#embed()
|
|
|
|
plt.subplots_adjust(left = 0.1, right = 0.9, bottom = 0.2, top = 0.95)
|
|
|
|
save_visualization(pdf=True)
|
|
|
|
|
|
def start_pos_modeldata():
|
|
return 1.03
|
|
|
|
|
|
def signal_component_name():
|
|
return r'$\xi_{signal}$'#signal noise'
|
|
|
|
|
|
def noise_component_name():#$\xi_{noise}$noise_name =
|
|
return r'$\xi_{noise}$'#'Noise component'#'intrinsic noise'
|
|
|
|
|
|
def ypos_x_modelanddata():
|
|
return -0.45
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
model = resave_small_files("models_big_fit_d_right.csv", load_folder='calc_model_core')
|
|
cells = model.cell.unique()
|
|
|
|
params = {'cells': cells}
|
|
|
|
show = True
|
|
# if show == False:
|
|
|
|
# low CV: cells = ['2012-07-03-ak-invivo-1']
|
|
plot_style()
|
|
default_settings(lw=0.5, column=2, length=3.35) #8.5
|
|
redo = False
|
|
D_extraction_method = ['additiv_cv_adapt_factor_scaled']
|
|
# D_extraction_method = ['additiv_visual_d_4_scaled']
|
|
|
|
##########################
|
|
# hier printen wir die table Werte zum kopieren in den Text
|
|
path = 'print_table_suscept-model_params_suscept_table.csv'
|
|
if os.path.exists(path):
|
|
table = pd.read_csv(path)
|
|
table_printen(table)
|
|
|
|
path = 'print_table_all-model_params_suscept_table.csv'
|
|
if os.path.exists(path):
|
|
table = pd.read_csv()
|
|
print('model big')
|
|
table_printen(table)
|
|
#embed()
|
|
|
|
##########################
|
|
#embed()
|
|
trialnr(D_extraction_method=D_extraction_method) #r'$\frac{1}{mV^2S}$'
|
|
|
|
|