本文整理汇总了Python中scipy.signal.medfilt方法的典型用法代码示例。如果您正苦于以下问题:Python signal.medfilt方法的具体用法?Python signal.medfilt怎么用?Python signal.medfilt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.signal
的用法示例。
在下文中一共展示了signal.medfilt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def test_basic(self):
f = [[50, 50, 50, 50, 50, 92, 18, 27, 65, 46],
[50, 50, 50, 50, 50, 0, 72, 77, 68, 66],
[50, 50, 50, 50, 50, 46, 47, 19, 64, 77],
[50, 50, 50, 50, 50, 42, 15, 29, 95, 35],
[50, 50, 50, 50, 50, 46, 34, 9, 21, 66],
[70, 97, 28, 68, 78, 77, 61, 58, 71, 42],
[64, 53, 44, 29, 68, 32, 19, 68, 24, 84],
[3, 33, 53, 67, 1, 78, 74, 55, 12, 83],
[7, 11, 46, 70, 60, 47, 24, 43, 61, 26],
[32, 61, 88, 7, 39, 4, 92, 64, 45, 61]]
d = signal.medfilt(f, [7, 3])
e = signal.medfilt2d(np.array(f, np.float), [7, 3])
assert_array_equal(d, [[0, 50, 50, 50, 42, 15, 15, 18, 27, 0],
[0, 50, 50, 50, 50, 42, 19, 21, 29, 0],
[50, 50, 50, 50, 50, 47, 34, 34, 46, 35],
[50, 50, 50, 50, 50, 50, 42, 47, 64, 42],
[50, 50, 50, 50, 50, 50, 46, 55, 64, 35],
[33, 50, 50, 50, 50, 47, 46, 43, 55, 26],
[32, 50, 50, 50, 50, 47, 46, 45, 55, 26],
[7, 46, 50, 50, 47, 46, 46, 43, 45, 21],
[0, 32, 33, 39, 32, 32, 43, 43, 43, 0],
[0, 7, 11, 7, 4, 4, 19, 19, 24, 0]])
assert_array_equal(d, e)
示例2: find_angle_graph
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def find_angle_graph(velocity, vertical_velocity, interp=False):
angle = []
for i in range(len(velocity)):
if velocity[i] == 0:
angle.append(angle[-1])
else:
ratio = max(-1, min(vertical_velocity[i] / velocity[i], 1))
angle.append(asin(ratio))
angle = savgol_filter(angle, 5, 1)
if interp:
angle = savgol_filter(angle, 11, 1)
return ss.medfilt(angle, kernel_size=7)
return angle
示例3: compute_medfilt
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def compute_medfilt(arr):
"""Median filtered signal as features.
Parameters
----------
arr : ndarray, shape (n_channels, n_times)
Returns
-------
output : (n_channels * n_times,)
"""
return medfilt(arr, kernel_size=(1, 5)).ravel()
###############################################################################
# Prepare for the classification task
# -----------------------------------
#
# In addition to the new feature function, we also propose to extract the
# mean of the data:
示例4: test_basic
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def test_basic(self):
f = [[50, 50, 50, 50, 50, 92, 18, 27, 65, 46],
[50, 50, 50, 50, 50, 0, 72, 77, 68, 66],
[50, 50, 50, 50, 50, 46, 47, 19, 64, 77],
[50, 50, 50, 50, 50, 42, 15, 29, 95, 35],
[50, 50, 50, 50, 50, 46, 34, 9, 21, 66],
[70, 97, 28, 68, 78, 77, 61, 58, 71, 42],
[64, 53, 44, 29, 68, 32, 19, 68, 24, 84],
[3, 33, 53, 67, 1, 78, 74, 55, 12, 83],
[7, 11, 46, 70, 60, 47, 24, 43, 61, 26],
[32, 61, 88, 7, 39, 4, 92, 64, 45, 61]]
d = signal.medfilt(f, [7, 3])
e = signal.medfilt2d(np.array(f, float), [7, 3])
assert_array_equal(d, [[0, 50, 50, 50, 42, 15, 15, 18, 27, 0],
[0, 50, 50, 50, 50, 42, 19, 21, 29, 0],
[50, 50, 50, 50, 50, 47, 34, 34, 46, 35],
[50, 50, 50, 50, 50, 50, 42, 47, 64, 42],
[50, 50, 50, 50, 50, 50, 46, 55, 64, 35],
[33, 50, 50, 50, 50, 47, 46, 43, 55, 26],
[32, 50, 50, 50, 50, 47, 46, 45, 55, 26],
[7, 46, 50, 50, 47, 46, 46, 43, 45, 21],
[0, 32, 33, 39, 32, 32, 43, 43, 43, 0],
[0, 7, 11, 7, 4, 4, 19, 19, 24, 0]])
assert_array_equal(d, e)
示例5: unmeasure_np
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def unmeasure_np(self, hparams, x_measured_val, theta_val):
if hparams.unmeasure_type == 'medfilt':
unmeasure_func = lambda image, mask: signal.medfilt(image)
elif hparams.unmeasure_type == 'inpaint-telea':
inpaint_type = cv2.INPAINT_TELEA
unmeasure_func = measure_utils.get_inpaint_func_opencv(hparams, inpaint_type)
elif hparams.unmeasure_type == 'inpaint-ns':
inpaint_type = cv2.INPAINT_NS
unmeasure_func = measure_utils.get_inpaint_func_opencv(hparams, inpaint_type)
elif hparams.unmeasure_type == 'inpaint-tv':
unmeasure_func = measure_utils.get_inpaint_func_tv()
elif hparams.unmeasure_type == 'blur':
unmeasure_func = measure_utils.get_blur_func()
else:
raise NotImplementedError
x_unmeasured_val = np.zeros_like(x_measured_val)
for i in range(x_measured_val.shape[0]):
x_unmeasured_val[i] = unmeasure_func(x_measured_val[i], theta_val[i])
return x_unmeasured_val
示例6: circular_filter_1d
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def circular_filter_1d(signal, window_size, kernel='gaussian'):
""" This function filters circularly the signal inputted with a median filter of inputted size, in this context
circularly means that the signal is wrapped around and then filtered
inputs :
- signal : 1D numpy array
- window_size : size of the kernel, an int
outputs :
- signal_smoothed : 1D numpy array, same size as signal"""
signal_extended = np.concatenate((signal, signal, signal)) # replicate signal at both ends
if kernel == 'gaussian':
signal_extended_smooth = ndimage.gaussian_filter(signal_extended, window_size) # gaussian
elif kernel == 'median':
signal_extended_smooth = medfilt(signal_extended, window_size) # median filtering
else:
raise Exception("Unknow type of kernel")
signal_smoothed = signal_extended_smooth[len(signal):2*len(signal)] # truncate back the signal
return signal_smoothed
示例7: transform
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def transform(self,X):
"""Detrend each column of X
Parameters
----------
X : DataFrame in `traces` structure [n_samples, n_traces]
Returns
-------
Xt : DataFrame in `traces` structure [n_samples, n_traces]
The detrended data.
"""
self.fit_params = {}
X_new = X.copy()
for col in X.columns:
tmp_data = X[col].values.astype(np.double)
mf = medfilt(tmp_data, self.window)
mf = np.minimum(mf, self.peak_std_threshold * self._robust_std(mf))
self.fit_params[col] = dict(mf=mf)
X_new[col] = tmp_data - mf
return X_new
示例8: loadData
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def loadData(log_folder, smooth, bin_size, is_es=False):
"""
:param log_folder: (str)
:param smooth: (int) Smoothing method
:param bin_size: (int)
:param is_es: (bool)
:return:
"""
result, timesteps = loadCsv(log_folder, is_es=is_es)
if len(result) < bin_size:
return [None, None]
x, y = np.array(result)[:, 0], np.array(result)[:, 1]
if smooth == 1:
x, y = smoothRewardCurve(x, y)
if smooth == 2:
y = medfilt(y, kernel_size=9)
x, y = fixPoint(x, y, bin_size)
return [x, y]
示例9: smooth_bbox_params
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def smooth_bbox_params(bbox_params, kernel_size=11, sigma=8):
"""
Applies median filtering and then gaussian filtering to bounding box
parameters.
Args:
bbox_params (Nx3): [cx, cy, scale].
kernel_size (int): Kernel size for median filtering (must be odd).
sigma (float): Sigma for gaussian smoothing.
Returns:
Smoothed bounding box parameters (Nx3).
"""
smoothed = np.array([signal.medfilt(param, kernel_size)
for param in bbox_params.T]).T
return np.array([gaussian_filter1d(traj, sigma) for traj in smoothed.T]).T
示例10: apply_median_filter
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def apply_median_filter(self, window_size=3):
if self.mean_signal is None:
self.x = signal.medfilt(self.x, window_size)
self.y = signal.medfilt(self.y, window_size)
self.z = signal.medfilt(self.z, window_size)
else:
self.mean_signal = signal.medfilt(self.mean_signal, window_size)
示例11: median_filter
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def median_filter(self) -> None:
"""
Applies a median filter on the internal 1d signal. Can be useful for cosmic ray correction
after temporal de-noising
Returns
-------
NoneType
None
"""
self._m_data = medfilt(self._m_data, 19)
示例12: test_none
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def test_none(self):
# Ticket #1124. Ensure this does not segfault.
try:
signal.medfilt(None)
except:
pass
# Expand on this test to avoid a regression with possible contiguous
# numpy arrays that have odd strides. The stride value below gets
# us into wrong memory if used (but it does not need to be used)
dummy = np.arange(10, dtype=np.float64)
a = dummy[5:6]
a.strides = 16
assert_(signal.medfilt(a, 1) == 5.)
示例13: test_refcounting
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def test_refcounting(self):
# Check a refcounting-related crash
a = Decimal(123)
x = np.array([a, a], dtype=object)
if hasattr(sys, 'getrefcount'):
n = 2 * sys.getrefcount(a)
else:
n = 10
# Shouldn't segfault:
for j in range(n):
signal.medfilt(x)
if hasattr(sys, 'getrefcount'):
assert_(sys.getrefcount(a) < n)
assert_equal(x, [a, a])
示例14: load_data
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def load_data(indir, smooth, bin_size):
datas = []
infiles = glob.glob(os.path.join(indir, '*.monitor.csv'))
for inf in infiles:
with open(inf, 'r') as f:
f.readline()
f.readline()
for line in f:
tmp = line.split(',')
t_time = float(tmp[2])
tmp = [t_time, int(tmp[1]), float(tmp[0])]
datas.append(tmp)
datas = sorted(datas, key=lambda d_entry: d_entry[0])
result = []
timesteps = 0
for i in range(len(datas)):
result.append([timesteps, datas[i][-1]])
timesteps += datas[i][1]
if len(result) < bin_size:
return [None, None]
x, y = np.array(result)[:, 0], np.array(result)[:, 1]
if smooth == 1:
x, y = smooth_reward_curve(x, y)
if smooth == 2:
y = medfilt(y, kernel_size=9)
x, y = fix_point(x, y, bin_size)
return [x, y]
示例15: smooth_bbox_params
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import medfilt [as 别名]
def smooth_bbox_params(bbox_params, kernel_size=11, sigma=8):
"""
Applies median filtering and then gaussian filtering to bounding box
parameters.
Args:
bbox_params (Nx3): [cx, cy, scale].
kernel_size (int): Kernel size for median filtering (must be odd).
sigma (float): Sigma for gaussian smoothing.
Returns:
Smoothed bounding box parameters (Nx3).
"""
smoothed = np.array([signal.medfilt(param, kernel_size)
for param in bbox_params.T]).T
return np.array([gaussian_filter1d(traj, sigma) for traj in smoothed.T]).T