Overhauled Thresh-LP analysis and figures (WIP).
This commit is contained in:
@@ -1,33 +1,14 @@
|
||||
from pyparsing import alphanums
|
||||
|
||||
import plotstyle_plt
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.transforms import BboxTransformTo
|
||||
from itertools import product
|
||||
from thunderhopper.filetools import search_files
|
||||
from thunderhopper.modeltools import load_data
|
||||
from color_functions import load_colors
|
||||
from plot_functions import hide_axis, ylimits, xlabel, ylabel, plot_line, plot_barcode, strip_zeros
|
||||
from plot_functions import hide_axis, ylimits, xlabel, ylabel,\
|
||||
plot_line, plot_barcode, strip_zeros, time_bar
|
||||
from IPython import embed
|
||||
|
||||
def time_bar(ax, dur, y0=0.9, y1=0.95, xshift=0.5, parent=None, transform=None, **kwargs):
|
||||
t0, t1 = ax.get_xlim()
|
||||
offset = (t1 - t0 - dur) * xshift
|
||||
x0 = t0 + offset
|
||||
x1 = x0 + dur
|
||||
if parent is None:
|
||||
parent = ax
|
||||
if transform is None:
|
||||
transform = BboxTransformTo(parent.bbox)
|
||||
if transform is not ax.transData:
|
||||
trans = ax.transData + transform.inverted()
|
||||
x0 = trans.transform((x0, 0))[0]
|
||||
x1 = trans.transform((x1, 0))[0]
|
||||
parent.add_artist(plt.Rectangle((x0, y0), x1 - x0, y1 - y0,
|
||||
transform=transform, **kwargs))
|
||||
return None
|
||||
|
||||
def add_snip_axes(fig, grid_kwargs):
|
||||
grid = fig.add_gridspec(**grid_kwargs)
|
||||
axes = np.zeros((grid.nrows, grid.ncols), dtype=object)
|
||||
@@ -53,8 +34,10 @@ def plot_bi_snippets(axes, time, binary, **kwargs):
|
||||
target = 'Omocestus_rufipes'
|
||||
data_paths = search_files(target, excl='noise', dir='../data/inv/thresh_lp/')
|
||||
stages = ['conv', 'bi', 'feat']
|
||||
files = stages + ['scales', 'example_scales', 'measure_conv', 'spread_conv',
|
||||
'measure_feat', 'spread_feat']
|
||||
load_kwargs = dict(
|
||||
files=stages,
|
||||
keywords=['scales', 'measure', 'spread']
|
||||
)
|
||||
save_path = '../figures/fig_invariance_thresh_lp.pdf'
|
||||
|
||||
# GRAPH SETTINGS:
|
||||
@@ -81,7 +64,7 @@ pure_grid_kwargs = dict(
|
||||
ncols=None,
|
||||
wspace=0.05,
|
||||
hspace=0.1,
|
||||
left=0.13,
|
||||
left=0.07,
|
||||
right=0.95,
|
||||
bottom=0.15,
|
||||
top=0.9
|
||||
@@ -91,7 +74,7 @@ noise_grid_kwargs = dict(
|
||||
ncols=None,
|
||||
wspace=0.05,
|
||||
hspace=0.1,
|
||||
left=0.13,
|
||||
left=0.07,
|
||||
right=0.95,
|
||||
bottom=0.15,
|
||||
top=0.9
|
||||
@@ -114,7 +97,10 @@ snip_specs = dict(
|
||||
|
||||
# PLOT SETTINGS:
|
||||
colors = load_colors('../data/stage_colors.npz')
|
||||
lw_snippets = 0.5
|
||||
lw_snippets = dict(
|
||||
conv=0.5,
|
||||
feat=2
|
||||
)
|
||||
lw_analysis = 3
|
||||
xlabels = dict(
|
||||
analysis='scale $\\alpha$',
|
||||
@@ -166,10 +152,10 @@ letter_analysis_kwargs = dict(
|
||||
)
|
||||
bar_time = 5
|
||||
bar_kwargs = dict(
|
||||
y0=0.5,
|
||||
y1=0.6,
|
||||
y0=0.7,
|
||||
y1=0.8,
|
||||
color='k',
|
||||
lw = 0,
|
||||
lw=0,
|
||||
)
|
||||
spread_kwargs = dict(
|
||||
alpha=0.3,
|
||||
@@ -183,8 +169,8 @@ for data_path in data_paths:
|
||||
print(f'Processing {data_path}')
|
||||
|
||||
# Load invariance data:
|
||||
pure_data, config = load_data(data_path, files)
|
||||
noise_data, _ = load_data(data_path.replace('.npz', '_noise.npz'), files)
|
||||
pure_data, config = load_data(data_path, **load_kwargs)
|
||||
noise_data, _ = load_data(data_path.replace('.npz', '_noise.npz'), **load_kwargs)
|
||||
t_full = np.arange(pure_data['conv'].shape[0]) / config['env_rate']
|
||||
|
||||
# Reduce snippet data to kernel subset:
|
||||
@@ -237,7 +223,7 @@ for data_path in data_paths:
|
||||
|
||||
# Plot pure-song kernel response snippets:
|
||||
plot_snippets(pure_axes[snip_specs['conv']], t_full, pure_data['conv'],
|
||||
ymin=0, c=colors['conv'], lw=lw_snippets)
|
||||
c=colors['conv'], lw=lw_snippets['conv'])
|
||||
|
||||
# Plot pure-song binary snippets:
|
||||
plot_bi_snippets(pure_axes[snip_specs['bi']], t_full, pure_data['bi'],
|
||||
@@ -245,14 +231,14 @@ for data_path in data_paths:
|
||||
|
||||
# Plot pure-song feature snippets:
|
||||
plot_snippets(pure_axes[snip_specs['feat']], t_full, pure_data['feat'],
|
||||
c=colors['feat'], lw=lw_snippets)
|
||||
ymin=0, ymax=1, c=colors['feat'], lw=lw_snippets['feat'])
|
||||
|
||||
# Indicate time scale:
|
||||
time_bar(pure_axes[snip_specs['conv']][0], bar_time, **bar_kwargs)
|
||||
|
||||
# Plot noise-song kernel response snippets:
|
||||
plot_snippets(noise_axes[snip_specs['conv']], t_full, noise_data['conv'],
|
||||
ymin=0, c=colors['conv'], lw=lw_snippets)
|
||||
c=colors['conv'], lw=lw_snippets['conv'])
|
||||
|
||||
# Plot noise-song binary snippets:
|
||||
plot_bi_snippets(noise_axes[snip_specs['bi']], t_full, noise_data['bi'],
|
||||
@@ -260,7 +246,7 @@ for data_path in data_paths:
|
||||
|
||||
# Plot noise-song feature snippets:
|
||||
plot_snippets(noise_axes[snip_specs['feat']], t_full, noise_data['feat'],
|
||||
c=colors['feat'], lw=lw_snippets)
|
||||
ymin=0, ymax=1, c=colors['feat'], lw=lw_snippets['feat'])
|
||||
|
||||
# Indicate time scale:
|
||||
time_bar(noise_axes[snip_specs['conv']][0], bar_time, **bar_kwargs)
|
||||
|
||||
Reference in New Issue
Block a user