]> git.parisson.com Git - timeside.git/commitdiff
Add/Modify doctest
authorThomas Fillon <thomas@parisson.com>
Tue, 1 Oct 2013 12:08:40 +0000 (14:08 +0200)
committerThomas Fillon <thomas@parisson.com>
Tue, 1 Oct 2013 12:08:40 +0000 (14:08 +0200)
timeside/analyzer/core.py
timeside/core.py
timeside/grapher/core.py

index a694f1980b969e1379f83246284335548731012f..6b2665d817ed20919d5f9d283998049e2b40301f 100644 (file)
@@ -406,7 +406,7 @@ class newAnalyzerResult(MetadataObject):
     """
     Object that contains the metadata and parameters of an analyzer process
 
-    Attributes
+    Parameters
     ----------
     dataMode : str
         dataMode describes the type of data :
@@ -418,12 +418,19 @@ class newAnalyzerResult(MetadataObject):
             - 'global'
             - 'segment'
             - 'event'
-    data : AnalyzerData
-    idMetadata : IdMetadata
-    audioMetadata : AudioMetadata
-    frameMetadata : FrameMetadata
-    labelMetadata : LabelMetadata
-    parameters : AnalyzerParameters Object
+
+
+    Returns
+    -------
+    A new MetadataObject with the following attributes :
+        - dataMode
+        - timeMode
+        - data : :class:`AnalyzerData`
+        - idMetadata : :class:`IdMetadata`
+        - audioMetadata : :class:`AudioMetadata`
+        - frameMetadata : :class:`FrameMetadata`
+        - labelMetadata : :class:`LabelMetadata`
+        - parameters : :class:`AnalyzerParameters` Object
 
     """
 
@@ -655,17 +662,18 @@ class AnalyzerResult(object):
 class AnalyzerResultContainer(object):
     '''
     >>> from timeside.decoder import FileDecoder
-    >>> #from timeside.analyzer.core import Analyzer
-    >>> #from timeside.analyzer import AnalyzerResultContainer, newAnalyzerResult
-    >>> wavFile = 'tests/samples/sweep.wav'
+    >>> import timeside.analyzer.core as coreA
+    >>> import os
+    >>> ModulePath =  os.path.dirname(os.path.realpath(coreA.__file__))
+    >>> wavFile = os.path.join(ModulePath , '../../tests/samples/sweep.wav')
     >>> d = FileDecoder(wavFile, start=1)
 
-    >>> a = Analyzer()
+    >>> a = coreA.Analyzer()
     >>> (d|a).run() #doctest: +ELLIPSIS
     <timeside.core.ProcessPipe object at 0x...>
     >>> a.new_result() #doctest: +ELLIPSIS
-    newAnalyzerResult(dataMode=None, timeMode=None, idMetadata=IdMetadata(id='', name='', unit='', description='', date='...', version='0.4.4', author='TimeSide'), data=AnalyzerData(data=None, time=None, duration=None, dataType=None), audioMetadata=AudioMetadata(uri='file:///home/thomas/code/timeside/TimeSide/tests/samples/sweep.wav', start=1.0, duration=7.0, channels=None, channelsManagement=''), frameMetadata=FrameMetadata(samplerate=None, blocksize=None, stepsize=None), labelMetadata=LabelMetadata(label=None, description=None, labelType='mono'), parameters={})
-    >>> resContainer = AnalyzerResultContainer()
+    newAnalyzerResult(dataMode=None, timeMode=None, idMetadata=IdMetadata(id='', name='', unit='', description='', date='...', version='...', author='TimeSide'), data=AnalyzerData(value=None, label=array([], dtype=int64), time=array([], dtype=float64), duration=array([], dtype=float64)), audioMetadata=AudioMetadata(uri='file:///.../tests/samples/sweep.wav', start=1.0, duration=7.0, channels=None, channelsManagement=''), frameMetadata=FrameMetadata(samplerate=None, blocksize=None, stepsize=None), labelMetadata=LabelMetadata(label=None, description=None, labelType='mono'), parameters={})
+    >>> resContainer = coreA.AnalyzerResultContainer()
 
     '''
     def __init__(self, analyzer_results=None):
