Test Common Spatial Patterns algorithm on epoched data. Compare the outputs when raw data is used.
()
| 277 | |
| 278 | |
| 279 | def test_ssd_epoched_data(): |
| 280 | """Test Common Spatial Patterns algorithm on epoched data. |
| 281 | |
| 282 | Compare the outputs when raw data is used. |
| 283 | """ |
| 284 | X, A, S = simulate_data(n_trials=100, n_channels=20, n_samples=500) |
| 285 | sf = 250 |
| 286 | n_channels = X.shape[0] |
| 287 | info = create_info(ch_names=n_channels, sfreq=sf, ch_types="eeg") |
| 288 | n_components_true = 5 |
| 289 | |
| 290 | # Build epochs as sliding windows over the continuous raw file |
| 291 | |
| 292 | # Epoch length is 1 second |
| 293 | X_e = np.reshape(X, (100, 20, 500)) |
| 294 | |
| 295 | # Fit |
| 296 | filt_params_signal = dict( |
| 297 | l_freq=freqs_sig[0], |
| 298 | h_freq=freqs_sig[1], |
| 299 | l_trans_bandwidth=4, |
| 300 | h_trans_bandwidth=4, |
| 301 | ) |
| 302 | filt_params_noise = dict( |
| 303 | l_freq=freqs_noise[0], |
| 304 | h_freq=freqs_noise[1], |
| 305 | l_trans_bandwidth=4, |
| 306 | h_trans_bandwidth=4, |
| 307 | ) |
| 308 | |
| 309 | # ssd on epochs |
| 310 | ssd_e = SSD(info, filt_params_signal, filt_params_noise) |
| 311 | ssd_e.fit(X_e) |
| 312 | # ssd on raw |
| 313 | ssd = SSD(info, filt_params_signal, filt_params_noise) |
| 314 | ssd.fit(X) |
| 315 | |
| 316 | # Check if the 5 first 5 components are the same for both |
| 317 | _, sorter_spec_e = _get_spectral_ratio( |
| 318 | ssd_e.transform(X_e), |
| 319 | ssd_e.sfreq_, |
| 320 | ssd_e.n_fft_, |
| 321 | ssd_e.freqs_signal_, |
| 322 | ssd_e.freqs_noise_, |
| 323 | ) |
| 324 | _, sorter_spec = _get_spectral_ratio( |
| 325 | ssd.transform(X), ssd.sfreq_, ssd.n_fft_, ssd.freqs_signal_, ssd.freqs_noise_ |
| 326 | ) |
| 327 | assert_array_equal( |
| 328 | sorter_spec_e[:n_components_true], sorter_spec[:n_components_true] |
| 329 | ) |
| 330 | |
| 331 | |
| 332 | def test_ssd_pipeline(): |
nothing calls this directly
no test coverage detected