Fetched bunch of species-specific song snippets.
Worked those into LogHP analysis. Worked results into fig_invariance_log-hp.pdf. Put details into new fig_invariance_log-hp_species.pdf (appendix).
This commit is contained in:
@@ -27,58 +27,29 @@ def plot_snippets(axes, time, snippets, ymin=None, ymax=None, **kwargs):
|
||||
handles.extend(plot_line(ax, time, snippet, ymin=ymin, ymax=ymax, **kwargs))
|
||||
return handles
|
||||
|
||||
def plot_dist_shifted(ax, data, axis, pdf=None, sigma=0.1, which='x',
|
||||
base=None, cap=None, add_pdf=False, shifted=False, **kwargs):
|
||||
if pdf is None:
|
||||
pdf, axis = get_kde(data, sigma, axis)
|
||||
if base is None:
|
||||
base = pdf.min()
|
||||
if cap is None:
|
||||
cap = pdf.max()
|
||||
pdf = (pdf - pdf.min()) / (pdf.max() - pdf.min()) * (cap - base) + base
|
||||
|
||||
if which == 'x':
|
||||
transform = ax.get_xaxis_transform()
|
||||
elif which == 'y':
|
||||
transform = ax.get_yaxis_transform()
|
||||
else:
|
||||
transform = ax.transData
|
||||
|
||||
rng = np.random.default_rng()
|
||||
handles = []
|
||||
for value in data:
|
||||
ind = np.nonzero(axis == value)[0][0]
|
||||
offset = base if not shifted else rng.uniform(base, pdf[ind])
|
||||
variables = (offset, value) if which=='y' else (value, offset)
|
||||
handles.extend(ax.plot(*variables, transform=transform, **kwargs))
|
||||
if add_pdf:
|
||||
variables = (pdf, axis) if which=='y' else (axis, pdf)
|
||||
pdf_handle = ax.plot(*variables, transform=transform, c='k', lw=1)
|
||||
return handles, pdf_handle
|
||||
return handles
|
||||
|
||||
def zalpha(handles, background='w', down=1):
|
||||
twins = []
|
||||
for handle in handles:
|
||||
twin = handle.copy()
|
||||
twin.set(color=background, alpha=1)
|
||||
twin.set_zorder(handle.get_zorder() - down)
|
||||
twins.append(twin)
|
||||
return twins
|
||||
# def zalpha(handles, background='w', down=1):
|
||||
# twins = []
|
||||
# for handle in handles:
|
||||
# twin = handle.copy()
|
||||
# twin.set(color=background, alpha=1)
|
||||
# twin.set_zorder(handle.get_zorder() - down)
|
||||
# twins.append(twin)
|
||||
# return twins
|
||||
|
||||
# GENERAL SETTINGS:
|
||||
target = 'Omocestus_rufipes'
|
||||
target = 'Omocestus_rufipes_DJN_32-40s724ms-48s779ms'
|
||||
data_paths = search_files(target, excl='noise', dir='../data/inv/log_hp/')
|
||||
ref_path = '../data/inv/log_hp/ref_measures.npz'
|
||||
save_path = '../figures/fig_invariance_log_hp.pdf'
|
||||
target_species = [
|
||||
'Omocestus_rufipes',
|
||||
'Chorthippus_biguttulus',
|
||||
'Chorthippus_mollis',
|
||||
'Chrysochraon_dispar',
|
||||
'Euchorthippus_declivus',
|
||||
'Gomphocerippus_rufus',
|
||||
'Omocestus_rufipes',
|
||||
'Pseudochorthippus_parallelus',
|
||||
]
|
||||
]
|
||||
stages = ['env', 'log', 'inv']
|
||||
load_kwargs = dict(
|
||||
files=stages,
|
||||
@@ -159,12 +130,13 @@ fs = dict(
|
||||
)
|
||||
colors = load_colors('../data/stage_colors.npz')
|
||||
species_colors = load_colors('../data/species_colors.npz')
|
||||
noise_colors = [(0.5, 0.5, 0.5), (0.7, 0.7, 0.7)]
|
||||
noise_colors = [(0.6,) * 3, (0.8,) * 3]
|
||||
lw = dict(
|
||||
snip=1,
|
||||
big=4,
|
||||
spec=2,
|
||||
plateau=1,
|
||||
plateau=1.5,
|
||||
legend=5,
|
||||
)
|
||||
xlabels = dict(
|
||||
big='scale $\\alpha$',
|
||||
@@ -273,7 +245,7 @@ leg_kwargs = dict(
|
||||
columnspacing=1,
|
||||
)
|
||||
diag_kwargs = dict(
|
||||
c=(0.75, 0.75, 0.75),
|
||||
c=(0.3,) * 3,
|
||||
lw=2,
|
||||
ls='--',
|
||||
zorder=1.9,
|
||||
@@ -297,18 +269,9 @@ plateau_line_kwargs = dict(
|
||||
)
|
||||
plateau_dot_kwargs = dict(
|
||||
marker='o',
|
||||
markersize=10,
|
||||
markeredgecolor='k',
|
||||
markersize=8,
|
||||
markeredgewidth=1,
|
||||
# alpha=1,
|
||||
zorder=6,
|
||||
clip_on=False,
|
||||
# base=0,
|
||||
# cap=0.15,
|
||||
# add_pdf=True,
|
||||
)
|
||||
kde_kwargs = dict(
|
||||
sigma=0.1,
|
||||
)
|
||||
|
||||
# PREPARATION:
|
||||
@@ -317,18 +280,12 @@ if compute_ratios:
|
||||
|
||||
species_measures = {}
|
||||
thresh_inds = np.zeros((len(target_species),), dtype=int)
|
||||
thresh_scales = np.zeros((len(target_species),), dtype=float)
|
||||
for i, species in enumerate(target_species):
|
||||
path = search_files(species, incl='noise', dir='../data/inv/log_hp/')[0]
|
||||
species_data = load_data(path, **load_kwargs)[0]
|
||||
measure = species_data['measure_inv']
|
||||
scales = species_data['scales']
|
||||
if compute_ratios:
|
||||
measure /= ref_measures['inv']
|
||||
spec_path = search_files(species, dir='../data/inv/log_hp/condensed/')[0]
|
||||
spec_data = dict(np.load(spec_path))
|
||||
measure = spec_data['mean'].mean(axis=1)
|
||||
species_measures[species] = measure
|
||||
thresh_inds[i] = get_saturation(measure, **plateau_settings)[1]
|
||||
thresh_scales[i] = scales[thresh_inds[i]]
|
||||
thresh_pdf, pdf_axis = get_kde(thresh_scales, axis=scales, **kde_kwargs)
|
||||
|
||||
# EXECUTION:
|
||||
for data_path in data_paths:
|
||||
@@ -460,24 +417,23 @@ for data_path in data_paths:
|
||||
big_axes[1].axvspan(noise_scales[low_ind], noise_scales[high_ind],
|
||||
fc=noise_colors[1], **plateau_rect_kwargs)
|
||||
|
||||
# Plot species-specific noise-song measures:
|
||||
# Plot species-specific noise-song invariance curves:
|
||||
for i, (species, measure) in enumerate(species_measures.items()):
|
||||
# Plot invariance curve:
|
||||
color = species_colors[species]
|
||||
ind, scale = thresh_inds[i], thresh_scales[i]
|
||||
big_axes[2].plot(noise_scales, measure, label=shorten_species(species),
|
||||
c=color, lw=lw['spec'])
|
||||
# Indicate saturation:
|
||||
ind = thresh_inds[i]
|
||||
scale = noise_scales[ind]
|
||||
big_axes[2].plot(scale, 0, c='w', alpha=1, zorder=5.5, **plateau_dot_kwargs,
|
||||
transform=big_axes[2].get_xaxis_transform())
|
||||
handle = big_axes[2].plot(scale, 0, c=color, alpha=0.5, **plateau_dot_kwargs,
|
||||
transform=big_axes[2].get_xaxis_transform())
|
||||
big_axes[2].plot(scale, 0, mfc=color, mec='k', alpha=0.75, zorder=6, **plateau_dot_kwargs,
|
||||
transform=big_axes[2].get_xaxis_transform())
|
||||
big_axes[2].vlines(scale, big_axes[2].get_ylim()[0], measure[ind],
|
||||
color=color, **plateau_line_kwargs)
|
||||
big_axes[2].legend(**leg_kwargs)
|
||||
|
||||
# handles = plot_dist_shifted(big_axes[2], species_threshs, axis=pdf_axis,
|
||||
# pdf=thresh_pdf, **plateau_dot_kwargs)[0]
|
||||
# [h.set_color(species_colors[s]) for h, s in zip(handles, target_species)]
|
||||
|
||||
legend = big_axes[2].legend(**leg_kwargs)
|
||||
[h.set_lw(lw['legend']) for h in legend.legend_handles]
|
||||
|
||||
if save_path is not None:
|
||||
fig.savefig(save_path, bbox_inches='tight')
|
||||
|
||||
Reference in New Issue
Block a user