annotate tests/test_load_features.py @ 3:230a0cf17de0 branch-tests

tests speech
author Maria Panteli
date Mon, 11 Sep 2017 11:32:45 +0100
parents dfd984dbfaea
children a35bd818d8e9
rev   line source
m@2 1 # -*- coding: utf-8 -*-
m@2 2 """
m@2 3 Created on Fri Sep 1 19:11:52 2017
m@2 4
m@2 5 @author: mariapanteli
m@2 6 """
m@2 7
m@2 8 import pytest
m@2 9
m@2 10 import numpy as np
m@2 11
Maria@3 12 import scripts.load_features as load_features
m@2 13
m@2 14 feat_loader = load_features.FeatureLoader(win2sec=8)
m@2 15
Maria@3 16
m@2 17 def test_get_music_idx_from_bounds():
Maria@3 18 bounds = np.array([['0', '10.5', 'm']])#,
Maria@3 19 #['10.5', '12.0', 's'],
Maria@3 20 #['12.0', '30.0', 'm']])
Maria@3 21 sr = feat_loader.framessr2
Maria@3 22 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
Maria@3 23 # upper bound minus half window size
Maria@3 24 half_win_sec = 4.0 # assume 8-second window
Maria@3 25 music_bounds_true = np.arange(np.round(sr * (np.float(bounds[-1, 1]) - half_win_sec)), dtype=int)
Maria@3 26 assert np.array_equal(music_bounds, music_bounds_true)
Maria@3 27
Maria@3 28
Maria@3 29 def test_get_music_idx_from_bounds_short_segment():
Maria@3 30 # anything less than half window size is not processed
Maria@3 31 bounds = np.array([['0', '3.8', 'm']])
Maria@3 32 sr = feat_loader.framessr2
Maria@3 33 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
Maria@3 34 music_bounds_true = np.array([])
Maria@3 35 assert np.array_equal(music_bounds, music_bounds_true)
Maria@3 36
Maria@3 37
Maria@3 38 def test_get_music_idx_from_bounds_mix_segments():
m@2 39 bounds = np.array([['0', '10.5', 'm'],
Maria@3 40 ['10.5', '3.0', 's'],
Maria@3 41 ['13.5', '5.0', 'm']])
m@2 42 sr = feat_loader.framessr2
m@2 43 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
Maria@3 44 music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5-4.0)), dtype=int),
Maria@3 45 np.arange(np.round(sr * (13.5-4.0)), np.round(sr * (18.5-4.0)), dtype=int)])
m@2 46 assert np.array_equal(music_bounds, music_bounds_true)
Maria@3 47