Skip to main content

pyPTE: Phase Transfer Entropy in Python

PyPI Python CI License

pyPTE estimates directed connectivity between oscillatory signals: given two channels of EEG, MEG or any rhythmic time series, it answers which one is leading the other.

It is worth being precise about the claim, because it is narrower than it first appears:

pyPTE recovers the direction of information flow between a pair of signals. It does not recover the wiring diagram of a network.

Direction is reliable. Which connections are direct is not recoverable from a bivariate measure, and what can fool it shows exactly how that fails, with numbers. Every claim below is produced by a script in examples/ that asserts its own result, so if something here stops being true, the test suite says so.

Based on:


Installation

pip install pyPTE          # or: uv add pyPTE

The core needs only NumPy and SciPy. Adapters are optional:

pip install "pyPTE[mne]"      # MNE-Python adapter (also installs pandas)
pip install "pyPTE[pandas]"   # pandas adapter

Requires Python 3.11 or newer. Dependencies are deliberately unpinned at the top end so pyPTE resolves alongside whatever NumPy and SciPy the rest of your environment needs.

Quickstart

PTE takes an (n_channels, n_samples) array and returns two matrices, where entry [i, j] describes flow from channel i to channel j.

import numpy as np
from pyPTE import PTE

rng = np.random.default_rng(0)
t = np.arange(8000) / 250.0

driver = np.sin(2 * np.pi * 10 * t) + 0.2 * rng.standard_normal(t.size)
target = 0.9 * np.roll(driver, 12) + 0.4 * rng.standard_normal(t.size)

dPTE, raw_PTE = PTE(np.vstack([driver, target]))

print(dPTE[0, 1])  # ~0.80 -> driver leads target
print(dPTE[1, 0])  # ~0.20 -> the reverse is suppressed

raw_PTE is transfer entropy in bits. dPTE is the direction-normalised form, where dPTE[i, j] + dPTE[j, i] == 1: above 0.5 means net flow from i to j, and exactly 0.5 means no preferred direction.

A raw dPTE value on its own is not a finding. See running a real analysis.

Documentation

patrk.github.io/pyPTE

Contributing

Contributions are welcome — issues, suggestions and pull requests alike.

git clone https://github.com/patrk/pyPTE && cd pyPTE
uv sync --all-extras
uv run pytest

Before opening a PR: uv run ruff check ., uv run ruff format ., uv run mypy pyPTE tests.

Citing

If pyPTE helps your research, please cite it. GitHub's "Cite this repository" button gives the details from CITATION.cff. Please also cite the papers that introduced the method:

  • Lobier, Siebenhühner, Palva & Palva (2014). Phase transfer entropy: a novel phase-based measure for directed connectivity in networks coupled by oscillatory interactions. NeuroImage 85, 853–872. doi:10.1016/j.neuroimage.2013.08.056
  • Hillebrand et al. (2016). Direction of information flow in large-scale resting-state networks is frequency-dependent. PNAS 113(14), 3867–3872. doi:10.1073/pnas.1515657113

License

pyPTE is released under GPL-3.0-or-later. See LICENSE.

Metadata

Release files for pyPTE 1.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyPTE 1.9.0
File Size Uploaded Provenance
pypte-1.9.0.tar.gz 56.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyPTE 1.9.0
File Interpreter ABI Platform
pypte-1.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 92.7 kB

Release files / pypte-1.9.0.tar.gz

Download URL pypte-1.9.0.tar.gz
Size 56.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ab19e7ef9c3629348402c091946ca82c2a3ebef95f37b82d37ea0806780d0aa6
BLAKE2b-256 checksum
How to use checksums
0c8723a5ba0fd5162293c04bd12fc6092ad4334dfe2b1c18dd2dcce6bc23aabe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / pypte-1.9.0-py3-none-any.whl

Download URL pypte-1.9.0-py3-none-any.whl
Size 36.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7412dbb2184eb1b6a2e8cb5978998feddcf1eb3db75be4bfa3a1c3f6f7939bb
BLAKE2b-256 checksum
How to use checksums
5e75cfdbbdf46efc6a805c66ba41f350d5a624d8a55b20c970ae55529165460f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for pyPTE 1.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pypte-1.9.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page