From 0b11c0245aeac0f27f0d39a42d5ce2e6b0f4898f Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Wed, 8 Jan 2014 15:18:25 +0100 Subject: [PATCH] tests/sandbox: Fix issue #28 --- .../{exemplesCMMR.py => example_CMMR.py} | 10 +++--- timeside/analyzer/core.py | 36 ++++++++++--------- timeside/core.py | 3 +- 3 files changed, 27 insertions(+), 22 deletions(-) rename tests/sandbox/{exemplesCMMR.py => example_CMMR.py} (92%) diff --git a/tests/sandbox/exemplesCMMR.py b/tests/sandbox/example_CMMR.py similarity index 92% rename from tests/sandbox/exemplesCMMR.py rename to tests/sandbox/example_CMMR.py index 603ac9a..5ff4516 100644 --- a/tests/sandbox/exemplesCMMR.py +++ b/tests/sandbox/example_CMMR.py @@ -10,7 +10,7 @@ import matplotlib.pyplot as plt import numpy as np import sys -if not '.wav' in sys.argv[-1]: +if not sys.argv[-1]: wav_file = 'toto.wav' else: wav_file = sys.argv[-1] @@ -24,9 +24,11 @@ specgram = timeside.analyzer.Spectrogram() waveform = timeside.analyzer.Waveform() #g = timeside.grapher.Spectrogram() -pipe = (decoder | aubio_pitch | aubio_temporal | specgram | waveform).run() +pipe = (decoder | aubio_pitch | aubio_temporal | specgram | waveform) +print pipe +pipe.run() -pipe.results.keys() +print pipe.results.keys() # Display Spectrogram + Aubio Pitch + Aubio Beat plt.figure(1) @@ -39,7 +41,7 @@ plt.imshow(20 * np.log10(spec_res.data.T), (N // 2 + 1) / N * spec_res.frame_metadata.samplerate], aspect='auto') -res_pitch = aubio_pitch.results['aubio_pitch'] +res_pitch = aubio_pitch.results['aubio_pitch.pitch'] plt.plot(res_pitch.time, res_pitch.data) diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 0da2341..44b5f46 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -382,8 +382,6 @@ class DataObject(MetadataObject): all([numpy.array_equal(self[key], other[key]) for key in self.keys()])) except AttributeError: - # print self - # print [self[key] == other[key] for key in self.keys()] return (isinstance(other, self.__class__) and all([bool(numpy.logical_and.reduce((self[key] == other[key]).ravel())) for key in self.keys()])) @@ -616,9 +614,8 @@ class AnalyzerResult(MetadataObject): @staticmethod def from_hdf5(h5group): # Read Sub-Group - result = AnalyzerResult.factory( - data_mode=h5group.attrs['data_mode'], - time_mode=h5group.attrs['time_mode']) + result = AnalyzerResult.factory(data_mode=h5group.attrs['data_mode'], + time_mode=h5group.attrs['time_mode']) for subgroup_name, h5subgroup in h5group.items(): result[subgroup_name].from_hdf5(h5subgroup) return result @@ -824,7 +821,7 @@ class AnalyzerResultContainer(dict): analyzer_result) #self.results += [analyzer_result] - def to_xml(self, output_file = None): + def to_xml(self, output_file=None): import xml.etree.ElementTree as ET # TODO : cf. telemeta util @@ -835,8 +832,10 @@ class AnalyzerResultContainer(dict): root.append(ET.fromstring(result.to_xml())) xml_str = ET.tostring(root, encoding="utf-8", method="xml") - if output_file: open(output_file, 'w').write(xml_str) - else: return xml_str + if output_file: + open(output_file, 'w').write(xml_str) + else: + return xml_str @staticmethod def from_xml(xml_string): @@ -852,7 +851,7 @@ class AnalyzerResultContainer(dict): return results - def to_json(self, output_file = None): + def to_json(self, output_file=None): #if data_list == None: data_list = self.results import simplejson as json @@ -864,9 +863,11 @@ class AnalyzerResultContainer(dict): raise TypeError(repr(obj) + " is not JSON serializable") json_str = json.dumps([res.as_dict() for res in self.values()], - default=NumpyArrayEncoder) - if output_file: open(output_file, 'w').write(json_str) - else: return json_str + default=NumpyArrayEncoder) + if output_file: + open(output_file, 'w').write(json_str) + else: + return json_str @staticmethod def from_json(json_str): @@ -907,8 +908,10 @@ class AnalyzerResultContainer(dict): yaml.add_representer(numpy.ndarray, numpyArray_representer) yaml_str = yaml.dump([res.as_dict() for res in self.values()]) - if output_file: open(output_file, 'w').write(yaml_str) - else: return yaml_str + if output_file: + open(output_file, 'w').write(yaml_str) + else: + return yaml_str @staticmethod def from_yaml(yaml_str): @@ -991,7 +994,6 @@ class Analyzer(Processor): @property def results(self): - return AnalyzerResultContainer( [self.process_pipe.results[key] for key in self.process_pipe.results.keys() if key.split('.')[0] == self.id()]) @@ -1026,7 +1028,7 @@ class Analyzer(Processor): from datetime import datetime result = AnalyzerResult.factory(data_mode=data_mode, - time_mode=time_mode) + time_mode=time_mode) # Automatically write known metadata result.id_metadata.date = datetime.now().replace( @@ -1053,4 +1055,4 @@ class Analyzer(Processor): if __name__ == "__main__": import doctest - doctest.testmod() + doctest.testmod() \ No newline at end of file diff --git a/timeside/core.py b/timeside/core.py index e817e25..4133319 100644 --- a/timeside/core.py +++ b/timeside/core.py @@ -247,7 +247,8 @@ class ProcessPipe(object): self.results = AnalyzerResultContainer() def __or__(self, other): - return ProcessPipe(self, other) + self |= other + return self def __ior__(self, other): if isinstance(other, Processor): -- 2.39.5