Added multi-thresh simulation to "full" and "short" (currently running).

Added complete "rect-lp" analysis except figure.
Added multiple appendix figs.
Overhauled normalization options across all condense scripts.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
j-hartling
2026-04-24 16:50:14 +02:00
parent 1a586848e8
commit 5411a309f7
48 changed files with 1549 additions and 300 deletions

View File

@@ -7,16 +7,18 @@ from thunderhopper.modeltools import load_data
from thunderhopper.filtertools import find_kern_specs
from misc_functions import get_saturation
from color_functions import load_colors
from plot_functions import hide_axis, ylimits, xlabel, ylabel, title_subplot,\
plot_line, strip_zeros, time_bar, set_clip_box,\
from plot_functions import hide_axis, reorder_by_sd, ylimits, super_xlabel, ylabel, title_subplot,\
plot_line, strip_zeros, time_bar, assign_colors,\
letter_subplot, letter_subplots
from IPython import embed
def plot_snippets(axes, time, snippets, ymin=None, ymax=None, **kwargs):
ymin, ymax = ylimits(snippets, minval=ymin, maxval=ymax, pad=0.05)
handles = []
for i, ax in enumerate(axes):
plot_line(ax, time, snippets[:, ..., i], ymin=ymin, ymax=ymax, **kwargs)
return None
handles.append(plot_line(ax, time, snippets[:, ..., i],
ymin=ymin, ymax=ymax, **kwargs))
return handles
def plot_curves(ax, scales, measures, fill_kwargs={}, **kwargs):
if measures.ndim == 1:
@@ -73,8 +75,8 @@ save_path = '../figures/fig_invariance_full.pdf'
exclude_zero = True
# SUBSET SETTINGS:
types = np.array([1, -1, 2, -2, 3, -3, 4, -4])
sigmas = np.array([0.004, 0.008, 0.016, 0.032])
types = np.array([1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10])
sigmas = np.array([0.001, 0.002, 0.004, 0.008, 0.016, 0.032])
# types = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]
# sigmas = [0.001, 0.002, 0.004, 0.008, 0.016, 0.032]
kernels = np.array([
@@ -111,20 +113,20 @@ snip_grid_kwargs = dict(
ncols=None,
wspace=0.1,
hspace=0.4,
left=0.08,
right=0.95,
left=0.11,
right=0.98,
bottom=0.08,
top=0.95
)
big_grid_kwargs = dict(
nrows=1,
ncols=3,
wspace=0.2,
wspace=0.4,
hspace=0,
left=snip_grid_kwargs['left'],
right=0.96,
bottom=0.2,
top=0.95
right=snip_grid_kwargs['right'],
bottom=0.13,
top=0.98
)
# PLOT SETTINGS:
@@ -137,6 +139,8 @@ fs = dict(
bar=16,
)
colors = load_colors('../data/stage_colors.npz')
conv_colors = load_colors('../data/conv_colors_all.npz')
feat_colors = load_colors('../data/feat_colors_all.npz')
lw = dict(
filt=0.25,
env=0.25,
@@ -154,10 +158,10 @@ ylabels = dict(
filt='$x_{\\text{filt}}$',
env='$x_{\\text{env}}$',
log='$x_{\\text{db}}$',
inv='$x_{\\text{inv}}$',
inv='$x_{\\text{adapt}}$',
conv='$c_i$',
feat='$f_i$',
big=['intensity', 'rel. intensity', 'norm. intensity']
big=['measure', 'rel. measure', 'norm. measure']
)
xlab_big_kwargs = dict(
y=0,
@@ -173,7 +177,7 @@ ylab_snip_kwargs = dict(
va='center'
)
ylab_big_kwargs = dict(
x=-0.12,
x=-0.2,
fontsize=fs['lab_norm'],
ha='center',
va='bottom',
@@ -183,7 +187,7 @@ yloc = dict(
env=1000,
log=50,
inv=20,
conv=2,
conv=1,
feat=1,
)
title_kwargs = dict(
@@ -262,6 +266,8 @@ if any(var is not None for var in [kernels, types, sigmas]):
kern_inds = find_kern_specs(config['k_specs'], kernels, types, sigmas)
data = reduce_kernel_set(data, kern_inds, keyword='mean')
snip = reduce_kernel_set(snip, kern_inds, keyword='snip')
config['k_specs'] = config['k_specs'][kern_inds, :]
config['kernels'] = config['kernels'][:, kern_inds]
reduce_kernels = True
# Adjust grid parameters:
@@ -300,13 +306,13 @@ for i in range(big_grid.ncols):
ax.set_xlim(scales[0], scales[-1])
ax.set_xscale('symlog', linthresh=scales[1], linscale=0.5)
ax.set_yscale('symlog', linthresh=0.01, linscale=0.1)
xlabel(ax, xlabels['big'], transform=big_subfig, **xlab_big_kwargs)
ylabel(ax, ylabels['big'][i], **ylab_big_kwargs)
if i < (big_grid.ncols - 1):
ax.set_ylim(scales[0], scales[-1])
else:
ax.set_ylim(0, 1)
big_axes[i] = ax
super_xlabel(xlabels['big'], big_subfig, big_axes[0], big_axes[-1], **xlab_big_kwargs)
letter_subplots(big_axes, 'bcd', **letter_big_kwargs)
if True:
@@ -327,12 +333,18 @@ if True:
c=colors['inv'], lw=lw['inv'])
# Plot kernel response snippets:
plot_snippets(snip_axes[4, :], t_full, snip['snip_conv'],
c=colors['conv'], lw=lw['conv'])
all_handles = plot_snippets(snip_axes[4, :], t_full, snip['snip_conv'],
c=colors['conv'], lw=lw['conv'])
for i, handles in enumerate(all_handles):
assign_colors(handles, config['k_specs'][:, 0], conv_colors)
reorder_by_sd(handles, snip['snip_conv'][..., i])
# Plot feature snippets:
plot_snippets(snip_axes[5, :], t_full, snip['snip_feat'],
ymin=0, ymax=1, c=colors['feat'], lw=lw['feat'])
all_handles = plot_snippets(snip_axes[5, :], t_full, snip['snip_feat'],
ymin=0, ymax=1, c=colors['feat'], lw=lw['feat'])
for i, handles in enumerate(all_handles):
assign_colors(handles, config['k_specs'][:, 0], feat_colors)
reorder_by_sd(handles, snip['snip_feat'][..., i])
del snip
# Remember saturation points:
@@ -387,7 +399,7 @@ if exclude_zero:
data = exclude_zero_scale(data, stages)
if reduce_kernels:
data = reduce_kernel_set(data, kern_inds, keyword='mean')
for stage in stages:
for stage in ['log', 'inv', 'conv', 'feat']:
# Plot average intensity measure across recordings:
curve = plot_curves(big_axes[2], scales, data[f'mean_{stage}'].mean(axis=-1),
c=colors[stage], lw=lw['big'],