Mercurial > hg > plosone_underreview
comparison tests/test_load_features.py @ 34:115774aff442 branch-tests
music bounds not centered but aligned with start of segment to match the way features are computed
author | Maria Panteli |
---|---|
date | Thu, 14 Sep 2017 10:16:59 +0100 |
parents | 0f3eba42b425 |
children | c4428589b82b |
comparison
equal
deleted
inserted
replaced
33:928d9bf9224f | 34:115774aff442 |
---|---|
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 sr = feat_loader.framessr2 | 19 sr = feat_loader.framessr2 |
20 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) |
21 # upper bound minus half window size | 21 # upper bound minus half window size |
22 half_win_sec = 4.0 # assume 8-second window | 22 #half_win_sec = 4.0 # assume 8-second window |
23 music_bounds_true = np.arange(np.round(sr * (np.float(bounds[-1, 1]) - half_win_sec)), dtype=int) | 23 win_sec = 8 |
24 music_bounds_true = np.arange(np.round(sr * (np.float(bounds[-1, 1]) - win_sec)), dtype=int) | |
24 assert np.array_equal(music_bounds, music_bounds_true) | 25 assert np.array_equal(music_bounds, music_bounds_true) |
25 | 26 |
26 | 27 |
27 def test_get_music_idx_from_bounds_short_segment(): | 28 def test_get_music_idx_from_bounds_short_segment(): |
28 # anything less than half window size is not processed | 29 # anything less than half window size is not processed |
29 bounds = np.array([['0', '3.8', 'm']]) | 30 bounds = np.array([['0', '7.9', 'm']]) |
30 sr = feat_loader.framessr2 | 31 sr = feat_loader.framessr2 |
31 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | 32 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) |
32 music_bounds_true = np.array([]) | 33 music_bounds_true = np.array([]) |
33 assert np.array_equal(music_bounds, music_bounds_true) | 34 assert np.array_equal(music_bounds, music_bounds_true) |
34 | 35 |
35 | 36 |
36 def test_get_music_idx_from_bounds_single_frame(): | 37 def test_get_music_idx_from_bounds_single_frame(): |
37 bounds = np.array([['0', '4.3', 'm']]) | 38 bounds = np.array([['0', '8.1', 'm']]) |
38 sr = feat_loader.framessr2 | 39 sr = feat_loader.framessr2 |
39 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | 40 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) |
40 music_bounds_true = np.array([0]) | 41 music_bounds_true = np.array([0]) |
41 assert np.array_equal(music_bounds, music_bounds_true) | 42 assert np.array_equal(music_bounds, music_bounds_true) |
42 | 43 |
43 | 44 |
45 bounds = np.array([['0', '10.5', 'm'], | 46 bounds = np.array([['0', '10.5', 'm'], |
46 ['10.5', '3.0', 's'], | 47 ['10.5', '3.0', 's'], |
47 ['13.5', '5.0', 'm']]) | 48 ['13.5', '5.0', 'm']]) |
48 sr = feat_loader.framessr2 | 49 sr = feat_loader.framessr2 |
49 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | 50 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) |
50 half_win_sec = 4.0 # assume 8-second window | 51 #half_win_sec = 4.0 # assume 8-second window |
51 music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int), | 52 win_sec = 8.0 # assume 8-second window |
52 np.arange(np.round(sr * (13.5 - half_win_sec)), | 53 music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - win_sec)), dtype=int), |
53 np.round(sr * (18.5 - half_win_sec)), dtype=int)]) | 54 np.arange(np.round(sr * 13.5), |
55 np.round(sr * (18.5 - win_sec)), dtype=int)]) | |
54 assert np.array_equal(music_bounds, music_bounds_true) | 56 assert np.array_equal(music_bounds, music_bounds_true) |
55 | 57 |
56 | 58 |
57 def test_get_music_idx_from_bounds_overlap_segments(): | 59 def test_get_music_idx_from_bounds_overlap_segments(): |
58 bounds = np.array([['0', '10.5', 'm'], | 60 bounds = np.array([['0', '10.5', 'm'], |
59 ['9.5', '3.0', 's'], | 61 ['9.5', '3.0', 's'], |
60 ['11.5', '5.0', 'm']]) | 62 ['11.5', '5.0', 'm']]) |
61 sr = feat_loader.framessr2 | 63 sr = feat_loader.framessr2 |
62 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) | 64 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) |
63 half_win_sec = 4.0 # assume 8-second window | 65 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), | 66 win_sec = 8.0 # assume 8-second window |
65 np.arange(np.round(sr * (11.5 - half_win_sec)), | 67 music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - win_sec)), dtype=int), |
66 np.round(sr * (16.5 - half_win_sec)), dtype=int)]) | 68 np.arange(np.round(sr * 11.5), |
69 np.round(sr * (16.5 - win_sec)), dtype=int)]) | |
67 assert np.array_equal(music_bounds, music_bounds_true) | 70 assert np.array_equal(music_bounds, music_bounds_true) |
68 | 71 |
69 | 72 |
70 def test_average_local_frames(): | 73 def test_average_local_frames(): |
71 frames = np.array([[0, 0.5, 1], [1, 1, 1]]) | 74 frames = np.array([[0, 0.5, 1], [1, 1, 1]]) |