<commit_before>#!/usr/bin/env python
# CREATED:2013-03-11 18:14:30 by <NAME> <<EMAIL>>
#  unit tests for librosa.beat


import librosa, numpy

from testLibrosaCore import files, load

def test_onset_strength():

    def __test(infile):
        DATA    = load(infile)

        # Compute onset envelope using the same spectrogram
        onsets  = librosa.onset.onset_strength(y=None, sr=8000, S=DATA['D'])

        assert numpy.allclose(onsets, DATA['onsetenv'][0])

        pass

    for infile in files('data/beat-onset-*.mat'):
        yield (__test, infile)
    pass

def test_tempo():
    def __test(infile):
        DATA    = load(infile)

        # Estimate tempo from the given onset envelope
        tempo   = librosa.beat.onset_estimate_bpm(  DATA['onsetenv'][0], 
                                                    120.0,  # starting bpm
                                                    8000 / 32)

        assert  (numpy.allclose(tempo, DATA['t'][0,0]) or 
                 numpy.allclose(tempo, DATA['t'][0,1]))
        pass

    for infile in files('data/beat-tempo-*.mat'):
        yield (__test, infile)
    pass

def test_beat():
    def __test(infile):
        DATA    = load(infile)
        
        (bpm, beats) = librosa.beat.beat_track(y=None, sr=8000, hop_length=32,
                                               onsets=DATA['onsetenv'][0], n_fft=None)

        print beats
        print DATA['beats']
        assert numpy.allclose(librosa.frames_to_time(beats, sr=8000, hop_length=32), DATA['beats'])
        pass
    for infile in files('data/beat-beat-*.mat'):
        yield (__test, infile)
    pass
<commit_msg>cleanup in beat unit test<commit_after>#!/usr/bin/env python
# CREATED:2013-03-11 18:14:30 by <NAME> <<EMAIL>>
#  unit tests for librosa.beat


import librosa, numpy

from testLibrosaCore import files, load

def test_onset_strength():

    def __test(infile):
        DATA    = load(infile)

        # Compute onset envelope using the same spectrogram
        onsets  = librosa.onset.onset_strength(y=None, sr=8000, S=DATA['D'])

        assert numpy.allclose(onsets, DATA['onsetenv'][0])

        pass

    for infile in files('data/beat-onset-*.mat'):
        yield (__test, infile)
    pass

def test_tempo():
    def __test(infile):
        DATA    = load(infile)

        # Estimate tempo from the given onset envelope
        tempo   = librosa.beat.onset_estimate_bpm(  DATA['onsetenv'][0], 
                                                    120.0,  # starting bpm
                                                    8000 / 32)

        assert  (numpy.allclose(tempo, DATA['t'][0,0]) or 
                 numpy.allclose(tempo, DATA['t'][0,1]))
        pass

    for infile in files('data/beat-tempo-*.mat'):
        yield (__test, infile)
    pass

def test_beat():
    def __test(infile):
        DATA    = load(infile)
        
        (bpm, beats) = librosa.beat.beat_track(y=None, sr=8000, hop_length=32,
                                               onsets=DATA['onsetenv'][0], n_fft=None)

        beat_times = librosa.frames_to_time(beats, sr=8000, hop_length=32)
        print beat_times
        print DATA['beats']
        assert numpy.allclose(beat_times, DATA['beats'])
        pass
    for infile in files('data/beat-beat-*.mat'):
        yield (__test, infile)
    pass

{'fraction_non_alphanumeric': 0.11904047976011994, 'fraction_numerical': 0.028185907046476763, 'mean_word_length': 1.9574468085106382, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5867508', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1038, 'n_words': 236}