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_predictionandsubset_pairwise_spectral_granger_prediction,sel(source=a, target=b)isa -> b; 2.x returnedb -> a. The 2.x wrapper rejected the transfer-function measures, andphase_slope_index,group_delay, anddelayare 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/targetcoordinates; 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
sourceandtargetas scalar coordinates.**kwargs – Keyword arguments for the measure (e.g.
group_labels).
- Returns:
The labeled result with provenance in
attrs; seemultitaper_connectivity()for the dimensions and orientation (sel(source=a, target=b)is the influencea -> b).- Return type:
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')