conpy.connectivity.VertexConnectivity

class conpy.connectivity.VertexConnectivity(data, pairs, vertices, vertex_degree=None, subject=None, directed=False)

Estimation of connectivity between vertices.

Parameters
datandarray, shape (n_pairs,)

For each connectivity source pair, a value describing the connection. For example, this can be the strength of the connection between the sources.

pairsndarray, shape (n_pairs, 2)

The vertices involved in the from-to connectivity pair. The vertices are listed as “vertex indices” in the array:

np.hstack((vertices[0], (vertices[1] + len(vertices[0]))))

verticeslist of two arrays of shape (n_vertices,)

For each hemisphere, the vertex numbers of sources defined in the corresponding source space.

vertex_degreetuple of lists (out_degree, in_degree) | None

For each vertex, the total number of possible connections from and to the vertex. This information is needed to perform weighting on the number of connections during visualization and statistics. If None, it is assumed that all possible connections are defined in the pairs parameter and the out- and in-degree of each vertex is computed.

subjectstr | None

The subject-id.

directedbool

Whether the connectivity is directed (from->to != to->from). Defaults to False.

Attributes
n_connectionsint

The number of connections.

n_sourcesint

The number of sources between possible connections were computed.

Methods

copy()

Return copy of the Connectivity object.

get_adjacency()

Get a source-to-source adjacency matrix.

is_compatible(other)

Check compatibility with another connectivity object.

make_stc([summary, weight_by_degree])

Obtain a summary of the connectivity as a SourceEstimate object.

parcellate(labels[, summary, …])

Get the connectivity parcellated according to the given labels.

save(fname)

Save the connectivity object to an HDF5 file.

threshold(thresh[, crit, direction, copy])

Threshold the connectivity.

to_original_src(src_orig[, subject_orig, …])

Get the connectivity from a morphed source to the original subject.

is_compatible(other)

Check compatibility with another connectivity object.

Two connectivity objects are compatible if they define the same connectivity pairs.

Returns
is_compatiblebool

Whether the given connectivity object is compatible with this one.

make_stc(summary='sum', weight_by_degree=True)

Obtain a summary of the connectivity as a SourceEstimate object.

Parameters
summary‘sum’ | ‘degree’ | ‘absmax’

How to summarize the adjacency data:

‘sum’sum the strenghts of both the incoming and outgoing

connections for each source.

‘degree’: count the number of incoming and outgoing

connections for each source.

‘absmax’show the strongest coherence across both incomoing

and outgoing connections at each source. In this setting, the weight_by_degree parameter is ignored.

Defaults to 'sum'.

weight_by_degreebool

Whether to weight the summary by the number of possible connections. Defaults to True.

Returns
stcinstance of SourceEstimate

The summary of the connectivity.

parcellate(labels, summary='sum', weight_by_degree=True, verbose=None)

Get the connectivity parcellated according to the given labels.

The coherence of all connections within a label are averaged.

Parameters
labelslist of (Label | BiHemiLabel)

The labels to use to parcellate the connectivity.

summary‘sum’ | ‘degree’ | ‘absmax’ | function

How to summarize the connectivity within a label. Either the summation of the connection values (‘sum’), the number of connections from and to the label is used (‘degree’), the absolute maximum value of the connections (‘absmax’), or a function can be specified, which is called for each label with the following signature:

>>> def summary(adjacency, vert_from, vert_to):
...     '''Summarize the connections within a label.
...
...     Parameters
...     ----------
...     adjacency : sparse matrix, shape (n_sources, n_sources)
...         The adjacency matrix that defines the connection
...         between the sources.
...     src_from : list of int
...         Indices of sources that are outside of the label.
...     src_to : list of int
...         Indices of sources that are inside the label.
...
...     Returns
...     -------
...     coh : float
...         Summarized coherence of the parcel.
weight_by_degreebool

Whether to weight the summary of each label by the number of possible connections from and to that label. Defaults to True.

verbosebool | str | int | None

If not None, override default verbose level (see mne.verbose() and Logging documentation for more).

Returns
coh_parcLabelConnectivity

The parcellated connectivity.

See also

mne.read_labels_from_annot

To read a list of labels from a FreeSurfer annotation.

to_original_src(src_orig, subject_orig=None, subjects_dir=None, verbose=None)

Get the connectivity from a morphed source to the original subject.

Parameters
src_originstance of SourceSpaces

The original source spaces that were morphed to the current subject.

subject_origstr | None

The original subject. For most source spaces this shouldn’t need to be provided, since it is stored in the source space itself.

subjects_dirstring, or None

Path to SUBJECTS_DIR if it is not set in the environment.

verbosebool | str | int | None

If not None, override default verbose level (see mne.verbose() and Logging documentation for more).

Returns
coninstance of VertexConnectivity

The transformed connectivity.