index 2b19beb3dbbf28a0d13a21c5b6d867e484dfa201..8cb548bdef719e90203ad251a5a1b51ad71b4cb4 100644 (file)
@@ -43,8 +43,15 @@ class MetaProcessor(MetaComponent):
         if new_class in implementations(IProcessor):
             id = str(new_class.id())
             if _processors.has_key(id):
-                raise ApiError("%s and %s have the same id: '%s'"
-                    % (new_class.__name__, _processors[id].__name__, id))
+                # Doctest test can duplicate a processor
+                # This can be identify by the conditon "module == '__main__'"
+                if new_class.__module__ == '__main__':
+                    new_class = _processors[id]
+                elif _processors[id].__module__ == '__main__':
+                    pass
+                else:
+                    raise ApiError("%s and %s have the same id: '%s'"
+                        % (new_class.__name__, _processors[id].__name__, id))
             if not MetaProcessor.valid_id.match(id):
                 raise ApiError("%s has a malformed id: '%s'"
                     % (new_class.__name__, id))
index fd794e89f95b3e0bb3341387e8906eaab102e3f6..1ed88871c6a9d729400cba251a61bc36777f2bb0 100644 (file)
@@ -619,37 +619,56 @@ def downsample(vector, factor):
 
 
 def smooth(x, window_len=10, window='hanning'):
-    """smooth the data using a window with requested size.
+    """
+    Smooth the data using a window with requested size.
 
     This method is based on the convolution of a scaled window with the signal.
     The signal is prepared by introducing reflected copies of the signal
     (with the window size) in both ends so that transient parts are minimized
     in the begining and end part of the output signal.
 
-    input:
-        x: the input signal
-        window_len: the dimension of the smoothing window
-        window: the type of window from 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'
-            flat window will produce a moving average smoothing.
-
-    output:
-        the smoothed signal
+    Parameters
+    ----------
+    x : numpy.array
+        the input signal
+    window_len : int
+        the dimension of the smoothing window
+    window : str
+        the type of window from 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'
+        flat window will produce a moving average smoothing.
 
-    example:
+    Returns
+    -------
+    The smoothed signal
 
-    import numpy as np
-    t = numpy.linspace(-2,2,0.1)
-    x = numpy.sin(t)+numpy.random.randn(len(t))*0.1
-    y = smooth(x)
-
-    see also:
+    See Also
+    --------
 
     numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve
     scipy.signal.lfilter
 
-    TODO: the window parameter could be the window itself if an array instead of a string
+
+    Examples
+    --------
+
+    >>> import numpy as np
+    >>> from timeside.grapher import smooth
+    >>> t = np.arange(-2,2,0.1)
+    >>> x = np.sin(t)+np.random.randn(len(t))*0.1
+    >>> y = smooth(x)
+    >>> import matplotlib.pyplot as plt
+    >>> plt.plot(x) # doctest: +ELLIPSIS
+    [<matplotlib.lines.Line2D object at 0x...>]
+    >>> plt.plot(y) # doctest: +ELLIPSIS
+    [<matplotlib.lines.Line2D object at 0x...>]
+    >>> plt.legend(['Source signal', 'Smoothed signal']) # doctest: +ELLIPSIS
+    <matplotlib.legend.Legend object at 0x...>
+    >>> #plt.show()
     """
 
+    # TODO: the window parameter could be the window itself if an array instead of a string
+
+
     if x.ndim != 1:
         raise ValueError, "smooth only accepts 1 dimension arrays."
 
@@ -698,3 +717,8 @@ def im_watermark(im, inputtext, font=None, color=None, opacity=.6, margin=(30,30
     if opacity != 1:
         textlayer = reduce_opacity(textlayer,opacity)
     return Image.composite(textlayer, im, textlayer)
+
+
+if __name__ == "__main__":
+    import doctest
+    doctest.testmod()
\ No newline at end of file