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 once the data are band-passed to the rhythm and checked with time reversal, and the coupling lag is more than a small fraction of a cycle; #85 maps where it breaks. 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 scipy.signal import butter, sosfiltfilt
from pyPTE import PTE

rng = np.random.default_rng(0)
fs, n, lag = 250, 30_000, 12  # two minutes; the target trails by 12 samples

# one 10 Hz rhythm with a drifting phase, seen by both channels with equal noise
drift = np.cumsum(rng.normal(0, 0.025, n + lag))
rhythm = np.sin(2 * np.pi * 10 * np.arange(n + lag) / fs + drift)
driver = rhythm[lag:] + rng.standard_normal(n)
target = rhythm[:n] + rng.standard_normal(n)

# band-pass to the rhythm, and cancel what noise alone would make look directed
alpha = butter(4, [8, 12], btype="band", fs=fs, output="sos")
signal = sosfiltfilt(alpha, np.vstack([driver, target]))
dPTE, raw_PTE = PTE(signal, time_reversal=True)

print(dPTE[0, 1])  # ~0.63 -> driver leads target
print(dPTE[1, 0])  # ~0.37 -> the reverse

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. Two independent rhythms with the same noise give about 0.5. Without the band-pass, or with unequal noise and no time_reversal, dPTE can point from the cleaner channel to the noisier one whatever the coupling.

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.14.2

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.14.2
File Size Uploaded Provenance
pypte-1.14.2.tar.gz 67.5 kB With provenance Details

Built distribution (wheel)

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

Total release size: 110.5 kB

Release files / pypte-1.14.2.tar.gz

Download URL pypte-1.14.2.tar.gz
Size 67.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c8a33ea75bf8ed8fc6fec9ae3f7974d2e3c4061185c065696df48d634e4b76fe
BLAKE2b-256 checksum
How to use checksums
72cc39125f04664be2ffa2be644285a3a54577903bd68716b0006ad45c01b20b
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 24, 2026.

Transparency log

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

Download URL pypte-1.14.2-py3-none-any.whl
Size 43.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df9b34afe2f807916040c9be3f12f13f065de1263b6016f03fa5ddb3cacb038b
BLAKE2b-256 checksum
How to use checksums
eb9249b3e703d28d89dc9589d60034055d086879033cd7a2eb180e4c6f6094b9
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 24, 2026.

Transparency log

Security for pyPTE 1.14.2

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.14.2.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 24, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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