From aba3042118a952a8f79c01edacf809314390accb Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Mon, 20 Jan 2014 15:37:11 +0100 Subject: [PATCH] Grapher : Add a generic Class to display Analyzers through their 'render' method. For now, it only support FrameValueResult analyzer --- timeside/analyzer/core.py | 18 +++++++++++++++++- timeside/core.py | 2 +- timeside/grapher/__init__.py | 1 + timeside/grapher/core.py | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index defe49e..bff6b86 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -29,6 +29,7 @@ import numpy from collections import OrderedDict import h5py import h5tools +import matplotlib.pyplot as plt numpy_data_types = [ #'float128', @@ -758,7 +759,22 @@ class GlobalLabelResult(LabelObject, GlobalObject, AnalyzerResult): class FrameValueResult(ValueObject, FramewiseObject, AnalyzerResult): - pass + def render(self, size=(1024, 256), dpi=80): + + image_width, image_height = size + + xSize = image_width / dpi + ySize = image_height / dpi + + fig = plt.figure(figsize=(xSize, ySize), dpi=dpi) + + ax = plt.Axes(fig, [0, 0, 1, 0.9]) + ax.set_frame_on(False) + ax.plot(self.time, self.data) + ax.axis('off') + fig.add_axes(ax) + + return fig class FrameLabelResult(LabelObject, FramewiseObject, AnalyzerResult): diff --git a/timeside/core.py b/timeside/core.py index 56036d4..629d4f4 100644 --- a/timeside/core.py +++ b/timeside/core.py @@ -83,7 +83,7 @@ class Processor(Component): self.parents = [] self.source_mediainfo = None - self.pipe = None + self.process_pipe = None self.UUID = uuid.uuid4() @interfacedoc diff --git a/timeside/grapher/__init__.py b/timeside/grapher/__init__.py index 1cfd820..4284bd4 100644 --- a/timeside/grapher/__init__.py +++ b/timeside/grapher/__init__.py @@ -6,3 +6,4 @@ from waveform_transparent import * from waveform_contour import * from spectrogram_log import * from spectrogram_lin import * +from render_analyzers import DisplayAubioPitch \ No newline at end of file diff --git a/timeside/grapher/core.py b/timeside/grapher/core.py index 550a513..ac416ad 100644 --- a/timeside/grapher/core.py +++ b/timeside/grapher/core.py @@ -158,7 +158,11 @@ class Grapher(Processor): @interfacedoc def render(self, output=None): if output: - self.image.save(output) + try: + self.image.save(output) + except AttributeError: + print "Pixel %s x %d" % (self.image_width, self.image_height) + self.image.savefig(output, dpi=341) return return self.image -- 2.39.5