MCPcopy Create free account
hub / github.com/PyWavelets/pywt / waverec

Function waverec

pywt/_multilevel.py:112–176  ·  view source on GitHub ↗

Multilevel 1D Inverse Discrete Wavelet Transform. Parameters ---------- coeffs : array_like Coefficients list [cAn, cDn, cDn-1, ..., cD2, cD1] wavelet : Wavelet object or name string Wavelet to use mode : str, optional Signal extension mode, see :ref

(coeffs, wavelet, mode='symmetric', axis=-1)

Source from the content-addressed store, hash-verified

110
111
112def waverec(coeffs, wavelet, mode='symmetric', axis=-1):
113 """
114 Multilevel 1D Inverse Discrete Wavelet Transform.
115
116 Parameters
117 ----------
118 coeffs : array_like
119 Coefficients list [cAn, cDn, cDn-1, ..., cD2, cD1]
120 wavelet : Wavelet object or name string
121 Wavelet to use
122 mode : str, optional
123 Signal extension mode, see :ref:`Modes <ref-modes>`.
124 axis: int, optional
125 Axis over which to compute the inverse DWT. If not given, the
126 last axis is used.
127
128 Notes
129 -----
130 It may sometimes be desired to run ``waverec`` with some sets of
131 coefficients omitted. This can best be done by setting the corresponding
132 arrays to zero arrays of matching shape and dtype. Explicitly removing
133 list entries or setting them to None is not supported.
134
135 Specifically, to ignore detail coefficients at level 2, one could do::
136
137 coeffs[-2] = np.zeros_like(coeffs[-2])
138
139 Examples
140 --------
141 >>> import pywt
142 >>> coeffs = pywt.wavedec([1,2,3,4,5,6,7,8], 'db1', level=2)
143 >>> pywt.waverec(coeffs, 'db1')
144 array([ 1., 2., 3., 4., 5., 6., 7., 8.])
145 """
146
147 if not isinstance(coeffs, (list, tuple)):
148 raise ValueError("Expected sequence of coefficient arrays.")
149
150 if len(coeffs) < 1:
151 raise ValueError(
152 "Coefficient list too short (minimum 1 arrays required).")
153 elif len(coeffs) == 1:
154 # level 0 transform (just returns the approximation coefficients)
155 return coeffs[0]
156
157 a, ds = coeffs[0], coeffs[1:]
158
159 for d in ds:
160 if d is not None and not isinstance(d, np.ndarray):
161 raise ValueError(
162 f"Unexpected detail coefficient type: {type(d)}. Detail coefficients "
163 "must be arrays as returned by wavedec. If you are using "
164 "pywt.array_to_coeffs or pywt.unravel_coeffs, please specify "
165 "output_format='wavedec'")
166 if (a is not None) and (d is not None):
167 try:
168 if a.shape[axis] == d.shape[axis] + 1:
169 a = a[tuple(slice(s) for s in d.shape)]

Callers 1

fswaverecnFunction · 0.85

Calls 1

idwtFunction · 0.90

Tested by

no test coverage detected