### Import modules and set up example Source: https://pybispectra.readthedocs.io/1.3/auto_examples/plot_compute_time_resolved.html Imports required libraries and PyBispectra modules for the example. The RandomState is used for reproducibility. ```python # Author(s): # Thomas S. Binns | github.com/tsbinns # sphinx_gallery_multi_image = "single" ``` ```python import numpy as np from matplotlib import pyplot as plt from numpy.random import RandomState from pybispectra import WaveShape, compute_tfr, get_example_data_paths ``` -------------------------------- ### Create uv environment and install PyBispectra Source: https://pybispectra.readthedocs.io/1.3/_sources/installation.rst.txt Creates a virtual environment named 'pybispectra_env' using uv, then installs PyBispectra with uv pip. Activate the environment first. ```bash uv venv pybispectra_env ``` ```bash uv pip install pybispectra ``` -------------------------------- ### Install pre-commit for PyBispectra Source: https://pybispectra.readthedocs.io/1.3/development.html Install pre-commit in the base directory to have style and spelling checks run automatically on each commit. ```bash pre-commit install ``` -------------------------------- ### Install PyBispectra in editable mode with development requirements Source: https://pybispectra.readthedocs.io/1.3/_sources/development.rst.txt Install the package in editable mode and install development dependencies using pip. Run these commands in the cloned repository directory. ```bash pip install -e . pip install .[dev] ``` -------------------------------- ### get_example_data_paths Source: https://pybispectra.readthedocs.io/1.3/_sources/utils.rst.txt Returns the file paths to example data included with the package. ```APIDOC ## get_example_data_paths ### Description Returns the file paths to example data included with the package. ### Method Function ### Signature get_example_data_paths(...) ### Returns - **paths** (list of str) - List of file paths to example data. ### Notes Refer to the pybispectra documentation for full parameter details. ``` -------------------------------- ### Install pre-commit hooks Source: https://pybispectra.readthedocs.io/1.3/_sources/development.rst.txt Install pre-commit hooks to automatically run style and spelling checks on each commit. Run in the base directory. ```bash pre-commit install ``` -------------------------------- ### Load example data and compute Fourier coefficients Source: https://pybispectra.readthedocs.io/1.3/_downloads/df175fc7c2712b645c381aa0f368a5cb/plot_compute_waveshape.ipynb Loads example data (sawtooth waves and peak/trough dominant waves) and computes Fourier coefficients using compute_fft. ```python # Load example data # (code not shown in source) ``` -------------------------------- ### Example script header with author and Sphinx-Gallery directive Source: https://pybispectra.readthedocs.io/1.3/auto_examples/plot_compute_tde_fbands.html Header comment block for the example script, including the author and a Sphinx-Gallery directive for rendering a single image. ```python # Author(s): # Thomas S. Binns | github.com/tsbinns # sphinx_gallery_multi_image = "single" ``` -------------------------------- ### Install PyBispectra with uv Source: https://pybispectra.readthedocs.io/1.3/_sources/installation.rst.txt Installs the PyBispectra package using uv's pip interface. ```bash uv pip install pybispectra ``` -------------------------------- ### Create conda environment and install PyBispectra Source: https://pybispectra.readthedocs.io/1.3/_sources/installation.rst.txt Creates a conda environment named 'pybispectra_env', activates it, and installs PyBispectra from conda-forge. ```bash conda create -n pybispectra_env ``` ```bash conda activate pybispectra_env ``` ```bash conda install -c conda-forge pybispectra ``` -------------------------------- ### Create venv environment and install PyBispectra Source: https://pybispectra.readthedocs.io/1.3/_sources/installation.rst.txt Creates a virtual environment named 'pybispectra_env' using venv, then installs PyBispectra with pip. Activate the environment first. ```bash python -m venv pybispectra_env ``` ```bash pip install pybispectra ``` -------------------------------- ### Install PyBispectra with pip Source: https://pybispectra.readthedocs.io/1.3/_sources/installation.rst.txt Installs the PyBispectra package using pip. Requires Python ≥ 3.10. ```bash pip install pybispectra ``` -------------------------------- ### Import modules for waveshape computation Source: https://pybispectra.readthedocs.io/1.3/_downloads/df175fc7c2712b645c381aa0f368a5cb/plot_compute_waveshape.ipynb Imports numpy, matplotlib, RandomState, and PyBispectra functions (WaveShape, compute_fft, get_example_data_paths) needed for the example. ```python import numpy as np from matplotlib import pyplot as plt from numpy.random import RandomState from pybispectra import WaveShape, compute_fft, get_example_data_paths ``` -------------------------------- ### get_example_data_paths Source: https://pybispectra.readthedocs.io/1.3/_sources/generated/pybispectra.utils.get_example_data_paths.rst.txt Returns the file paths to example data files bundled with the pybispectra package. This function is part of the pybispectra.utils module and is used to locate example datasets for testing and demonstration purposes. ```APIDOC ## get_example_data_paths ### Description Returns the file paths to example data files bundled with the pybispectra package. This function is part of the pybispectra.utils module and is used to locate example datasets for testing and demonstration purposes. ### Function Signature `get_example_data_paths()` ### Parameters None ### Returns - **paths** (list of str) - List of file paths to the example data files. ### Example ```python from pybispectra.utils import get_example_data_paths paths = get_example_data_paths() print(paths) ``` ``` -------------------------------- ### Import PyBispectra modules Source: https://pybispectra.readthedocs.io/1.3/_downloads/9bc501133a13404e9f275d38327de709/plot_compute_pac.ipynb Imports required for the example: numpy and the PyBispectra functions compute_fft and get_example_data_paths, as well as the PAC class. ```python import numpy as np from pybispectra import PAC, compute_fft, get_example_data_paths ``` -------------------------------- ### Import required libraries Source: https://pybispectra.readthedocs.io/1.3/_downloads/df378e14326b24e9d8dcce7efdebff44/plot_compute_time_resolved.ipynb Imports numpy, matplotlib, RandomState, and PyBispectra functions for the example. ```python import numpy as np from matplotlib import pyplot as plt from numpy.random import RandomState from pybispectra import WaveShape, compute_tfr, get_example_data_paths ``` -------------------------------- ### Install PyBispectra with pixi Source: https://pybispectra.readthedocs.io/1.3/_sources/installation.rst.txt Adds PyBispectra as a dependency to a pixi project. ```bash pixi add pybispectra ``` -------------------------------- ### Import NumPy and PyBispectra modules Source: https://pybispectra.readthedocs.io/1.3/auto_examples/plot_compute_tde_fbands.html Imports required for the example: NumPy and the PyBispectra functions/classes TDE, compute_fft, and get_example_data_paths. ```python import numpy as np from pybispectra import TDE, compute_fft, get_example_data_paths ``` -------------------------------- ### Import PyBispectra modules for TDE computation Source: https://pybispectra.readthedocs.io/1.3/_downloads/193d002eb10af492d167a98732c9e4d0/plot_compute_tde.ipynb Imports numpy and the TDE, compute_fft, and get_example_data_paths functions from pybispectra. This is the initial setup for computing time delay estimates. ```python import numpy as np from pybispectra import TDE, compute_fft, get_example_data_paths ``` -------------------------------- ### Install PyBispectra with conda Source: https://pybispectra.readthedocs.io/1.3/_sources/installation.rst.txt Installs the PyBispectra package from conda-forge using conda. ```bash conda install -c conda-forge pybispectra ``` -------------------------------- ### Build documentation with Sphinx Source: https://pybispectra.readthedocs.io/1.3/_sources/development.rst.txt Build the documentation locally using Sphinx. Run in the /docs directory; outputs are placed in /docs/build/html. ```bash make html ``` -------------------------------- ### Initialize pixi project and add PyBispectra Source: https://pybispectra.readthedocs.io/1.3/_sources/installation.rst.txt Initializes a pixi project, runs the shell hook, and adds PyBispectra as a dependency. ```bash pixi init ``` ```bash pixi shell-hook ``` ```bash pixi add pybispectra ``` -------------------------------- ### Build PyBispectra documentation with Sphinx Source: https://pybispectra.readthedocs.io/1.3/development.html Build the documentation locally from the /docs directory. Outputs are placed in /docs/build/html. ```bash make html ``` -------------------------------- ### Load example data and perform HPMax spatio-spectral filtering Source: https://pybispectra.readthedocs.io/1.3/_sources/auto_examples/plot_compute_waveshape_noisy_data.rst.txt Loads example data and applies HPMax filtering to improve the signal-to-noise ratio. The signal band is 18-22 Hz, noise bands are 15-18 Hz and 22-25 Hz, and harmonics at 36-44 Hz and 54-66 Hz are included. Only the first component is kept. ```Python # Load the example data data = np.load(get_example_data_paths()["sim_data"])["data"] sfreq = 200 # Compute the FFT of the data fft = compute_fft(data, sfreq=sfreq) # Compute the rank of the data rank = compute_rank(data) # Initialise the SpatioSpectralFilter object ssf = SpatioSpectralFilter(data, sfreq=sfreq) # Compute HPMax filters ssf.fit_transform_hpmax( signal_freqs=[18, 22], noise_freqs=[[15, 18], [22, 25]], harmonics=[2, 3], rank=rank, ) # Transform the data using the filters filtered_data = ssf.transform(data, n_components=1) ``` -------------------------------- ### Author comment Source: https://pybispectra.readthedocs.io/1.3/_downloads/9bc501133a13404e9f275d38327de709/plot_compute_pac.ipynb A comment line indicating the author of the example. This is not executable code but is part of the source code cell. ```python # Author(s): # Thomas S. Binns | github.com/tsbinns ```