Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mpl2 display #234

Merged
merged 5 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ before_install:
- pip install numpydoc

install:
- pip install -e .[display]
- pip install -e .[display,testing]

before_script:
- pep8 mir_eval evaluators tests

script:
- nosetests -v --with-coverage --cover-package=mir_eval
- nosetests -v --with-coverage --cover-package=mir_eval -w tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the -w tests tells nosetests it's running within the tests folder, and this is why you removed the tests prefix from all the paths?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. This way you can also execute from within the tests directory, and the tests don't have to know that they live within the tests/ directory of the repo.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool.

- python setup.py build_sphinx
- python setup.py egg_info -b.dev sdist --formats gztar

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
],
extras_require={
'display': ['matplotlib>=1.5.0',
'scipy>=0.16.0']
'scipy>=0.16.0'],
'testing': ['matplotlib>=2.0.0']
}
)
Empty file removed tests/__init__.py
Empty file.
Binary file added tests/baseline_images/test_display/events.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/baseline_images/test_display/piano_roll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/baseline_images/test_display/pitch_hz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/baseline_images/test_display/pitch_midi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/baseline_images/test_display/segment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests/baseline_images/tests.test_display/events.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/baseline_images/tests.test_display/segment.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
20 changes: 10 additions & 10 deletions tests/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ def load_separation_data(folder):
# that task will be generated.
tasks = {}
tasks['beat'] = (mir_eval.beat, mir_eval.io.load_events,
'tests/data/beat/{}*.txt')
'data/beat/{}*.txt')
tasks['chord'] = (mir_eval.chord, mir_eval.io.load_labeled_intervals,
'tests/data/chord/{}*.lab')
'data/chord/{}*.lab')
tasks['melody'] = (mir_eval.melody, mir_eval.io.load_time_series,
'tests/data/melody/{}*.txt')
'data/melody/{}*.txt')
tasks['multipitch'] = (mir_eval.multipitch,
mir_eval.io.load_ragged_time_series,
'tests/data/multipitch/()*.txt')
'data/multipitch/()*.txt')
tasks['onset'] = (mir_eval.onset, mir_eval.io.load_events,
'tests/data/onset/{}*.txt')
'data/onset/{}*.txt')
tasks['pattern'] = (mir_eval.pattern, mir_eval.io.load_patterns,
'tests/data/pattern/{}*.txt')
'data/pattern/{}*.txt')
tasks['segment'] = (mir_eval.segment, mir_eval.io.load_labeled_intervals,
'tests/data/segment/{}*.lab')
'data/segment/{}*.lab')
tasks['separation'] = (mir_eval.separation, load_separation_data,
'tests/data/separation/{}*')
'data/separation/{}*')
tasks['transcription'] = (mir_eval.transcription,
mir_eval.io.load_valued_intervals,
'tests/data/transcription/{}*.txt')
'data/transcription/{}*.txt')
tasks['key'] = (mir_eval.key, mir_eval.io.load_key,
'tests/data/key/{}*.txt')
'data/key/{}*.txt')
# Get task keys from argv
for task in sys.argv[1:]:
print('Generating data for {}'.format(task))
Expand Down
6 changes: 3 additions & 3 deletions tests/test_beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
A_TOL = 1e-12

# Path to the fixture files
REF_GLOB = 'tests/data/beat/ref*.txt'
EST_GLOB = 'tests/data/beat/est*.txt'
SCORES_GLOB = 'tests/data/beat/output*.json'
REF_GLOB = 'data/beat/ref*.txt'
EST_GLOB = 'data/beat/est*.txt'
SCORES_GLOB = 'data/beat/output*.json'


def test_trim_beats():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_chord.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
A_TOL = 1e-12

# Path to the fixture files
REF_GLOB = 'tests/data/chord/ref*.lab'
EST_GLOB = 'tests/data/chord/est*.lab'
SCORES_GLOB = 'tests/data/chord/output*.json'
REF_GLOB = 'data/chord/ref*.lab'
EST_GLOB = 'data/chord/est*.lab'
SCORES_GLOB = 'data/chord/output*.json'


def __check_valid(function, parameters, result):
Expand Down
82 changes: 38 additions & 44 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
matplotlib.use('Agg') # nopep8

import matplotlib.pyplot as plt
from matplotlib.style import context as style_context
import numpy as np

# Import the hacked image comparison module
from tests.mpl_ic import image_comparison
from mpl_ic import image_comparison

from nose.tools import raises

