Debian Codegraph @

doc/source/regression/modes.rst

raw
1 .. _reg-modes:
2
3 .. currentmodule:: pywt
4
5
6 Signal Extension Modes
7 ======================
8
9 Import :mod:`pywt` first
10
11 >>> import pywt
12
13 >>> def format_array(a):
14 ... """Consistent array representation across different systems"""
15 ... import numpy
16 ... a = numpy.where(numpy.abs(a) < 1e-5, 0, a)
17 ... return numpy.array2string(a, precision=5, separator=' ', suppress_small=True)
18
19 List of available signal extension :ref:`modes <Modes>`:
20
21 >>> print(pywt.Modes.modes)
22 ['zero', 'constant', 'symmetric', 'periodic', 'smooth', 'periodization', 'reflect', 'antisymmetric', 'antireflect']
23
24
25 Invalid mode name should rise a :exc:`ValueError`:
26
27 >>> pywt.dwt([1,2,3,4], 'db2', 'invalid')
28 Traceback (most recent call last):
29 ...
30 ValueError: Unknown mode name 'invalid'.
31
32
33 You can also refer to modes via :ref:`Modes <Modes>` class attributes:
34
35 >>> x = [1, 2, 1, 5, -1, 8, 4, 6]
36 >>> for mode_name in ['zero', 'constant', 'symmetric', 'reflect', 'periodic', 'smooth', 'periodization']:
37 ... mode = getattr(pywt.Modes, mode_name)
38 ... cA, cD = pywt.dwt(x, 'db2', mode)
39 ... print("Mode: %d (%s)" % (mode, mode_name))
40 Mode: 0 (zero)
41 Mode: 2 (constant)
42 Mode: 1 (symmetric)
43 Mode: 6 (reflect)
44 Mode: 4 (periodic)
45 Mode: 3 (smooth)
46 Mode: 5 (periodization)
47
48
49 The default mode is :ref:`symmetric <Modes.symmetric>`:
50
51 >>> cA, cD = pywt.dwt(x, 'db2')
52 >>> print(cA)
53 [ 1.76776695 1.73309178 3.40612438 6.32928585 7.77817459]
54 >>> print(cD)
55 [-0.61237244 -2.15599552 -5.95034847 -1.21545369 1.22474487]
56 >>> print(pywt.idwt(cA, cD, 'db2'))
57 [ 1. 2. 1. 5. -1. 8. 4. 6.]
58
59
60 And using a keyword argument:
61
62 >>> cA, cD = pywt.dwt(x, 'db2', mode='symmetric')
63 >>> print(cA)
64 [ 1.76776695 1.73309178 3.40612438 6.32928585 7.77817459]
65 >>> print(cD)
66 [-0.61237244 -2.15599552 -5.95034847 -1.21545369 1.22474487]
67 >>> print(pywt.idwt(cA, cD, 'db2'))
68 [ 1. 2. 1. 5. -1. 8. 4. 6.]