Migrating from 2.x to 3.0#
spectral_connectivity 3.0 corrects several numerical definitions, so it is a major version. Recompute affected results rather than comparing them directly with results from 2.x. The changelog lists everything that was added and fixed; this page lists what code written for 2.x has to change.
If you only change five things#
Swap the indices of directed results. The
Connectivitymethods of the spectral Granger family,directed_transfer_function,directed_coherence,partial_directed_coherence,generalized_partial_directed_coherence, anddirect_directed_transfer_functionreturn[..., source, target]:result[..., i, j]is nowi -> j, where 2.x returnedj -> i. In the wrapper results,multitaper_connectivity(...).sel(source="a", target="b")of pairwise and subset spectral Granger prediction is nowa -> b, where 2.x returnedb -> a. Code written for 2.x still runs but reads the opposite direction, so swap its indices and recompute stored results.phase_slope_index,group_delay, anddelaywere already source first: do not swap them. Until 3.2 theConnectivitymethods that existed in 2.x (pairwise and subset spectral Granger, directed transfer function, directed coherence, (generalized) partial directed coherence, and direct directed transfer function),Connectivity.jackknifeof those measures, andmultitaper_connectivityandconnectivity_to_xarrayfor pairwise and subset spectral Granger prediction emit aDirectedOrientationWarningas a reminder, once per Python session for each measure (and once more if the same measure is computed both through a wrapper and through itsConnectivitymethod). Show it at every call withwarnings.simplefilter("always", spectral_connectivity.DirectedOrientationWarning), or silence it withwarnings.filterwarnings("ignore", category=spectral_connectivity.DirectedOrientationWarning).Expect one-sided power.
Connectivity.power()returns the one-sided density: the bins between 0 Hz and Nyquist are twice the 2.x values.power(one_sided=False)returns the 2.x values. Until 3.2, callingConnectivity.power()withoutone_sidedon two-sided coefficients emits aSidednessWarning, once per Python session (warnings.simplefilter("always", spectral_connectivity.SidednessWarning)shows it at every call); passone_sided=Trueto silence it. The power inmultitaper_connectivityandconnectivity_to_xarrayresults changed the same way without a warning: halve its interior bins to compare with 2.x.Connectivity.global_coherencereturns the non-negative frequencies only, and emits the sameSidednessWarningnotice (Other measures, power, and statistics).Recompute results whose values changed without an error. Besides direction and power, other changes give code written for 2.x different numbers without an error. Among them (the tables below list them all):
windows are labeled by their center time, not their first sample, and a window step given in seconds is rounded to the nearest sample rather than truncated, which can change the number of windows, their
timecoordinates, and averaged values;phase_slope_indexsums adjacent frequency bins only, so its values are much smaller: re-derive any threshold;delayreturns seconds, not cycles;multitaper_connectivitytakes the axis roles of anxarray.DataArrayfrom its dimension names, not their positions;several measures’ values were corrected, among them every spectral Granger and transfer-function measure on an even FFT length,
directed_coherence,direct_directed_transfer_function,global_coherence(whose components also now come strongest first for everymax_rank),canonical_coherencefor groups with a dead or duplicated channel, andpower_confidence_intervals(Directed measures and Other measures, power, and statistics).
Read
magnitude_squared_coherence, notcoherence_magnitude. The defaultmultitaper_connectivityDataset has nocoherence_magnitudevariable, so indexing it by the old name raisesKeyErrororAttributeError. Requestingmethod="coherence_magnitude"or callingConnectivity.coherence_magnitude()still works through 3.x, with aDeprecationWarning.Replace the deprecated spellings. Each old spelling still works through 3.x with a
DeprecationWarningthat names its replacement, and is removed in 4.0:Connectivity.from_multitaper(m)→Connectivity.from_transform(m);frequencies_of_interest=(low, high)→frequency_range=(low, high)forphase_slope_index,group_delay, anddelay.frequency_rangeincludes both endpoints, wherefrequencies_of_interestexcluded a bin on either edge;power_confidence_intervals(n_tapers=n, ...)→n_observations=n, and itsci=→confidence_level=;suggest_parameters(desired_freq_resolution=...)→frequency_resolution=...;method="coherence_magnitude"andConnectivity.coherence_magnitude()→magnitude_squared_coherence(item 4);advanced settings passed to the wrappers as plain keyword arguments (
multitaper_connectivity(x, fs, n_fft_samples=1024)) →transform_kwargs={"n_fft_samples": 1024}orconnectivity_kwargs={...}.
The tables below list every change, including that Multitaper now requires
sampling_frequency (2.x defaulted it to 1000 Hz).
Changes for code written against 2.0.1#
If your code was written against 2.0.1 or earlier, this section covers your changes; you can skip the development-builds section after it.
Directed measures#
The spectral Granger and transfer-function measures: their orientation, and the values corrected in their Wilson factorization.
Previous behavior |
New behavior / required action |
|---|---|
|
|
|
All directed |
Every measure built on the Wilson factorization (the spectral Granger family, DTF, directed coherence, PDC, gPDC, dDTF) used, on an even FFT length, a factor that did not reproduce the spectrum: it ignored the lag |
The factor reproduces the spectrum on even and odd FFT lengths alike. Recompute directed measures that used an even FFT length (the default length is often even). In long, well-resolved simulated recordings the largest change at any frequency was typically 0.1% to 5% of the measure’s largest value in the recording (5e-4 to 1e-2 in absolute terms for DTF and PDC, which lie in [0, 1]); for short windows, few observations, or highly correlated channels it reached the whole range of DTF. Values from an odd FFT length are unchanged |
The spectral Granger and transfer-function measures (DTF, PDC, directed coherence) depended on the data’s units, through an absolute convergence threshold: values changed by 1e-4 to 0.1 for data at 1e-6 of unit variance (microvolt signals stored in volts), and by more below that |
Invariant to the data’s scale. Recompute directed results obtained from small-amplitude data |
|
Returns the squared dDTF of Korzeniewska et al. (2003), |
|
Uses the correct source-axis noise variance and is bounded in |
Spectral Granger measures returned |
Exact zeros and roundoff-negative values are returned as |
|
The default |
Other measures, power, and statistics#
Values that changed for the functional, lead/lag, and group measures, the power spectrum, and the statistics helpers.
Previous behavior |
New behavior / required action |
|---|---|
|
Returns each component’s fraction of the total coherent power, in |
|
Always strongest first, the values and their vectors alike, so |
|
Returns only the non-negative frequencies, labelled by |
|
Follows |
|
Invariant to the data’s amplitude. Recompute weighted phase-lag results obtained from data stored in small units |
A zero-lag pair (a channel and a scaled copy of it) gave a |
0 for all three, and 0.5 for |
|
Equals the value for the group’s independent channels, with a warning naming the group. Recompute canonical coherence for groups that may contain such a channel |
One-sided |
Interior positive-frequency bins are doubled; DC and Nyquist are unchanged. |
|
Say which density the spectrum is. With 3.0’s one-sided |
|
Pass the second condition’s measured rate, added spikes included. A call with a non-zero noise rate warns about this until 4.0. Calls with the default noise of 0 are unchanged and silent |
|
|
|
Uses adjacent frequency bins, following Nolte et al. (2008). The sign is unchanged, but the sum has far fewer terms, so values are smaller by one to several orders of magnitude: recompute, and re-derive any threshold |
|
Returns seconds; DC is |
|
The one-sample z-score has no second-sample terms, and |
|
Corrected formulas — recompute power confidence intervals and log-power z-tests |
Multi-component CaCoh from mne-connectivity 0.9 ( |
|
|
Both are 0 there; elsewhere the values agree to rounding. Code that dropped self-pairs or real bins with |
|
|
Windows, time labels, inputs, and result attributes#
How time series are read and windowed, and what the results record.
Previous behavior |
New behavior / required action |
|---|---|
Multitaper windows were labeled by their first sample |
Windows are labeled by their center time, the midpoint of the window’s first and last samples: the 2.x label plus |
|
|
|
|
|
The constructor raises the |
Result attributes |
Read |
Window durations and steps given in seconds: 2.x truncated a step to whole samples ( |
A step is rounded to the nearest sample (57 samples, 16 windows above), so window counts, |
Assigning |
Settings are read-only and assignment raises |
API spellings and removed options#
Renamed, deprecated, and removed arguments, names, and defaults.
Previous behavior |
New behavior / required action |
|---|---|
|
Drop it: memory is now bounded automatically. Recompute phase-lag-index results that were obtained with |
|
Remove both arguments (passing either raises |
|
Remove |
|
|
SciPy 1.10 / CuPy 12 GPU extra |
Upgrade to |
|
Use |
|
Pass |
|
Pass the same count as |
|
Pass |
|
Pass |
|
Pass them as |
|
Use |
|
|
|
Removed with that solver (the tapers now come from SciPy’s exact |
Names reachable through |
|
Changes to interfaces that existed only in development builds#
Skip this section if you used only the 2.0.1 release. It covers interfaces
of development builds after 2.0.1 that were renamed before their first
release, with no compatibility path. Most old spellings raise an error or no
longer exist. Two fail silently: a positional call to
simulate_lagged_broadband still runs but now returns a trial axis, and the
backend attribute is still present but lowercase, so comparing it with
"CPU" or "GPU" is always false (see their rows).
Previous behavior |
New behavior / required action |
|---|---|
|
|
Component results’ |
|
Transform-prefixed result attributes ( |
The shared keys of the result schema ( |
|
|
|
|
Settings of the new APIs passed by position: |
Pass them by keyword; a positional value raises |
|
|
|
|