Package timeside :: Package grapher :: Module utils
[hide private]
[frames] | no frames]

Module utils

source code

Functions [hide private]
 
interpolate_colors(colors, flat=False, num_colors=256)
Given a list of colors, create a larger list of colors interpolating the first one.
source code
 
downsample(vector, factor)
downsample(vector, factor): Downsample (by averaging) a vector by an integer factor.
source code
 
smooth(x, window_len=10, window='hanning')
Smooth the data using a window with requested size.
source code
 
reduce_opacity(im, opacity)
Returns an image with reduced opacity.
source code
 
im_watermark(im, inputtext, font=None, color=None, opacity=0.6, margin=(30, 30))
imprints a PIL image with the indicated text in lower-right corner
source code
 
peaks(samples)
Find the minimum and maximum peak of the samples.
source code
 
color_from_value(self, value)
given a value between 0 and 1, return an (r,g,b) tuple
source code
 
mean(samples) source code
 
normalize(contour) source code
Variables [hide private]
  __package__ = 'timeside.grapher'
Function Details [hide private]

interpolate_colors(colors, flat=False, num_colors=256)

source code 

Given a list of colors, create a larger list of colors interpolating the first one. If flatten is True a list of numers will be returned. If False, a list of (r,g,b) tuples. num_colors is the number of colors wanted in the final list

smooth(x, window_len=10, window='hanning')

source code 

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.

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.

Returns
-------
The smoothed signal

See Also
-------

numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve
scipy.signal.lfilter

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: +SKIP
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.plot(y) # doctest: +SKIP
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.legend(['Source signal', 'Smoothed signal']) # doctest: +SKIP
<matplotlib.legend.Legend object at 0x...>
>>> plt.show() # doctest: +SKIP

peaks(samples)

source code 

Find the minimum and maximum peak of the samples. Returns that pair in the order they were found. So if min was found first, it returns (min, max) else the other way around.