"""
Object that contains the metadata and parameters of an analyzer process
- Attributes
+ Parameters
----------
dataMode : str
dataMode describes the type of data :
- '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
"""
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):
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))
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."
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