Skip to main content

Generalized Phase Locking Analysis (GPLA) toolkit in Python.

Project description

PyGPLA: Generalized Phase Locking Analysis in Python

License: BSD-2-Clause

PyGPLA is a Python package for analyzing multichannel spike–field coupling using Generalized Phase Locking Analysis (GPLA) as introduced in:

Safavi et al. (2023), Uncovering the organization of neural circuits with Generalized Phase Locking Analysis, PLOS Computational Biology.

GPLA summarizes high-dimensional spike–Local Field Potential (LFP) coupling by constructing a complex coupling matrix and computing its dominant low-rank structure via Singular Value Decomposition (SVD). The output includes:

  • a scalar coupling strength (gPLV)
  • an LFP vector and spike vector whose magnitudes/phases are interpretable at the population level
  • optional significance testing (analytical RMT-based or spike-jitter surrogates)

Features

  • GPLA core: coupling matrix construction + SVD + phase convention
  • Statistical testing:
    • fast RMT-based heuristic (Marchenko–Pastur edge)
    • spike-jitter surrogate tests (interval / ISI-preserved / group-preserved / population)
  • Preprocessing hooks: trial concatenation, spike-count filtering, optional PCA whitening
  • Simulations: phase-locked and transient coupling generators
  • Figure reproduction: a Figure 2-style simulation and visualization script

Installation

From PyPI (placeholder)

PyPI publishing is planned; once available:

pip install pygpla

From source (recommended for now)

git clone https://github.com/CMC-lab/PyGPLA.git
cd PyGPLA
pip install -e .

Optional extras

# SciPy (for simulations and real-data style filtering/Hilbert workflows)
pip install -e ".[sim]"

# Documentation build (Sphinx + MyST)
pip install -e ".[docs]"

# Tests
pip install -e ".[tests]"

Quick start

This minimal example simulates transiently coupled spikes and an analytic LFP signal, then runs GPLA via pygpla.api.gpla.

import numpy as np

from pygpla.api import gpla
from pygpla.simulations import simulate_transient_locked

rng = np.random.default_rng(123)

signal_params = dict(nCh=1, nUnit=12, SF=600.0, nTr=6, signalLength=6.0)
global_params = dict(
    oscFreq=20.0,
    nCycl=15,
    syncSigProportion=0.7,
    lfpPhaseNoise_kappa=8.0,
    whiteNoise_sigma=0.05,
)
spike_params = dict(avefiringRate=18.0)
coupling_params = dict(lockingStrength_kappa=10.0, lockingPhase=0.0)

lfp_real, lfp_analytic, spikes, meta = simulate_transient_locked(
    global_params,
    spike_params,
    coupling_params,
    signal_params,
    return_analytic=True,
    rng=rng,
)

result = gpla(
    spikes,
    lfp_analytic,                     # shape: (channels, samples, trials), complex dtype
    stats_config=None,                # or {"testType": "RMT-based"} / spike-jitter config
    plvNrmlzMethed="var1_theoretical",
    flag_whitening=0,
    flag_lfpNrmlz=0,
)

print("gPLV:", result.gplv)
print("LFP vector shape:", result.lfp_vector.shape)
print("Spike vector shape:", result.spike_vector.shape)

Input conventions:

  • spike trains: list of trials, each (n_units, n_samples)
  • analytic LFP: (n_channels, n_samples, n_trials) complex array (bandpass + Hilbert in real data)

Reproducing Figure 2 from the original paper (Safavi et al., 2023)

Run:

python paper/figures/figure2.py

This generates paper/figures/figure2_python.png.

Documentation

Build the docs locally:

pip install -e ".[docs]"
sphinx-build -b html docs docs/_build/html

Start reading at docs/_build/html/index.html.

Testing

pip install -e ".[tests]"
pytest

Citing

If you use PyGPLA in your research, please cite the original GPLA method paper:

Safavi, S., et al. (2023). Uncovering the organization of neural circuits with Generalized Phase Locking Analysis. PLOS Computational Biology.

@article{safavi2023uncovering,
  title   = {Uncovering the organization of neural circuits with Generalized Phase Locking Analysis},
  author  = {Safavi, Shervin and others},
  journal = {PLOS Computational Biology},
  year    = {2023}
}

A dedicated software citation (JOSS) will be added here once the paper is published.

License

BSD 2-Clause License. See LICENSE.

Acknowledgments

Developed at the CMC-Lab.

Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygpla-0.0.1.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygpla-0.0.1-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file pygpla-0.0.1.tar.gz.

File metadata

  • Download URL: pygpla-0.0.1.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for pygpla-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2a5f56c6da8294d3a3475b93e48d4b8c4358058d5f9745c2a887d0b63669aa4b
MD5 e667c4ca3dc73ddc42da52397efffab8
BLAKE2b-256 ddf6d7340f6f04fabcade5694a5222690d0a86e5f56a32eac5e799cd3169474a

See more details on using hashes here.

File details

Details for the file pygpla-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pygpla-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for pygpla-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f1e164823100458123dfad9818c0b120b16700de7536985e7041d3bcbe4eefb
MD5 ab91a78979a5385d905a46708205922b
BLAKE2b-256 028285e136a233c94aca4cb39803c51c5d3c6138b7fcdf047aec7f4bc0f0850c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page