From: Thomas Fillon Date: Tue, 24 Jun 2014 13:39:09 +0000 (+0200) Subject: feature(graphers): add grapher for limsi_sad and provide legend for segmentation... X-Git-Tag: 0.6~4^2~85 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=c0b95ac35f89811a8b7d58d78644f8ff9edec99a;p=timeside.git feature(graphers): add grapher for limsi_sad and provide legend for segmentation+label results --- diff --git a/tests/test_graphers_render_analyzers.py b/tests/test_graphers_render_analyzers.py new file mode 100644 index 0000000..5a9dc2f --- /dev/null +++ b/tests/test_graphers_render_analyzers.py @@ -0,0 +1,62 @@ +#! /usr/bin/env python +from __future__ import division + +from unit_timeside import unittest, TestRunner +import timeside +from scipy.signal import chirp +import numpy as np +from tempfile import NamedTemporaryFile +import os + +PLOT = False + + +class Test_graphers_analyzers(unittest.TestCase): + """ test Graphers from analyzers""" + + def setUp(self): + samplerate = 16000 # LimsiSad require Fs = 16000 Hz + duration = 10 + t = np.arange(0, duration, 1/samplerate) + samples = chirp(t=t, f0=20, t1=t[-1], f1=samplerate/2, + method='logarithmic') + decoder_cls = timeside.core.get_processor('array_dec') + self.decoder = decoder_cls(samples, samplerate=samplerate) + + def _perform_test(self, grapher_cls): + """Internal function that test grapher for a given analyzer""" + grapher = grapher_cls() + pipe = (self.decoder | grapher) + pipe.run() + + if PLOT: + grapher.render().show() + else: + self.temp_file = NamedTemporaryFile(suffix='.png', + delete=False) + grapher.render(self.temp_file.name) + + def tearDown(self): + # Clean-up : delete temp file + os.unlink(self.temp_file.name) + +list_graphers = timeside.core.processors(timeside.api.IGrapher) +module = 'timeside.grapher.render_analyzers' +grapher_analyzers = [grapher for grapher in list_graphers + if grapher.__module__ == module] + +for grapher in grapher_analyzers: + + def _test_func_factory(grapher): + test_func = lambda self: self._perform_test(grapher) + test_func.__doc__ = 'Test Graphers : %s' % grapher.name() + return test_func + + test_func_name = "test_%s" % grapher.name() + test_func = _test_func_factory(grapher) + + setattr(Test_graphers_analyzers, test_func_name, test_func) + + +if __name__ == '__main__': + unittest.main(testRunner=TestRunner()) diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index d1ba38c..3ca5428 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -676,7 +676,7 @@ class AnalyzerResult(MetadataObject): # see http://stackoverflow.com/a/8881973 fig, ax = plt.subplots() - self._render_plot(ax) + self.data_object._render_plot(ax) return fig def _render_PIL(self, size=(1024, 256), dpi=80): @@ -690,7 +690,7 @@ class AnalyzerResult(MetadataObject): ax = fig.add_axes([0, 0, 1, 1], frame_on=False) - self._render_plot(ax) + self.data_object._render_plot(ax) ax.autoscale(axis='x', tight=True) @@ -887,11 +887,16 @@ class SegmentLabelObject(LabelObject, SegmentObject): import itertools colors = itertools.cycle(['b', 'g', 'r', 'c', 'm', 'y', 'k']) ax_color = {} - for key in self.label_metadata.label.keys(): + artist = {} + for key, label in self.label_metadata.label.items(): ax_color[key] = colors.next() + artist[key] = plt.Line2D((0, 1), (0, 0), color=ax_color[key]) for time, duration, label in zip(self.time, self.duration, self.data): ax.axvspan(time, time + duration, color=ax_color[label], alpha=0.3) + #Create legend from custom artist/label lists + ax.legend(artist.values(), self.label_metadata.label.values()) + class AnalyzerResultContainer(dict): diff --git a/timeside/grapher/render_analyzers.py b/timeside/grapher/render_analyzers.py index 627a043..f53a0d9 100644 --- a/timeside/grapher/render_analyzers.py +++ b/timeside/grapher/render_analyzers.py @@ -122,9 +122,12 @@ class DisplayAnalyzer(Grapher): return NewGrapher +#------------------------------------------------- +# From here define new Graphers based on Analyzers +#------------------------------------------------- -# From here define new Grapher based on Analyzers -try: +# Aubio Pitch +try: # because of the dependencies on the Aubio librairy aubiopitch = get_processor('aubio_pitch')() DisplayAubioPitch = DisplayAnalyzer.create( analyzer=aubiopitch, @@ -135,6 +138,7 @@ try: except PIDError: pass +# Onset Detection Function odf = get_processor('odf')() DisplayOnsetDetectionFunction = DisplayAnalyzer.create( analyzer=odf, @@ -142,12 +146,14 @@ DisplayOnsetDetectionFunction = DisplayAnalyzer.create( grapher_id='grapher_odf', grapher_name='Onset detection function') +# Waveform wav = get_processor('waveform_analyzer')() DisplayWaveform = DisplayAnalyzer.create(analyzer=wav, result_id='waveform_analyzer', grapher_id='grapher_waveform', grapher_name='Waveform from Analyzer') +# IRIT 4Hz irit4hz = get_processor('irit_speech_4hz')() Display4hzSpeechSegmentation = DisplayAnalyzer.create( analyzer=irit4hz, @@ -155,7 +161,9 @@ Display4hzSpeechSegmentation = DisplayAnalyzer.create( grapher_id='grapher_irit_speech_4hz_segments', grapher_name='Irit 4Hz Speech Segmentation', background='waveform') -try: + +# IRIT Monopoly +try: # because of the dependencies on Aubio Pitch iritmonopoly = get_processor('irit_monopoly')() DisplayMonopoly = DisplayAnalyzer.create( analyzer=iritmonopoly, @@ -165,3 +173,24 @@ try: background='waveform') except PIDError: pass + +# Limsi SAD : 2 models +try: + limsi_sad_etape = get_processor('limsi_sad')(sad_model='etape') + limsi_sad_maya = get_processor('limsi_sad')(sad_model='maya') + DisplayLIMSI_SAD_etape = DisplayAnalyzer.create( + analyzer=limsi_sad_etape, + result_id='limsi_sad.sad_lhh_diff', + grapher_id='grapher_limsi_sad_etape', + grapher_name='LIMSI SAD with ETAPE model', + background='waveform') + + DisplayLIMSI_SAD_maya = DisplayAnalyzer.create( + analyzer=limsi_sad_maya, + result_id='limsi_sad.sad_lhh_diff', + grapher_id='grapher_limsi_sad_maya', + grapher_name='LIMSI SAD with Mayan model', + background='waveform') + +except PIDError: + pass