API reference#

All names in this page are importable from dirconn unless a module is given.

Data structures#

TimeSeries

Multichannel time series with explicit segmentation.

ChannelMeta

Description of one channel (or node) of a time series.

Connectivity

Directed connectivity with fixed dimensions (source, target, freq, time).

Provenance

Everything needed to understand and reproduce a result.

AssumptionChecklist

An ordered set of assumption checks with unique names.

AssumptionCheck

Outcome of one assumption diagnostic.

Simulation#

Network

A directed network of cortical regions and direct (invasive) nodes.

Edge

A directed coupling from source to target.

dk_node

Return a cortical node for a Desikan-Killiany label such as "inferiortemporal-lh".

direct_node

Return a direct node: an invasive channel used as recorded, for example "STN-L".

NodeDynamics

Own dynamics of a network node.

simulate

Simulate sensor data generated by a directed network.

SimulatedData

Output of simulate().

coupled_nonlinear

Three channels where X drives Y through a chosen function and Z is independent.

Estimators#

Estimator

Base class for all directed-connectivity estimators.

MethodInfo

Structured description of a method, enforced at run time.

GC

Granger causality log(var_reduced / var_full) from a pooled least-squares VAR model.

DTF

Directed transfer function (Kaminski and Blinowska), a predictive spectral measure.

PDC

Partial directed coherence (Baccala and Sameshima), a predictive spectral measure.

GPDC

Generalised partial directed coherence (Baccala et al. 2007).

RPDC

Renormalised partial directed coherence (Schelter et al. 2009), a predictive measure.

SSGC

Spectral Granger causality from the state-space form of the VAR (Barnett and Seth 2015).

ADTF

Adaptive directed transfer function: the DTF at every time point.

TPDC

Time-varying partial directed coherence: the PDC at every time point.

WDTF

Windowed directed transfer function: one DTF per window or per segment.

TRGC

Time-reversed Granger causality, difference-based (Haufe et al. 2013; Winkler et al. 2016).

ImCoh

Imaginary part of coherency (Nolte et al. 2004), per frequency.

PSI

Phase slope index (Nolte et al. 2008) in one or more frequency bands.

MTGC

Pairwise spectral Granger causality from multitaper spectra, without a fitted model.

PCMCI

PCMCI with the partial-correlation (ParCorr) test, lagged links only.

TE

Transfer entropy with the KSG estimator: multivariate (default), pairwise or conditional.

fit_var

Fit a VAR model by pooled least squares.

select_order

Choose the VAR order with an information criterion or by cross-validation.

VarFit

A fitted VAR model.

OrderSelection

Result of select_order().

Every estimator class has a lower-case shorthand that builds the estimator and fits it in one call:

dirconn.gc(data: TimeSeries, **params: Any) → Connectivity#

Granger causality of data; shorthand for GC(**params).fit(data).

See GC for the parameters.

dirconn.dtf(data: TimeSeries, **params: Any) → Connectivity#

Directed transfer function of data; shorthand for DTF(**params).fit(data).

dirconn.pdc(data: TimeSeries, **params: Any) → Connectivity#

Partial directed coherence of data; shorthand for PDC(**params).fit(data).

dirconn.gpdc(data: TimeSeries, **params: Any) → Connectivity#

Generalised PDC of data; shorthand for GPDC(**params).fit(data).

dirconn.rpdc(data: TimeSeries, **params: Any) → Connectivity#

Renormalised PDC of data; shorthand for RPDC(**params).fit(data).

dirconn.ssgc(data: TimeSeries, **params: Any) → Connectivity#

State-space spectral GC of data; shorthand for SSGC(**params).fit(data).

dirconn.adtf(data: TimeSeries, **params: Any) → Connectivity#

Adaptive DTF of data; shorthand for ADTF(**params).fit(data).

dirconn.tpdc(data: TimeSeries, **params: Any) → Connectivity#

Time-varying PDC of data; shorthand for TPDC(**params).fit(data).

dirconn.wdtf(data: TimeSeries, **params: Any) → Connectivity#

Windowed DTF of data; shorthand for WDTF(**params).fit(data).

dirconn.trgc(data: TimeSeries, **params: Any) → Connectivity#

Time-reversed Granger causality of data; shorthand for TRGC(**params).fit(data).

dirconn.imcoh(data: TimeSeries, **params: Any) → Connectivity#

Imaginary coherence of data; shorthand for ImCoh(**params).fit(data).

dirconn.psi(data: TimeSeries, **params: Any) → Connectivity#

Phase slope index of data; shorthand for PSI(**params).fit(data).

dirconn.mtgc(data: TimeSeries, **params: Any) → Connectivity#

Multitaper Granger causality of data; shorthand for MTGC(**params).fit(data).

dirconn.pcmci(data: TimeSeries, **params: Any) → Connectivity#

PCMCI of data; shorthand for PCMCI(**params).fit(data).

dirconn.te(data: TimeSeries, **params: Any) → Connectivity#

Transfer entropy of data; shorthand for TE(**params).fit(data).

