Lots of stuff. Syncing to home.
This commit is contained in:
@@ -3,7 +3,6 @@ import numpy as np
|
||||
from thunderhopper.modeltools import load_data, save_data
|
||||
from thunderhopper.filetools import crop_paths
|
||||
from thunderhopper.filters import decibel, sosfilter
|
||||
from thunderhopper.model import extract_env
|
||||
from IPython import embed
|
||||
|
||||
# GENERAL SETTINGS:
|
||||
@@ -12,21 +11,18 @@ data_paths = glob.glob(f'../data/processed/{target}*.npz')
|
||||
save_path = '../data/inv/log_hp/'
|
||||
|
||||
# ANALYSIS SETTINGS:
|
||||
add_noise = True
|
||||
single_db_ref = True
|
||||
example_scales = np.array([0, 0.1, 1, 10, 100, 200])
|
||||
scales = np.geomspace(0.1, 1000, 100)
|
||||
if not add_noise:
|
||||
example_scales = example_scales[example_scales > 0]
|
||||
add_noise = False
|
||||
example_scales = np.array([0.1, 1, 10, 30, 100, 300])
|
||||
scales = np.geomspace(0.1, 10000, 1000)
|
||||
scales = np.unique(np.concatenate((scales, example_scales)))
|
||||
|
||||
# EXECUTION:
|
||||
for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
print(f'Processing {name}')
|
||||
|
||||
# Get song envelope:
|
||||
data, config = load_data(data_path, files='env')
|
||||
song, rate = data['env'], config['env_rate']
|
||||
# Get filtered song (prior to envelope extraction):
|
||||
data, config = load_data(data_path, files='filt')
|
||||
song, rate = data['filt'], config['rate']
|
||||
|
||||
# Get song segment to be analyzed:
|
||||
time = np.arange(song.shape[0]) / rate
|
||||
@@ -40,19 +36,20 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
mix = song[:, None] * scales[None, :]
|
||||
|
||||
if add_noise:
|
||||
# Add normalized noise envelope:
|
||||
# Add normalized envelopenoise:
|
||||
rng = np.random.default_rng()
|
||||
noise = rng.normal(size=song.shape)
|
||||
noise = extract_env(noise, rate, config=config)
|
||||
noise = rng.normal(scale=1, size=song.shape)
|
||||
noise /= noise[segment].std()
|
||||
mix += noise[:, None]
|
||||
|
||||
# Process mixture:
|
||||
mix_log = decibel(mix, axis=None if single_db_ref else 0)
|
||||
mix = sosfilter(np.abs(mix), rate, config['env_fcut'], 'lp',
|
||||
padtype='even', padlen=config['padlen'])
|
||||
mix_log = decibel(mix, ref=1)
|
||||
mix_inv = sosfilter(mix_log, rate, config['inv_fcut'], 'hp',
|
||||
padtype='constant', padlen=config['padlen'])
|
||||
|
||||
# Get "intensity measure" per stage:
|
||||
# Get intensity measure per stage:
|
||||
measure_env = mix[segment, :].std(axis=0)
|
||||
measure_log = mix_log[segment, :].std(axis=0)
|
||||
measure_inv = mix_inv[segment, :].std(axis=0)
|
||||
@@ -63,9 +60,9 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
data = dict(
|
||||
scales=scales,
|
||||
example_scales=example_scales,
|
||||
env=mix[:, save_inds],
|
||||
log=mix_log[:, save_inds],
|
||||
inv=mix_inv[:, save_inds],
|
||||
snip_env=mix[:, save_inds],
|
||||
snip_log=mix_log[:, save_inds],
|
||||
snip_inv=mix_inv[:, save_inds],
|
||||
measure_env=measure_env,
|
||||
measure_log=measure_log,
|
||||
measure_inv=measure_inv,
|
||||
|
||||
Reference in New Issue
Block a user