当前位置: 首页>>代码示例>>Python>>正文


Python pywt.wavedec方法代码示例

本文整理汇总了Python中pywt.wavedec方法的典型用法代码示例。如果您正苦于以下问题:Python pywt.wavedec方法的具体用法?Python pywt.wavedec怎么用?Python pywt.wavedec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pywt的用法示例。


在下文中一共展示了pywt.wavedec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _assert_all_coeffs_equal

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [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 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:18,代码来源:test_concurrent.py

示例2: _wavelet_coefs

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def _wavelet_coefs(data, wavelet_name='db4'):
    """Compute Discrete Wavelet Transform coefficients.

    Parameters
    ----------
    data : ndarray, shape (n_channels, n_times)

    wavelet_name : str (default: db4)
         Wavelet name (to be used with ``pywt.Wavelet``). The full list of
         Wavelet names are given by: ``[name for family in pywt.families() for
         name in pywt.wavelist(family)]``.

    Returns
    -------
    coefs : list of ndarray
         Coefficients of a DWT (Discrete Wavelet Transform). ``coefs[0]`` is
         the array of approximation coefficient and ``coefs[1:]`` is the list
         of detail coefficients.
    """
    wavelet = pywt.Wavelet(wavelet_name)
    levdec = min(pywt.dwt_max_level(data.shape[-1], wavelet.dec_len), 6)
    coefs = pywt.wavedec(data, wavelet=wavelet, level=levdec)
    return coefs 
开发者ID:mne-tools,项目名称:mne-features,代码行数:25,代码来源:utils.py

示例3: denoise

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def denoise(X,wave0):
    wavelet=wave0
    if len(X)>=8:
        level0= 1
        if np.floor(np.log(len(X)))>7:
           level0= np.floor(np.log(len(X))/2.0) 
        thres = 2*np.sqrt(2*np.log(len(X))/len(X))*np.std(X)
        thres = 0.0
        WaveletCoeffs = pywt.wavedec(X, wavelet, level=level0)
        NewWaveletCoeffs = map (lambda x: pywt.threshold(x, thres, mode='hard'),WaveletCoeffs)
        newWave2 = pywt.waverec( NewWaveletCoeffs, wavelet)
        return newWave2
    else:
        logging.warning( "the series is too short")
        return X


#compute the liquidity index 
开发者ID:jiansenzheng,项目名称:oanda_trading,代码行数:20,代码来源:forex17_0724_RevTreTickNW_EURUSD.py

示例4: test_coeffs_to_array

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def test_coeffs_to_array():
    # single element list returns the first element
    a_coeffs = [np.arange(8).reshape(2, 4), ]
    arr, arr_slices = pywt.coeffs_to_array(a_coeffs)
    assert_allclose(arr, a_coeffs[0])
    assert_allclose(arr, arr[arr_slices[0]])

    assert_raises(ValueError, pywt.coeffs_to_array, [])
    # invalid second element:  array as in wavedec, but not 1D
    assert_raises(ValueError, pywt.coeffs_to_array, [a_coeffs[0], ] * 2)
    # invalid second element:  tuple as in wavedec2, but not a 3-tuple
    assert_raises(ValueError, pywt.coeffs_to_array, [a_coeffs[0],
                                                     (a_coeffs[0], )])
    # coefficients as None is not supported
    assert_raises(ValueError, pywt.coeffs_to_array, [None, ])
    assert_raises(ValueError, pywt.coeffs_to_array, [a_coeffs,
                                                     (None, None, None)])

    # invalid type for second coefficient list element
    assert_raises(ValueError, pywt.coeffs_to_array, [a_coeffs, None])

    # use an invalid key name in the coef dictionary
    coeffs = [np.array([0]), dict(d=np.array([0]), c=np.array([0]))]
    assert_raises(ValueError, pywt.coeffs_to_array, coeffs) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:26,代码来源:test_multilevel.py

示例5: test_wavedecn_coeff_reshape_even

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [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) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:27,代码来源:test_multilevel.py

示例6: apply

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def apply(self, data):
        # data[ch][dim0]
        shape = data.shape
        out = np.empty((shape[0], 4 * (self.n * 2 + 1)), dtype=np.float64)

        def set_stats(outi, x, offset):
            outi[offset*4] = np.mean(x)
            outi[offset*4+1] = np.std(x)
            outi[offset*4+2] = np.min(x)
            outi[offset*4+3] = np.max(x)

        for i in range(len(data)):
            outi = out[i]
            new_data = pywt.wavedec(data[i], 'db%d' % self.n, level=self.n*2)
            for i, x in enumerate(new_data):
                set_stats(outi, x, i)

        return out 
开发者ID:MichaelHills,项目名称:seizure-detection,代码行数:20,代码来源:transforms.py

示例7: compute_wavelet_descriptor

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def compute_wavelet_descriptor(beat, family, level):
    wave_family = pywt.Wavelet(family)
    coeffs = pywt.wavedec(beat, wave_family, level=level)
    return coeffs[0]

# Compute my descriptor based on amplitudes of several intervals 
开发者ID:mondejar,项目名称:ecg-classification,代码行数:8,代码来源:features_ECG.py

示例8: denoise

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def denoise(X,wave0):
	wavelet=wave0
	if len(X)>=8:
		level0= 1
		if np.floor(np.log(len(X)))>7:
		   level0= np.floor(np.log(len(X))/2.0) 
		thres = 2*np.sqrt(2*np.log(len(X))/len(X))*np.std(X)
		thres = 0.0
		WaveletCoeffs = pywt.wavedec(X, wavelet, level=level0)
		NewWaveletCoeffs = map (lambda x: pywt.threshold(x, thres, mode='hard'),WaveletCoeffs)
		newWave2 = pywt.waverec( NewWaveletCoeffs, wavelet)
		return newWave2
	else:
		logging.warning("the series is too short!")
		return X 
开发者ID:jiansenzheng,项目名称:oanda_trading,代码行数:17,代码来源:trading_global_functions.py

示例9: test_wavedec

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def test_wavedec():
    x = [3, 7, 1, 1, -2, 5, 4, 6]
    db1 = pywt.Wavelet('db1')
    cA3, cD3, cD2, cD1 = pywt.wavedec(x, db1)
    assert_almost_equal(cA3, [8.83883476])
    assert_almost_equal(cD3, [-0.35355339])
    assert_allclose(cD2, [4., -3.5])
    assert_allclose(cD1, [-2.82842712, 0, -4.94974747, -1.41421356])
    assert_(pywt.dwt_max_level(len(x), db1) == 3) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:11,代码来源:test_multilevel.py

示例10: test_waverec_accuracies

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def test_waverec_accuracies():
    rstate = np.random.RandomState(1234)
    x0 = rstate.randn(8)
    for dt, tol in dtypes_and_tolerances:
        x = x0.astype(dt)
        if np.iscomplexobj(x):
            x += 1j*rstate.randn(8).astype(x.real.dtype)
        coeffs = pywt.wavedec(x, 'db1')
        assert_allclose(pywt.waverec(coeffs, 'db1'), x, atol=tol, rtol=tol) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:11,代码来源:test_multilevel.py

示例11: test_waverec_none

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def test_waverec_none():
    x = [3, 7, 1, 1, -2, 5, 4, 6]
    coeffs = pywt.wavedec(x, 'db1')

    # set some coefficients to None
    coeffs[2] = None
    coeffs[0] = None
    assert_(pywt.waverec(coeffs, 'db1').size, len(x)) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:10,代码来源:test_multilevel.py

示例12: test_waverec_odd_length

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def test_waverec_odd_length():
    x = [3, 7, 1, 1, -2, 5]
    coeffs = pywt.wavedec(x, 'db1')
    assert_allclose(pywt.waverec(coeffs, 'db1'), x, rtol=1e-12) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:6,代码来源:test_multilevel.py

示例13: test_waverec_complex

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def test_waverec_complex():
    x = np.array([3, 7, 1, 1, -2, 5, 4, 6])
    x = x + 1j
    coeffs = pywt.wavedec(x, 'db1')
    assert_allclose(pywt.waverec(coeffs, 'db1'), x, rtol=1e-12) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:7,代码来源:test_multilevel.py

示例14: test_waverec_all_wavelets_modes

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def test_waverec_all_wavelets_modes():
    # test 2D case using all wavelets and modes
    rstate = np.random.RandomState(1234)
    r = rstate.randn(80)
    for wavelet in wavelist:
        for mode in pywt.Modes.modes:
            coeffs = pywt.wavedec(r, wavelet, mode=mode)
            assert_allclose(pywt.waverec(coeffs, wavelet, mode=mode),
                            r, rtol=tol_single, atol=tol_single)

####
# 2d multilevel dwt function tests
#### 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:15,代码来源:test_multilevel.py

示例15: test_wavedecn_coeff_reshape_axes_subset

# 需要导入模块: import pywt [as 别名]
# 或者: from pywt import wavedec [as 别名]
def test_wavedecn_coeff_reshape_axes_subset():
    # verify round trip is correct when only a subset of axes are transformed:
    #   wavedecn - >coeffs_to_array-> array_to_coeffs -> waverecn
    # This is done for wavedec{1, 2, n}
    rng = np.random.RandomState(1234)
    mode = 'symmetric'
    w = pywt.Wavelet('db2')
    N = 16
    ndim = 3
    for axes in [(-1, ), (0, ), (1, ), (0, 1), (1, 2), (0, 2), None]:
        x1 = rng.randn(*([N] * ndim))
        coeffs = pywt.wavedecn(x1, w, mode=mode, axes=axes)
        coeff_arr, coeff_slices = pywt.coeffs_to_array(coeffs, axes=axes)
        if axes is not None:
            # if axes is not None, it must be provided to coeffs_to_array
            assert_raises(ValueError, pywt.coeffs_to_array, coeffs)

        # mismatched axes size
        assert_raises(ValueError, pywt.coeffs_to_array, coeffs,
                      axes=(0, 1, 2, 3))
        assert_raises(ValueError, pywt.coeffs_to_array, coeffs,
                      axes=())

        coeffs2 = pywt.array_to_coeffs(coeff_arr, coeff_slices)
        x1r = pywt.waverecn(coeffs2, w, mode=mode, axes=axes)

        assert_allclose(x1, x1r, rtol=1e-4, atol=1e-4) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:29,代码来源:test_multilevel.py


注:本文中的pywt.wavedec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。