The state-space form behind GC(method="state_space") and SSGC, for VAR coefficients known in advance (for example the truth of a simulation):

methods.statespace.var_to_state_space

Write a VAR model in innovations form.

methods.statespace.reduced_model

Return the innovations form of a subset of the observed channels of model.

methods.statespace.state_space_gc

Time-domain Granger causality of a VAR model from its state-space form.

methods.statespace.spectral_state_space_gc

Spectral (Geweke) Granger causality of a VAR model from its state-space form.

methods.statespace.InnovationsForm

A state-space model in innovations form.

A heuristic that compares any estimator with itself on time-reversed data (not an estimator, not a test):

time_reversal_asymmetry

Compare an estimator's result on the data with its result on the time-reversed data.

TimeReversalAsymmetry

Result of time_reversal_asymmetry().

Statistics#

significance_test

Test the significance of an estimator's result.

surrogate_test

Test an estimator's result against surrogates of the data.

SurrogateTestResult

Outcome of a surrogate test, with the premise it rests on.

analytic_gc_test

Test Granger causality with the F distribution of nested least-squares models.

AnalyticTestResult

F-test p-values of a Granger result, with the premise they rest on.

analytic_pdc_test

Test PDC at every frequency with its asymptotic distribution (Schelter et al. 2006).

analytic_rpdc_test

Test rPDC at every frequency with its asymptotic distribution (Schelter et al. 2009).

AsymptoticTestResult

Per-frequency p-values and thresholds of PDC or rPDC, with the premise they rest on.

pcmci_test

Fit PCMCI and return its own MCI p-values as a test result.

PCMCITestResult

PCMCI's own MCI p-values, as a test result that the correction code can use.

bootstrap

Bootstrap an estimator's result.

BootstrapResult

Percentile bands of the magnitude of a connectivity result.

contrast_test

Test whether connectivity differs between two conditions or two segments of the same trials.

ContrastResult

Outcome of a condition contrast, with the premise it rests on.

adjust_pvalues

Adjust p-values so that adjusted <= alpha is the corrected decision.

baseline_normalise

Express the connectivity of active relative to that of baseline.

Figures#

Connectivity.plot(kind=...) draws the result alone (matrices, spectra, panels and small graphs; see dirconn.Connectivity.plot()). The functions of dirconn.viz need more than a result: several results side by side, a grouping of the nodes, or the cortical surface.

connectivity_grids

Draw several results side by side, one panel each, on one shared colour scale.

chord_diagram

Draw the connectivity between groups of nodes as a directed chord diagram (pyCirclize).

degree_imbalance_map

Colour the cortical surface by log(D_out) - log(D_in) of every region (MNE 3D plot).

group_matrix

Summarise a result between groups of nodes.

yeo_networks

Return the network of every Desikan-Killiany region, computed from the vertex overlap.

yeo_groups

Return {region: network} for region names such as "precuneus-lh".

region_values

Return {region: value} from a mapping, a Series or a result of degree_imbalance.

dominant_networks

Assign every region to the network that holds most of its vertices.

Files and data#

read_bids

Read one recording from a BIDS dataset as a TimeSeries.

write_roi_bids

Write region-level time series as a BIDS-Derivatives dataset (dirconn convention v0).

read_simulation_bids

Read a simulation written by write_simulation_bids().

write_simulation_bids

Write a simulation as a raw BIDS dataset plus a derivatives dataset.

SimulationRecord

A simulation read back from BIDS by read_simulation_bids().

datasets.require_sample

Return the root of the MNE sample dataset, or stop with instructions.

Modules the tutorials use#

simulation.scenario.load_scenario

Load a scenario from a YAML file or by the name of a shipped one.

simulation.scenario.list_scenarios

Return the names of the shipped scenarios, sorted.

simulation.simulation.simulate_on_head

Simulate sensor data of a network through a realistic head model.

simulation.headmodel.load_head_model

Load the head model of the MNE sample subject for one sensor type.

simulation.inverse.roi_series

Return the time courses of regions estimated from sensor data.

simulation.inverse.crosstalk

Measure the leakage between regions of a head model for an inverse method and region mode.

diagnostics.regions.centre_distances

Return the distances in mm between the centre sources of all regions.

Modules#

The package is split into eight subpackages of dirconn (see 0002 — Package layout: eight subpackages and a fixed dependency direction). The old top-level module paths (such as dirconn.granger or dirconn.plotting) are deprecated shims that warn on import and are removed in dirconn 0.4.0.

data

The data model: time series, channels, networks, results, provenance, bands, RNG, exceptions.

io

Reading and writing data.

methods

Connectivity estimators: autoregressive, spectral, information-theoretic, causal discovery.

stats

Statistical inference: surrogates, bootstrap, analytic tests, contrasts, correction.

diagnostics

Diagnostics: model-order stability, leakage and region handling.

simulation

Synthetic data: network simulation, scenario library, head model, inverse and empty-room.

validation

Validation: protocols, sweeps, benchmark, metrics, studies and the method-validation runner.

viz

Figures of connectivity results.