changeset 2:dfd984dbfaea branch-tests

started tests
author Maria Panteli <m.x.panteli@gmail.com>
date Fri, 01 Sep 2017 19:25:52 +0300
parents f4ea2872bd62
children 230a0cf17de0
files load_features.py tests/test_load_features.py
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/load_features.py	Fri Sep 01 18:51:59 2017 +0300
+++ b/load_features.py	Fri Sep 01 19:25:52 2017 +0300
@@ -12,7 +12,6 @@
 import OPMellin as opm
 import MFCC as mfc
 import PitchBihist as pbi
-import contour_features
 
 
 class FeatureLoader:
@@ -61,21 +60,6 @@
             ch = (ch - np.nanmean(ch)) / np.nanstd(ch)                        
         return ch
     
-    
-    def get_contour_feat_from_melodia(self, melodia_file=None, scale=True):
-        cf = []
-        if not os.path.exists(melodia_file):
-            return cf
-        print 'extracting contour features...'
-        cf = contour_features.extract_features_for_file(melodia_file=melodia_file, win2_sec=self.win2sec, stop_sec=90.0)  # only first 1.5 minutes
-        cf = pd.DataFrame(cf.T)
-        if scale:
-            # scale all frames by mean and std of recording
-            cf = cf - np.nanmean(cf)
-            if np.nanstd(cf) > 0:
-                 cf = cf / np.nanstd(cf)
-        return cf
-    
         
     def get_music_idx_from_bounds(self, bounds, sr=None):
         music_idx = []
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_load_features.py	Fri Sep 01 19:25:52 2017 +0300
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Sep  1 19:11:52 2017
+
+@author: mariapanteli
+"""
+
+import pytest
+
+import numpy as np
+
+import 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)
+    music_bounds_true = np.arange(np.round(sr * np.float(bounds[-1, 1])))
+    assert np.array_equal(music_bounds, music_bounds_true)
+    
+test_get_music_idx_from_bounds()
\ No newline at end of file