--- /dev/null
+#! /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())
# 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):
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)
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):
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,
except PIDError:
pass
+# Onset Detection Function
odf = get_processor('odf')()
DisplayOnsetDetectionFunction = DisplayAnalyzer.create(
analyzer=odf,
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,
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,
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