updated final figure

This commit is contained in:
saschuta 2024-05-23 15:53:27 +02:00
parent c54959839b
commit f583969974
6 changed files with 10101 additions and 44 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

After

Width:  |  Height:  |  Size: 213 KiB

View File

@ -1,19 +1,24 @@
##from update_project import ** ##from update_project import **
import sys
import numpy as np import numpy as np
from IPython import embed
from matplotlib import gridspec, pyplot as plt from matplotlib import gridspec, pyplot as plt
from threefish.core_calc_fft import create_full_matrix2 from threefish.core_calc_fft import create_full_matrix2, get_transfer_from_timesignal
from threefish.core_reformat import chose_mat_max_value, get_axis_on_full_matrix, get_psds_ROC, get_transfer_from_model, \ from threefish.core_reformat import chose_mat_max_value, get_axis_on_full_matrix, get_psds_ROC, \
get_transfer_for_model_full, get_transfer_from_model, \
load_b_public, load_stack_data_susept load_b_public, load_stack_data_susept
from threefish.core_reformat_RAM import convert_csv_str_to_float from threefish.core_reformat_RAM import convert_csv_str_to_float
from threefish.core_plot_subplots import colors_suscept_paper_dots, plt_model_full_model2, plt_model_letters, \ from threefish.core_plot_subplots import colors_suscept_paper_dots, letters_for_full_model, plt_model_full_model2, \
plt_psds_ROC, plt_RAM_perc plt_model_letters, \
from threefish.core_load import save_visualization plt_psds_ROC, plt_RAM_perc, recalc_fr_to_DF1
from threefish.core_load import resave_small_files, save_visualization
from threefish.core_values import vals_model_full from threefish.core_values import vals_model_full
from threefish.core_cell_choice import find_all_dir_cells from threefish.core_cell_choice import find_all_dir_cells
from threefish.core_filenames import version_final from threefish.core_filenames import version_final
from threefish.core_plot_suscept import perc_model_full, plt_model_big from threefish.core_plot_suscept import perc_model_full, plt_model_big
from threefish.core import find_code_vs_not from threefish.core import find_code_vs_not, info
from plotstyle import plot_style from plotstyle import plot_style
import time import time
from threefish.defaults import default_diagonal_points, default_figsize from threefish.defaults import default_diagonal_points, default_figsize
@ -36,12 +41,13 @@ def model_full(c1=10, mult_type='_multsorted2_', devs=['05'], end='all', chose_s
plot_style() plot_style()
default_figsize(column=2, length=3.5)#2.7 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=1, top=0.92, left=0.06, right=0.98)#hspace=0.25, 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.92, left=0.06, right=0.98)#hspace=0.25,
axes = [] axes = []
a_size = 0.0065#und 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
@ -60,27 +66,76 @@ def model_full(c1=10, mult_type='_multsorted2_', devs=['05'], end='all', chose_s
#embed() #embed()
fr_waves = 139 fr_waves = 139
color01, color012, color01_2, color02, color0_burst, color0 = colors_suscept_paper_dots() color01, color012, color01_2, color02, color0_burst, color0 = colors_suscept_paper_dots()
DF1_frmult, DF2_frmult = vals_model_full(val=0.30833333333333335)
############################################# #############################################
# plot coherence # plot coherence
loaded_from_calc_RAM_model = False
if loaded_from_calc_RAM_model:
cross = get_transfer_from_model(stack_saved) cross = get_transfer_from_model(stack_saved)
axc = plt.subplot(grid[0, 1]) axc = plt.subplot(grid[0, 1])
axc.plot(stack_saved.index, cross, color = 'black') axc.plot(stack_saved.index, cross, color = 'black')
axc.set_xlabel('Frequency [Hz]') axc.set_xlabel('Frequency [Hz]')
axc.set_ylabel(xlabel_transfer_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_big_fit_d_right.csv",
load_folder='calc_model_core')
flowchart_cell = '2012-07-03-ak-invivo-1'
model_params = models[models['cell'] == flowchart_cell].iloc[0]
print('cell=' + str(flowchart_cell))
model_params = models[models['cell'] == flowchart_cell].iloc[0]
print('cell=' + str(flowchart_cell))
# amp_frame = pd.read_csv('peak_amplitudes_power.csv')
cell = 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,
var_type='additiv_cv_adapt_factor_scaled')
axc = plt.subplot(grid[0, 1])
f_same = frame.index
#embed()
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)
# data part #if c == 0:
axc.set_ylabel(r'$|\chi_1|^2$')
data_square_extra = False
if data_square_extra:
ax, cell, stack_final = plt_data_matrix(ax, axes, cell, grid, ls, lw, perc, stack_final)
################# #################
# power spectra data # power spectra data
log = ''#'log'#'log'#'log'#'log'#'log' log = 'log'#'log'#'log'#'log'#'log'#'log'
ylim_log = (-14.2, 3)#(-14.2, 3) ylim_log = (-14.2, 3)#(-14.2, 3)
nfft = 20000#2 ** 13 nfft = 20000#2 ** 13
xlim_psd = [0, 300] xlim_psd = [0, 300]
@ -93,18 +148,9 @@ def model_full(c1=10, mult_type='_multsorted2_', devs=['05'], end='all', chose_s
markers = ['s', 'o'] markers = ['s', 'o']
ms = 14 ms = 14
data_extra = False
if data_extra:
DF1_desired, DF1_frmult, DF2_desired, DF2_frmult, eod_fr, grid0 = 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)
else:
markers = ['o', 'o', 'o', 'o', ] markers = ['o', 'o', 'o', 'o', ]
DF1_frmult, DF2_frmult = vals_model_full(val = 0.30833333333333335)
#0.16666666666666666 #0.16666666666666666
grid0 = gridspec.GridSpecFromSubplotSpec(2, 2, wspace=0.15, hspace=0.4, grid0 = gridspec.GridSpecFromSubplotSpec(2, 2, wspace=0.15, hspace=0.4,
subplot_spec=grid[1,1]) subplot_spec=grid[1,1])
@ -122,31 +168,41 @@ def model_full(c1=10, mult_type='_multsorted2_', devs=['05'], end='all', chose_s
diagonal = 'diagonal1' diagonal = 'diagonal1'
diagonal = '' diagonal = ''
plus_q = 'plus' # 'minus'#'plus'##'minus' plus_q = 'plus' # 'minus'#'plus'##'minus'
length = 1#2*40 # 5 length = 100#2*40 # 5
reshuffled = '' # , reshuffled = '' # ,
array_len = 1
alphas = [1,0.5] alphas = [1,0.5]
#a_size = 0.0065#0.0125#25#0.04#0.015 #a_size = 0.0065#0.0125#25#0.04#0.015
a_size = 0.0065#und 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
# ATTENTION: Diese Zelle ('2012-07-03-ak-invivo-1') braucht längere Abschnitte, mindsetesn 5 Sekunden damit das Powerspectrum nicht so niosy ist! # ATTENTION: Diese Zelle ('2012-07-03-ak-invivo-1') braucht längere Abschnitte, mindsetesn 5 Sekunden damit das Powerspectrum nicht so niosy ist!
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, 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, stimulus_length=length, plus_q=plus_q, stack_saved = stack_saved,
diagonal=diagonal, runs=1, nfft = nfft, xlim_psd = xlim_psd, 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, cells=[cell], dev_spikes ='original', markers = markers, DF1_frmult = DF1_frmult, DF2_frmult = DF2_frmult,
log = log, ms = ms, 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' log = log, ms = ms, 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
if data_extra:
plt_data_peaks_letters(DF1_desired, DF2_desired, axm, color012, color01_2, eod_fr, fr_noise, fr_waves, markers)
else:
plt_model_letters(DF1_frmult, DF2_frmult, axm, color012, color01_2, fr_noise, markers) plt_model_letters(DF1_frmult, DF2_frmult, axm, color012, color01_2, fr_noise, markers)
# letters for the transfer function
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)))
axc.text(df1_recalc, np.mean(transfer[pos_df1-array_len:pos_df1+array_len]),
letters[f], color=color01, ha='center',
va='center', zorder = 100) # , alpha = alphas[f]
axc.text(df2_recalc, np.mean(transfer[pos_df2-array_len:pos_df2+array_len]),
letters[f], color=color02, ha='center',
va='center', zorder = 100) # , alpha = alphas[f]
fig = plt.gcf()#[axes[0], axes[3], axes[4]] fig = plt.gcf()#[axes[0], axes[3], axes[4]]
fig.tag([axes[0], axc, axes2[0], axes2[1], axes2[2], axes2[3]], xoffs=-4.5, yoffs=1.2) # ax_ams[3], fig.tag([axes[0], axc, axes2[0], axes2[1], axes2[2], axes2[3]], xoffs=-4.5, yoffs=1.2) # ax_ams[3],
#plt.show() #plt.show()
@ -550,4 +606,5 @@ def plt_data_full_model(c1, chose_score, detections, devs, dfs, end, grid, mult_
if __name__ == '__main__': if __name__ == '__main__':
#embed() #embed()
sys.excepthook = info
model_full() model_full()

View File

@ -597,7 +597,7 @@ We estimated the second-order susceptibility of P-unit responses using RAM stimu
\begin{figure*}[t] \begin{figure*}[t]
\includegraphics[width=\columnwidth]{model_full} \includegraphics[width=\columnwidth]{model_full}
\caption{\label{fig:model_full} Using second-order susceptibility to predict responses to sine-wave stimuli. \figitem[]{A} Absolute value of the second-order susceptibility, \Eqnref{eq:susceptibility}, for both positive and negative frequencies. \susceptf{} was estimated from $N=10^6$ trials of model simulations in the noise-split condition (cell 2012-07-03-ak, see table~\ref{modelparams} for model parameters). White lines indicate zero frequencies. Nonlinear responses at \fsum{} are quantified in the upper right and lower left quadrants. Nonlinear responses at \fdiff{} are quantified in the upper left and lower right quadrants. Baseline firing rate of this cell was at $\fbase=120$\,Hz. The position of the orange/red letters correspond to the beat frequencies used for the stimulation with pure sine-waves in the subsequent panels and indicate the sum/difference of those beat frequencies. \figitem[]{B} Absolute value of the first-order susceptibility. \figitem{C--F} Black line -- power spectral density of model simulations in response to stimulation with two pure sine waves, \fone{} and \ftwo, in addition to the receiving fish's own EOD (three fish scenario). The contrasts of beat beats is 0.0065. Colored circles highlight the height of selected peaks in the power spectrum. Black circles highlight the peak height that can be predicted from \panel{A, B}. Grey line -- power spectral density of model in the baseline condition. \figitem{B} The sum of the two beat frequencies match \fbase{}. \figitem{C} The difference of \fone{} and \ftwo{} match \fbase{}. \figitem{D} Only the first beat frequency matches \fbase{}. \figitem{C} None of the two beat frequencies matches \fbase{}.} \caption{\label{fig:model_full} Using second-order susceptibility to predict responses to sine-wave stimuli. \figitem[]{A} Absolute value of the second-order susceptibility, \Eqnref{eq:susceptibility}, for both positive and negative frequencies. \susceptf{} was estimated from $N=10^6$ trials of model simulations in the noise-split condition (cell 2012-07-03-ak, see table~\ref{modelparams} for model parameters). White lines indicate zero frequencies. Nonlinear responses at \fsum{} are quantified in the upper right and lower left quadrants. Nonlinear responses at \fdiff{} are quantified in the upper left and lower right quadrants. Baseline firing rate of this cell was at $\fbase=120$\,Hz. The position of the orange/red letters correspond to the beat frequencies used for the stimulation with pure sine-waves in the subsequent panels and indicate the sum/difference of those beat frequencies. \figitem[]{B} Absolute value of the first-order susceptibility. \figitem{C--F} Black line -- power spectral density of model simulations in response to stimulation with two pure sine waves, \fone{} and \ftwo, in addition to the receiving fish's own EOD (three fish scenario). The contrasts of beat beats is 0.0065. Colored circles highlight the height of selected peaks in the power spectrum. Black circles highlight the peak height that can be predicted from \panel{A, B}. Grey line -- power spectral density of model in the baseline condition. \figitem{B} The sum of the two beat frequencies match \fbase{}. \figitem{C} The difference of \fone{} and \ftwo{} match \fbase{}. \figitem{D} Only the first beat frequency matches \fbase{}. \figitem{C} None of the two beat frequencies matches \fbase{}. \noteab{Für die Transfer Funktion habe ich jetzt einen Faktor 1, für die Nichtlinearität einen Faktor 30, aber vielleicht wenn ich über mehrere Punkte mitteln muss und das alles so noisy ist das eben noch keine Gute Abschätzung in der Stauration?}}
\end{figure*} \end{figure*}
However, the second-order susceptibility \Eqnref{eq:susceptibility} is a spectral measure that is based on Fourier transforms and thus is also defined for negative stimulus frequencies. The full \susceptf{} matrix is symmetric with respect to the origin. In the upper-right and lower-left quadrants of \susceptf{}, stimulus-evoked responses at \fsum{} are shown, whereas in the lower-right and upper-left quadrants nonlinear responses at the difference \fdiff{} are shown (\figref{fig:model_full}). The vertical and horizontal lines at \foneb{} and \ftwob{} are very pronounced in the upper-right quadrant of \subfigrefb{fig:model_full}{A} for nonlinear responses at \fsum{} and extend into the upper-left quadrant (representing \fdiff) where they fade out towards more negative $f_1$ frequencies. The peak in the response power-spectrum at \fdiff{} evoked by pure sine-wave stimulation (\subfigrefb{fig:motivation}{D}) is predicted by the horizontal line in the upper-left quadrant (\subfigrefb{fig:model_full}{A}, \cite{Schlungbaum2023}). However, the second-order susceptibility \Eqnref{eq:susceptibility} is a spectral measure that is based on Fourier transforms and thus is also defined for negative stimulus frequencies. The full \susceptf{} matrix is symmetric with respect to the origin. In the upper-right and lower-left quadrants of \susceptf{}, stimulus-evoked responses at \fsum{} are shown, whereas in the lower-right and upper-left quadrants nonlinear responses at the difference \fdiff{} are shown (\figref{fig:model_full}). The vertical and horizontal lines at \foneb{} and \ftwob{} are very pronounced in the upper-right quadrant of \subfigrefb{fig:model_full}{A} for nonlinear responses at \fsum{} and extend into the upper-left quadrant (representing \fdiff) where they fade out towards more negative $f_1$ frequencies. The peak in the response power-spectrum at \fdiff{} evoked by pure sine-wave stimulation (\subfigrefb{fig:motivation}{D}) is predicted by the horizontal line in the upper-left quadrant (\subfigrefb{fig:model_full}{A}, \cite{Schlungbaum2023}).

View File

@ -597,7 +597,7 @@ We estimated the second-order susceptibility of P-unit responses using RAM stimu
\begin{figure*}[t] \begin{figure*}[t]
\includegraphics[width=\columnwidth]{model_full} \includegraphics[width=\columnwidth]{model_full}
\caption{\label{fig:model_full} Using second-order susceptibility to predict responses to sine-wave stimuli. \figitem[]{A} Absolute value of the second-order susceptibility, \Eqnref{eq:susceptibility}, for both positive and negative frequencies. \susceptf{} was estimated from $N=10^6$ trials of model simulations in the noise-split condition (cell 2012-07-03-ak, see table~\ref{modelparams} for model parameters). White lines indicate zero frequencies. Nonlinear responses at \fsum{} are quantified in the upper right and lower left quadrants. Nonlinear responses at \fdiff{} are quantified in the upper left and lower right quadrants. Baseline firing rate of this cell was at $\fbase=120$\,Hz. The position of the orange/red letters correspond to the beat frequencies used for the stimulation with pure sine-waves in the subsequent panels and indicate the sum/difference of those beat frequencies. \figitem[]{B} Absolute value of the first-order susceptibility. \figitem{C--F} Black line -- power spectral density of model simulations in response to stimulation with two pure sine waves, \fone{} and \ftwo, in addition to the receiving fish's own EOD (three fish scenario). The contrasts of beat beats is 0.0065. Colored circles highlight the height of selected peaks in the power spectrum. Black circles highlight the peak height that can be predicted from \panel{A, B}. Grey line -- power spectral density of model in the baseline condition. \figitem{B} The sum of the two beat frequencies match \fbase{}. \figitem{C} The difference of \fone{} and \ftwo{} match \fbase{}. \figitem{D} Only the first beat frequency matches \fbase{}. \figitem{C} None of the two beat frequencies matches \fbase{}.} \caption{\label{fig:model_full} Using second-order susceptibility to predict responses to sine-wave stimuli. \figitem[]{A} Absolute value of the second-order susceptibility, \Eqnref{eq:susceptibility}, for both positive and negative frequencies. \susceptf{} was estimated from $N=10^6$ trials of model simulations in the noise-split condition (cell 2012-07-03-ak, see table~\ref{modelparams} for model parameters). White lines indicate zero frequencies. Nonlinear responses at \fsum{} are quantified in the upper right and lower left quadrants. Nonlinear responses at \fdiff{} are quantified in the upper left and lower right quadrants. Baseline firing rate of this cell was at $\fbase=120$\,Hz. The position of the orange/red letters correspond to the beat frequencies used for the stimulation with pure sine-waves in the subsequent panels and indicate the sum/difference of those beat frequencies. \figitem[]{B} Absolute value of the first-order susceptibility. \figitem{C--F} Black line -- power spectral density of model simulations in response to stimulation with two pure sine waves, \fone{} and \ftwo, in addition to the receiving fish's own EOD (three fish scenario). The contrasts of beat beats is 0.0065. Colored circles highlight the height of selected peaks in the power spectrum. Black circles highlight the peak height that can be predicted from \panel{A, B}. Grey line -- power spectral density of model in the baseline condition. \figitem{B} The sum of the two beat frequencies match \fbase{}. \figitem{C} The difference of \fone{} and \ftwo{} match \fbase{}. \figitem{D} Only the first beat frequency matches \fbase{}. \figitem{C} None of the two beat frequencies matches \fbase{}. \noteab{Für die Transfer Funktion habe ich jetzt einen Faktor 1, für die Nichtlinearität einen Faktor 30, aber vielleicht wenn ich über mehrere Punkte mitteln muss und das alles so noisy ist das eben noch keine Gute Abschätzung in der Stauration?}}
\end{figure*} \end{figure*}
However, the second-order susceptibility \Eqnref{eq:susceptibility} is a spectral measure that is based on Fourier transforms and thus is also defined for negative stimulus frequencies. The full \susceptf{} matrix is symmetric with respect to the origin. In the upper-right and lower-left quadrants of \susceptf{}, stimulus-evoked responses at \fsum{} are shown, whereas in the lower-right and upper-left quadrants nonlinear responses at the difference \fdiff{} are shown (\figref{fig:model_full}). The vertical and horizontal lines at \foneb{} and \ftwob{} are very pronounced in the upper-right quadrant of \subfigrefb{fig:model_full}{A} for nonlinear responses at \fsum{} and extend into the upper-left quadrant (representing \fdiff) where they fade out towards more negative $f_1$ frequencies. The peak in the response power-spectrum at \fdiff{} evoked by pure sine-wave stimulation (\subfigrefb{fig:motivation}{D}) is predicted by the horizontal line in the upper-left quadrant (\subfigrefb{fig:model_full}{A}, \cite{Schlungbaum2023}). However, the second-order susceptibility \Eqnref{eq:susceptibility} is a spectral measure that is based on Fourier transforms and thus is also defined for negative stimulus frequencies. The full \susceptf{} matrix is symmetric with respect to the origin. In the upper-right and lower-left quadrants of \susceptf{}, stimulus-evoked responses at \fsum{} are shown, whereas in the lower-right and upper-left quadrants nonlinear responses at the difference \fdiff{} are shown (\figref{fig:model_full}). The vertical and horizontal lines at \foneb{} and \ftwob{} are very pronounced in the upper-right quadrant of \subfigrefb{fig:model_full}{A} for nonlinear responses at \fsum{} and extend into the upper-left quadrant (representing \fdiff) where they fade out towards more negative $f_1$ frequencies. The peak in the response power-spectrum at \fdiff{} evoked by pure sine-wave stimulation (\subfigrefb{fig:motivation}{D}) is predicted by the horizontal line in the upper-left quadrant (\subfigrefb{fig:model_full}{A}, \cite{Schlungbaum2023}).