From: Thomas Fillon Date: Sun, 26 Jan 2014 23:51:43 +0000 (+0000) Subject: Implement rendering capability for event and segment analyzers + add some more analyz... X-Git-Tag: 0.5.3~8^2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=77c6d075ba9651f59c20d23d2047996f5020cc54;p=timeside.git Implement rendering capability for event and segment analyzers + add some more analyzer graphers --- diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 87a905c..32e3e2f 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -767,6 +767,9 @@ class EventObject(object): def duration(self): return numpy.zeros(len(self)) + def _render_plot(self, ax): + ax.stem(self.time, self.data) + class SegmentObject(EventObject): _time_mode = 'segment' @@ -799,25 +802,29 @@ class FrameLabelResult(LabelObject, FramewiseObject, AnalyzerResult): class EventValueResult(ValueObject, EventObject, AnalyzerResult): - def _render_plot(self, ax): - for time, value in (self.time, self.data): - ax.axvline(time, ymin=0, ymax=value, color='r') - # TODO : check value shape !!! - + pass class EventLabelResult(LabelObject, EventObject, AnalyzerResult): - def _render_plot(self, ax): - pass - + pass class SegmentValueResult(ValueObject, SegmentObject, AnalyzerResult): def _render_plot(self, ax): - pass + import itertools + colors = itertools.cycle(['b', 'g', 'r', 'c', 'm', 'y', 'k']) + for time, value in (self.time, self.data): + ax.axvline(time, ymin=0, ymax=value, color='r') + # TODO : check value shape !!! class SegmentLabelResult(LabelObject, SegmentObject, AnalyzerResult): def _render_plot(self, ax): - pass + import itertools + colors = itertools.cycle(['b', 'g', 'r', 'c', 'm', 'y', 'k']) + ax_color = {} + for key in self.label_metadata.label.keys(): + ax_color[key] = colors.next() + for time, duration, label in zip(self.time, self.duration, self.data): + ax.axvspan(time, time+duration, color=ax_color[label], alpha=0.3) class AnalyzerResultContainer(dict): @@ -832,7 +839,6 @@ class AnalyzerResultContainer(dict): >>> a.new_result() #doctest: +ELLIPSIS FrameValueResult(id_metadata=IdMetadata(id='analyzer', name='Generic analyzer', unit='', description='', date='...', version='...', author='TimeSide', uuid='...'), data_object=DataObject(value=array([], dtype=float64)), audio_metadata=AudioMetadata(uri='...', start=0.0, duration=8.0..., is_segment=False, channels=None, channelsManagement=''), frame_metadata=FrameMetadata(samplerate=44100, blocksize=8192, stepsize=8192), parameters={}) >>> resContainer = timeside.analyzer.core.AnalyzerResultContainer() - ''' diff --git a/timeside/grapher/render_analyzers.py b/timeside/grapher/render_analyzers.py index a43bee1..063a0a4 100644 --- a/timeside/grapher/render_analyzers.py +++ b/timeside/grapher/render_analyzers.py @@ -94,6 +94,8 @@ class DisplayAnalyzer(Grapher): def name(): return grapher_name + __doc__ = """Builds a PIL image representing """ + grapher_name + NewGrapher.__name__ = 'Display'+result_id return NewGrapher @@ -119,3 +121,8 @@ DisplayWaveform = DisplayAnalyzer.create(analyzer=wav, result_id='waveform_analyzer', grapher_id='grapher_waveform', grapher_name='Waveform from Analyzer') +irit4hz = analyzer.IRITSpeech4Hz() +Display4hzSpeechSegmentation = DisplayAnalyzer.create(analyzer=irit4hz, + result_id='irit_speech_4hz.segments', + grapher_id='grapher_irit_speech_4hz_segments', + grapher_name='Irit 4Hz Speech Segmentation')