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

@@ -42,6 +42,7 @@ target_species = ['Pseudochorthippus_parallelus']
mode = ['song', 'noise'][0]
stages = ['raw', 'filt', 'env', 'log', 'inv', 'conv', 'feat']
search_path = f'../data/inv/field/{mode}/'
ref_path = f'../data/inv/field/ref_measures.npz'
save_path = f'../data/inv/field/{mode}/condensed/'
sources = [
'JJ',
@@ -53,16 +54,27 @@ normalization = 'none'
if mode == 'song':
normalization = [
'none',
# 'base',
'min',
'max',
'base',
'range'
][-1]
][1]
suffix = dict(
none='_unnormed',
min='_norm-min',
max='_norm-max',
base='_norm-base',
range='_norm-range'
)[normalization]
if normalization == 'base':
ref_data = dict(np.load(ref_path))
# EXECUTION:
for i, species in enumerate(target_species):
print(f'Processing {species}')
# Fetch all species-specific song files:
all_paths = search_files(species, ext='npz', dir=search_path)
all_paths = search_files(species, excl='merged_noise', ext='npz', dir=search_path)
if not all_paths:
continue
@@ -94,7 +106,17 @@ for i, species in enumerate(target_species):
for stage in stages:
mkey = f'measure_{stage}'
if normalization == 'range':
if normalization == 'min':
# Minimum normalization:
data[mkey] /= data[mkey].min(axis=0, keepdims=True)
elif normalization == 'max':
# Maximum normalization:
data[mkey] /= data[mkey].max(axis=0, keepdims=True)
elif normalization == 'base':
# Noise baseline normalization:
data[mkey] /= ref_data[stage]
# data[mkey] /= data[mkey][0]
elif normalization == 'range':
# Min-max normalization:
min_measure = data[mkey].min(axis=0, keepdims=True)
max_measure = data[mkey].max(axis=0, keepdims=True)
@@ -106,18 +128,15 @@ for i, species in enumerate(target_species):
for stage in stages:
rec_mean[f'mean_{stage}'][..., j] = np.nanmean(file_data[stage], axis=-1)
rec_sd[f'sd_{stage}'][..., j] = np.nanstd(file_data[stage], axis=-1)
if len(sorted_paths) == 1:
# Prune recording dimension for single recording:
rec_mean[f'mean_{stage}'] = rec_mean[f'mean_{stage}'][..., 0]
rec_sd[f'sd_{stage}'] = rec_sd[f'sd_{stage}'][..., 0]
# Save condensed recording data:
save_name = save_path + species
if normalization == 'none':
save_name += '_unnormed'
elif normalization == 'base':
save_name += '_norm-base'
elif normalization == 'range':
save_name += '_norm-range'
archive = dict(distances=data['distances'])
archive.update(rec_mean)
archive.update(rec_sd)
save_data(save_name, archive, config, overwrite=True)
save_data(save_path + species + suffix, archive, config, overwrite=True)
print('Done.')