Overhauled Thresh-LP analysis and figures (WIP).
This commit is contained in:
@@ -12,25 +12,29 @@ data_paths = glob.glob(f'../data/processed/{target}*.npz')
|
||||
save_path = '../data/inv/log_hp/'
|
||||
|
||||
# ANALYSIS SETTINGS:
|
||||
add_noise = False
|
||||
add_noise = True
|
||||
single_db_ref = True
|
||||
# find_saturation = add_noise and False
|
||||
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]
|
||||
scales = np.unique(np.concatenate((scales, example_scales)))
|
||||
# if find_saturation:
|
||||
# scales = np.append(scales, 10e10)
|
||||
|
||||
# EXECUTION:
|
||||
for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
print(f'Processing {name}')
|
||||
|
||||
# Get normalized song envelope:
|
||||
# Get song envelope:
|
||||
data, config = load_data(data_path, files='env')
|
||||
song, rate = data['env'], config['env_rate']
|
||||
song /= song.std()
|
||||
|
||||
# Get song segment to be analyzed:
|
||||
time = np.arange(song.shape[0]) / rate
|
||||
start, end = data['songs_0'].ravel()
|
||||
segment = (time >= start) & (time <= end)
|
||||
|
||||
# Normalize song component:
|
||||
song /= song[segment].std()
|
||||
|
||||
# Rescale song component:
|
||||
mix = song[:, None] * scales[None, :]
|
||||
@@ -40,7 +44,7 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
rng = np.random.default_rng()
|
||||
noise = rng.normal(size=song.shape)
|
||||
noise = extract_env(noise, rate, config=config)
|
||||
noise /= noise.std()
|
||||
noise /= noise[segment].std()
|
||||
mix += noise[:, None]
|
||||
|
||||
# Process mixture:
|
||||
@@ -49,17 +53,9 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
padtype='constant', padlen=config['padlen'])
|
||||
|
||||
# Get "intensity measure" per stage:
|
||||
measure_env = mix.std(axis=0)
|
||||
measure_log = mix_log.std(axis=0)
|
||||
measure_inv = mix_inv.std(axis=0)
|
||||
|
||||
# # Find saturation level:
|
||||
# if find_saturation:
|
||||
# limit = measure_inv[-1]
|
||||
# scales = scales[:-1]
|
||||
# measure_env = measure_env[:-1]
|
||||
# measure_log = measure_log[:-1]
|
||||
# measure_inv = measure_inv[:-1]
|
||||
measure_env = mix[segment, :].std(axis=0)
|
||||
measure_log = mix_log[segment, :].std(axis=0)
|
||||
measure_inv = mix_inv[segment, :].std(axis=0)
|
||||
|
||||
# Save analysis results:
|
||||
save_inds = np.nonzero(np.isin(scales, example_scales))[0]
|
||||
@@ -74,8 +70,6 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
measure_log=measure_log,
|
||||
measure_inv=measure_inv,
|
||||
)
|
||||
# if find_saturation:
|
||||
# data['limit'] = limit
|
||||
file_name = save_path + name
|
||||
if add_noise:
|
||||
file_name += '_noise'
|
||||
|
||||
Reference in New Issue
Block a user