Mercurial > hg > plosone_underreview
diff tests/test_load_features.py @ 6:a35bd818d8e9 branch-tests
notebook to test music segments
author | Maria Panteli <m.x.panteli@gmail.com> |
---|---|
date | Mon, 11 Sep 2017 14:22:17 +0100 |
parents | 230a0cf17de0 |
children | 0f3eba42b425 |
line wrap: on
line diff
--- a/tests/test_load_features.py Mon Sep 11 12:01:28 2017 +0100 +++ b/tests/test_load_features.py Mon Sep 11 14:22:17 2017 +0100 @@ -15,9 +15,7 @@ def test_get_music_idx_from_bounds(): - bounds = np.array([['0', '10.5', 'm']])#, - #['10.5', '12.0', 's'], - #['12.0', '30.0', 'm']]) + bounds = np.array([['0', '10.5', 'm']]) sr = feat_loader.framessr2 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) # upper bound minus half window size @@ -29,19 +27,43 @@ def test_get_music_idx_from_bounds_short_segment(): # anything less than half window size is not processed bounds = np.array([['0', '3.8', 'm']]) - sr = feat_loader.framessr2 + sr = feat_loader.framessr2 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) music_bounds_true = np.array([]) assert np.array_equal(music_bounds, music_bounds_true) +def test_get_music_idx_from_bounds_single_frame(): + bounds = np.array([['0', '4.3', 'm']]) + sr = feat_loader.framessr2 + music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) + music_bounds_true = np.array([0]) + assert np.array_equal(music_bounds, music_bounds_true) + + def test_get_music_idx_from_bounds_mix_segments(): bounds = np.array([['0', '10.5', 'm'], ['10.5', '3.0', 's'], ['13.5', '5.0', 'm']]) sr = feat_loader.framessr2 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) - music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5-4.0)), dtype=int), - np.arange(np.round(sr * (13.5-4.0)), np.round(sr * (18.5-4.0)), dtype=int)]) + half_win_sec = 4.0 # assume 8-second window + music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int), + np.arange(np.round(sr * (13.5 - half_win_sec)), + np.round(sr * (18.5 - half_win_sec)), dtype=int)]) assert np.array_equal(music_bounds, music_bounds_true) - \ No newline at end of file + + +def test_get_music_idx_from_bounds_overlap_segments(): + bounds = np.array([['0', '10.5', 'm'], + ['9.5', '3.0', 's'], + ['11.5', '5.0', 'm']]) + sr = feat_loader.framessr2 + music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) + half_win_sec = 4.0 # assume 8-second window + music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int), + np.arange(np.round(sr * (11.5 - half_win_sec)), + np.round(sr * (16.5 - half_win_sec)), dtype=int)]) + assert np.array_equal(music_bounds, music_bounds_true) + +