Single-level n-dimensional Discrete Wavelet Transform. Parameters ---------- data : array_like n-dimensional array with input data. wavelet : Wavelet object or name string, or tuple of wavelets Wavelet to use. This can also be a tuple containing a wavelet to
(data, wavelet, mode='symmetric', axes=None)
| 117 | |
| 118 | |
| 119 | def dwtn(data, wavelet, mode='symmetric', axes=None): |
| 120 | """ |
| 121 | Single-level n-dimensional Discrete Wavelet Transform. |
| 122 | |
| 123 | Parameters |
| 124 | ---------- |
| 125 | data : array_like |
| 126 | n-dimensional array with input data. |
| 127 | wavelet : Wavelet object or name string, or tuple of wavelets |
| 128 | Wavelet to use. This can also be a tuple containing a wavelet to |
| 129 | apply along each axis in ``axes``. |
| 130 | mode : str or tuple of string, optional |
| 131 | Signal extension mode used in the decomposition, |
| 132 | see :ref:`Modes <ref-modes>`. This can also be a tuple of modes |
| 133 | specifying the mode to use on each axis in ``axes``. |
| 134 | axes : sequence of ints, optional |
| 135 | Axes over which to compute the DWT. Repeated elements mean the DWT will |
| 136 | be performed multiple times along these axes. A value of ``None`` (the |
| 137 | default) selects all axes. |
| 138 | |
| 139 | Axes may be repeated, but information about the original size may be |
| 140 | lost if it is not divisible by ``2 ** nrepeats``. The reconstruction |
| 141 | will be larger, with additional values derived according to the |
| 142 | ``mode`` parameter. ``pywt.wavedecn`` should be used for multilevel |
| 143 | decomposition. |
| 144 | |
| 145 | Returns |
| 146 | ------- |
| 147 | coeffs : dict |
| 148 | Results are arranged in a dictionary, where key specifies |
| 149 | the transform type on each dimension and value is a n-dimensional |
| 150 | coefficients array. |
| 151 | |
| 152 | For example, for a 2D case the result will look something like this:: |
| 153 | |
| 154 | {'aa': <coeffs> # A(LL) - approx. on 1st dim, approx. on 2nd dim |
| 155 | 'ad': <coeffs> # V(LH) - approx. on 1st dim, det. on 2nd dim |
| 156 | 'da': <coeffs> # H(HL) - det. on 1st dim, approx. on 2nd dim |
| 157 | 'dd': <coeffs> # D(HH) - det. on 1st dim, det. on 2nd dim |
| 158 | } |
| 159 | |
| 160 | For user-specified ``axes``, the order of the characters in the |
| 161 | dictionary keys map to the specified ``axes``. |
| 162 | |
| 163 | """ |
| 164 | data = np.asarray(data) |
| 165 | if not _have_c99_complex and np.iscomplexobj(data): |
| 166 | real = dwtn(data.real, wavelet, mode, axes) |
| 167 | imag = dwtn(data.imag, wavelet, mode, axes) |
| 168 | return {k: real[k] + 1j * imag[k] for k in real} |
| 169 | |
| 170 | if data.dtype == np.dtype('object'): |
| 171 | raise TypeError("Input must be a numeric array-like") |
| 172 | if data.ndim < 1: |
| 173 | raise ValueError("Input data must be at least 1D") |
| 174 | |
| 175 | if axes is None: |
| 176 | axes = range(data.ndim) |
no test coverage detected