Finished (:D) fig_invariance_log_hp.pdf.
Added movable label string to time_bar().
This commit is contained in:
@@ -17,7 +17,7 @@ fig_kwargs = dict(
|
||||
gridspec_kw=dict(
|
||||
wspace=0,
|
||||
hspace=0.1,
|
||||
left=0.065,
|
||||
left=0.09,
|
||||
right=0.98,
|
||||
bottom=0.08,
|
||||
top=0.95,
|
||||
@@ -92,7 +92,7 @@ fig.suptitle(**title_kwargs)
|
||||
ax1.grid(**grid_line_kwargs)
|
||||
ax1.set_xlim(data['scales'][0], data['scales'][-1])
|
||||
ax1.set_xscale('symlog', linthresh=data['scales'][1], linscale=0.5)
|
||||
ax1.set_ylim(0.4, 1.2)
|
||||
ax1.set_ylim(0, 0.1)
|
||||
ylabel(ax1, ylabels['top'], transform=fig.transFigure, **ylab_kwargs)
|
||||
ax2.grid(**grid_line_kwargs)
|
||||
xlabel(ax2, xlabels['bottom'], transform=fig.transFigure, **xlab_kwargs)
|
||||
|
||||
@@ -70,6 +70,14 @@ big_grid_kwargs = dict(
|
||||
)
|
||||
|
||||
# PLOT SETTINGS:
|
||||
fs = dict(
|
||||
lab_norm=16,
|
||||
lab_tex=20,
|
||||
letter=22,
|
||||
tit_norm=16,
|
||||
tit_tex=20,
|
||||
bar=16,
|
||||
)
|
||||
colors = load_colors('../data/stage_colors.npz')
|
||||
colors['raw'] = "#000000"
|
||||
lw = dict(
|
||||
@@ -100,26 +108,26 @@ ylabels = dict(
|
||||
)
|
||||
xlab_snip_kwargs = dict(
|
||||
y=0,
|
||||
fontsize=16,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='center',
|
||||
va='bottom',
|
||||
)
|
||||
xlab_big_kwargs = dict(
|
||||
y=0,
|
||||
fontsize=16,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='center',
|
||||
va='bottom',
|
||||
)
|
||||
ylab_snip_kwargs = dict(
|
||||
x=0,
|
||||
fontsize=20,
|
||||
fontsize=fs['lab_tex'],
|
||||
rotation=0,
|
||||
ha='left',
|
||||
va='center'
|
||||
)
|
||||
ylab_big_kwargs = dict(
|
||||
x=0,
|
||||
fontsize=16,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='center',
|
||||
va='top',
|
||||
)
|
||||
@@ -137,14 +145,14 @@ title_kwargs = dict(
|
||||
yref=1,
|
||||
ha='center',
|
||||
va='top',
|
||||
fontsize=16,
|
||||
fontsize=fs['tit_norm'],
|
||||
)
|
||||
letter_snip_kwargs = dict(
|
||||
x=0.02,
|
||||
y=1,
|
||||
ha='left',
|
||||
va='top',
|
||||
fontsize=22,
|
||||
fontsize=fs['letter'],
|
||||
fontweight='bold'
|
||||
)
|
||||
letter_big_kwargs = dict(
|
||||
@@ -152,15 +160,25 @@ letter_big_kwargs = dict(
|
||||
y=1,
|
||||
ha='left',
|
||||
va='top',
|
||||
fontsize=22,
|
||||
fontsize=fs['letter'],
|
||||
fontweight='bold'
|
||||
)
|
||||
bar_time = 5
|
||||
bar_kwargs = dict(
|
||||
y0=0.8,
|
||||
y1=0.9,
|
||||
dur=bar_time,
|
||||
y0=-0.25,
|
||||
y1=-0.1,
|
||||
xshift=1,
|
||||
color='k',
|
||||
lw=0,
|
||||
clip_on=False,
|
||||
text_pos=(-0.1, 0.5),
|
||||
text_str=f'${bar_time}\\,\\text{{s}}$',
|
||||
text_kwargs=dict(
|
||||
fontsize=fs['bar'],
|
||||
ha='right',
|
||||
va='center',
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -197,8 +215,7 @@ for data_path in data_paths:
|
||||
if stages[i] != 'bi':
|
||||
ax.yaxis.set_major_locator(plt.MultipleLocator(yloc[stages[i]]))
|
||||
snip_axes[i, j] = ax
|
||||
super_xlabel(xlabels['snip'], snip_subfig, snip_axes[-1, 0], snip_axes[-1, -1], **xlab_snip_kwargs)
|
||||
time_bar(snip_axes[0, 0], bar_time, **bar_kwargs)
|
||||
time_bar(snip_axes[-1, -1], **bar_kwargs)
|
||||
|
||||
# Prepare single analysis axis:
|
||||
big_subfig = fig.add_subfigure(super_grid[subfig_specs['big']])
|
||||
|
||||
@@ -7,7 +7,7 @@ from thunderhopper.modeltools import load_data
|
||||
from color_functions import load_colors
|
||||
from plot_functions import hide_axis, ylimits, xlabel, ylabel, hide_ticks,\
|
||||
plot_line, strip_zeros, time_bar, zoom_inset,\
|
||||
letter_subplot, letter_subplots, title_subplot
|
||||
letter_subplot, title_subplot
|
||||
from IPython import embed
|
||||
|
||||
def add_snip_axes(fig, grid_kwargs):
|
||||
@@ -28,7 +28,6 @@ def plot_snippets(axes, time, snippets, ymin=None, ymax=None, **kwargs):
|
||||
|
||||
|
||||
# GENERAL SETTINGS:
|
||||
compute_ratios = True
|
||||
target = 'Omocestus_rufipes'
|
||||
data_paths = search_files(target, excl='noise', dir='../data/inv/log_hp/')
|
||||
stages = ['env', 'log', 'inv']
|
||||
@@ -37,10 +36,14 @@ load_kwargs = dict(
|
||||
keywords=['scales', 'snip', 'measure']
|
||||
)
|
||||
save_path = '../figures/fig_invariance_log_hp.pdf'
|
||||
compute_ratios = True
|
||||
show_diag = True
|
||||
show_noise = True
|
||||
if compute_ratios:
|
||||
ref_data = load_data('../data/processed/white_noise_sd-1.npz', files=stages)[0]
|
||||
ref_measures = {k: v.std() for k, v in ref_data.items() if not k.endswith('rate')}
|
||||
|
||||
|
||||
# GRAPH SETTINGS:
|
||||
fig_kwargs = dict(
|
||||
figsize=(32/2.54, 16/2.54),
|
||||
@@ -60,22 +63,35 @@ subfig_specs = dict(
|
||||
noise=(1, slice(0, -1)),
|
||||
big=(slice(None), -1),
|
||||
)
|
||||
snip_grid_kwargs = dict(
|
||||
block_height = 0.8
|
||||
edge_padding = 0.08
|
||||
pure_grid_kwargs = dict(
|
||||
nrows=len(stages),
|
||||
ncols=None,
|
||||
wspace=0.1,
|
||||
hspace=0.15,
|
||||
left=0.16,
|
||||
right=0.95,
|
||||
bottom=0.1,
|
||||
top=0.94,
|
||||
bottom=1 - block_height - edge_padding,
|
||||
top=1 - edge_padding,
|
||||
height_ratios=[1, 2, 1]
|
||||
)
|
||||
noise_grid_kwargs = dict(
|
||||
nrows=len(stages),
|
||||
ncols=None,
|
||||
wspace=0.1,
|
||||
hspace=0.15,
|
||||
left=0.16,
|
||||
right=0.95,
|
||||
bottom=edge_padding,
|
||||
top=edge_padding + block_height,
|
||||
height_ratios=[1, 2, 1]
|
||||
)
|
||||
big_grid_kwargs = dict(
|
||||
nrows=2,
|
||||
ncols=1,
|
||||
wspace=0,
|
||||
hspace=0.1,
|
||||
hspace=0.3,
|
||||
left=0.19,
|
||||
right=0.96,
|
||||
bottom=0.09,
|
||||
@@ -94,9 +110,10 @@ fs = dict(
|
||||
letter=22,
|
||||
tit_norm=16,
|
||||
tit_tex=20,
|
||||
bar=16,
|
||||
)
|
||||
colors = load_colors('../data/stage_colors.npz')
|
||||
lw_snippets = 0.5
|
||||
lw_snippets = 1
|
||||
lw_big = 3
|
||||
xlabels = dict(
|
||||
big='scale $\\alpha$',
|
||||
@@ -105,7 +122,7 @@ ylabels = dict(
|
||||
env='$x_{\\text{env}}$',
|
||||
log='$x_{\\text{dB}}$',
|
||||
inv='$x_{\\text{adapt}}$',
|
||||
big='$\\sigma_{\\alpha}\\,/\\,\\sigma_{0}$',
|
||||
big='$\\sigma_{\\alpha}\\,/\\,\\sigma_{\\eta}$',
|
||||
)
|
||||
xlab_big_kwargs = dict(
|
||||
y=0,
|
||||
@@ -121,7 +138,7 @@ ylab_snip_kwargs = dict(
|
||||
va='center',
|
||||
)
|
||||
ylab_big_kwargs = dict(
|
||||
x=0,
|
||||
x=0.05,
|
||||
fontsize=fs['lab_tex'],
|
||||
ha='center',
|
||||
va='top',
|
||||
@@ -133,23 +150,23 @@ yloc = dict(
|
||||
)
|
||||
title_kwargs = dict(
|
||||
x=0.5,
|
||||
yref=1,
|
||||
y=1,
|
||||
ha='center',
|
||||
va='top',
|
||||
va='bottom',
|
||||
fontsize=fs['tit_norm'],
|
||||
)
|
||||
letter_snip_kwargs = dict(
|
||||
x=0,
|
||||
y=1,
|
||||
yref=0.5,
|
||||
ha='left',
|
||||
va='top',
|
||||
va='center',
|
||||
fontsize=fs['letter'],
|
||||
)
|
||||
letter_big_kwargs = dict(
|
||||
x=0,
|
||||
yref=letter_snip_kwargs['y'],
|
||||
x=0.05,
|
||||
yref=letter_snip_kwargs['yref'],
|
||||
ha='left',
|
||||
va='top',
|
||||
va='center',
|
||||
fontsize=fs['letter'],
|
||||
)
|
||||
zoom_inset_bounds = [0.1, 0.2, 0.8, 0.6]
|
||||
@@ -164,13 +181,31 @@ zoom_kwargs = dict(
|
||||
lw=1,
|
||||
alpha=1,
|
||||
)
|
||||
inset_tick_kwargs = dict(
|
||||
axis='y',
|
||||
length=3,
|
||||
pad=1,
|
||||
left=False,
|
||||
labelleft=False,
|
||||
right=True,
|
||||
labelright=True,
|
||||
)
|
||||
bar_time = 5
|
||||
bar_kwargs = dict(
|
||||
y0=-0.2,
|
||||
y1=-0.05,
|
||||
dur=bar_time,
|
||||
y0=-0.25,
|
||||
y1=-0.1,
|
||||
xshift=1,
|
||||
color='k',
|
||||
lw=0,
|
||||
clip_on=False,
|
||||
text_pos=(-0.1, 0.5),
|
||||
text_str=f'${bar_time}\\,\\text{{s}}$',
|
||||
text_kwargs=dict(
|
||||
fontsize=fs['bar'],
|
||||
ha='right',
|
||||
va='center',
|
||||
)
|
||||
)
|
||||
diag_kwargs = dict(
|
||||
c=(0.75, 0.75, 0.75),
|
||||
@@ -178,6 +213,13 @@ diag_kwargs = dict(
|
||||
ls='--',
|
||||
zorder=1.9,
|
||||
)
|
||||
noise_rel_thresh = 0.95
|
||||
noise_kwargs = dict(
|
||||
fc=(0.9, 0.9, 0.9),
|
||||
ec='none',
|
||||
lw=0,
|
||||
zorder=1.5,
|
||||
)
|
||||
|
||||
# EXECUTION:
|
||||
for data_path in data_paths:
|
||||
@@ -192,37 +234,39 @@ for data_path in data_paths:
|
||||
# Prepare overall graph:
|
||||
fig = plt.figure(**fig_kwargs)
|
||||
super_grid = fig.add_gridspec(**super_grid_kwargs)
|
||||
fig.canvas.draw()
|
||||
|
||||
# Prepare pure-song snippet axes:
|
||||
snip_grid_kwargs['ncols'] = pure_data['example_scales'].size
|
||||
pure_grid_kwargs['ncols'] = pure_data['example_scales'].size
|
||||
pure_subfig = fig.add_subfigure(super_grid[subfig_specs['pure']])
|
||||
pure_axes = add_snip_axes(pure_subfig, snip_grid_kwargs)
|
||||
pure_axes = add_snip_axes(pure_subfig, pure_grid_kwargs)
|
||||
for ax, stage in zip(pure_axes[:, 0], stages):
|
||||
ax.yaxis.set_major_locator(plt.MultipleLocator(yloc[stage]))
|
||||
ylabel(ax, ylabels[stage], **ylab_snip_kwargs,
|
||||
transform=pure_subfig.transSubfigure)
|
||||
for ax, scale in zip(pure_axes[0, :], pure_data['example_scales']):
|
||||
title_subplot(ax, f'$\\alpha={strip_zeros(scale)}$', ref=pure_subfig, **title_kwargs)
|
||||
pure_title = title_subplot(ax, f'$\\alpha={strip_zeros(scale)}$', **title_kwargs)
|
||||
letter_subplot(pure_subfig, 'a', ref=pure_title, **letter_snip_kwargs)
|
||||
pure_inset = pure_axes[0, 0].inset_axes(zoom_inset_bounds)
|
||||
pure_inset.spines[:].set(visible=True, lw=zoom_kwargs['lw'])
|
||||
pure_inset.tick_params(**inset_tick_kwargs)
|
||||
hide_ticks(pure_inset, 'bottom', ticks=False)
|
||||
hide_ticks(pure_inset, 'left', ticks=False)
|
||||
|
||||
# Prepare noise-song snippet axes:
|
||||
snip_grid_kwargs['ncols'] = noise_data['example_scales'].size
|
||||
noise_grid_kwargs['ncols'] = noise_data['example_scales'].size
|
||||
noise_subfig = fig.add_subfigure(super_grid[subfig_specs['noise']])
|
||||
noise_axes = add_snip_axes(noise_subfig, snip_grid_kwargs)
|
||||
noise_axes = add_snip_axes(noise_subfig, noise_grid_kwargs)
|
||||
for ax, stage in zip(noise_axes[:, 0], stages):
|
||||
ax.yaxis.set_major_locator(plt.MultipleLocator(yloc[stage]))
|
||||
ylabel(ax, ylabels[stage], **ylab_snip_kwargs,
|
||||
transform=noise_subfig.transSubfigure)
|
||||
for ax, scale in zip(noise_axes[0, :], noise_data['example_scales']):
|
||||
title_subplot(ax, f'$\\alpha={strip_zeros(scale)}$', ref=noise_subfig, **title_kwargs)
|
||||
letter_subplots([pure_subfig, noise_subfig], 'ac', **letter_snip_kwargs)
|
||||
noise_title = title_subplot(ax, f'$\\alpha={strip_zeros(scale)}$', **title_kwargs)
|
||||
letter_subplot(noise_subfig, 'c', ref=noise_title, **letter_snip_kwargs)
|
||||
noise_inset = noise_axes[0, 0].inset_axes(zoom_inset_bounds)
|
||||
noise_inset.spines[:].set(visible=True, lw=zoom_kwargs['lw'])
|
||||
noise_inset.tick_params(**inset_tick_kwargs)
|
||||
hide_ticks(noise_inset, 'bottom', ticks=False)
|
||||
hide_ticks(noise_inset, 'left', ticks=False)
|
||||
|
||||
# Prepare analysis axes:
|
||||
big_subfig = fig.add_subfigure(super_grid[subfig_specs['big']])
|
||||
@@ -238,17 +282,17 @@ for data_path in data_paths:
|
||||
ylabel(ax, ylabels['big'], transform=big_subfig.transSubfigure, **ylab_big_kwargs)
|
||||
if i == 0:
|
||||
hide_ticks(ax, 'bottom')
|
||||
letter_subplot(big_subfig, 'b', ref=pure_subfig, **letter_big_kwargs)
|
||||
letter_subplot(big_subfig, 'b', ref=pure_title, **letter_big_kwargs)
|
||||
else:
|
||||
xlabel(ax, xlabels['big'], transform=big_subfig.transSubfigure, **xlab_big_kwargs)
|
||||
letter_subplot(big_subfig, 'd', ref=noise_subfig, **letter_big_kwargs)
|
||||
letter_subplot(big_subfig, 'd', ref=noise_title, **letter_big_kwargs)
|
||||
big_axes[i] = ax
|
||||
|
||||
# Plot pure-song envelope snippets:
|
||||
handle = plot_snippets(pure_axes[0, :], t_full, pure_data['snip_env'],
|
||||
ymin=0, c=colors['env'], lw=lw_snippets)[0]
|
||||
zoom_inset(pure_axes[0, 0], pure_inset, handle, transform=pure_axes[0, 0].transAxes, **zoom_kwargs)
|
||||
|
||||
|
||||
# Plot pure-song logarithmic snippets:
|
||||
plot_snippets(pure_axes[1, :], t_full, pure_data['snip_log'],
|
||||
c=colors['log'], lw=lw_snippets)
|
||||
@@ -258,20 +302,23 @@ for data_path in data_paths:
|
||||
c=colors['inv'], lw=lw_snippets)
|
||||
|
||||
# Plot noise-song envelope snippets:
|
||||
ymin, ymax = pure_axes[0, 0].get_ylim()
|
||||
handle = plot_snippets(noise_axes[0, :], t_full, noise_data['snip_env'],
|
||||
ymin=0, c=colors['env'], lw=lw_snippets)[0]
|
||||
ymin, ymax, c=colors['env'], lw=lw_snippets)[0]
|
||||
zoom_inset(noise_axes[0, 0], noise_inset, handle, transform=noise_axes[0, 0].transAxes, **zoom_kwargs)
|
||||
|
||||
# Plot noise-song logarithmic snippets:
|
||||
ymin, ymax = pure_axes[1, 0].get_ylim()
|
||||
plot_snippets(noise_axes[1, :], t_full, noise_data['snip_log'],
|
||||
c=colors['log'], lw=lw_snippets)
|
||||
ymin, ymax, c=colors['log'], lw=lw_snippets)
|
||||
|
||||
# Plot noise-song invariant snippets:
|
||||
ymin, ymax = pure_axes[2, 0].get_ylim()
|
||||
plot_snippets(noise_axes[2, :], t_full, noise_data['snip_inv'],
|
||||
c=colors['inv'], lw=lw_snippets)
|
||||
ymin, ymax, c=colors['inv'], lw=lw_snippets)
|
||||
|
||||
# Indicate time scale:
|
||||
time_bar(noise_axes[2, -1], bar_time, **bar_kwargs)
|
||||
time_bar(noise_axes[-1, -1], **bar_kwargs)
|
||||
|
||||
if compute_ratios:
|
||||
# Relate pure-song measures to zero scale:
|
||||
@@ -293,12 +340,25 @@ for data_path in data_paths:
|
||||
big_axes[1].plot(noise_scales, noise_data['measure_log'], c=colors['log'], lw=lw_big)
|
||||
big_axes[1].plot(noise_scales, noise_data['measure_inv'], c=colors['inv'], lw=lw_big)
|
||||
|
||||
# Indicate diagonal:
|
||||
big_axes[0].plot(pure_scales, pure_scales, **diag_kwargs)
|
||||
big_axes[1].plot(noise_scales, noise_scales, **diag_kwargs)
|
||||
if show_diag:
|
||||
# Indicate diagonal:
|
||||
big_axes[0].plot(pure_scales, pure_scales, **diag_kwargs)
|
||||
big_axes[1].plot(noise_scales, noise_scales, **diag_kwargs)
|
||||
|
||||
if show_noise:
|
||||
# Indicate noise floor:
|
||||
if compute_ratios:
|
||||
span_measure = noise_data['measure_inv'][-1] - ref_measures['inv']
|
||||
thresh_measure = ref_measures['inv'] + noise_rel_thresh * span_measure
|
||||
else:
|
||||
span_measure = noise_data['measure_inv'][-1] - noise_data['measure_inv'][0]
|
||||
thresh_measure = noise_data['measure_inv'][0] + noise_rel_thresh * span_measure
|
||||
thresh_ind = np.nonzero(noise_data['measure_inv'] < thresh_measure)[0][-1]
|
||||
thresh_scale = noise_scales[thresh_ind]
|
||||
big_axes[1].axvspan(noise_scales[0], thresh_scale, **noise_kwargs)
|
||||
|
||||
if save_path is not None:
|
||||
fig.savefig(save_path)
|
||||
fig.savefig(save_path, bbox_inches='tight')
|
||||
plt.show()
|
||||
|
||||
print('Done.')
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import plotstyle_plt
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from itertools import product
|
||||
from thunderhopper.filetools import search_files
|
||||
from thunderhopper.modeltools import load_data
|
||||
from thunderhopper.filtertools import find_kern_specs
|
||||
@@ -116,6 +115,14 @@ snip_specs = dict(
|
||||
inset_bounds = [1.02, 0, 0.2, 1]
|
||||
|
||||
# PLOT SETTINGS:
|
||||
fs = dict(
|
||||
lab_norm=16,
|
||||
lab_tex=20,
|
||||
letter=22,
|
||||
tit_norm=16,
|
||||
tit_tex=20,
|
||||
bar=16,
|
||||
)
|
||||
colors = load_colors('../data/stage_colors.npz')
|
||||
color_factors = [0.2, -0.2]
|
||||
lw = dict(
|
||||
@@ -136,32 +143,32 @@ ylabels = dict(
|
||||
)
|
||||
xlab_snip_kwargs = dict(
|
||||
y=0,
|
||||
fontsize=16,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='center',
|
||||
va='bottom',
|
||||
)
|
||||
xlab_big_kwargs = dict(
|
||||
y=0,
|
||||
fontsize=16,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='center',
|
||||
va='bottom',
|
||||
)
|
||||
ylab_snip_kwargs = dict(
|
||||
x=0.08,
|
||||
fontsize=20,
|
||||
fontsize=fs['lab_tex'],
|
||||
rotation=0,
|
||||
ha='right',
|
||||
va='center',
|
||||
)
|
||||
ylab_super_kwargs = dict(
|
||||
x=0,
|
||||
fontsize=16,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='left',
|
||||
va='center',
|
||||
)
|
||||
ylab_big_kwargs = dict(
|
||||
x=0,
|
||||
fontsize=20,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='center',
|
||||
va='top',
|
||||
)
|
||||
@@ -176,21 +183,21 @@ title_kwargs = dict(
|
||||
yref=1,
|
||||
ha='center',
|
||||
va='top',
|
||||
fontsize=16,
|
||||
fontsize=fs['tit_norm'],
|
||||
)
|
||||
letter_snip_kwargs = dict(
|
||||
x=0,
|
||||
y=1,
|
||||
ha='left',
|
||||
va='top',
|
||||
fontsize=22,
|
||||
fontsize=fs['letter'],
|
||||
)
|
||||
letter_big_kwargs = dict(
|
||||
x=0,
|
||||
yref=letter_snip_kwargs['y'],
|
||||
ha='left',
|
||||
va='top',
|
||||
fontsize=22,
|
||||
fontsize=fs['letter'],
|
||||
)
|
||||
dist_kwargs = dict(
|
||||
nbins=50,
|
||||
@@ -203,10 +210,20 @@ dist_fill_kwargs = dict(
|
||||
)
|
||||
bar_time = 0.1
|
||||
bar_kwargs = dict(
|
||||
y0=0.3,
|
||||
y1=0.4,
|
||||
dur=bar_time,
|
||||
y0=-0.25,
|
||||
y1=-0.1,
|
||||
xshift=1,
|
||||
color='k',
|
||||
lw=0,
|
||||
clip_on=False,
|
||||
text_pos=(-0.1, 0.5),
|
||||
text_str=f'${int(1000 * bar_time)}\\,\\text{{ms}}$',
|
||||
text_kwargs=dict(
|
||||
fontsize=fs['bar'],
|
||||
ha='right',
|
||||
va='center',
|
||||
)
|
||||
)
|
||||
kernel = np.array([
|
||||
[1, 0.008],
|
||||
@@ -264,13 +281,12 @@ for data_path in data_paths:
|
||||
ylabel(ax, ylabels[stage], **ylab_snip_kwargs,
|
||||
transform=snip_subfig.transSubfigure)
|
||||
if i == 0:
|
||||
axes[0, 0].set_xlim(t_full[0], t_full[-1])
|
||||
time_bar(axes[0, 0], bar_time, **bar_kwargs)
|
||||
for ax, scale in zip(axes[0, :], data['example_scales']):
|
||||
title = f'$\\alpha={strip_zeros(scale)}$'
|
||||
title_subplot(ax, title, **title_kwargs, ref=fig)
|
||||
elif i == data['threshs'].size - 1:
|
||||
super_xlabel(xlabels['snip'], snip_subfig, axes[-1, 0], axes[-1, -1], **xlab_snip_kwargs)
|
||||
elif i == data['threshs'].size - 1:
|
||||
axes[-1, -1].set_xlim(t_full[0], t_full[-1])
|
||||
time_bar(axes[-1, -1], **bar_kwargs)
|
||||
letter_subplots(snip_axes.keys(), **letter_snip_kwargs)
|
||||
|
||||
# Prepare analysis axis:
|
||||
|
||||
@@ -200,6 +200,14 @@ inset_kwargs = dict(
|
||||
)
|
||||
|
||||
# PLOT SETTINGS:
|
||||
fs = dict(
|
||||
lab_norm=16,
|
||||
lab_tex=20,
|
||||
letter=22,
|
||||
tit_norm=16,
|
||||
tit_tex=20,
|
||||
bar=16,
|
||||
)
|
||||
base_color = load_colors('../data/stage_colors.npz')['feat']
|
||||
spec_cmaps = [
|
||||
'Reds',
|
||||
@@ -224,31 +232,31 @@ ylabels = dict(
|
||||
)
|
||||
xlab_spec_kwargs = dict(
|
||||
y=0,
|
||||
fontsize=16,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='center',
|
||||
va='bottom',
|
||||
)
|
||||
xlab_big_kwargs = dict(
|
||||
y=0,
|
||||
fontsize=20,
|
||||
fontsize=fs['lab_tex'],
|
||||
ha='center',
|
||||
va='bottom',
|
||||
)
|
||||
ylab_spec_kwargs = dict(
|
||||
x=0,
|
||||
fontsize=20,
|
||||
fontsize=fs['lab_tex'],
|
||||
ha='left',
|
||||
va='center',
|
||||
)
|
||||
ylab_big_kwargs = dict(
|
||||
x=0.03,
|
||||
fontsize=20,
|
||||
fontsize=fs['lab_tex'],
|
||||
ha='center',
|
||||
va='center',
|
||||
)
|
||||
ylab_cbar_kwargs = dict(
|
||||
x=1,
|
||||
fontsize=16,
|
||||
fontsize=fs['lab_norm'],
|
||||
ha='center',
|
||||
va='bottom',
|
||||
)
|
||||
@@ -264,14 +272,14 @@ letter_spec_kwargs = dict(
|
||||
yref=1,
|
||||
ha='center',
|
||||
va='top',
|
||||
fontsize=22,
|
||||
fontsize=fs['letter'],
|
||||
)
|
||||
letter_big_kwargs = dict(
|
||||
x=0,
|
||||
yref=1,
|
||||
ha='center',
|
||||
va='top',
|
||||
fontsize=22,
|
||||
fontsize=fs['letter'],
|
||||
)
|
||||
time_bar_kwargs = dict(
|
||||
dur=0.05,
|
||||
|
||||
@@ -16,41 +16,56 @@ def hide_axis(ax, side='bottom'):
|
||||
which='both', **params)
|
||||
return None
|
||||
|
||||
def get_trans_artist(artist):
|
||||
artist_type = type(artist).__name__
|
||||
if artist_type == 'Axes':
|
||||
return artist.transAxes
|
||||
elif artist_type == 'Figure':
|
||||
return artist.transFigure
|
||||
elif artist_type == 'Subfigure':
|
||||
return artist.transSubfigure
|
||||
elif hasattr(artist, 'bbox'):
|
||||
return BboxTransformTo(artist.bbox)
|
||||
renderer = artist.get_figure(root=True).canvas.get_renderer()
|
||||
if hasattr(artist, 'get_window_extent'):
|
||||
return BboxTransformTo(artist.get_window_extent(renderer))
|
||||
elif hasattr(artist, 'get_tightbbox'):
|
||||
return BboxTransformTo(artist.get_tightbbox(renderer))
|
||||
raise ValueError('Artist does not have a bounding box to use as transform.')
|
||||
|
||||
def title_subplot(artist, title, x=0.5, y=1.0, xref=None, yref=None, ref=None,
|
||||
ha='center', va='bottom', fontsize=16, fontweight='normal', **kwargs):
|
||||
|
||||
trans_artist = BboxTransformTo(artist.bbox)
|
||||
trans_artist = get_trans_artist(artist)
|
||||
if xref is not None or yref is not None:
|
||||
transform = BboxTransformTo(ref.bbox) + trans_artist.inverted()
|
||||
transform = get_trans_artist(ref) + trans_artist.inverted()
|
||||
if xref is not None:
|
||||
x = transform.transform((xref, 0))[0]
|
||||
if yref is not None:
|
||||
y = transform.transform((0, yref))[1]
|
||||
artist.text(x, y, title, transform=trans_artist, ha=ha, va=va,
|
||||
fontsize=fontsize, fontweight=fontweight, **kwargs)
|
||||
return None
|
||||
return artist.text(x, y, title, transform=trans_artist, ha=ha, va=va,
|
||||
fontsize=fontsize, fontweight=fontweight, **kwargs)
|
||||
|
||||
def letter_subplot(artist, label, x=None, y=None, xref=None, yref=None, ref=None,
|
||||
ha='left', va='bottom', fontsize=16, fontweight='bold', **kwargs):
|
||||
trans_artist = BboxTransformTo(artist.bbox)
|
||||
trans_artist = get_trans_artist(artist)
|
||||
if x is None or y is None:
|
||||
transform = BboxTransformTo(ref.bbox) + trans_artist.inverted()
|
||||
transform = get_trans_artist(ref) + trans_artist.inverted()
|
||||
if x is None:
|
||||
x = transform.transform([xref, 0])[0]
|
||||
if y is None:
|
||||
y = transform.transform([0, yref])[1]
|
||||
artist.text(x, y, label, transform=trans_artist, ha=ha, va=va,
|
||||
fontsize=fontsize, fontweight=fontweight, **kwargs)
|
||||
return None
|
||||
return artist.text(x, y, label, transform=trans_artist, ha=ha, va=va,
|
||||
fontsize=fontsize, fontweight=fontweight, **kwargs)
|
||||
|
||||
def letter_subplots(artists, labels=None, x=None, y=None, xref=None, yref=None, ref=None,
|
||||
ha='left', va='bottom', fontsize=16, fontweight='bold', **kwargs):
|
||||
if labels is None:
|
||||
labels = string.ascii_lowercase
|
||||
handles = []
|
||||
for artist, label in zip(artists, labels):
|
||||
letter_subplot(artist, label, x, y, xref, yref, ref=ref, ha=ha, va=va,
|
||||
fontsize=fontsize, fontweight=fontweight, **kwargs)
|
||||
return None
|
||||
handles.append(letter_subplot(artist, label, x, y, xref, yref, ref,
|
||||
ha=ha, va=va, fontsize=fontsize, fontweight=fontweight, **kwargs))
|
||||
return handles
|
||||
|
||||
def xlimits(time, ax=None, minval=None, maxval=None, pad=0.05):
|
||||
limits = [minval, maxval]
|
||||
@@ -83,34 +98,32 @@ def ylimits(signal, ax=None, minval=None, maxval=None, pad=0.05):
|
||||
return limits
|
||||
|
||||
def xlabel(ax, label, x=None, y=-0.1, fontsize=20, transform=None, **kwargs):
|
||||
ax.set_xlabel(label, fontsize=fontsize, **kwargs)
|
||||
if x is None:
|
||||
x = 0.5
|
||||
if transform is not None:
|
||||
x = (ax.transAxes + transform.inverted()).transform((x, 0))[0]
|
||||
ax.xaxis.set_label_coords(x, y, transform=transform)
|
||||
return None
|
||||
return ax.set_xlabel(label, fontsize=fontsize, **kwargs)
|
||||
|
||||
def ylabel(ax, label, x=-0.2, y=None, fontsize=20, transform=None, **kwargs):
|
||||
ax.set_ylabel(label, fontsize=fontsize, **kwargs)
|
||||
if y is None:
|
||||
y = 0.5
|
||||
if transform is not None:
|
||||
y = (ax.transAxes + transform.inverted()).transform((0, y))[1]
|
||||
ax.yaxis.set_label_coords(x, y, transform=transform)
|
||||
return None
|
||||
return ax.set_ylabel(label, fontsize=fontsize, **kwargs)
|
||||
|
||||
def super_xlabel(label, fig, left_ax, right_ax, y=0.005,
|
||||
left_fig=None, right_fig=None, **kwargs):
|
||||
left_x = left_ax.get_position().x0
|
||||
right_x = right_ax.get_position().x1
|
||||
if left_fig is not None or right_fig is not None:
|
||||
trans_fig = BboxTransformTo(fig.bbox)
|
||||
trans_fig = get_trans_artist(fig)
|
||||
if left_fig is not None:
|
||||
transform = BboxTransformTo(left_fig.bbox) + trans_fig.inverted()
|
||||
transform = get_trans_artist(left_fig) + trans_fig.inverted()
|
||||
left_x = transform.transform((left_x, 0))[0]
|
||||
if right_fig is not None:
|
||||
transform = BboxTransformTo(right_fig.bbox) + trans_fig.inverted()
|
||||
transform = get_trans_artist(right_fig) + trans_fig.inverted()
|
||||
right_x = transform.transform((right_x, 0))[0]
|
||||
return fig.supxlabel(label, x=(left_x + right_x) / 2, y=y, **kwargs)
|
||||
|
||||
@@ -119,12 +132,12 @@ def super_ylabel(label, fig, low_ax, high_ax, x=0.005,
|
||||
low_y = high_ax.get_position().y0
|
||||
high_y = low_ax.get_position().y1
|
||||
if low_fig is not None or high_fig is not None:
|
||||
trans_fig = BboxTransformTo(fig.bbox)
|
||||
trans_fig = get_trans_artist(fig)
|
||||
if low_fig is not None:
|
||||
transform = BboxTransformTo(low_fig.bbox) + trans_fig.inverted()
|
||||
transform = get_trans_artist(low_fig) + trans_fig.inverted()
|
||||
low_y = transform.transform((0, low_y))[1]
|
||||
if high_fig is not None:
|
||||
transform = BboxTransformTo(high_fig.bbox) + trans_fig.inverted()
|
||||
transform = get_trans_artist(high_fig) + trans_fig.inverted()
|
||||
high_y = transform.transform((0, high_y))[1]
|
||||
return fig.supylabel(label, x=x, y=(low_y + high_y) / 2, **kwargs)
|
||||
|
||||
@@ -161,9 +174,8 @@ def indicate_zoom(fig, high_ax, low_ax, zoom_abs, **kwargs):
|
||||
transform = low_ax.transData + fig.transFigure.inverted()
|
||||
x0 = transform.transform((zoom_abs[0], 0))[0]
|
||||
x1 = transform.transform((zoom_abs[1], 0))[0]
|
||||
fig.add_artist(plt.Rectangle((x0, y0), x1 - x0, y1 - y0,
|
||||
transform=fig.transFigure, **kwargs))
|
||||
return None
|
||||
return fig.add_artist(plt.Rectangle((x0, y0), x1 - x0, y1 - y0,
|
||||
transform=fig.transFigure, **kwargs))
|
||||
|
||||
def assign_colors(handles, types, colors):
|
||||
for handle, type_id in zip(handles, types):
|
||||
@@ -187,22 +199,30 @@ def strip_zeros(num, right_digits=5):
|
||||
return f'{left}.{right}'
|
||||
return left
|
||||
|
||||
def time_bar(ax, dur, y0=0.9, y1=0.95, xshift=0.5, parent=None, **kwargs):
|
||||
def time_bar(ax, dur, y0=0.9, y1=0.95, xshift=0.5, parent=None,
|
||||
text_pos=None, text_str=None, text_kwargs={}, **kwargs):
|
||||
if parent is None:
|
||||
parent = ax
|
||||
trans_parent = BboxTransformTo(parent.bbox)
|
||||
kwargs['transform'] = trans_parent
|
||||
trans_parent = get_trans_artist(parent)
|
||||
transform = ax.transData + trans_parent.inverted()
|
||||
t0 = ax.get_xlim()[0]
|
||||
x0 = transform.transform((t0, 0))[0]
|
||||
x1 = transform.transform((t0 + dur, 0))[0]
|
||||
dur = x1 - x0
|
||||
x0 = (1 - dur) * xshift
|
||||
parent.add_artist(plt.Rectangle((x0, y0), dur, y1 - y0, **kwargs))
|
||||
return None
|
||||
rect = parent.add_artist(plt.Rectangle((x0, y0), dur, y1 - y0,
|
||||
transform=trans_parent, **kwargs))
|
||||
if text_pos is not None:
|
||||
trans_bar = get_trans_artist(rect)
|
||||
text_pos = (trans_bar + trans_parent.inverted()).transform(text_pos)
|
||||
if text_str is None:
|
||||
text_str = f'{dur:.2f} s'
|
||||
t = parent.text(*text_pos, text_str, transform=trans_parent, **text_kwargs)
|
||||
return rect, t
|
||||
return rect
|
||||
|
||||
def zoom_inset(ax, inset, handle, x0=None, x1=None, y0=None, y1=None, ref='x',
|
||||
transform = None,
|
||||
transform=None,
|
||||
low_left=False, up_left=False, low_right=False, up_right=False,
|
||||
props=['c', 'lw', 'ls', 'zorder', 'alpha'], **kwargs):
|
||||
if not kwargs:
|
||||
|
||||
@@ -12,7 +12,7 @@ save_path = '../data/inv/noise_env/'
|
||||
|
||||
# ANALYSIS SETTINGS:
|
||||
scales = np.geomspace(0.1, 10000, 200)
|
||||
sd_inputs = np.arange(10.9, 11.1, 0.01)
|
||||
sd_inputs = np.array([1.0])
|
||||
n_trials = 10
|
||||
tol_to_one = 0.1
|
||||
|
||||
@@ -32,15 +32,16 @@ signal /= signal[segment].std()
|
||||
signal = signal[:, None] * scales[None, :]
|
||||
|
||||
# Prepare storage:
|
||||
current_match = 0
|
||||
storage = dict(
|
||||
scales=scales,
|
||||
n_trials=n_trials,
|
||||
sd_factor=np.array([0.]),
|
||||
trials=np.zeros((scales.size, n_trials), dtype=float),
|
||||
mean=np.zeros(scales.size, dtype=float),
|
||||
spread=np.zeros(scales.size, dtype=float),
|
||||
)
|
||||
if sd_inputs.size > 1:
|
||||
current_match = 0
|
||||
storage = dict(
|
||||
scales=scales,
|
||||
n_trials=n_trials,
|
||||
sd_factor=np.array([0.]),
|
||||
trials=np.zeros((scales.size, n_trials), dtype=float),
|
||||
mean=np.zeros(scales.size, dtype=float),
|
||||
spread=np.zeros(scales.size, dtype=float),
|
||||
)
|
||||
|
||||
# Analyze piece-wise:
|
||||
rng = np.random.default_rng()
|
||||
@@ -59,7 +60,22 @@ for i, sigma in enumerate(sd_inputs):
|
||||
|
||||
# Estimate noise SD:
|
||||
sd = mix.std(axis=0)
|
||||
# Average SD over trials:
|
||||
mean_sd = sd.mean(axis=-1)
|
||||
|
||||
# Log single-run results:
|
||||
if sd_inputs.size == 1:
|
||||
storage = dict(
|
||||
scales=scales,
|
||||
n_trials=n_trials,
|
||||
sd_factor=sigma,
|
||||
trials=sd,
|
||||
mean=mean_sd,
|
||||
spread=sd.std(axis=-1),
|
||||
)
|
||||
break
|
||||
|
||||
# Update multi-run results if better than previous:
|
||||
n_match = (np.abs(1 - mean_sd) <= tol_to_one).sum()
|
||||
if n_match > current_match:
|
||||
print(f'Found better SD: {sigma:.3f} with {n_match} matches (previous: {current_match})')
|
||||
@@ -70,13 +86,10 @@ for i, sigma in enumerate(sd_inputs):
|
||||
current_match = n_match
|
||||
del mix
|
||||
del signal
|
||||
|
||||
if save_path is not None:
|
||||
np.savez(save_path + 'sd_conversion.npz', **storage)
|
||||
|
||||
plt.plot(scales, storage['mean'], 'k')
|
||||
plt.show()
|
||||
embed()
|
||||
|
||||
print('Done.')
|
||||
embed()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user