Python pywt.wavelist() Examples
The following are 17
code examples of pywt.wavelist().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pywt
, or try the search function
.
Example #1
Source File: utils.py From mne-features with BSD 3-Clause "New" or "Revised" License | 7 votes |
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
Example #2
Source File: timedenoising.py From PynPoint with GNU General Public License v3.0 | 6 votes |
def __init__(self, wavelet: str = 'db8') -> None: """ Parameters ---------- wavelet : str Wavelet. Returns ------- NoneType None """ # create list of supported wavelets supported = [] for family in pywt.families(): supported += pywt.wavelist(family) # check if wavelet is supported if wavelet not in supported: raise ValueError(f'DWT supports only {supported} as input wavelet.') self.m_wavelet = wavelet
Example #3
Source File: test_perfect_reconstruction.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
def test_perfect_reconstruction(): families = ('db', 'sym', 'coif', 'bior', 'rbio') wavelets = sum([pywt.wavelist(name) for name in families], []) # list of mode names in pywt and matlab modes = [('zero', 'zpd'), ('constant', 'sp0'), ('symmetric', 'sym'), ('periodic', 'ppd'), ('smooth', 'sp1'), ('periodization', 'per')] dtypes = (np.float32, np.float64) for wavelet in wavelets: for pmode, mmode in modes: for dt in dtypes: yield check_reconstruction, pmode, mmode, wavelet, dt
Example #4
Source File: test_multilevel.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
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)
Example #5
Source File: wfun.py From scaleogram with MIT License | 5 votes |
def get_wavlist(): """Returns the list of continuous wavelet functions available in the PyWavelets library. """ l = [] for name in pywt.wavelist(kind='continuous'): # supress warnings when the wavelet name is missing parameters completion = { 'cmor': 'cmor1.5-1.0', 'fbsp': 'fbsp1-1.5-1.0', 'shan': 'shan1.5-1.0' } if name in completion: name = completion[name]# supress warning l.append( name+" :\t"+pywt.ContinuousWavelet(name).family_name ) return l
Example #6
Source File: DWT.py From pylops with GNU Lesser General Public License v3.0 | 5 votes |
def _checkwavelet(wavelet): """Check that wavelet belongs to pywt.wavelist """ wavelist = pywt.wavelist(kind='discrete') if wavelet not in wavelist: raise ValueError("'%s' not in family set = %s" % (wavelet, wavelist))
Example #7
Source File: dtcwt.py From scikit-ued with MIT License | 5 votes |
def available_first_stage_filters(): """ Iterable of available wavelet filters compatible with the first stage of dual-tree complex wavelent transform. Returns ------- wavelets : iterable List of sorted string names. The wavelet numerical values can be retrieved from the :func:`dt_first_stage` function. """ return sorted(filter(lambda name: name != "dmey", wavelist(kind="discrete"))) # For backwards compatibility with iris
Example #8
Source File: test_multidim.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_dwdtn_idwtn_allwavelets(): rstate = np.random.RandomState(1234) r = rstate.randn(16, 16) # test 2D case only for all wavelet types wavelist = pywt.wavelist() if 'dmey' in wavelist: wavelist.remove('dmey') for wavelet in wavelist: if isinstance(pywt.DiscreteContinuousWavelet(wavelet), pywt.Wavelet): for mode in pywt.Modes.modes: coeffs = pywt.dwtn(r, wavelet, mode=mode) assert_allclose(pywt.idwtn(coeffs, wavelet, mode=mode), r, rtol=1e-7, atol=1e-7)
Example #9
Source File: test__pywt.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_wavelist(): for name in pywt.wavelist(family='coif'): assert_(name.startswith('coif')) assert_('cgau7' in pywt.wavelist(kind='continuous')) assert_('sym20' in pywt.wavelist(kind='discrete')) assert_(len(pywt.wavelist(kind='continuous')) + len(pywt.wavelist(kind='discrete')) == len(pywt.wavelist(kind='all'))) assert_raises(ValueError, pywt.wavelist, kind='foobar')
Example #10
Source File: test__pywt.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_compare_downcoef_coeffs(): rstate = np.random.RandomState(1234) r = rstate.randn(16) # compare downcoef against wavedec outputs for nlevels in [1, 2, 3]: for wavelet in pywt.wavelist(): wavelet = pywt.DiscreteContinuousWavelet(wavelet) if isinstance(wavelet, pywt.Wavelet): max_level = pywt.dwt_max_level(r.size, wavelet.dec_len) if nlevels <= max_level: a = pywt.downcoef('a', r, wavelet, level=nlevels) d = pywt.downcoef('d', r, wavelet, level=nlevels) coeffs = pywt.wavedec(r, wavelet, level=nlevels) assert_allclose(a, coeffs[0]) assert_allclose(d, coeffs[1])
Example #11
Source File: test_swt.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_swt2_iswt2_integration(): # This function performs a round-trip swt2/iswt2 transform test on # all available types of wavelets in PyWavelets - except the # 'dmey' wavelet. The latter has been excluded because it does not # produce very precise results. This is likely due to the fact # that the 'dmey' wavelet is a discrete approximation of a # continuous wavelet. All wavelets are tested up to 3 levels. The # test validates neither swt2 or iswt2 as such, but it does ensure # that they are each other's inverse. max_level = 3 wavelets = pywt.wavelist() if 'dmey' in wavelets: # The 'dmey' wavelet seems to be a bit special - disregard it for now wavelets.remove('dmey') for current_wavelet_str in wavelets: current_wavelet = pywt.DiscreteContinuousWavelet(current_wavelet_str) if isinstance(current_wavelet, pywt.Wavelet): input_length_power = int(np.ceil(np.log2(max( current_wavelet.dec_len, current_wavelet.rec_len)))) input_length = 2**(input_length_power + max_level - 1) X = np.arange(input_length**2).reshape(input_length, input_length) with warnings.catch_warnings(): warnings.simplefilter('ignore', FutureWarning) coeffs = pywt.swt2(X, current_wavelet, max_level) Y = pywt.iswt2(coeffs, current_wavelet) assert_allclose(Y, X, rtol=1e-5, atol=1e-5)
Example #12
Source File: test_multilevel.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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)
Example #13
Source File: test_multilevel.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_waverec2_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.wavedec2(r, wavelet, mode=mode) assert_allclose(pywt.waverec2(coeffs, wavelet, mode=mode), r, rtol=tol_single, atol=tol_single)
Example #14
Source File: test_multilevel.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
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 ####
Example #15
Source File: test_wavelet.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def test_wavelet_coefficients(): families = ('db', 'sym', 'coif', 'bior', 'rbio') wavelets = sum([pywt.wavelist(name) for name in families], []) for wavelet in wavelets: if (pywt.Wavelet(wavelet).orthogonal): yield check_coefficients_orthogonal, wavelet elif(pywt.Wavelet(wavelet).biorthogonal): yield check_coefficients_biorthogonal, wavelet else: yield check_coefficients, wavelet
Example #16
Source File: generate_features_material_samples.py From opensurfaces with MIT License | 4 votes |
def handle(self, *args, **options): substance_names = [ 'Painted', 'Wood', 'Fabric/cloth', 'Tile', 'Metal', 'Carpet/rug', 'Ceramic', 'Leather', 'Food', 'Brick', 'Stone', 'Skin' ] try: os.makedirs('svm') except Exception as e: print e all_samples = ShapeImageSample.objects.filter( shape__substance__name__in=substance_names ).order_by('?') train = [] test = [] # split training and testing print 'splitting training/test...' users = all_samples.distinct('shape__photo__flickr_user').values_list('shape__photo__flickr_user', flat=True).order_by() for u in progress.bar(users): if len(test) > len(train): train += all_samples.filter(shape__photo__flickr_user_id=u) else: test += all_samples.filter(shape__photo__flickr_user_id=u) print 'train size: %s' % len(train) print 'test size: %s' % len(test) for wavelet in progress.bar(pywt.wavelist('db') + pywt.wavelist('haar')): for training in [True, False]: print 'features for %s (training=%s)...' % (wavelet, training) cur_samples = train if training else test image_paths = [s.image.path for s in cur_samples] p = Pool(32) features = p.map(functools.partial(compute_features, wavelet), image_paths) p.close() with open('svm/%s-%s.svm' % (wavelet, 'train' if training else 'test'), 'w') as outfile: for i_s, s in enumerate(cur_samples): class_str = substance_names.index(s.shape.substance.name) feature_str = ' '.join(['%s:%s' % (i_f+1, f) for (i_f, f) in enumerate(features[i_s])]) print >>outfile, class_str, feature_str
Example #17
Source File: generate_features_material_samples.py From opensurfaces with MIT License | 4 votes |
def handle(self, *args, **options): substance_names = [ 'Painted', 'Wood', 'Fabric/cloth', 'Tile', 'Metal', 'Carpet/rug', 'Ceramic', 'Leather', 'Food', 'Brick', 'Stone', 'Skin' ] try: os.makedirs('svm') except Exception as e: print e all_samples = ShapeImageSample.objects.filter( shape__substance__name__in=substance_names ).order_by('?') train = [] test = [] # split training and testing print 'splitting training/test...' users = all_samples.distinct('shape__photo__flickr_user').values_list('shape__photo__flickr_user', flat=True).order_by() for u in progress.bar(users): if len(test) > len(train): train += all_samples.filter(shape__photo__flickr_user_id=u) else: test += all_samples.filter(shape__photo__flickr_user_id=u) print 'train size: %s' % len(train) print 'test size: %s' % len(test) for wavelet in progress.bar(pywt.wavelist('db') + pywt.wavelist('haar')): for training in [True, False]: print 'features for %s (training=%s)...' % (wavelet, training) cur_samples = train if training else test image_paths = [s.image.path for s in cur_samples] p = Pool(32) features = p.map(functools.partial(compute_features, wavelet), image_paths) p.close() with open('svm/%s-%s.svm' % (wavelet, 'train' if training else 'test'), 'w') as outfile: for i_s, s in enumerate(cur_samples): class_str = substance_names.index(s.shape.substance.name) feature_str = ' '.join(['%s:%s' % (i_f+1, f) for (i_f, f) in enumerate(features[i_s])]) print >>outfile, class_str, feature_str