本文整理汇总了Python中pywt.dwt方法的典型用法代码示例。如果您正苦于以下问题:Python pywt.dwt方法的具体用法?Python pywt.dwt怎么用?Python pywt.dwt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywt
的用法示例。
在下文中一共展示了pywt.dwt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _assert_all_coeffs_equal
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def _assert_all_coeffs_equal(coefs1, coefs2):
# return True only if all coefficients of SWT or DWT match over all levels
if len(coefs1) != len(coefs2):
return False
for (c1, c2) in zip(coefs1, coefs2):
if isinstance(c1, tuple):
# for swt, swt2, dwt, dwt2, wavedec, wavedec2
for a1, a2 in zip(c1, c2):
assert_array_equal(a1, a2)
elif isinstance(c1, dict):
# for swtn, dwtn, wavedecn
for k, v in c1.items():
assert_array_equal(v, c2[k])
else:
return False
return True
示例2: test_dwt_idwt_basic
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_dwt_idwt_basic():
x = [3, 7, 1, 1, -2, 5, 4, 6]
cA, cD = pywt.dwt(x, 'db2')
cA_expect = [5.65685425, 7.39923721, 0.22414387, 3.33677403, 7.77817459]
cD_expect = [-2.44948974, -1.60368225, -4.44140056, -0.41361256,
1.22474487]
assert_allclose(cA, cA_expect)
assert_allclose(cD, cD_expect)
x_roundtrip = pywt.idwt(cA, cD, 'db2')
assert_allclose(x_roundtrip, x, rtol=1e-10)
# mismatched dtypes OK
x_roundtrip2 = pywt.idwt(cA.astype(np.float64), cD.astype(np.float32),
'db2')
assert_allclose(x_roundtrip2, x, rtol=1e-7, atol=1e-7)
assert_(x_roundtrip.dtype == np.float64)
示例3: test_dwt_idwt_partial_complex
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_dwt_idwt_partial_complex():
x = np.asarray([3, 7, 1, 1, -2, 5, 4, 6])
x = x + 0.5j*x
cA, cD = pywt.dwt(x, 'haar')
cA_rec_expect = np.array([5.0+2.5j, 5.0+2.5j, 1.0+0.5j, 1.0+0.5j,
1.5+0.75j, 1.5+0.75j, 5.0+2.5j, 5.0+2.5j])
cA_rec = pywt.idwt(cA, None, 'haar')
assert_allclose(cA_rec, cA_rec_expect)
cD_rec_expect = np.array([-2.0-1.0j, 2.0+1.0j, 0.0+0.0j, 0.0+0.0j,
-3.5-1.75j, 3.5+1.75j, -1.0-0.5j, 1.0+0.5j])
cD_rec = pywt.idwt(None, cD, 'haar')
assert_allclose(cD_rec, cD_rec_expect)
assert_allclose(cA_rec + cD_rec, x)
示例4: test_dwt_short_input_allmodes
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_dwt_short_input_allmodes():
# some test cases where the input is shorter than the DWT filter
x = [1, 2, 3]
wavelet = 'db2'
# manually pad each end by the filter size (4 for 'db2' used here)
padded_x = {'zero': [0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0],
'constant': [1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 3],
'symmetric': [3, 3, 2, 1, 1, 2, 3, 3, 2, 1, 1],
'reflect': [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3],
'periodic': [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1],
'smooth': [-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7],
}
for mode, xpad in padded_x.items():
# DWT of the manually padded array. will discard edges later so
# symmetric mode used here doesn't matter.
cApad, cDpad = pywt.dwt(xpad, wavelet, mode='symmetric')
# central region of the padded output (unaffected by mode )
expected_result = (cApad[2:-2], cDpad[2:-2])
cA, cD = pywt.dwt(x, wavelet, mode)
assert_allclose(cA, expected_result[0], rtol=1e-7, atol=1e-8)
assert_allclose(cD, expected_result[1], rtol=1e-7, atol=1e-8)
示例5: plot_signal_decomp
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def plot_signal_decomp(data, w, title):
"""Decompose and plot a signal S.
S = An + Dn + Dn-1 + ... + D1
"""
w = pywt.Wavelet(w)
a = data
ca = []
cd = []
for i in range(5):
(a, d) = pywt.dwt(a, w, mode)
ca.append(a)
cd.append(d)
rec_a = []
rec_d = []
for i, coeff in enumerate(ca):
coeff_list = [coeff, None] + [None] * i
rec_a.append(pywt.waverec(coeff_list, w))
for i, coeff in enumerate(cd):
coeff_list = [None, coeff] + [None] * i
rec_d.append(pywt.waverec(coeff_list, w))
fig = plt.figure()
ax_main = fig.add_subplot(len(rec_a) + 1, 1, 1)
ax_main.set_title(title)
ax_main.plot(data)
ax_main.set_xlim(0, len(data) - 1)
for i, y in enumerate(rec_a):
ax = fig.add_subplot(len(rec_a) + 1, 2, 3 + i * 2)
ax.plot(y, 'r')
ax.set_xlim(0, len(y) - 1)
ax.set_ylabel("A%d" % (i + 1))
for i, y in enumerate(rec_d):
ax = fig.add_subplot(len(rec_d) + 1, 2, 4 + i * 2)
ax.plot(y, 'g')
ax.set_xlim(0, len(y) - 1)
ax.set_ylabel("D%d" % (i + 1))
示例6: test_mode_equivalence
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_mode_equivalence():
old_new = [('zpd', 'zero'),
('cpd', 'constant'),
('sym', 'symmetric'),
('ppd', 'periodic'),
('sp1', 'smooth'),
('per', 'periodization')]
x = np.arange(8.)
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
for old, new in old_new:
assert_array_equal(pywt.dwt(x, 'db2', mode=old),
pywt.dwt(x, 'db2', mode=new))
示例7: check_reconstruction
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def check_reconstruction(pmode, mmode, wavelet, dtype):
data_size = list(range(2, 40)) + [100, 200, 500, 1000, 2000, 10000,
50000, 100000]
np.random.seed(12345)
# TODO: smoke testing - more failures for different seeds
if dtype == np.float32:
# was 3e-7 has to be lowered as db21, db29, db33, db35, coif14, coif16 were failing
epsilon = 6e-7
else:
epsilon = 5e-11
for N in data_size:
data = np.asarray(np.random.random(N), dtype)
# compute dwt coefficients
pa, pd = pywt.dwt(data, wavelet, pmode)
# compute reconstruction
rec = pywt.idwt(pa, pd, wavelet, pmode)
if len(data) % 2:
rec = rec[:len(data)]
rms_rec = np.sqrt(np.mean((data-rec)**2))
msg = ('[RMS_REC > EPSILON] for Mode: %s, Wavelet: %s, '
'Length: %d, rms=%.3g' % (pmode, wavelet, len(data), rms_rec))
assert_(rms_rec < epsilon, msg=msg)
示例8: test_concurrent_dwt
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_concurrent_dwt():
# dwt on 1D data calls the Cython dwt_single
# other cases call dwt_axis
for dwt_func, x in zip([pywt.dwt, pywt.dwt2, pywt.dwtn],
[np.ones(8), np.eye(16), np.eye(16)]):
transform = partial(dwt_func, wavelet='haar')
for _ in range(10):
arrs = [x.copy() for _ in range(100)]
with futures.ThreadPoolExecutor(max_workers=max_workers) as ex:
results = list(ex.map(transform, arrs))
# validate result from one of the concurrent runs
expected_result = transform(x)
_assert_all_coeffs_equal([expected_result, ], [results[-1], ])
示例9: _check_accuracy
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def _check_accuracy(data, w, pmode, ma, md, wavelet, epsilon):
# PyWavelets result
pa, pd = pywt.dwt(data, w, pmode)
# calculate error measures
rms_a = np.sqrt(np.mean((pa - ma) ** 2))
rms_d = np.sqrt(np.mean((pd - md) ** 2))
msg = ('[RMS_A > EPSILON] for Mode: %s, Wavelet: %s, '
'Length: %d, rms=%.3g' % (pmode, wavelet, len(data), rms_a))
assert_(rms_a < epsilon, msg=msg)
msg = ('[RMS_D > EPSILON] for Mode: %s, Wavelet: %s, '
'Length: %d, rms=%.3g' % (pmode, wavelet, len(data), rms_d))
assert_(rms_d < epsilon, msg=msg)
示例10: test_dwt_idwt_dtypes
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_dwt_idwt_dtypes():
wavelet = pywt.Wavelet('haar')
for dt_in, dt_out in zip(dtypes_in, dtypes_out):
x = np.ones(4, dtype=dt_in)
errmsg = "wrong dtype returned for {0} input".format(dt_in)
cA, cD = pywt.dwt(x, wavelet)
assert_(cA.dtype == cD.dtype == dt_out, "dwt: " + errmsg)
x_roundtrip = pywt.idwt(cA, cD, wavelet)
assert_(x_roundtrip.dtype == dt_out, "idwt: " + errmsg)
示例11: test_dwt_idwt_basic_complex
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_dwt_idwt_basic_complex():
x = np.asarray([3, 7, 1, 1, -2, 5, 4, 6])
x = x + 0.5j*x
cA, cD = pywt.dwt(x, 'db2')
cA_expect = np.asarray([5.65685425, 7.39923721, 0.22414387, 3.33677403,
7.77817459])
cA_expect = cA_expect + 0.5j*cA_expect
cD_expect = np.asarray([-2.44948974, -1.60368225, -4.44140056, -0.41361256,
1.22474487])
cD_expect = cD_expect + 0.5j*cD_expect
assert_allclose(cA, cA_expect)
assert_allclose(cD, cD_expect)
x_roundtrip = pywt.idwt(cA, cD, 'db2')
assert_allclose(x_roundtrip, x, rtol=1e-10)
示例12: test_dwt_single_axis
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_dwt_single_axis():
x = [[3, 7, 1, 1],
[-2, 5, 4, 6]]
cA, cD = pywt.dwt(x, 'db2', axis=-1)
cA0, cD0 = pywt.dwt(x[0], 'db2')
cA1, cD1 = pywt.dwt(x[1], 'db2')
assert_allclose(cA[0], cA0)
assert_allclose(cA[1], cA1)
assert_allclose(cD[0], cD0)
assert_allclose(cD[1], cD1)
示例13: test_idwt_single_axis
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_idwt_single_axis():
x = [[3, 7, 1, 1],
[-2, 5, 4, 6]]
x = np.asarray(x)
x = x + 1j*x # test with complex data
cA, cD = pywt.dwt(x, 'db2', axis=-1)
x0 = pywt.idwt(cA[0], cD[0], 'db2', axis=-1)
x1 = pywt.idwt(cA[1], cD[1], 'db2', axis=-1)
assert_allclose(x[0], x0)
assert_allclose(x[1], x1)
示例14: test_dwt_axis_arg
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_dwt_axis_arg():
x = [[3, 7, 1, 1],
[-2, 5, 4, 6]]
cA_, cD_ = pywt.dwt(x, 'db2', axis=-1)
cA, cD = pywt.dwt(x, 'db2', axis=1)
assert_allclose(cA_, cA)
assert_allclose(cD_, cD)
示例15: test_idwt_axis_arg
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import dwt [as 别名]
def test_idwt_axis_arg():
x = [[3, 7, 1, 1],
[-2, 5, 4, 6]]
cA, cD = pywt.dwt(x, 'db2', axis=1)
x_ = pywt.idwt(cA, cD, 'db2', axis=-1)
x = pywt.idwt(cA, cD, 'db2', axis=1)
assert_allclose(x_, x)