Expand All @@ -28,15 +27,10 @@
from mir_eval.io import load_wav


# Test fixtures will use seaborn-muted style
GLOBAL_STYLE = 'seaborn-muted'


@decorator
def styled(f, *args, **kwargs):
matplotlib.rcParams.update(matplotlib.rcParamsDefault)
with style_context(GLOBAL_STYLE):
return f(*args, **kwargs)
matplotlib.rcdefaults()
return f(*args, **kwargs)


@image_comparison(baseline_images=['segment'], extensions=['png'])
Expand All @@ -46,7 +40,7 @@ def test_display_segment():
plt.figure()

# Load some segment data
intervals, labels = load_labeled_intervals('tests/data/segment/ref00.lab')
intervals, labels = load_labeled_intervals('data/segment/ref00.lab')

# Plot the segments with no labels
mir_eval.display.segments(intervals, labels, text=False)
Expand All @@ -61,7 +55,7 @@ def test_display_segment_text():
plt.figure()

# Load some segment data
intervals, labels = load_labeled_intervals('tests/data/segment/ref00.lab')
intervals, labels = load_labeled_intervals('data/segment/ref00.lab')

# Plot the segments with no labels
mir_eval.display.segments(intervals, labels, text=True)
Expand All @@ -74,7 +68,7 @@ def test_display_labeled_intervals():
plt.figure()

# Load some chord data
intervals, labels = load_labeled_intervals('tests/data/chord/ref01.lab')
intervals, labels = load_labeled_intervals('data/chord/ref01.lab')

# Plot the chords with nothing fancy
mir_eval.display.labeled_intervals(intervals, labels)
Expand All @@ -88,7 +82,7 @@ def test_display_labeled_intervals_noextend():
plt.figure()

# Load some chord data
intervals, labels = load_labeled_intervals('tests/data/chord/ref01.lab')
intervals, labels = load_labeled_intervals('data/chord/ref01.lab')

# Plot the chords with nothing fancy
ax = plt.axes()
Expand All @@ -107,8 +101,8 @@ def test_display_labeled_intervals_compare():
plt.figure()

# Load some chord data
ref_int, ref_labels = load_labeled_intervals('tests/data/chord/ref01.lab')
est_int, est_labels = load_labeled_intervals('tests/data/chord/est01.lab')
ref_int, ref_labels = load_labeled_intervals('data/chord/ref01.lab')
est_int, est_labels = load_labeled_intervals('data/chord/est01.lab')

