Mercurial > hg > plosone_underreview
view tests/test_load_features.py @ 6:a35bd818d8e9 branch-tests
notebook to test music segments
author | Maria Panteli <m.x.panteli@gmail.com> |
---|---|
date | Mon, 11 Sep 2017 14:22:17 +0100 |
parents | 230a0cf17de0 |
children | 0f3eba42b425 |
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']]) 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_single_frame(): bounds = np.array([['0', '4.3', 'm']]) sr = feat_loader.framessr2 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) music_bounds_true = np.array([0]) 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) half_win_sec = 4.0 # assume 8-second window music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int), np.arange(np.round(sr * (13.5 - half_win_sec)), np.round(sr * (18.5 - half_win_sec)), dtype=int)]) assert np.array_equal(music_bounds, music_bounds_true) def test_get_music_idx_from_bounds_overlap_segments(): bounds = np.array([['0', '10.5', 'm'], ['9.5', '3.0', 's'], ['11.5', '5.0', 'm']]) sr = feat_loader.framessr2 music_bounds = feat_loader.get_music_idx_from_bounds(bounds, sr=sr) half_win_sec = 4.0 # assume 8-second window music_bounds_true = np.concatenate([np.arange(np.round(sr * (10.5 - half_win_sec)), dtype=int), np.arange(np.round(sr * (11.5 - half_win_sec)), np.round(sr * (16.5 - half_win_sec)), dtype=int)]) assert np.array_equal(music_bounds, music_bounds_true)