mne_connectivity.EpochTemporalConnectivity#
- class mne_connectivity.EpochTemporalConnectivity(data, times, n_nodes, names=None, indices='all', method=None, **kwargs)[source]#
Temporal connectivity class over Epochs.
This is an array of shape (n_epochs, n_connections, n_times), or (n_epochs, n_nodes, n_nodes, n_times). This describes how connectivity varies over time for different epochs.
- Parameters
data :
np.ndarray([epochs], n_estimated_nodes, [freqs], [times])The connectivity data that is a raveled array of
(n_estimated_nodes, ...)shape. Then_estimated_nodesis equal ton_nodes_in * n_nodes_outif one is computing the full connectivity, or a subset of nodes equal to the length ofindicespassed in.times :
list|np.ndarrayThe times at which the connectivity data is computed over.
n_nodes :
intThe number of nodes in the dataset used to compute connectivity. This should be equal to the number of signals in the original dataset.
names :
list|np.ndarray|NoneThe names of the nodes of the dataset used to compute connectivity. If ‘None’ (default), then names will be a list of integers from 0 to
n_nodes. If a list of names, then it must be equal in length ton_nodes.indices :
tupleof arrays |str|NoneThe indices of relevant connectivity data. If
'all'(default), then data is connectivity between all nodes. If'symmetric', then data is symmetric connectivity between all nodes. If a tuple, then the first list represents the “in nodes”, and the second list represents the “out nodes”. See “Notes” for more information.method :
str, optionalThe method name used to compute connectivity.
**kwargs :
dictExtra connectivity parameters. These may include
freqsfor spectral connectivity, and/ortimesfor connectivity over time. In addition, these may include extra parameters that are stored as xarrayattrs.- Attributes
-
Xarray attributes of connectivity.
Generate block companion matrix.
The coordinates of the xarray data.
The dimensions of the xarray data.
Indices of connectivity data.
The method used to compute connectivity.
The number of epochs the connectivity data varies over.
Number of epochs used in computation of connectivity.
The number of nodes in the original dataset.
Node names.
Shape of raveled connectivity.
The time points of the connectivity data.
Xarray of the connectivity data.
Methods
append(epoch_conn)Append another connectivity structure.
combine([combine])Combine connectivity data over epochs.
get_data([output])Get connectivity data as a numpy array.
plot_circle(**kwargs)Visualize connectivity as a circular graph.
predict(data)Predict samples on actual data.
rename_nodes(mapping)Rename nodes.
save(fname)Save connectivity data to disk.
simulate(n_samples[, noise_func, random_state])Simulate vector autoregressive (VAR) model.
copy
eigvals
get_epoch_annotations
is_stable
- append(epoch_conn)#
Append another connectivity structure.
- Parameters
epoch_conn : instance of
ConnectivityThe Epoched Connectivity class to append.
- Returns
self : instance of
ConnectivityThe altered Epoched Connectivity class.
- property attrs#
Xarray attributes of connectivity.
See
xarray’sattrs.
- combine(combine='mean')#
Combine connectivity data over epochs.
- Parameters
combine : ‘mean’ | ‘median’ |
callable()How to combine correlation estimates across epochs. Default is ‘mean’. If callable, it must accept one positional input. For example:
combine = lambda data: np.median(data, axis=0)
- Returns
conn : instance of
ConnectivityThe combined connectivity data structure.
- property companion#
Generate block companion matrix.
Returns the data matrix if the model is VAR(1).
- property coords#
The coordinates of the xarray data.
- property dims#
The dimensions of the xarray data.
- get_data(output='compact')#
Get connectivity data as a numpy array.
- Parameters
output :
str, optionalHow to format the output, by default ‘raveled’, which will represent each connectivity matrix as a
(n_nodes_in * n_nodes_out,)list. If ‘dense’, then will return each connectivity matrix as a 2D array. If ‘compact’ (default) then will return ‘raveled’ ifindiceswere defined as a list of tuples, ordenseif indices is ‘all’.- Returns
data :
np.ndarrayThe output connectivity data.
- property indices#
Indices of connectivity data.
- property method#
The method used to compute connectivity.
- property n_epochs#
The number of epochs the connectivity data varies over.
- property n_epochs_used#
Number of epochs used in computation of connectivity.
Can be ‘None’, if there was no epochs used. This is equivalent to the number of epochs, if there is no combining of epochs.
- property n_nodes#
The number of nodes in the original dataset.
Even if
indicesdefines a subset of nodes that were computed, this should be the total number of nodes in the original dataset.
- property names#
Node names.
- plot_circle(**kwargs)#
Visualize connectivity as a circular graph.
- Parameters
-
Node names. The order corresponds to the order in con.
indices :
tupleofarray|NoneTwo arrays with indices of connections for which the connections strengths are defined in con. Only needed if con is a 1D array.
If not None, only the n_lines strongest connections (strength=abs(con)) are drawn.
node_angles :
array, shape (n_node_names,) |NoneArray with node positions in degrees. If None, the nodes are equally spaced on the circle. See mne.viz.circular_layout.
Width of each node in degrees. If None, the minimum angle between any two nodes is used as the width.
node_colors :
listoftuple|listofstrList with the color to use for each node. If fewer colors than nodes are provided, the colors will be repeated. Any color supported by matplotlib can be used, e.g., RGBA tuples, named colors.
facecolor :
strColor to use for background. See matplotlib.colors.
textcolor :
strColor to use for text. See matplotlib.colors.
node_edgecolor :
strColor to use for lines around nodes. See matplotlib.colors.
linewidth :
floatLine width to use for connections.
colormap :
str| instance ofmatplotlib.colors.LinearSegmentedColormapColormap to use for coloring the connections.
Minimum value for colormap. If None, it is determined automatically.
Maximum value for colormap. If None, it is determined automatically.
colorbar : bool
Display a colorbar or not.
title :
strThe figure title.
colorbar_size :
floatSize of the colorbar.
colorbar_pos :
tuple, shape (2,)Position of the colorbar.
fontsize_title :
intFont size to use for title.
fontsize_names :
intFont size to use for node names.
fontsize_colorbar :
intFont size to use for colorbar.
padding :
floatSpace to add around figure to accommodate long labels.
fig :
None| instance ofmatplotlib.figure.FigureThe figure to use. If None, a new figure with the specified background color will be created.
subplot :
int|tuple, shape (3,)Location of the subplot when creating figures with multiple plots. E.g. 121 or (1, 2, 1) for 1 row, 2 columns, plot 1. See matplotlib.pyplot.subplot.
interactive : bool
When enabled, left-click on a node to show only connections to that node. Right-click shows all connections.
node_linewidth :
floatLine with for nodes.
show : bool
Show figure if True.
- Returns
fig : instance of
matplotlib.figure.FigureThe figure handle.
axes : instance of
matplotlib.projections.polar.PolarAxesThe subplot handle.
Notes
This code is based on a circle graph example by Nicolas P. Rougier
By default,
matplotlib.pyplot.savefig()does not takefacecolorinto account when saving, even if set when a figure is generated. This can be addressed via, e.g.:>>> fig.savefig(fname_fig, facecolor='black')
If
facecoloris not set viamatplotlib.pyplot.savefig(), the figure labels, title, and legend may be cut off in the output figure.
- predict(data)#
Predict samples on actual data.
The result of this function is used for calculating the residuals.
- Parameters
data :
arrayEpoched or continuous data set. Has shape (n_epochs, n_signals, n_times) or (n_signals, n_times).
- Returns
predicted :
arrayData as predicted by the VAR model of shape same as
data.
Notes
Residuals are obtained by r = x - var.predict(x).
To compute residual covariances:
# compute the covariance of the residuals # row are observations, columns are variables t = residuals.shape[0] sampled_residuals = np.concatenate( np.split(residuals[:, :, lags:], t, 0), axis=2 ).squeeze(0) rescov = np.cov(sampled_residuals)
- rename_nodes(mapping)#
Rename nodes.
- Parameters
mapping :
dictMapping from original node names (keys) to new node names (values).
- save(fname)#
Save connectivity data to disk.
- Parameters
fname :
str|pathlib.PathThe filepath to save the data. Data is saved as netCDF files (
.ncextension).
- property shape#
Shape of raveled connectivity.
- simulate(n_samples, noise_func=None, random_state=None)#
Simulate vector autoregressive (VAR) model.
This function generates data from the VAR model.
- Parameters
n_samples :
intNumber of samples to generate.
noise_func : func, optional
This function is used to create the generating noise process. If set to None, Gaussian white noise with zero mean and unit variance is used.
random_state :
None|int| instance ofRandomStateIf
random_stateis anint, it will be used as a seed forRandomState. IfNone, the seed will be obtained from the operating system (seeRandomStatefor details). Default isNone.- Returns
data :
array, shape (n_samples, n_channels)Generated data.
- property times#
The time points of the connectivity data.
- property xarray#
Xarray of the connectivity data.