view 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
line wrap: on
line source
# -*- coding: utf-8 -*-
"""
Created on Fri Sep  1 19:11:52 2017

@author: mariapanteli
"""

import pytest

import numpy as np

import scripts.load_features as load_features

feat_loader = load_features.FeatureLoader(win2sec=8)


def test_get_music_idx_from_bounds():
    bounds = np.array([['0', '10.5', 'm']])#, 
              #['10.5', '12.0', 's'],
              #['12.0', '30.0', 'm']])
    sr = feat_loader.framessr2            
    music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
    # upper bound minus half window size
    half_win_sec = 4.0  # assume 8-second window
    music_bounds_true = np.arange(np.round(sr * (np.float(bounds[-1, 1]) - half_win_sec)), dtype=int)
    assert np.array_equal(music_bounds, music_bounds_true)
    
    
def test_get_music_idx_from_bounds_short_segment():
    # anything less than half window size is not processed
    bounds = np.array([['0', '3.8', 'm']])
    sr = feat_loader.framessr2            
    music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
    music_bounds_true = np.array([])
    assert np.array_equal(music_bounds, music_bounds_true)


def test_get_music_idx_from_bounds_mix_segments():
    bounds = np.array([['0', '10.5', 'm'], 
              ['10.5', '3.0', 's'],
              ['13.5', '5.0', 'm']])
    sr = feat_loader.framessr2
    music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr)
    music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5-4.0)), dtype=int),
                                        np.arange(np.round(sr * (13.5-4.0)), np.round(sr * (18.5-4.0)), dtype=int)])
    assert np.array_equal(music_bounds, music_bounds_true)