1import numpy as np 2 3from PyQt5 import QtGui 4 5 6def smooth(x, window_len=11, window='hanning'): 7 """Smooth 1D signal using specified window with given size""" 8 x = np.array(x) 9 if window_len < 3: 10 return x 11 12 if x.size < window_len: 13 raise ValueError("Input data length must be greater than window size") 14 15 if window not in ['rectangular', 'hanning', 'hamming', 'bartlett', 'blackman']: 16 raise ValueError("Window must be 'rectangular', 'hanning', 'hamming', 'bartlett' or 'blackman'") 17 18 if window == 'rectangular': 19 # Moving average 20 w = np.ones(window_len, 'd') 21 else: 22 w = getattr(np, window)(window_len) 23 24 s = np.r_[2 * x[0] - x[window_len:1:-1], x, 2 * x[-1] - x[-1:-window_len:-1]] 25 y = np.convolve(w / w.sum(), s, mode='same') 26 27 return y[window_len - 1:-window_len + 1] 28 29 30def str_to_color(color_string): 31 """Create QColor from comma sepparated RGBA string""" 32 return QtGui.QColor(*[int(c.strip()) for c in color_string.split(',')]) 33 34 35def color_to_str(color): 36 """Create comma separated RGBA string from QColor""" 37 return ", ".join([str(color.red()), str(color.green()), str(color.blue()), str(color.alpha())]) 38