spectral_connectivity.wrapper.connectivity_to_xarray#

connectivity_to_xarray(m: Any, method: str = 'coherence_magnitude', signal_names: Sequence[str | bytes | bool | int | float | integer | floating | bool | str_ | bytes_ | datetime64 | timedelta64] | None = None, squeeze: bool = False, **kwargs: Any) → DataArray | Dataset[source]#

Calculate one connectivity measure and return a labeled array.

Ordinary pairwise measures return a DataArray; component-resolved or multi-quantity measures return a Dataset with explicit semantic axes.

Changed in version 3.0: For pairwise_spectral_granger_prediction and subset_pairwise_spectral_granger_prediction, sel(source=a, target=b) is a -> b; 2.x returned b -> a. The 2.x wrapper rejected the transfer-function measures, and phase_slope_index, group_delay, and delay are unchanged.

Parameters:
  • m (transform) – A spectral transform (e.g. Multitaper, MorletWavelet, Welch) whose coefficients the measure is computed from.

  • method (str, default="coherence_magnitude") – Measure name from list_measures().

  • signal_names (sequence, optional) – Labels for the source/target coordinates; defaults to "0", "1", ….

  • squeeze (bool, default=False) – With exactly 2 signals, reduce a pairwise measure to the ordered pair (first source, last target), keeping source and target as scalar coordinates.

  • **kwargs – Keyword arguments for the measure (e.g. group_labels).

Returns:

The labeled result with provenance in attrs; see multitaper_connectivity() for the dimensions and orientation (sel(source=a, target=b) is the influence a -> b).

Return type:

xarray.DataArray or xarray.Dataset

Examples

>>> import numpy as np
>>> from spectral_connectivity.transforms import Multitaper
>>> data = np.random.default_rng(0).standard_normal((100, 5, 3))
>>> mt = Multitaper(data, sampling_frequency=1000)
>>> connectivity_to_xarray(mt).dims
('time', 'frequency', 'source', 'target')