]> git.parisson.com Git - timeside.git/commitdiff
tests/sandbox: Fix issue #28
authorThomas Fillon <thomas@parisson.com>
Wed, 8 Jan 2014 14:18:25 +0000 (15:18 +0100)
committerThomas Fillon <thomas@parisson.com>
Wed, 8 Jan 2014 14:18:25 +0000 (15:18 +0100)
tests/sandbox/example_CMMR.py [new file with mode: 0644]
tests/sandbox/exemplesCMMR.py [deleted file]
timeside/analyzer/core.py
timeside/core.py

diff --git a/tests/sandbox/example_CMMR.py b/tests/sandbox/example_CMMR.py
new file mode 100644 (file)
index 0000000..5ff4516
--- /dev/null
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Tue Jul 16 13:04:49 2013
+
+@author: thomas
+"""
+from __future__ import division
+import timeside
+import matplotlib.pyplot as plt
+import numpy as np
+import sys
+
+if not sys.argv[-1]:
+    wav_file = 'toto.wav'
+else:
+    wav_file = sys.argv[-1]
+
+# normal
+decoder = timeside.decoder.FileDecoder(wav_file, start=10, duration=15)
+#e = timeside.encoder.VorbisEncoder('output.ogg', overwrite = True)
+aubio_pitch = timeside.analyzer.AubioPitch()
+aubio_temporal = timeside.analyzer.AubioTemporal()
+specgram = timeside.analyzer.Spectrogram()
+waveform = timeside.analyzer.Waveform()
+#g  =  timeside.grapher.Spectrogram()
+
+pipe = (decoder | aubio_pitch | aubio_temporal | specgram | waveform)
+print pipe
+pipe.run()
+
+print pipe.results.keys()
+
+# Display Spectrogram + Aubio Pitch + Aubio Beat
+plt.figure(1)
+
+spec_res = specgram.results['spectrogram_analyzer']
+N = spec_res.parameters['FFT_SIZE']
+plt.imshow(20 * np.log10(spec_res.data.T),
+           origin='lower',
+           extent=[spec_res.time[0], spec_res.time[-1], 0,
+                   (N // 2 + 1) / N * spec_res.frame_metadata.samplerate],
+           aspect='auto')
+
+res_pitch = aubio_pitch.results['aubio_pitch.pitch']
+plt.plot(res_pitch.time, res_pitch.data)
+
+
+res_beats = aubio_temporal.results['aubio_temporal.beat']
+
+for time in res_beats.time:
+    plt.axvline(time, color='r')
+
+plt.title('Spectrogram + Aubio pitch + Aubio beat')
+plt.grid()
+
+# Display waveform + Onsets
+plt.figure(2)
+res_wave = waveform.results['waveform_analyzer']
+plt.plot(res_wave.time, res_wave.data)
+res_onsets = aubio_temporal.results['aubio_temporal.onset']
+for time in res_onsets.time:
+    plt.axvline(time, color='g')
+plt.grid()
+plt.title('Waveform + Aubio onset')
+plt.show()
diff --git a/tests/sandbox/exemplesCMMR.py b/tests/sandbox/exemplesCMMR.py
deleted file mode 100644 (file)
index 603ac9a..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on Tue Jul 16 13:04:49 2013
-
-@author: thomas
-"""
-from __future__ import division
-import timeside
-import matplotlib.pyplot as plt
-import numpy as np
-import sys
-
-if not '.wav' in sys.argv[-1]:
-    wav_file = 'toto.wav'
-else:
-    wav_file = sys.argv[-1]
-
-# normal
-decoder = timeside.decoder.FileDecoder(wav_file, start=10, duration=15)
-#e = timeside.encoder.VorbisEncoder('output.ogg', overwrite = True)
-aubio_pitch = timeside.analyzer.AubioPitch()
-aubio_temporal = timeside.analyzer.AubioTemporal()
-specgram = timeside.analyzer.Spectrogram()
-waveform = timeside.analyzer.Waveform()
-#g  =  timeside.grapher.Spectrogram()
-
-pipe = (decoder | aubio_pitch | aubio_temporal | specgram | waveform).run()
-
-pipe.results.keys()
-
-# Display Spectrogram + Aubio Pitch + Aubio Beat
-plt.figure(1)
-
-spec_res = specgram.results['spectrogram_analyzer']
-N = spec_res.parameters['FFT_SIZE']
-plt.imshow(20 * np.log10(spec_res.data.T),
-           origin='lower',
-           extent=[spec_res.time[0], spec_res.time[-1], 0,
-                   (N // 2 + 1) / N * spec_res.frame_metadata.samplerate],
-           aspect='auto')
-
-res_pitch = aubio_pitch.results['aubio_pitch']
-plt.plot(res_pitch.time, res_pitch.data)
-
-
-res_beats = aubio_temporal.results['aubio_temporal.beat']
-
-for time in res_beats.time:
-    plt.axvline(time, color='r')
-
-plt.title('Spectrogram + Aubio pitch + Aubio beat')
-plt.grid()
-
-# Display waveform + Onsets
-plt.figure(2)
-res_wave = waveform.results['waveform_analyzer']
-plt.plot(res_wave.time, res_wave.data)
-res_onsets = aubio_temporal.results['aubio_temporal.onset']
-for time in res_onsets.time:
-    plt.axvline(time, color='g')
-plt.grid()
-plt.title('Waveform + Aubio onset')
-plt.show()
index 0da2341475165e80ccb4736d68f7b2fb3f6fe1b9..44b5f466d2d5039700b4c732f3d853618e9fc232 100644 (file)
@@ -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
index e817e252ea6848296353bfa20380d885833fdf8a..413331900e2a79ce026f17c1408cb1d05f13196a 100644 (file)
@@ -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):