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

Function test_xdawn_apply_transform

mne/preprocessing/tests/test_xdawn.py:132–175  ·  view source on GitHub ↗

Test Xdawn apply and transform.

()

Source from the content-addressed store, hash-verified

130
131
132def test_xdawn_apply_transform():
133 """Test Xdawn apply and transform."""
134 # Get data
135 raw, events, picks = _get_data()
136 raw.pick(picks="eeg")
137 epochs = Epochs(
138 raw,
139 events,
140 event_id,
141 tmin,
142 tmax,
143 proj=False,
144 preload=True,
145 baseline=None,
146 verbose=False,
147 )
148 n_components = 2
149 # Fit Xdawn
150 xd = Xdawn(n_components=n_components, correct_overlap=False)
151 xd.fit(epochs)
152
153 # Apply on different types of instances
154 for inst in [raw, epochs.average(), epochs]:
155 denoise = xd.apply(inst)
156 # Apply on other thing should raise an error
157 pytest.raises(ValueError, xd.apply, 42)
158
159 # Transform on Epochs
160 xd.transform(epochs)
161 # Transform on Evoked
162 xd.transform(epochs.average())
163 # Transform on ndarray
164 xd.transform(epochs._data)
165 xd.transform(epochs._data[0])
166 # Transform on something else
167 pytest.raises(ValueError, xd.transform, 42)
168
169 # Check numerical results with shuffled epochs
170 rng = np.random.RandomState(0)
171 idx = np.arange(len(epochs))
172 rng.shuffle(idx)
173 xd.fit(epochs[idx])
174 denoise_shfl = xd.apply(epochs)
175 assert_array_almost_equal(denoise["cond2"]._data, denoise_shfl["cond2"]._data)
176
177
178def test_xdawn_regularization():

Callers

nothing calls this directly

Calls 8

fitMethod · 0.95
applyMethod · 0.95
transformMethod · 0.95
EpochsClass · 0.90
XdawnClass · 0.90
_get_dataFunction · 0.70
pickMethod · 0.45
averageMethod · 0.45

Tested by

no test coverage detected