MCPcopy
hub / github.com/mne-tools/mne-python / ctps

Function ctps

mne/preprocessing/ctps_.py:28–79  ·  view source on GitHub ↗

Compute cross-trial-phase-statistics [1]. Note. It is assumed that the sources are already appropriately filtered Parameters ---------- data: ndarray, shape (n_epochs, n_channels, n_times) Any kind of data of dimensions trials, traces, features. is_raw : bool

(data, is_raw=True)

Source from the content-addressed store, hash-verified

26
27
28def ctps(data, is_raw=True):
29 """Compute cross-trial-phase-statistics [1].
30
31 Note. It is assumed that the sources are already
32 appropriately filtered
33
34 Parameters
35 ----------
36 data: ndarray, shape (n_epochs, n_channels, n_times)
37 Any kind of data of dimensions trials, traces, features.
38 is_raw : bool
39 If True it is assumed that data haven't been transformed to Hilbert
40 space and phase angles haven't been normalized. Defaults to True.
41
42 Returns
43 -------
44 ks_dynamics : ndarray, shape (n_sources, n_times)
45 The kuiper statistics.
46 pk_dynamics : ndarray, shape (n_sources, n_times)
47 The normalized kuiper index for ICA sources and
48 time slices.
49 phase_angles : ndarray, shape (n_epochs, n_sources, n_times) | None
50 The phase values for epochs, sources and time slices. If ``is_raw``
51 is False, None is returned.
52
53 References
54 ----------
55 [1] Dammers, J., Schiek, M., Boers, F., Silex, C., Zvyagintsev,
56 M., Pietrzyk, U., Mathiak, K., 2008. Integration of amplitude
57 and phase statistics for complete artifact removal in independent
58 components of neuromagnetic recordings. Biomedical
59 Engineering, IEEE Transactions on 55 (10), 2353-2362.
60 """
61 if not data.ndim == 3:
62 raise ValueError(f"Data must have 3 dimensions, not {data.ndim}.")
63
64 if is_raw:
65 phase_angles = _compute_normalized_phase(data)
66 else:
67 phase_angles = data # phase angles can be computed externally
68
69 # initialize array for results
70 ks_dynamics = np.zeros_like(phase_angles[0])
71 pk_dynamics = np.zeros_like(phase_angles[0])
72
73 # calculate Kuiper's statistic for each source
74 for ii, source in enumerate(np.transpose(phase_angles, [1, 0, 2])):
75 ks, pk = kuiper(source)
76 pk_dynamics[ii, :] = pk
77 ks_dynamics[ii, :] = ks
78
79 return ks_dynamics, pk_dynamics, phase_angles if is_raw else None
80
81
82def kuiper(data, dtype=np.float64): # noqa: D401

Callers 2

find_bads_ecgMethod · 0.90
test_ctpsFunction · 0.90

Calls 2

kuiperFunction · 0.85

Tested by 1

test_ctpsFunction · 0.72