Discrete and continuous wavelet transforms for signal and image processing with comprehensive 1D, 2D, and nD transform support.
npx @tessl/cli install tessl/pypi-pywavelets@1.9.0A comprehensive Python library for wavelet transforms providing discrete and continuous wavelet analysis for signal and image processing. PyWavelets offers extensive functionality including 1D, 2D, and nD transforms, multilevel decomposition, stationary wavelets, continuous wavelet transforms, and wavelet packet analysis with over 100 built-in wavelet filters.
pip install PyWaveletsimport pywtCommon pattern for specific functions:
from pywt import dwt, idwt, wavedec, waverecimport pywt
import numpy as np
# Create test signal
data = np.sin(np.linspace(0, 4*np.pi, 100))
# Single-level discrete wavelet transform
coeffs = pywt.dwt(data, 'db4')
cA, cD = coeffs # approximation and detail coefficients
# Reconstruct signal
reconstructed = pywt.idwt(cA, cD, 'db4')
# Multi-level wavelet decomposition
coeffs = pywt.wavedec(data, 'db4', level=3)
# coeffs = [cA3, cD3, cD2, cD1] - approximation + details
# Reconstruct from multi-level coefficients
reconstructed = pywt.waverec(coeffs, 'db4')
# 2D transform for images
import matplotlib.pyplot as plt
# Create sample 2D data
image = np.random.random((64, 64))
# 2D wavelet transform
coeffs2d = pywt.dwt2(image, 'db4')
cA, (cH, cV, cD) = coeffs2d
# Reconstruct
reconstructed2d = pywt.idwt2(coeffs2d, 'db4')PyWavelets is built around several key components:
The library follows a consistent API pattern where transform functions take data, wavelet specification, mode, and dimensional parameters, returning coefficient tuples or arrays that can be directly used for reconstruction.
Core wavelet objects, available wavelets, and utility functions for wavelet analysis including frequency analysis and filter bank operations.
class Wavelet:
def __init__(self, name: str, filter_bank=None): ...
def wavefun(self, level: int = 8): ...
class ContinuousWavelet:
def __init__(self, name: str, dtype=np.float64): ...
def wavefun(self, level: int = 8, length=None): ...
def wavelist(family: str = None, kind: str = 'all') -> list: ...
def families(short: bool = True) -> list: ...Single-level forward and inverse discrete wavelet transforms for 1D, 2D, and nD data with complete coefficient decomposition.
def dwt(data, wavelet, mode: str = 'symmetric', axis: int = -1): ...
def idwt(cA, cD, wavelet, mode: str = 'symmetric', axis: int = -1): ...
def dwt2(data, wavelet, mode: str = 'symmetric', axes=(-2, -1)): ...
def idwt2(coeffs, wavelet, mode: str = 'symmetric', axes=(-2, -1)): ...
def dwtn(data, wavelet, mode: str = 'symmetric', axes=None): ...
def idwtn(coeffs, wavelet, mode: str = 'symmetric', axes=None): ...
def dwt_max_level(data_len: int, filter_len: int) -> int: ...
def dwt_coeff_len(data_len: int, filter_len: int, mode: str) -> int: ...
def dwtn_max_level(shape: tuple, wavelet, axes=None) -> int: ...
def downcoef(part: str, data, wavelet, mode: str = 'symmetric', level: int = 1): ...
def upcoef(part: str, coeffs, wavelet, level: int = 1, take: int = 0): ...
def pad(x, pad_widths, mode: str): ...Multi-level wavelet decomposition and reconstruction providing hierarchical analysis with automatic or specified decomposition levels. Includes fully separable transforms for axis-specific decomposition control.
def wavedec(data, wavelet, mode: str = 'symmetric', level: int = None, axis: int = -1): ...
def waverec(coeffs, wavelet, mode: str = 'symmetric', axis: int = -1): ...
def wavedec2(data, wavelet, mode: str = 'symmetric', level: int = None, axes=(-2, -1)): ...
def waverec2(coeffs, wavelet, mode: str = 'symmetric', axes=(-2, -1)): ...
def wavedecn(data, wavelet, mode: str = 'symmetric', level: int = None, axes=None): ...
def waverecn(coeffs, wavelet, mode: str = 'symmetric', axes=None): ...
def fswavedecn(data, wavelet, mode: str = 'symmetric', levels=None, axes=None): ...
def fswaverecn(fswavedecn_result): ...Stationary (undecimated) wavelet transforms providing translation-invariant analysis with no downsampling, preserving all frequency information.
def swt(data, wavelet, level: int = None, start_level: int = 0, axis: int = -1,
trim_approx: bool = False, norm: bool = False): ...
def iswt(coeffs, wavelet, norm: bool = False, axis: int = -1): ...
def swt2(data, wavelet, level: int, start_level: int = 0, axes=(-2, -1),
trim_approx: bool = False, norm: bool = False): ...
def iswt2(coeffs, wavelet, norm: bool = False, axes=(-2, -1)): ...Continuous wavelet transform for time-frequency analysis providing detailed spectral analysis with adjustable time-frequency resolution.
def cwt(data, scales, wavelet, sampling_period: float = 1.0,
method: str = 'conv', axis: int = -1, *, precision: int = 12): ...
def next_fast_len(n: int) -> int: ...Wavelet packet decomposition providing complete binary tree analysis for detailed frequency localization and adaptive basis selection.
class WaveletPacket:
def __init__(self, data, wavelet, mode: str = 'symmetric', maxlevel=None): ...
def decompose(self): ...
def reconstruct(self, update: bool = False): ...
class WaveletPacket2D:
def __init__(self, data, wavelet, mode: str = 'symmetric', maxlevel=None): ...
def get_graycode_order(level: int, x: str = 'a', y: str = 'd') -> list: ...Utilities for converting between different coefficient representations, packing/unpacking coefficients, and working with coefficient arrays.
def coeffs_to_array(coeffs, padding: int = 0, axes=None): ...
def array_to_coeffs(arr, coeff_slices, output_format: str = 'wavedecn'): ...
def ravel_coeffs(coeffs, axes=None): ...
def unravel_coeffs(arr, coeff_slices, coeff_shapes, output_format: str = 'wavedecn'): ...Signal thresholding functions for noise reduction, feature extraction, and signal enhancement with various thresholding methods.
def threshold(data, value, mode: str = 'soft', substitute: float = 0): ...
def threshold_firm(data, value_low, value_high): ...Multiresolution analysis providing direct access to approximation components at each decomposition level for signal analysis and reconstruction.
def mra(data, wavelet, level: int = None, axis: int = -1,
transform: str = 'swt', mode: str = 'periodization'): ...
def imra(mra_coeffs): ...Test datasets and demo signals for experimentation and learning with various data types including images and time series.
def pywt.data.aero(): ...
def pywt.data.ascent(): ...
def pywt.data.camera(): ...
def pywt.data.ecg(): ...
def pywt.data.nino(): ...
def demo_signal(name: str, n: int = None): ...The data module provides built-in test datasets including 512x512 grayscale images (aero, ascent, camera), physiological signals (ecg), climate data (nino), and various synthetic test signals through demo_signal().
# Wavelet specification can be:
# - str: wavelet name ('db4', 'haar', 'sym8', etc.)
# - Wavelet: Wavelet object
# - ContinuousWavelet: Continuous wavelet object
# Extension modes for boundary handling
Mode = Literal[
'zero', 'constant', 'symmetric', 'periodic',
'smooth', 'periodization', 'reflect',
'antisymmetric', 'antireflect'
]
# Common coefficient formats
CoeffsFormat1D = Tuple[np.ndarray, np.ndarray] # (cA, cD)
CoeffsFormat2D = Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray, np.ndarray]] # (cA, (cH, cV, cD))
CoeffsFormatND = Dict[str, np.ndarray] # {'aa': cA, 'ad': cH, 'da': cV, 'dd': cD, ...}
# Multi-level coefficient formats
MultiLevelCoeffs1D = List[np.ndarray] # [cAn, cDn, ..., cD1]
MultiLevelCoeffs2D = List[Union[np.ndarray, Tuple[np.ndarray, np.ndarray, np.ndarray]]]
MultiLevelCoeffsND = List[Union[np.ndarray, Dict[str, np.ndarray]]]