#####################################
params = tune_window_preprocessing_params(audio_dirs, params)

###################################################
# 2) Train a generative model on these syllables. #
###################################################
partition = get_window_partition(audio_dirs, roi_dirs, 1)
partition['test'] = partition['train']
num_workers = min(7, os.cpu_count() - 1)
loaders = get_fixed_window_data_loaders(partition, params, \
 num_workers=num_workers, batch_size=128)
loaders['test'] = loaders['train']
model = VAE(save_dir=root)
model.train_loop(loaders, epochs=101, test_freq=None)

########################
# 3) Plot and analyze. #
########################
from ava.plotting.tooltip_plot import tooltip_plot_DC
from ava.plotting.latent_projection import latent_projection_plot_DC
from ava.plotting.trace_plot import warped_trace_plot_DC

loaders['test'].dataset.write_hdf5_files(spec_dirs[0], num_files=1000)
latent_projection_plot_DC(dc, alpha=0.25, s=0.5)
tooltip_plot_DC(dc, num_imgs=2000)

if __name__ == '__main__':
    pass

###
model = VAE(save_dir=root)
model.train_loop(loaders, epochs=101, save_freq=20, test_freq=None)

#############
# 3) Plot . #
#############
from ava.plotting.tooltip_plot import tooltip_plot_DC
from ava.plotting.latent_projection import latent_projection_plot_DC

# Write random spectrograms into a single directory.
loaders['test'].dataset.write_hdf5_files(spec_dirs[0], num_files=1000)

# Redefine the DataContainer so it only looks in that single directory.
temp_dc = DataContainer(projection_dirs=proj_dirs[:1], \
 audio_dirs=audio_dirs[:1], spec_dirs=spec_dirs[:1], plots_dir=root, \
 model_filename=model_filename)

latent_projection_plot_DC(temp_dc, alpha=0.25, s=0.5)
tooltip_plot_DC(temp_dc, num_imgs=2000)

################################
# 4) The world is your oyster. #
################################
latent = dc.request('latent_means')
pass

if __name__ == '__main__':
    pass

###