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,\
letter_subplot, letter_subplots
from plot_functions import hide_axis, ylimits, super_xlabel, ylabel, title_subplot,\
plot_line, strip_zeros, time_bar, assign_colors,\
letter_subplot, letter_subplots, reorder_by_sd
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:
@@ -62,7 +64,7 @@ example_file = {
'Omocestus_rufipes': 'Omocestus_rufipes_DJN_32-40s724ms-48s779ms',
'Pseudochorthippus_parallelus': 'Pseudochorthippus_parallelus_GBC_88-6s678ms-9s32.3ms'
}[target_species]
stages = ['filt', 'env', 'conv', 'feat']
stages = ['filt', 'env', 'inv', 'conv', 'feat']
raw_path = search_files(target_species, incl='unnormed', dir='../data/inv/short/condensed/')[0]
base_path = search_files(target_species, incl='base', dir='../data/inv/short/condensed/')[0]
range_path = search_files(target_species, incl='range', dir='../data/inv/short/condensed/')[0]
@@ -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,10 +139,13 @@ 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,
conv=0.25,
inv=0.25,
feat=1,
big=3,
plateau=1.5,
@@ -151,9 +156,10 @@ xlabels = dict(
ylabels = dict(
filt='$x_{\\text{filt}}$',
env='$x_{\\text{env}}$',
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,
@@ -169,7 +175,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',
@@ -177,6 +183,7 @@ ylab_big_kwargs = dict(
yloc = dict(
filt=3000,
env=1000,
inv=1000,
conv=30,
feat=1,
)
@@ -294,13 +301,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:
@@ -312,13 +319,23 @@ if True:
plot_snippets(snip_axes[1, :], t_full, snip['snip_env'],
ymin=0, c=colors['env'], lw=lw['env'])
# Plot "adapted" snippets:
plot_snippets(snip_axes[2, :], t_full, snip['snip_inv'],
c=colors['inv'], lw=lw['inv'])
# Plot kernel response snippets:
plot_snippets(snip_axes[2, :], t_full, snip['snip_conv'],
c=colors['conv'], lw=lw['conv'])
all_handles = plot_snippets(snip_axes[3, :], 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[3, :], t_full, snip['snip_feat'],
ymin=0, ymax=1, c=colors['feat'], lw=lw['feat'])
all_handles = plot_snippets(snip_axes[4, :], 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:
@@ -373,7 +390,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 ['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'],