Mercurial > hg > simscene-py
changeset 9:53ee437b5ba3
added a proper piano roll; fixed a bug with plotting the final scene, added another verbosity level
author | Emmanouil Thoefanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Tue, 03 Oct 2017 15:18:08 +0100 |
parents | 0f8d8ff0ece7 |
children | 8637c974b4bc |
files | simscene.py |
diffstat | 1 files changed, 29 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/simscene.py Tue Oct 03 13:56:15 2017 +0100 +++ b/simscene.py Tue Oct 03 15:18:08 2017 +0100 @@ -26,6 +26,8 @@ import librosa.output # Matplotlib +from matplotlib import rc +# rc('text', usetex=True) import matplotlib.pyplot as plt import matplotlib.patches as patches from cycler import cycler @@ -222,7 +224,6 @@ while new_start_time < track_end_time: offset = float(mean_time_between_instances) +\ float(events_df['time_between_instances_stddev'].loc[n]*np.random.randn()) - logging.debug(offset) new_start_time += offset new_end_time += offset @@ -267,7 +268,8 @@ Fdb = librosa.amplitude_to_db(F) plt.subplot(2,1,2) librosa.display.specshow(Fdb, sr=SR, x_axis='time', y_axis='hz') - plt.savefig('{}/{}.{}'.format(output_path, label, image_format)) + plt.tight_layout() + plt.savefig('{}/{}.{}'.format(output_path, label, image_format),dpi=300) scene_starting_times.append((label, start_times)) @@ -275,42 +277,44 @@ if figure_verbosity > 0: plt.figure() - plt.subplot(3,1,1) - plt.title('Waveform and spectrogram for the full track') - librosa.display.waveplot(scene_arr) + ax0 = plt.subplot(3,1,1) + plt.title('Synthesized Scene') + librosa.display.waveplot(scene_arr, sr=SR) F = librosa.stft(scene_arr) Fdb = librosa.amplitude_to_db(F) - plt.subplot(3,1,2) + ax1 = plt.subplot(3,1,2) librosa.display.specshow(Fdb, sr=SR, x_axis='time', y_axis='hz') - ax = plt.subplot(3,1,3) - ax.set_xlim([0,scene_duration]) - ax.set_ylim([-0.5, len(scene_starting_times)-0.5]) + ax2 = plt.subplot(3,1,3) + ax2.set_xlim([0,scene_duration]) + ax2.set_ylim([-0.5, len(scene_starting_times)-0.5]) # Get labels labels = [s[0] for s in scene_starting_times] plt.yticks(range(len(scene_starting_times)), labels) - plt.rc('lines', linewidth=4) - plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) + - cycler('linestyle', ['-', '--', ':', '-.']))) - for n in range(len(scene_starting_times)): label = scene_starting_times[n][0] start_times = scene_starting_times[n][1] end_times = scene_ending_times[n][1] + color = ['r', 'g', 'y'][n % 3] + for m in range(len(start_times)): - plt.axhline(float(n), start_times[m], start_times[m]+1.0) - # for m in range(len(start_times)): - # plt.text( - # start_times[m], - # n, - # label, - # size=9,ha='center',va='center', - # bbox=dict(boxstyle='square', ec=(1., 0.5, 0.5), fc=(1., 1-n/float(len(scene_starting_times)), n/float(len(scene_starting_times)))), - # ) - - plt.savefig('{}/full-scene.{}'.format(output_path, image_format)) + plt.hlines(y=float(n), xmin=start_times[m], xmax=end_times[m], alpha=0.5, color=color, linewidth=4) + if figure_verbosity > 2: + ax0.axvline(start_times[m], color=color, alpha=0.1) + ax0.axvline(end_times[m], color=color, alpha=0.1) + ax0.axvspan(start_times[m], end_times[m], color=color, alpha=0.1) + ax1.axvline(start_times[m], color=color, alpha=0.1) + ax1.axvline(end_times[m], color=color, alpha=0.1) + ax1.axvline(end_times[m], color=color, alpha=0.1) + ax1.axvspan(start_times[m], end_times[m], color=color, alpha=0.1) + ax2.axvline(start_times[m], color=color, alpha=0.1) + ax2.axvline(end_times[m], color=color, alpha=0.1) + ax2.axvline(end_times[m], color=color, alpha=0.1) + ax2.axvspan(start_times[m], end_times[m], color=color, alpha=0.1) + plt.tight_layout() + plt.savefig('{}/full-scene.{}'.format(output_path, image_format),dpi=300) if figure_verbosity > 1: plt.show() @@ -396,7 +400,7 @@ argparser.add_argument( '-v', '--figure-verbosity', action='count', - help="Increase figure verbosity. (Default) 0 - Don't save or display figures, 1 - Save pictures but do not display them, 2 - Save and display figures" + help="Increase figure verbosity. (Default) 0 - Don't save or display figures, 1 - Save pictures but do not display them, 2 - Save and display figures, 3 - Add shades over the events in the final plot" ) figure_verbosity = None