### Check demo examples Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/testing.rst Verify the examples in the demo subfolder by running the refguide_check.py script. ```bash python util/refguide_check.py ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/how_to_build_the_docs.rst Installs the necessary Python packages for building documentation. Ensure you have Spin and Ninja installed first. ```bash pip install spin ninja ``` ```bash pip install -r util/readthedocs/requirements.txt ``` -------------------------------- ### Install Basic Build Tools on Debian/Ubuntu Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/preparing_linux_build_environment.rst Use this command to install essential build tools like gcc, python-dev, and git on Debian-based systems. Ensure you have aptitude installed or use your preferred package manager. ```bash aptitude install build-essential gcc python-dev git-core ``` -------------------------------- ### List Available Signal Extension Modes Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/signal-extension-modes.rst This example shows how to retrieve a list of all available signal extension modes in PyWavelets. No specific setup is required beyond importing the library. ```python import pywt print(pywt.Modes.modes) ``` -------------------------------- ### Run tests with Tox Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/testing.rst Execute tests for specific Python versions using Tox. Install Tox first. This example runs tests for Python 3.10, 3.11, and 3.12. ```bash tox -e py310,py311,py312 ``` -------------------------------- ### Build and Install from Source Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/building_extension.rst Build and install the PyWavelets package after cloning the source code. Ensure your Python virtual environment is activated. ```bash pip install . ``` -------------------------------- ### Install Development Version (Alternative) Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/building_extension.rst Install a development version of PyWavelets using a specific version tag. ```bash pip install PyWavelets==dev ``` -------------------------------- ### Install Sphinx using pip Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/installing_build_dependencies.rst Install Sphinx, a documentation generator, using pip. This is used for generating project documentation. ```bash pip install Sphinx ``` -------------------------------- ### Set up Python Virtual Environment Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/installing_build_dependencies.rst Create and activate a Python virtual environment using virtualenv. Ensure virtualenv is installed first if you don't have it. ```bash curl -O https://raw.github.usercontent.com/pypa/virtualenv/master/virtualenv.py python virtualenv.py . /bin/activate ``` -------------------------------- ### Example Datasets Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/other-functions.rst Access to example datasets within the pywt.data module. ```APIDOC ## pywt.data Module ### Description Provides access to various example datasets for testing and demonstration purposes. ### Available Datasets - **ecg**: ECG waveform (1024 samples) - **aero**: grayscale image (512x512) - **ascent**: grayscale image (512x512) - **camera**: grayscale image (512x512) - **nino**: sea surface temperature (264 samples) - **demo_signal**: various synthetic 1d test signals ### Method N/A (Function Call for each dataset) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python import pywt.data ecg_data = pywt.data.ecg() aero_image = pywt.data.aero() demo = pywt.data.demo_signal() ``` ### Response #### Success Response (200) - **dataset** (numpy.ndarray or similar) - The loaded example dataset. #### Response Example ```json { "example": "numpy.ndarray representing the dataset" } ``` ``` -------------------------------- ### Install Development Version from Git Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/building_extension.rst Install a development version of PyWavelets directly from its source repository using pip. ```bash pip install -e git+https://github.com/PyWavelets/pywt.git#egg=PyWavelets ``` -------------------------------- ### Install Regular Release from PyPI Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/building_extension.rst Install a regular release of PyWavelets from the Python Package Index (PyPI) using pip. ```bash pip install PyWavelets ``` -------------------------------- ### Serve Built HTML Files Locally Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/how_to_build_the_docs.rst Starts a local HTTP server to serve the generated HTML documentation. This allows you to preview the documentation in a web browser. ```bash python -m http.server -d doc/build/html 8000 ``` -------------------------------- ### Install Cython using pip Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/installing_build_dependencies.rst Install the Cython package, which is required for building Python extensions, using pip. ```bash pip install Cython ``` -------------------------------- ### Verify PyWavelets Installation Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/building_extension.rst Run pytest in the cloned source directory to verify the installation of PyWavelets. ```bash pytest . ``` -------------------------------- ### Import and Perform 1D DWT Source: https://github.com/pywavelets/pywt/blob/main/doc/source/index.rst Import the pywt library and perform a discrete wavelet transform on a 1D list. This is a basic example to get started with PyWavelets. ```python import pywt cA, cD = pywt.dwt([1, 2, 3, 4], 'db1') ``` -------------------------------- ### Install numpydoc using pip Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/installing_build_dependencies.rst Install numpydoc, a Sphinx extension for formatting NumPy-style API documentation, using pip. ```bash pip install numpydoc ``` -------------------------------- ### Install numpy using pip Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/installing_build_dependencies.rst Install the numpy library, a fundamental package for scientific computing in Python, using pip. ```bash pip install numpy ``` -------------------------------- ### Get List of Wavelet Families Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Use the `families()` function to retrieve a list of all available wavelet families in PyWavelets. No setup is required beyond importing the library. ```python import pywt print(pywt.families()) ``` -------------------------------- ### Install PyWavelets using conda Source: https://github.com/pywavelets/pywt/blob/main/doc/source/install.rst For users of the Anaconda distribution, install PyWavelets from the main or conda-forge channel. ```bash conda install pywavelets ``` -------------------------------- ### Get Nodes at Level 3 Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Retrieves nodes at the third decomposition level. This example shows how to iterate and print paths at a specific level, handling output formatting. ```python print(len(wp.get_level(3))) ``` ```python paths = [node.path for node in wp.get_level(3)] for i, path in enumerate(paths): if (i+1) % 8 == 0: print(path) else: print(path, end=' ') ``` -------------------------------- ### Initialize WaveletPacket2D for Lazy Evaluation Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Initializes a WaveletPacket2D with data. This setup is used to demonstrate lazy evaluation, where nodes are computed only when accessed. ```python x = numpy.array([[1, 2, 3, 4, 5, 6, 7, 8]] * 8) wp = pywt.WaveletPacket2D(data=x, wavelet='db1', mode='symmetric') ``` -------------------------------- ### Handling unavailable features in benchmarks Source: https://github.com/pywavelets/pywt/blob/main/benchmarks/README.rst To mark newer functions as 'n/a' for older versions instead of 'failed', raise a NotImplementedError in the setup method if a feature is not available. ```python try: from pywt import cwt except ImportError: raise NotImplementedError("cwt not available") ``` -------------------------------- ### Get List of Built-in Wavelets Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Use the `wavelist()` function to get a list of all built-in wavelets. You can optionally filter by family. ```python import pywt print(pywt.wavelist(family='haar')) ``` -------------------------------- ### Helper Function for Array Formatting Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/modes.md A utility function to format NumPy arrays for consistent output. This is for example purposes and not required for PyWavelets usage. ```python def format_array(a): """Consistent array representation across different systems""" import numpy a = numpy.where(numpy.abs(a) < 1e-5, 0, a) return numpy.array2string(a, precision=5, separator=' ', suppress_small=True) ``` -------------------------------- ### Access subnodes by path Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp.md Subnodes within a WaveletPacket tree can be accessed using dictionary-like syntax with their path. This example shows accessing nodes at different decomposition levels. ```python x = [1, 2, 3, 4, 5, 6, 7, 8] wp = pywt.WaveletPacket(data=x, wavelet='db1', mode='symmetric') ``` ```python print(wp['a'].data) ``` ```python print(wp['a'].path) ``` ```python print(wp['aa'].data) ``` ```python print(wp['aa'].path) ``` ```python print(wp['aaa'].data) ``` ```python print(wp['aaa'].path) ``` -------------------------------- ### Illustrating Exception Handling in MyST Markdown Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/README.md This example demonstrates how to use MyST-NB to remove generated output for exception-raising code cells and display hand-coded exception tracebacks for documentation purposes. The `remove-output` tag prevents generated output during HTML conversion, while the `jupyterlite_sphinx_strip` tag excludes hand-coded output during notebook conversion. ```markdown ```{\n code-cell}\n :tags: [raises-exception, remove-output]\n1 / 0\n```\n\n+++ {\"tags\": [\"jupyterlite_sphinx_strip\"]}\n\n```{\n code-block}\n :class: pywt-handcoded-cell-output\nTraceback (most recent call last):\n...\nZeroDivisionError: division by zero\n``` ``` -------------------------------- ### Get Wavelet Packet root path Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp.md The path for the root node of a WaveletPacket is an empty string, indicating the starting point of the decomposition tree. ```python print(repr(wp.path)) ``` -------------------------------- ### Preview benchmark results Source: https://github.com/pywavelets/pywt/blob/main/benchmarks/README.rst Run this command to view the benchmark results in a web browser. ```bash asv preview ``` -------------------------------- ### Publish benchmark results Source: https://github.com/pywavelets/pywt/blob/main/benchmarks/README.rst Execute this command to record the benchmark results. ```bash asv publish ``` -------------------------------- ### Run all benchmarks Source: https://github.com/pywavelets/pywt/blob/main/benchmarks/README.rst Navigate to the benchmarks subfolder and execute this command to run all benchmarks against the current build of PyWavelets. ```bash cd benchmarks asv run --python=same --quick ``` -------------------------------- ### Add Release Note Files Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/how_to_release.rst Stages new release note files for the upcoming release. Replace X.X.X with the version number. ```bash git add doc/release/X.X.X-notes.rst ``` ```bash git add doc/source/release.X.X.X.rst ``` -------------------------------- ### Build Sphinx Documentation Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/how_to_build_the_docs.rst Uses the 'spin' command to build the Sphinx documentation. This command processes the documentation source files and generates HTML output. ```bash spin docs ``` -------------------------------- ### Run doctests locally Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/testing.rst Execute the older doctests by running the test_doc.py script from the project root. Ensure you are in the doc directory to run 'make doctest'. ```bash python pywt/tests/test_doc.py ``` ```bash cd doc make doctest ``` -------------------------------- ### Create Source Distribution Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/how_to_release.rst Creates a source distribution (sdist) of the project using the 'build' package. ```bash python -m build --sdist ``` -------------------------------- ### Get Wavelet Symmetry Property Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wavelet.md Retrieve the symmetry property of a `Wavelet` object, which indicates its symmetry characteristics. ```python print(w.symmetry) ``` -------------------------------- ### Using Custom Wavelets Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Demonstrates how to create custom Wavelet objects using filter banks, either as a list or a filter bank-like object. ```APIDOC ## Using Custom Wavelets PyWavelets allows the creation of custom wavelets if a specific wavelet is not included in the built-in list. This can be achieved by providing a list of four filters or an object with a `filter_bank` attribute to the `Wavelet` constructor. ### Filter Bank Structure The filters list must be in the following order: 1. Lowpass decomposition filter 2. Highpass decomposition filter 3. Lowpass reconstruction filter 4. Highpass reconstruction filter ### Example 1: Using a Python List for Filter Bank ```python import pywt import math c = math.sqrt(2)/2 dec_lo, dec_hi, rec_lo, rec_hi = [c, c], [-c, c], [c, c], [c, -c] filter_bank = [dec_lo, dec_hi, rec_lo, rec_hi] myWavelet = pywt.Wavelet(name="myHaarWavelet", filter_bank=filter_bank) ``` ### Example 2: Using a Filter Bank-like Object ```python import pywt import math class HaarFilterBank(object): @property def filter_bank(self): c = math.sqrt(2)/2 dec_lo, dec_hi, rec_lo, rec_hi = [c, c], [-c, c], [c, c], [c, -c] return [dec_lo, dec_hi, rec_lo, rec_hi] filter_bank = HaarFilterBank() myOtherWavelet = pywt.Wavelet(name="myHaarWavelet", filter_bank=filter_bank) ``` ``` -------------------------------- ### Get Wavelet Packet root level Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp.md The root node of a WaveletPacket is at level 0 of the decomposition tree. ```python print(wp.level) ``` -------------------------------- ### Get Nodes at Level 0 Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Retrieves the root node of the WaveletPacket2D. Use this to access the initial data structure. ```python len(wp.get_level(0)) ``` ```python print([node.path for node in wp.get_level(0)]) ``` -------------------------------- ### Initialize Wavelet Object Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wavelet.md Instantiate a Wavelet object for 'sym3' to check its orthogonality. ```python w = pywt.Wavelet('sym3') w.orthogonal ``` -------------------------------- ### Get Wavelet Filter Lengths Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wavelet.md Access the lengths of the decomposition (`dec_len`) and reconstruction (`rec_len`) filters for a `Wavelet` object. ```python w.dec_len w.rec_len ``` -------------------------------- ### Get Wavelet Packet Path and Level Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Access the path and decomposition level of the root node in the WaveletPacket2D object. ```python print(repr(wp.path)) ``` ```python print(wp.level) ``` -------------------------------- ### Create and Initialize WaveletPacket2D Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Creates a new 2D Wavelet Packet structure and initializes it with data from existing nodes. Ensure the wavelet and mode are correctly specified. ```python new_wp = pywt.WaveletPacket2D(data=None, wavelet='db1', mode='symmetric') ``` -------------------------------- ### Get Nodes at Level 1 Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Retrieves nodes at the first decomposition level. This shows the immediate sub-bands after the first transform. ```python len(wp.get_level(1)) ``` ```python print([node.path for node in wp.get_level(1)]) ``` -------------------------------- ### Get Leaf Nodes Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Retrieves a list of all non-zero leaf nodes from the WaveletPacket2D tree. This is useful for identifying active components in the decomposition. ```python print([n.path for n in new_wp.get_leaf_nodes()]) ``` -------------------------------- ### Instantiate ContinuousWavelet Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Create a ContinuousWavelet object by specifying its name. The name must be a valid wavelet name from pywt.wavelist. ```python import pywt wavelet = pywt.ContinuousWavelet('gaus1') ``` -------------------------------- ### Instantiate and Print DiscreteContinuousWavelet Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Instantiate a DiscreteContinuousWavelet object and print its properties. This is useful for inspecting the characteristics of different wavelets. ```python import pywt wavelet = pywt.DiscreteContinuousWavelet('db1') print(wavelet) ``` ```python import pywt wavelet = pywt.DiscreteContinuousWavelet('gaus1') print(wavelet) ``` -------------------------------- ### Run benchmarks on a specific tag/commit Source: https://github.com/pywavelets/pywt/blob/main/benchmarks/README.rst Use this command to run benchmarks against a specific tag or commit. A Python version for the virtualenv must be provided. ```bash asv run --python=3.5 --quick v0.4.0^! ``` -------------------------------- ### Import PyWavelets Library Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/modes.md Import the PyWavelets library to access its functionalities. ```python import pywt ``` -------------------------------- ### Get Nodes at Level 2 Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Retrieves nodes at the second decomposition level. This demonstrates accessing deeper levels of the wavelet packet tree. ```python len(wp.get_level(2)) ``` ```python paths = [node.path for node in wp.get_level(2)] for i, path in enumerate(paths): if (i+1) % 4 == 0: print(path) else: print(path, end=' ') ``` -------------------------------- ### Create Wavelet Packet instance Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp.md Initialize a WaveletPacket object with input data, a specified wavelet, and decomposition mode. The `data` attribute stores the input and coefficients. ```python x = [1, 2, 3, 4, 5, 6, 7, 8] wp = pywt.WaveletPacket(data=x, wavelet='db1', mode='symmetric') ``` -------------------------------- ### List All Wavelet Families Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wavelet.md Use `pywt.families()` to get a list of all available wavelet family names. This is useful for understanding the organization of wavelets in the library. ```python import pywt pywt.families() ``` -------------------------------- ### Get All Leaf Nodes with Full Decomposition Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Forces a full decomposition up to the maximum level and then collects all leaf nodes. This ensures all possible sub-bands are considered. ```python paths = [n.path for n in new_wp.get_leaf_nodes(decompose=True)] len(paths) ``` ```python for i, path in enumerate(paths): if (i+1) % 8 == 0: print(path) else: try: print(path, end=' ') except: print(path, end=' ') ``` -------------------------------- ### Upload Release to PyPI with Twine Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/how_to_release.rst Uploads distribution files (wheels and sdist) from the 'dist' directory to PyPI using twine. The '-s' flag signs the uploads. ```bash twine upload -s dist/* ``` -------------------------------- ### Get maximum decomposition level Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp.md The `maxlevel` attribute of a WaveletPacket node indicates the maximum depth of the decomposition tree. It is automatically computed if not provided during initialization. ```python print(wp['ad'].maxlevel) ``` -------------------------------- ### Quadrature Mirror Filter (QMF) Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/other-functions.rst Applies the Quadrature Mirror Filter. ```APIDOC ## qmf ### Description Applies the Quadrature Mirror Filter. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python qmf_coeffs = pywt.qmf(wavelet) ``` ### Response #### Success Response (200) - **qmf_coeffs** (array) - The coefficients of the Quadrature Mirror Filter. #### Response Example ```json { "example": "[coeff1, coeff2, ...]" } ``` ``` -------------------------------- ### Get Full List of Built-in Wavelets Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wavelet.md Call `pywt.wavelist()` without arguments to retrieve a comprehensive list of all built-in wavelet names supported by PyWavelets. ```python pywt.wavelist() ``` -------------------------------- ### Run pytest locally Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/testing.rst Execute tests using pytest from the project root. Use the --pyargs flag to specify the package. ```bash pytest --pyargs pywt -v ``` -------------------------------- ### Calculate Central Frequency Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/other-functions.rst Calculates the central frequency of the \"psi\" wavelet function. No specific setup is required beyond having the wavelet object. ```python central_frequency(wavelet) ``` -------------------------------- ### Importing modules in benchmarks Source: https://github.com/pywavelets/pywt/blob/main/benchmarks/README.rst When benchmarking old versions of PyWavelets, ensure modules are importable. Use a try-except block to handle potential ImportErrors. ```python try: from pywt import cwt except ImportError: pass ``` -------------------------------- ### Get Vanishing Moments Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wavelet.md Access the number of vanishing moments for the scaling function (`vanishing_moments_phi`) and the wavelet function (`vanishing_moments_psi`) associated with a `Wavelet` object's filters. ```python w.vanishing_moments_phi w.vanishing_moments_psi ``` -------------------------------- ### DiscreteContinuousWavelet Initialization Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Initializes a Wavelet or ContinuousWavelet object based on the provided name. ```APIDOC ## DiscreteContinuousWavelet ### Description Initializes a Wavelet or a ContinuousWavelet object depending on the given name. ### Method __init__ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (str) - Required - The name of the wavelet. - **filter_bank** (object) - Optional - The filter bank to use. ### Request Example ```json { "name": "db1" } ``` ### Response #### Success Response (200) - **wavelet_object** (Wavelet or ContinuousWavelet) - The initialized wavelet object. #### Response Example ```json { "wavelet_object": "Wavelet db1" } ``` ``` -------------------------------- ### Generate Author List Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/how_to_release.rst Generates the author list for release notes. Replace vP.P.P with the previous release number. ```python python ./util/authors.py vP.P.P.. ``` -------------------------------- ### Assign Data to WaveletPacket2D Nodes Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Assigns data to specific nodes ('vh', 'vv', 'vd') within a WaveletPacket2D. Note that 'vh' and 'vv' are assigned the same data in this example. ```python new_wp['vh'] = wp['vh'].data # [[0.0, 0.0], [0.0, 0.0]] new_wp['vv'] = wp['vh'].data # [[0.0, 0.0], [0.0, 0.0]] new_wp['vd'] = [[0.0, 0.0], [0.0, 0.0]] ``` -------------------------------- ### IDWT with Mismatched Coefficients Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/dwt-idwt.md This example shows that `pywt.idwt` raises a ValueError if the input coefficient arrays do not have the same size. Ensure all coefficient arrays are of equal length before calling `idwt`. ```python print(pywt.idwt([1, 2, 3, 4, 5], [1, 2, 3, 4], 'db2', 'symmetric')) ``` -------------------------------- ### Import PyWavelets and NumPy Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Import necessary libraries for wavelet transform operations and numerical computations. ```python import pywt import numpy ``` -------------------------------- ### Instantiate a Wavelet Object Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Create a `Wavelet` object by providing the name of a built-in wavelet. This object provides access to the wavelet's properties and filter banks. ```python import pywt wavelet = pywt.Wavelet('db1') ``` -------------------------------- ### Get Leaf Nodes of Wavelet Packet Tree Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp.md Retrieves all leaf nodes from a WaveletPacket tree. The `data` parameter determines whether to include nodes with computed data. ```python print([n.path for n in new_wp.get_leaf_nodes(False)]) ``` ```python print([n.path for n in new_wp.get_leaf_nodes(True)]) ``` -------------------------------- ### Quadrature Mirror Filter (QMF) Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/other-functions.rst Computes the Quadrature Mirror Filter (QMF) for a given wavelet. This is a fundamental operation in wavelet-based signal processing for perfect reconstruction. ```python qmf(wavelet) ``` -------------------------------- ### Create New Wavelet Packet Instance Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp.md Creates a new, empty WaveletPacket instance. This is useful for building a packet tree from scratch or for specific node manipulations. ```python new_wp = pywt.WaveletPacket(data=None, wavelet='db1', mode='symmetric') ``` -------------------------------- ### Get List of Continuous Wavelets - PyWavelets Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/cwt.rst Retrieves a list of all available continuous wavelet names compatible with the `cwt` function. This is useful for understanding the options for wavelet analysis. ```python import pywt wavelist = pywt.wavelist(kind='continuous') ``` -------------------------------- ### IDWT with None for Detail Coefficients Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/dwt-idwt.md Demonstrates IDWT when the detail coefficients (cD) are unknown or zero by passing `None`. This is equivalent to passing a zero-filled array for cD. ```python print(pywt.idwt(None, [1, 2, 0, 1], 'db2', 'symmetric')) ``` ```python print(pywt.idwt([0, 0, 0, 0], [1, 2, 0, 1], 'db2', 'symmetric')) ``` -------------------------------- ### Get Filter Bank Tuple Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wavelet.md The `filter_bank` attribute returns a tuple containing all four filter coefficients (decomposition lowpass, decomposition highpass, reconstruction lowpass, reconstruction highpass). This can be compared to individual filter attributes. ```python w.filter_bank == (w.dec_lo, w.dec_hi, w.rec_lo, w.rec_hi) ``` -------------------------------- ### Clone PyWavelets Repository Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/building_extension.rst Clone the PyWavelets repository from GitHub to your local machine. ```bash git clone https://github.com/PyWavelets/pywt.git PyWavelets ``` -------------------------------- ### IDWT with Invalid Coefficient Length Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/dwt-idwt.md This example demonstrates that `pywt.idwt` will fail with a ValueError if the input arrays are invalid, meaning they could not have been produced by a `dwt` decomposition with the same wavelet and mode. The minimal output length for `db4` with `Modes.symmetric` is 4, not 3. ```python pywt.idwt([1,2,4], [4,1,3], 'db4', 'symmetric') ``` -------------------------------- ### Demonstrate Lazy Evaluation of Wavelet Packet Nodes Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp.md Illustrates the lazy evaluation of nodes in a WaveletPacket. Initially, node attributes like 'a' are None and are computed only upon first access. ```python x = [1, 2, 3, 4, 5, 6, 7, 8] wp = pywt.WaveletPacket(data=x, wavelet='db1', mode='symmetric') ``` ```python print(wp.a) ``` ```python print(wp['a']) ``` ```python print(wp.a) ``` ```python print(wp.d) ``` -------------------------------- ### List Available Signal Extension Modes Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/modes.md Retrieve a list of all available signal extension modes supported by PyWavelets. ```python pywt.Modes.modes ``` -------------------------------- ### IDWT with None for Approximation Coefficients Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/dwt-idwt.md Shows how to perform IDWT when the approximation coefficients (cA) are unknown or zero by passing `None`. This is equivalent to passing a zero-filled array for cA. ```python print(pywt.idwt([1,2,0,1], None, 'db2', 'symmetric')) ``` ```python print(pywt.idwt([1, 2, 0, 1], [0, 0, 0, 0], 'db2', 'symmetric')) ``` -------------------------------- ### Create Custom Wavelet from Filter List Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Instantiate a custom Wavelet object by providing a list of filter coefficients. Ensure the filters are in the order: lowpass decomposition, highpass decomposition, lowpass reconstruction, highpass reconstruction. ```python import pywt, math c = math.sqrt(2)/2 dec_lo, dec_hi, rec_lo, rec_hi = [c, c], [-c, c], [c, c], [c, -c] filter_bank = [dec_lo, dec_hi, rec_lo, rec_hi] myWavelet = pywt.Wavelet(name="myHaarWavelet", filter_bank=filter_bank) ``` -------------------------------- ### Load Demo Signal Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/other-functions.rst Loads a synthetic 1D test signal from the pywt.data module. This function is useful for testing and demonstrating wavelet algorithms. ```python demo_signal() ``` -------------------------------- ### Initialize Biorthogonal Wavelet Object Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wavelet.md Instantiate a Wavelet object for 'bior1.3' to check its orthogonality. Biorthogonal wavelets are non-orthogonal. ```python w = pywt.Wavelet('bior1.3') w.orthogonal ``` -------------------------------- ### ContinuousWavelet Object Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Details about the ContinuousWavelet object, its properties, and how to use its methods. ```APIDOC ## ContinuousWavelet Object ### Description The `ContinuousWavelet` object describes the properties of a continuous wavelet identified by a given name. The name must be a valid wavelet name from the `pywt.wavelist`. ### Constructor `ContinuousWavelet(name, dtype=np.float64)` - **name** (string): The name of the wavelet. Must be a valid name from `pywt.wavelist`. - **dtype** (numpy.dtype): The data type to use for the wavelet. Can be `numpy.float64` or `numpy.float32`. ### Example ```python import pywt wavelet = pywt.ContinuousWavelet('gaus1') ``` ### Properties - **name** (string): Continuous Wavelet name. - **short_family_name** (string): Wavelet short family name. - **family_name** (string): Wavelet family name. - **orthogonal** (boolean): True if the wavelet is orthogonal. - **biorthogonal** (boolean): True if the wavelet is biorthogonal. - **complex_cwt** (boolean): True if the wavelet is complex. - **lower_bound** (float): The lower bound of the effective support. - **upper_bound** (float): The upper bound of the effective support. - **center_frequency** (float): The center frequency for shan, fbsp, and cmor wavelets. - **bandwidth_frequency** (float): The bandwidth frequency for shan, fbsp, and cmor wavelets. - **fbsp_order** (int): The order for the fbsp wavelet. - **symmetry** (string): Describes the symmetry of the wavelet ('asymmetric', 'near symmetric', 'symmetric', 'anti-symmetric'). ### Method: `wavefun()` `ContinuousWavelet.wavefun(level, length=None)` Calculates approximations of the scaling function (`psi`) with grid coordinates (`x`). - **level** (int): The level of detail for the approximation. - **length** (int, optional): The desired vector length. If not set, it defaults to `2**level`. Returns: - **psi** (numpy.ndarray): The approximation of the wavelet function. - **x** (numpy.ndarray): The grid coordinates. For complex wavelets, returns complex approximations. ### Example: Using `wavefun()` ```python import pywt wavelet = pywt.ContinuousWavelet('gaus1') psi, x = wavelet.wavefun(level=5) ``` ### String Representation ```python import pywt wavelet = pywt.ContinuousWavelet('gaus1') print(wavelet) # Output: # ContinuousWavelet gaus1 # Family name: Gaussian # Short name: gaus # Symmetry: anti-symmetric # DWT: False # CWT: True # Complex CWT: False ``` ``` -------------------------------- ### Perform DWT with Different Mode Specifications Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/signal-extension-modes.rst Demonstrates two equivalent ways to specify the wavelet and extension mode when performing a Discrete Wavelet Transform (DWT). The first uses string names, while the second uses Wavelet and Modes objects. ```python import pywt (a, d) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth') ``` ```python import pywt (a, d) = pywt.dwt([1,2,3,4,5,6], pywt.Wavelet('db2'), pywt.Modes.smooth) ``` -------------------------------- ### Create 2D Wavelet Packet Structure Source: https://github.com/pywavelets/pywt/blob/main/doc/source/regression/wp2d.md Initialize a 2D Wavelet Packet object with input data, wavelet type, and mode. The input data is a NumPy array. ```python x = numpy.array([[1, 2, 3, 4, 5, 6, 7, 8]] * 8, 'd') print(x) ``` ```python wp = pywt.WaveletPacket2D(data=x, wavelet='db1', mode='symmetric') ``` -------------------------------- ### Tag Release with Git Source: https://github.com/pywavelets/pywt/blob/main/doc/source/dev/how_to_release.rst Tags the current release using Git. Ensure ISRELEASED is set to True in util/version_utils.py before tagging. Replace vX.X.X with the actual release number. ```bash git tag -s vX.X.X ``` -------------------------------- ### Create Custom Wavelet from Filter Bank Object Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst Instantiate a custom Wavelet object using an object that provides a filter_bank property. This is an alternative to passing a direct list of filters. ```python class HaarFilterBank(object): @property def filter_bank(self): c = math.sqrt(2)/2 dec_lo, dec_hi, rec_lo, rec_hi = [c, c], [-c, c], [c, c], [c, -c] return [dec_lo, dec_hi, rec_lo, rec_hi] filter_bank = HaarFilterBank() myOtherWavelet = pywt.Wavelet(name="myHaarWavelet", filter_bank=filter_bank) ``` -------------------------------- ### Calculate Wavelet and Scaling Functions (Biorthogonal) Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst For biorthogonal wavelets (that are not orthogonal), `wavefun()` returns approximations for both decomposition (`phi_d`, `psi_d`) and reconstruction (`phi_r`, `psi_r`), along with the x-grid coordinates, at a specified refinement level. ```python import pywt wavelet = pywt.Wavelet('bior3.5') phi_d, psi_d, phi_r, psi_r, x = wavelet.wavefun(level=5) ``` -------------------------------- ### Thresholding Functions Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/thresholding-functions.rst The `pywt.thresholding` module provides implementations for common signal thresholding techniques. ```APIDOC ## Thresholding Functions ### Description Provides implementations for popular signal thresholding functions. ### Functions - `pywt.threshold(data, level, mode='soft', substitute=None)` - `pywt.threshold_firm(data, level, substitute=None)` ### Details - **`threshold`**: Implements standard thresholding methods like soft and hard thresholding. Non-negative Garotte thresholding is also available and is intermediate between soft and hard thresholding. - **`threshold_firm`**: Implements firm thresholding, which transitions between soft and hard thresholding behavior. It requires a pair of threshold values to define the transition region. ### Example Usage ```python import pywt import numpy as np data = np.linspace(0, 1, 10) # Soft thresholding thresholded_soft = pywt.threshold(data, level=0.5, mode='soft') # Firm thresholding thresholded_firm = pywt.threshold_firm(data, level=0.5) print("Soft Thresholded:", thresholded_soft) print("Firm Thresholded:", thresholded_firm) ``` ### Plot A plot illustrating the behavior of different thresholding methods is available in the documentation, showing non-negative Garotte thresholding as intermediate between soft and hard thresholding, and firm thresholding's transition behavior. ``` -------------------------------- ### Calculate Wavelet and Scaling Functions (Orthogonal) Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelets.rst For orthogonal wavelets, `wavefun()` returns approximations of the scaling function (`phi`) and wavelet function (`psi`), along with their corresponding x-grid coordinates, at a specified refinement level. ```python import pywt wavelet = pywt.Wavelet('db2') phi, psi, x = wavelet.wavefun(level=5) ``` -------------------------------- ### WaveletPacket Class Methods Source: https://github.com/pywavelets/pywt/blob/main/doc/source/ref/wavelet-packets.rst Methods for the WaveletPacket class, including initialization and level-based node retrieval. ```APIDOC ## WaveletPacket Class Methods ### __init__ Initializes a WaveletPacket object. ### Method `__init__(data, wavelet, [mode='symmetric', [maxlevel=None, [axis=-1]]])` ### Parameters #### Path Parameters - **data** (N-dimensional numeric array) - Required - Data associated with the node. - **wavelet** (wavelet) - Required - The wavelet to use. - **mode** (str) - Optional - Signal extension mode for DWT and IDWT. - **maxlevel** (int) - Optional - Maximum allowed level of decomposition. - **axis** (int) - Optional - The axis of the array that is to be transformed. ### get_level Collects nodes from the given level of decomposition. ### Method `get_level(level, [order="natural", [decompose=True]])` ### Parameters #### Path Parameters - **level** (int) - Required - Specifies decomposition level from which the nodes will be collected. - **order** (str) - Optional - Order of nodes collection. - **decompose** (bool) - Optional - If ``decompose`` is ``True``, the method will try to decompose the tree up to the :attr:`maximum level `. ```