# Plot reference and estimates using label set extension
mir_eval.display.labeled_intervals(ref_int, ref_labels,
Expand All @@ -127,8 +121,8 @@ def test_display_labeled_intervals_compare_noextend():
plt.figure()

# Load some chord data
ref_int, ref_labels = load_labeled_intervals('tests/data/chord/ref01.lab')
est_int, est_labels = load_labeled_intervals('tests/data/chord/est01.lab')
ref_int, ref_labels = load_labeled_intervals('data/chord/ref01.lab')
est_int, est_labels = load_labeled_intervals('data/chord/est01.lab')

# Plot reference and estimate, but only use the reference labels
mir_eval.display.labeled_intervals(ref_int, ref_labels,
Expand All @@ -148,8 +142,8 @@ def test_display_labeled_intervals_compare_common():
plt.figure()

# Load some chord data
ref_int, ref_labels = load_labeled_intervals('tests/data/chord/ref01.lab')
est_int, est_labels = load_labeled_intervals('tests/data/chord/est01.lab')
ref_int, ref_labels = load_labeled_intervals('data/chord/ref01.lab')
est_int, est_labels = load_labeled_intervals('data/chord/est01.lab')

label_set = list(sorted(set(ref_labels) | set(est_labels)))

Expand All @@ -171,8 +165,8 @@ def test_display_hierarchy_nolabel():
plt.figure()

# Load some chord data
int0, lab0 = load_labeled_intervals('tests/data/hierarchy/ref00.lab')
int1, lab1 = load_labeled_intervals('tests/data/hierarchy/ref01.lab')
int0, lab0 = load_labeled_intervals('data/hierarchy/ref00.lab')
int1, lab1 = load_labeled_intervals('data/hierarchy/ref01.lab')

# Plot reference and estimate with a common label set
mir_eval.display.hierarchy([int0, int1],
Expand All @@ -188,8 +182,8 @@ def test_display_hierarchy_label():
plt.figure()

# Load some chord data
int0, lab0 = load_labeled_intervals('tests/data/hierarchy/ref00.lab')
int1, lab1 = load_labeled_intervals('tests/data/hierarchy/ref01.lab')
int0, lab0 = load_labeled_intervals('data/hierarchy/ref00.lab')
int1, lab1 = load_labeled_intervals('data/hierarchy/ref01.lab')

# Plot reference and estimate with a common label set
mir_eval.display.hierarchy([int0, int1],
Expand All @@ -204,8 +198,8 @@ def test_display_hierarchy_label():
def test_pitch_hz():
plt.figure()

ref_times, ref_freqs = load_labeled_events('tests/data/melody/ref00.txt')
est_times, est_freqs = load_labeled_events('tests/data/melody/est00.txt')
ref_times, ref_freqs = load_labeled_events('data/melody/ref00.txt')
est_times, est_freqs = load_labeled_events('data/melody/est00.txt')

# Plot pitches on a Hz scale
mir_eval.display.pitch(ref_times, ref_freqs, unvoiced=True,
Expand All @@ -220,7 +214,7 @@ def test_pitch_hz():
def test_pitch_midi():
plt.figure()

times, freqs = load_labeled_events('tests/data/melody/ref00.txt')
times, freqs = load_labeled_events('data/melody/ref00.txt')

# Plot pitches on a midi scale with note tickers
mir_eval.display.pitch(times, freqs, midi=True)
Expand All @@ -232,7 +226,7 @@ def test_pitch_midi():
def test_pitch_midi_hz():
plt.figure()

times, freqs = load_labeled_events('tests/data/melody/ref00.txt')
times, freqs = load_labeled_events('data/melody/ref00.txt')

# Plot pitches on a midi scale with note tickers
mir_eval.display.pitch(times, freqs, midi=True)
Expand All @@ -245,7 +239,7 @@ def test_pitch_midi_hz():
def test_multipitch_hz_unvoiced():
plt.figure()

times, pitches = load_ragged_time_series('tests/data/multipitch/est01.txt')
times, pitches = load_ragged_time_series('data/multipitch/est01.txt')

# Plot pitches on a midi scale with note tickers
mir_eval.display.multipitch(times, pitches, midi=False, unvoiced=True)
Expand All @@ -256,7 +250,7 @@ def test_multipitch_hz_unvoiced():
def test_multipitch_hz_voiced():
plt.figure()

times, pitches = load_ragged_time_series('tests/data/multipitch/est01.txt')
times, pitches = load_ragged_time_series('data/multipitch/est01.txt')

mir_eval.display.multipitch(times, pitches, midi=False, unvoiced=False)

Expand All @@ -266,8 +260,8 @@ def test_multipitch_hz_voiced():
def test_multipitch_midi():
plt.figure()

ref_t, ref_p = load_ragged_time_series('tests/data/multipitch/ref01.txt')
est_t, est_p = load_ragged_time_series('tests/data/multipitch/est01.txt')
ref_t, ref_p = load_ragged_time_series('data/multipitch/ref01.txt')
est_t, est_p = load_ragged_time_series('data/multipitch/est01.txt')

# Plot pitches on a midi scale with note tickers
mir_eval.display.multipitch(ref_t, ref_p, midi=True,
Expand All @@ -283,8 +277,8 @@ def test_multipitch_midi():
def test_pianoroll():
plt.figure()

ref_t, ref_p = load_valued_intervals('tests/data/transcription/ref04.txt')
est_t, est_p = load_valued_intervals('tests/data/transcription/est04.txt')
ref_t, ref_p = load_valued_intervals('data/transcription/ref04.txt')
est_t, est_p = load_valued_intervals('data/transcription/est04.txt')

mir_eval.display.piano_roll(ref_t, ref_p,
label='Reference', alpha=0.5)
Expand All @@ -299,8 +293,8 @@ def test_pianoroll():
def test_pianoroll_midi():
plt.figure()

ref_t, ref_p = load_valued_intervals('tests/data/transcription/ref04.txt')
est_t, est_p = load_valued_intervals('tests/data/transcription/est04.txt')
ref_t, ref_p = load_valued_intervals('data/transcription/ref04.txt')
est_t, est_p = load_valued_intervals('data/transcription/est04.txt')

ref_midi = mir_eval.util.hz_to_midi(ref_p)
est_midi = mir_eval.util.hz_to_midi(est_p)
Expand All @@ -327,9 +321,9 @@ def test_ticker_midi_zoom():
def test_separation():
plt.figure()

x0, fs = load_wav('tests/data/separation/ref05/0.wav')
x1, fs = load_wav('tests/data/separation/ref05/1.wav')
x2, fs = load_wav('tests/data/separation/ref05/2.wav')
x0, fs = load_wav('data/separation/ref05/0.wav')
x1, fs = load_wav('data/separation/ref05/1.wav')
x2, fs = load_wav('data/separation/ref05/2.wav')

mir_eval.display.separation([x0, x1, x2], fs=fs)

Expand All @@ -339,9 +333,9 @@ def test_separation():
def test_separation_label():
plt.figure()

x0, fs = load_wav('tests/data/separation/ref05/0.wav')
x1, fs = load_wav('tests/data/separation/ref05/1.wav')
x2, fs = load_wav('tests/data/separation/ref05/2.wav')
x0, fs = load_wav('data/separation/ref05/0.wav')
x1, fs = load_wav('data/separation/ref05/1.wav')
x2, fs = load_wav('data/separation/ref05/2.wav')

mir_eval.display.separation([x0, x1, x2], fs=fs,
labels=['Alice', 'Bob', 'Carol'])
Expand All @@ -355,8 +349,8 @@ def test_events():
plt.figure()

# Load some event data
beats_ref = mir_eval.io.load_events('tests/data/beat/ref00.txt')[:30]
beats_est = mir_eval.io.load_events('tests/data/beat/est00.txt')[:30]
beats_ref = mir_eval.io.load_events('data/beat/ref00.txt')[:30]
beats_est = mir_eval.io.load_events('data/beat/est00.txt')[:30]

# Plot both with labels
mir_eval.display.events(beats_ref, label='reference')
Expand All @@ -370,7 +364,7 @@ def test_labeled_events():
plt.figure()

# Load some event data
beats_ref = mir_eval.io.load_events('tests/data/beat/ref00.txt')[:10]
beats_ref = mir_eval.io.load_events('data/beat/ref00.txt')[:10]

labels = list('abcdefghijklmnop')
# Plot both with labels
Expand Down
6 changes: 3 additions & 3 deletions tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def __test(window, frame_size):

def test_tmeasure_regression():

ref_files = sorted(glob('tests/data/hierarchy/ref*.lab'))
est_files = sorted(glob('tests/data/hierarchy/est*.lab'))
out_files = sorted(glob('tests/data/hierarchy/output*.json'))
ref_files = sorted(glob('data/hierarchy/ref*.lab'))
est_files = sorted(glob('data/hierarchy/est*.lab'))
out_files = sorted(glob('data/hierarchy/output*.json'))

ref_hier = [mir_eval.io.load_labeled_intervals(_) for _ in ref_files]
est_hier = [mir_eval.io.load_labeled_intervals(_) for _ in est_files]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,27 @@ def test_load_ragged_time_series():

def test_load_tempo():
# Test the tempo loader
tempi, weight = mir_eval.io.load_tempo('tests/data/tempo/ref01.lab')
tempi, weight = mir_eval.io.load_tempo('data/tempo/ref01.lab')

assert np.allclose(tempi, [60, 120])
assert weight == 0.5


@nose.tools.raises(ValueError)
def test_load_tempo_multiline():
tempi, weight = mir_eval.io.load_tempo('tests/data/tempo/bad00.lab')
tempi, weight = mir_eval.io.load_tempo('data/tempo/bad00.lab')


@nose.tools.raises(ValueError)
def test_load_tempo_badweight():
tempi, weight = mir_eval.io.load_tempo('tests/data/tempo/bad01.lab')
tempi, weight = mir_eval.io.load_tempo('data/tempo/bad01.lab')


def test_load_bad_tempi():

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
tempi, weight = mir_eval.io.load_tempo('tests/data/tempo/bad02.lab')
tempi, weight = mir_eval.io.load_tempo('data/tempo/bad02.lab')

assert len(w) == 1
assert issubclass(w[-1].category, UserWarning)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
A_TOL = 1e-12

# Path to the fixture files
REF_GLOB = 'tests/data/key/ref*.txt'
EST_GLOB = 'tests/data/key/est*.txt'
SCORES_GLOB = 'tests/data/key/output*.json'
REF_GLOB = 'data/key/ref*.txt'
EST_GLOB = 'data/key/est*.txt'
SCORES_GLOB = 'data/key/output*.json'


def __unit_test_key_function(metric):
Expand Down
Loading