Mercurial > hg > plosone_underreview
comparison 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 |
comparison
equal
deleted
inserted
replaced
5:543744ed1ae7 | 6:a35bd818d8e9 |
---|---|
13 | 13 |
14 feat_loader = load_features.FeatureLoader(win2sec=8) | 14 feat_loader = load_features.FeatureLoader(win2sec=8) |
15 | 15 |
16 | 16 |
17 def test_get_music_idx_from_bounds(): | 17 def test_get_music_idx_from_bounds(): |
18 bounds = np.array([['0', '10.5', 'm']])#, | 18 bounds = np.array([['0', '10.5', 'm']]) |
19 #['10.5', '12.0', 's'], | |
20 #['12.0', '30.0', 'm']]) | |
21 sr = feat_loader.framessr2 | 19 sr = feat_loader.framessr2 |
22 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | 20 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) |
23 # upper bound minus half window size | 21 # upper bound minus half window size |
24 half_win_sec = 4.0 # assume 8-second window | 22 half_win_sec = 4.0 # assume 8-second window |
25 music_bounds_true = np.arange(np.round(sr * (np.float(bounds[-1, 1]) - half_win_sec)), dtype=int) | 23 music_bounds_true = np.arange(np.round(sr * (np.float(bounds[-1, 1]) - half_win_sec)), dtype=int) |
27 | 25 |
28 | 26 |
29 def test_get_music_idx_from_bounds_short_segment(): | 27 def test_get_music_idx_from_bounds_short_segment(): |
30 # anything less than half window size is not processed | 28 # anything less than half window size is not processed |
31 bounds = np.array([['0', '3.8', 'm']]) | 29 bounds = np.array([['0', '3.8', 'm']]) |
32 sr = feat_loader.framessr2 | 30 sr = feat_loader.framessr2 |
33 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | 31 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) |
34 music_bounds_true = np.array([]) | 32 music_bounds_true = np.array([]) |
33 assert np.array_equal(music_bounds, music_bounds_true) | |
34 | |
35 | |
36 def test_get_music_idx_from_bounds_single_frame(): | |
37 bounds = np.array([['0', '4.3', 'm']]) | |
38 sr = feat_loader.framessr2 | |
39 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | |
40 music_bounds_true = np.array([0]) | |
35 assert np.array_equal(music_bounds, music_bounds_true) | 41 assert np.array_equal(music_bounds, music_bounds_true) |
36 | 42 |
37 | 43 |
38 def test_get_music_idx_from_bounds_mix_segments(): | 44 def test_get_music_idx_from_bounds_mix_segments(): |
39 bounds = np.array([['0', '10.5', 'm'], | 45 bounds = np.array([['0', '10.5', 'm'], |
40 ['10.5', '3.0', 's'], | 46 ['10.5', '3.0', 's'], |
41 ['13.5', '5.0', 'm']]) | 47 ['13.5', '5.0', 'm']]) |
42 sr = feat_loader.framessr2 | 48 sr = feat_loader.framessr2 |
43 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | 49 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) |
44 music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5-4.0)), dtype=int), | 50 half_win_sec = 4.0 # assume 8-second window |
45 np.arange(np.round(sr * (13.5-4.0)), np.round(sr * (18.5-4.0)), dtype=int)]) | 51 music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int), |
52 np.arange(np.round(sr * (13.5 - half_win_sec)), | |
53 np.round(sr * (18.5 - half_win_sec)), dtype=int)]) | |
46 assert np.array_equal(music_bounds, music_bounds_true) | 54 assert np.array_equal(music_bounds, music_bounds_true) |
47 | 55 |
56 | |
57 def test_get_music_idx_from_bounds_overlap_segments(): | |
58 bounds = np.array([['0', '10.5', 'm'], | |
59 ['9.5', '3.0', 's'], | |
60 ['11.5', '5.0', 'm']]) | |
61 sr = feat_loader.framessr2 | |
62 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | |
63 half_win_sec = 4.0 # assume 8-second window | |
64 music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int), | |
65 np.arange(np.round(sr * (11.5 - half_win_sec)), | |
66 np.round(sr * (16.5 - half_win_sec)), dtype=int)]) | |
67 assert np.array_equal(music_bounds, music_bounds_true) | |
68 | |
69 |