本文整理汇总了Python中pywt.waverecn方法的典型用法代码示例。如果您正苦于以下问题:Python pywt.waverecn方法的具体用法?Python pywt.waverecn怎么用?Python pywt.waverecn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywt
的用法示例。
在下文中一共展示了pywt.waverecn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_waverecn_invalid_coeffs
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_invalid_coeffs():
# approximation coeffs as None and no valid detail oeffs
coeffs = [None, {}]
assert_raises(ValueError, pywt.waverecn, coeffs, 'db1')
# use of None for a coefficient value
coeffs = [np.ones((2, 2, 2)), {}, {'daa': None}, ]
assert_raises(ValueError, pywt.waverecn, coeffs, 'db1')
# invalid key names in coefficient list
coeffs = [np.ones((4, 4, 4)), {'daa': np.ones((4, 4, 4)),
'foo': np.ones((4, 4, 4))}]
assert_raises(ValueError, pywt.waverecn, coeffs, 'db1')
# mismatched key name lengths
coeffs = [np.ones((4, 4, 4)), {'daa': np.ones((4, 4, 4)),
'da': np.ones((4, 4, 4))}]
assert_raises(ValueError, pywt.waverecn, coeffs, 'db1')
# key name lengths don't match the array dimensions
coeffs = [[[[1.0]]], {'ad': [[[0.0]]], 'da': [[[0.0]]], 'dd': [[[0.0]]]}]
assert_raises(ValueError, pywt.waverecn, coeffs, 'db1')
# input list cannot be empty
assert_raises(ValueError, pywt.waverecn, [], 'haar')
示例2: test_wavedecn_coeff_reshape_even
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_wavedecn_coeff_reshape_even():
# verify round trip is correct:
# wavedecn - >coeffs_to_array-> array_to_coeffs -> waverecn
# This is done for wavedec{1, 2, n}
rng = np.random.RandomState(1234)
params = {'wavedec': {'d': 1, 'dec': pywt.wavedec, 'rec': pywt.waverec},
'wavedec2': {'d': 2, 'dec': pywt.wavedec2, 'rec': pywt.waverec2},
'wavedecn': {'d': 3, 'dec': pywt.wavedecn, 'rec': pywt.waverecn}}
N = 28
for f in params:
x1 = rng.randn(*([N] * params[f]['d']))
for mode in pywt.Modes.modes:
for wave in wavelist:
w = pywt.Wavelet(wave)
maxlevel = pywt.dwt_max_level(np.min(x1.shape), w.dec_len)
if maxlevel == 0:
continue
coeffs = params[f]['dec'](x1, w, mode=mode)
coeff_arr, coeff_slices = pywt.coeffs_to_array(coeffs)
coeffs2 = pywt.array_to_coeffs(coeff_arr, coeff_slices,
output_format=f)
x1r = params[f]['rec'](coeffs2, w, mode=mode)
assert_allclose(x1, x1r, rtol=1e-4, atol=1e-4)
示例3: test_waverecn_coeff_reshape_odd
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_coeff_reshape_odd():
# verify round trip is correct:
# wavedecn - >coeffs_to_array-> array_to_coeffs -> waverecn
rng = np.random.RandomState(1234)
x1 = rng.randn(35, 33)
for mode in pywt.Modes.modes:
for wave in ['haar', ]:
w = pywt.Wavelet(wave)
maxlevel = pywt.dwt_max_level(np.min(x1.shape), w.dec_len)
if maxlevel == 0:
continue
coeffs = pywt.wavedecn(x1, w, mode=mode)
coeff_arr, coeff_slices = pywt.coeffs_to_array(coeffs)
coeffs2 = pywt.array_to_coeffs(coeff_arr, coeff_slices)
x1r = pywt.waverecn(coeffs2, w, mode=mode)
# truncate reconstructed values to original shape
x1r = x1r[[slice(s) for s in x1.shape]]
assert_allclose(x1, x1r, rtol=1e-4, atol=1e-4)
示例4: _rmatvec
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def _rmatvec(self, x):
if self.reshape:
x = np.reshape(x, self.dimsd)
x = pywt.array_to_coeffs(x, self.sl, output_format='wavedecn')
y = pywt.waverecn(x, wavelet=self.waveletadj, mode='periodization',
axes=(self.dir, ))
y = self.pad.rmatvec(y.ravel())
return y
示例5: inverse_wavelet_transform
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def inverse_wavelet_transform(w_coeffs_rgb, coeff_slices, x_shape):
x_hat = np.zeros(x_shape)
for i in range(w_coeffs_rgb.shape[0]):
w_coeffs_list = pywt.array_to_coeffs(w_coeffs_rgb[i,:,:], coeff_slices)
x_hat[0,:,:,i] = pywt.waverecn(w_coeffs_list, wavelet='db4', mode='periodization')
return x_hat
示例6: test_waverecn
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn():
rstate = np.random.RandomState(1234)
# test 1D through 4D cases
for nd in range(1, 5):
x = rstate.randn(*(4, )*nd)
coeffs = pywt.wavedecn(x, 'db1')
assert_(len(coeffs) == 3)
assert_allclose(pywt.waverecn(coeffs, 'db1'), x, rtol=tol_double)
示例7: test_waverecn_empty_coeff
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_empty_coeff():
coeffs = [np.ones((2, 2, 2)), {}, {}]
assert_equal(pywt.waverecn(coeffs, 'db1').shape, (8, 8, 8))
assert_equal(pywt.waverecn(coeffs, 'db1').shape, (8, 8, 8))
coeffs = [np.ones((2, 2, 2)), {}, {'daa': np.ones((4, 4, 4))}]
coeffs = [np.ones((2, 2, 2)), {}, {}, {'daa': np.ones((8, 8, 8))}]
assert_equal(pywt.waverecn(coeffs, 'db1').shape, (16, 16, 16))
示例8: test_waverecn_lists
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_lists():
# support coefficient arrays specified as lists instead of arrays
coeffs = [[[1.0]], {'ad': [[0.0]], 'da': [[0.0]], 'dd': [[0.0]]}]
assert_equal(pywt.waverecn(coeffs, 'db1').shape, (2, 2))
示例9: test_waverecn_invalid_coeffs2
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_invalid_coeffs2():
# shape mismatch should raise an error
coeffs = [np.ones((4, 4, 4)), {'ada': np.ones((4, 4))}]
assert_raises(ValueError, pywt.waverecn, coeffs, 'db1')
示例10: test_multilevel_dtypes_nd
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_multilevel_dtypes_nd():
wavelet = pywt.Wavelet('haar')
for dt_in, dt_out in zip(dtypes_in, dtypes_out):
# wavedecn, waverecn
x = np.ones((8, 8), dtype=dt_in)
errmsg = "wrong dtype returned for {0} input".format(dt_in)
cA, coeffsD2, coeffsD1 = pywt.wavedecn(x, wavelet, level=2)
assert_(cA.dtype == dt_out, "wavedecn: " + errmsg)
for key, c in coeffsD1.items():
assert_(c.dtype == dt_out, "wavedecn: " + errmsg)
for key, c in coeffsD2.items():
assert_(c.dtype == dt_out, "wavedecn: " + errmsg)
x_roundtrip = pywt.waverecn([cA, coeffsD2, coeffsD1], wavelet)
assert_(x_roundtrip.dtype == dt_out, "waverecn: " + errmsg)
示例11: test_wavedecn_complex
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_wavedecn_complex():
data = np.ones((4, 4, 4)) + 1j
coeffs = pywt.wavedecn(data, 'db1')
assert_allclose(pywt.waverecn(coeffs, 'db1'), data, rtol=1e-12)
示例12: test_waverecn_dtypes
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_dtypes():
x = np.ones((4, 4, 4))
for dt, tol in dtypes_and_tolerances:
coeffs = pywt.wavedecn(x.astype(dt), 'db1')
assert_allclose(pywt.waverecn(coeffs, 'db1'), x, atol=tol, rtol=tol)
示例13: test_waverecn_all_wavelets_modes
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_all_wavelets_modes():
# test 2D case using all wavelets and modes
rstate = np.random.RandomState(1234)
r = rstate.randn(80, 96)
for wavelet in wavelist:
for mode in pywt.Modes.modes:
coeffs = pywt.wavedecn(r, wavelet, mode=mode)
assert_allclose(pywt.waverecn(coeffs, wavelet, mode=mode),
r, rtol=tol_single, atol=tol_single)
示例14: test_waverecn_axes_subsets
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_axes_subsets():
rstate = np.random.RandomState(0)
data = rstate.standard_normal((8, 8, 8, 8))
# test all combinations of 3 out of 4 axes transformed
for axes in combinations((0, 1, 2, 3), 3):
coefs = pywt.wavedecn(data, 'haar', axes=axes)
rec = pywt.waverecn(coefs, 'haar', axes=axes)
assert_allclose(rec, data, atol=1e-14)
示例15: test_waverecn_int_axis
# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import waverecn [as 别名]
def test_waverecn_int_axis():
# waverecn should also work for axes as an integer
rstate = np.random.RandomState(0)
data = rstate.standard_normal((8, 8))
for axis in [0, 1]:
coefs = pywt.wavedecn(data, 'haar', axes=axis)
rec = pywt.waverecn(coefs, 'haar', axes=axis)
assert_allclose(rec, data, atol=1e-14)