Mercurial > hg > plosone_underreview
comparison tests/test_PitchBihist.py @ 37:2cc444441f42 branch-tests
refactor pitchbihist and introduce default melody_sr
author | Maria Panteli |
---|---|
date | Thu, 14 Sep 2017 14:50:00 +0100 |
parents | 3b67cd634b9a |
children | 0e70021f251e |
comparison
equal
deleted
inserted
replaced
36:3b67cd634b9a | 37:2cc444441f42 |
---|---|
30 | 30 |
31 | 31 |
32 def test_get_melody_from_file(): | 32 def test_get_melody_from_file(): |
33 melodia_file = 'data/sample_dataset/Melodia/mel_1_2_1.csv' | 33 melodia_file = 'data/sample_dataset/Melodia/mel_1_2_1.csv' |
34 melody = pbi.get_melody_from_file(melodia_file) | 34 melody = pbi.get_melody_from_file(melodia_file) |
35 assert len(melody) < 12. * pbi.chromasr | 35 assert len(melody) < 12. * pbi.melody_sr |
36 | 36 |
37 | 37 |
38 def test_get_melody_matrix(): | 38 def test_get_melody_matrix(): |
39 melody = 440 * np.ones(1000) | 39 melody = 440 * np.ones(1000) |
40 melody_matrix = pbi.get_melody_matrix(melody) | 40 melody_matrix = pbi.get_melody_matrix(melody) |
70 bihist = pbi.bihistogram(melody_matrix, align=False) | 70 bihist = pbi.bihistogram(melody_matrix, align=False) |
71 # expect only element [45, 0] to be non-zero | 71 # expect only element [45, 0] to be non-zero |
72 assert bihist[45, 0] > 0 and (np.sum(bihist) - bihist[45, 0]) == 0 | 72 assert bihist[45, 0] > 0 and (np.sum(bihist) - bihist[45, 0]) == 0 |
73 | 73 |
74 | 74 |
75 | 75 def test_bihistogram_align(): |
76 melody = np.concatenate([660 * np.ones(250), 440 * np.ones(500)]) | |
77 melody_matrix = pbi.get_melody_matrix(melody) | |
78 # bin of max magnitude = A = 45/60 | |
79 bihist = pbi.bihistogram(melody_matrix, align=True) | |
80 # bihist[20, 45] == 0 | |
81 # we shift up 45 so rows 20-45 and left 45 so cols 45-45 | |
82 assert bihist[20-45, 0] == 1 |