Mercurial > hg > plosone_underreview
comparison tests/test_OPMellin.py @ 39:0e70021f251e branch-tests
some tests on OPmellin
author | Maria Panteli |
---|---|
date | Thu, 14 Sep 2017 16:30:41 +0100 |
parents | |
children | 9b2beffa5fdd |
comparison
equal
deleted
inserted
replaced
38:e5e8e8a96948 | 39:0e70021f251e |
---|---|
1 # -*- coding: utf-8 -*- | |
2 """ | |
3 Created on Fri Sep 1 19:11:52 2017 | |
4 | |
5 @author: mariapanteli | |
6 """ | |
7 | |
8 import pytest | |
9 | |
10 import numpy as np | |
11 | |
12 import scripts.OPMellin as OPMellin | |
13 | |
14 | |
15 opm = OPMellin.OPMellin() | |
16 | |
17 | |
18 def test_load_audiofile(): | |
19 audiofile = 'data/sample_dataset/Audio/mel_1_2_1.wav' | |
20 opm.load_audiofile(audiofile, segment=False) | |
21 assert opm.y is not None and opm.sr is not None | |
22 | |
23 | |
24 def test_mel_spectrogram(): | |
25 audiofile = 'data/sample_dataset/Audio/mel_1_2_1.wav' | |
26 opm.load_audiofile(audiofile, segment=False) | |
27 opm.mel_spectrogram(y=opm.y, sr=opm.sr) | |
28 # assume 40 mel bands | |
29 assert opm.melspec.shape[0] == 40 | |
30 | |
31 | |
32 def test_post_process_spec(): | |
33 audiofile = 'data/sample_dataset/Audio/mel_1_2_1.wav' | |
34 opm.load_audiofile(audiofile, segment=False) | |
35 opm.mel_spectrogram(y=opm.y, sr=opm.sr) | |
36 melspec = opm.melspec | |
37 opm.post_process_spec(melspec=melspec) | |
38 proc_melspec = opm.melspec | |
39 assert melspec.shape == proc_melspec.shape | |
40 | |
41 | |
42 def test_onset_patterns_n_frames(): | |
43 audiofile = 'data/sample_dataset/Audio/mel_1_2_1.wav' | |
44 opm.load_audiofile(audiofile, segment=False) | |
45 opm.mel_spectrogram(y=opm.y, sr=opm.sr) | |
46 opm.onset_patterns(melspec=opm.melspec, melsr=opm.melsr) | |
47 assert opm.op.shape[2] == np.round(((opm.melspec.shape[1] / opm.melsr) - opm.win2sec) * 2.) | |
48 | |
49 | |
50 def test_onset_patterns_n_bins(): | |
51 audiofile = 'data/sample_dataset/Audio/mel_1_2_1.wav' | |
52 opm.load_audiofile(audiofile, segment=False) | |
53 opm.mel_spectrogram(y=opm.y, sr=opm.sr) | |
54 opm.onset_patterns(melspec=opm.melspec, melsr=opm.melsr) | |
55 assert opm.op.shape[0] == 40 | |
56 | |
57 | |
58 def test_post_process_op(): | |
59 audiofile = 'data/sample_dataset/Audio/mel_1_2_1.wav' | |
60 opm.load_audiofile(audiofile, segment=False) | |
61 opm.mel_spectrogram(y=opm.y, sr=opm.sr) | |
62 opm.onset_patterns(melspec=opm.melspec, melsr=opm.melsr) | |
63 op = opm.op | |
64 opm.post_process_op() | |
65 proc_op = opm.op | |
66 assert op.shape == proc_op.shape |