dirconn
Directed functional connectivity for neurophysiology signals (EEG, MEG, iEEG, LFP) at sensor and region level.
dirconn estimates predictive directed influence (Granger causality and related measures). It does not establish interventional causality, and every result records the assumptions it relies on and the checks that were run on them.
Status: alpha. The API can still change between minor versions.
Documentation, tutorials and API reference: https://hanweiliu-viola.github.io/dirconn/
What it does
- Data and results: a
TimeSeriesof trials × channels × samples for sensors, cortical regions (Desikan-Killiany names) and directly recorded nodes such as a subthalamic LFP; aConnectivityresult that carries its provenance (method, model order, assumptions, checks) and is saved as NetCDF; region time series in a BIDS-like layout. - Methods: conditional and pairwise Granger causality (refitted reduced models or the state-space form of the VAR), conditional spectral Granger causality from the state-space form, DTF, PDC, generalised and renormalised PDC (rPDC); controls for zero-delay mixing (time-reversed Granger causality, imaginary coherence, phase slope index); Granger causality from multitaper spectra without a fitted model; PCMCI; transfer entropy with the KSG estimator (multivariate by default, optionally on a GPU); time-varying measures (ADTF, TPDC, windowed DTF).
- Statistics: surrogate and permutation tests, asymptotic per-frequency tests of PDC and rPDC, multiple-comparison correction, bootstrap intervals, and a residual whiteness check on every VAR fit.
- Simulation and validation: networks with a known truth, simulated through the head models of
the MNE
sampledataset, so that leakage, observation noise and hidden drivers can be measured instead of assumed. The benchmark protocols, their saved results and what they do and do not show are part of the repository (validation/protocols/,validation/results/,docs/benchmark*.md).
Install
pip install dirconn
pip install "dirconn[plot,stats]" # with plotting and the statsmodels-based tests
Optional extras: connectivity (mne-connectivity), pcmci (tigramite), stats (statsmodels),
parallel (joblib), speed (numba), gpu (torch), plot (matplotlib, pyCirclize), plot-extra
(3D maps of the cortical surface), app (pydantic and joblib, for the dirconn-bids command line),
all. Python 3.10 to 3.13.
From a clone, for development:
pip install -e ".[dev,all]"
pytest
The MNE sample dataset (about 1.5 GB) is needed only for the benchmark and for tutorials 7, 8, 13
and 14. It is never downloaded without being asked; see CONTRIBUTING.md.
A first example
import dirconn
from dirconn import Edge, Network, dk_node
from dirconn.simulation import NodeDynamics, simulate
A, B, C = "cuneus-rh", "precuneus-rh", "insula-rh"
network = Network(
nodes=[dk_node(A), dk_node(B), dk_node(C)],
edges=[Edge(A, B, strength=0.4, delay_ms=10.0), Edge(B, C, strength=0.4, delay_ms=10.0)],
name="chain",
)
dynamics = {
A: NodeDynamics(kind="oscillator", freq_hz=10.0),
B: NodeDynamics(kind="oscillator", freq_hz=20.0),
C: NodeDynamics(kind="oscillator", freq_hz=15.0),
}
sim = simulate(
network,
sfreq=100.0,
n_times=12000,
seed=0,
dynamics=dynamics,
snr_db=10.0,
n_background=0,
node_scale="unit",
)
data = sim.roi_observations(snr_db=10.0, seed=1)
result = dirconn.gc(data, order="bic") # conditional Granger causality
print(result.provenance.claim)
for check in result.provenance.assumptions.checks:
print(check.name, check.status)
The tutorials go on from here: model order, frequency-domain measures, significance, results that mislead (indirect paths, shared and hidden drivers), time-varying connectivity, sensors to regions and leakage, sources and sinks, zero-delay controls, PCMCI, transfer entropy, and the renormalised PDC. Each ends on what its result does and does not show.
Command line
dirconn-bids runs the pipeline on a BIDS dataset (BIDS App convention, participant level): it reads
the region-level series of every recording, estimates, tests and controls directed connectivity as a
TOML file configures it, and writes a derivatives dataset to OUTPUT_DIR/dirconn. Runs can be
repeated and resumed; every run records its provenance. For each subject it also writes a
self-contained report page, sub-XX.html, with the diagnostics, figures, tests and failures, and a
methods text with references in logs/CITATION.*; --reports-only rebuilds them without computing
anything.
pip install "dirconn[app]"
dirconn-bids /data/bids /data/out participant --participant-label 01 --config my_config.toml
Options, configuration fields and output files are described in the
documentation (docs/usage.rst,
docs/configuration.rst, docs/outputs.rst, and docs/report.rst for the report).
Reproducible Docker environment
The Dockerfile builds one image with two uses. It freezes the whole scientific stack
(exact versions in constraints/docker.txt; the image also carries the full
pip freeze in /opt/environment-lock.txt) for analyses whose numbers must be computable again
later, and its entrypoint is the BIDS App dirconn-bids. It holds no data. The tutorials are in
/opt/dirconn/tutorials as notebooks; 7, 8, 13 and 14 need the MNE sample dataset mounted at
/mne_data.
BIDS App. Mount the BIDS dataset read-only at /data and an output directory at /out; the
arguments are those of dirconn-bids (BIDS_DIR OUTPUT_DIR participant, see --help):
docker pull ghcr.io/hanweiliu-viola/dirconn:<tag>
docker run --rm -v /path/to/bids:/data:ro -v /path/to/out:/out \
ghcr.io/hanweiliu-viola/dirconn:<tag> /data /out participant
The reports and the derivatives are written to /out/dirconn; each run's provenance.json names
the image tag, and the run directory keeps a copy of environment-lock.txt. The image does not
contain bids-validator: the CLI warns and skips the validation, so --skip-bids-validation is not
needed. Without arguments, docker run --rm IMAGE prints the help.
Environment. Replace the entrypoint to get a shell or Jupyter; mount your scripts or notebooks
into /work and the data read-only into /data:
docker run --rm -it --entrypoint bash -v /path/to/analysis:/work -v /path/to/data:/data:ro \
ghcr.io/hanweiliu-viola/dirconn:<tag>
docker run --rm -p 127.0.0.1:8888:8888 --entrypoint jupyter -v /path/to/analysis:/work \
-v /path/to/data:/data:ro ghcr.io/hanweiliu-viola/dirconn:<tag> lab --ip=0.0.0.0 --no-browser
Jupyter listens only on the local machine (127.0.0.1); open the URL with the token it prints.
OMP_NUM_THREADS=1 is set on purpose, because the number of threads changes floating-point sums;
parallelise over subjects or surrogates (joblib, explicit seeds) instead, and on a shared machine
cap the container with --cpus and --memory. Reading through a Docker Desktop bind mount is slow;
keep large data on an SSD, or copy it into a Docker volume first. The image contains no torch and no
3D plotting: surface maps are drawn on the host from saved results. Under Apptainer the image runs
unchanged (apptainer pull docker://ghcr.io/hanweiliu-viola/dirconn:<tag>); nothing is written into
it at run time. The image is checked against the published validation numbers with
tools/validate_methods.py and tools/compare_validation.py.
Citing
If you use dirconn, please cite the version you used; the metadata are in CITATION.cff, and every release gets a DOI on Zenodo. The DOI 10.5281/zenodo.24036991 always resolves to the latest version; the Zenodo page lists the DOI of each version (0.1.0: 10.5281/zenodo.24036992).
Author and licence
Hanwei Liu, University Hospital of Wuerzburg. BSD-3-Clause, see LICENSE.
Parts of the code and documentation were written with the help of an AI coding assistant; the author reviewed all of it, and it is covered by the tests and the simulation benchmark described above.
Metadata
Release files for dirconn 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dirconn-0.2.0.tar.gz | 7.1 MB | With provenance | Details for dirconn-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dirconn-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for dirconn-0.2.0-py3-none-any.whl |
Total release size: 7.6 MB
Release files / dirconn-0.2.0.tar.gz
| Download URL | dirconn-0.2.0.tar.gz |
|---|---|
| Size | 7.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
540653fb11ff7397b39d0eed80e78cd1f43efd65190549919533b1a24ad8c74a
|
|
BLAKE2b-256 checksum How to use checksums |
924f911a3a9cc4ff820903f25222434c6c53f0f1a1bc0b211e01c84bbb89b2e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logRelease files / dirconn-0.2.0-py3-none-any.whl
| Download URL | dirconn-0.2.0-py3-none-any.whl |
|---|---|
| Size | 487.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6175beee27f71d4fc937e38b175b31997932b65b4bb324d6906e9c829889fb31
|
|
BLAKE2b-256 checksum How to use checksums |
c3b94d7e63f325b0e6fdc57d0f6580016ad4bc2eb22ffb971cb9a18ab02d130c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logSecurity for dirconn 0.2.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
Both files in this release have been uploaded with provenance metadata.
Attestation for dirconn-0.2.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 Nov 30, 2026.
Transparency logA 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.