Test ICA on raw and epochs.
(method, n_components, noise_cov, n_pca_components, browser_backend)
| 464 | @pytest.mark.parametrize("noise_cov", (False, True)) |
| 465 | @pytest.mark.parametrize("n_pca_components", [20]) |
| 466 | def test_ica_core(method, n_components, noise_cov, n_pca_components, browser_backend): |
| 467 | """Test ICA on raw and epochs.""" |
| 468 | _skip_check_picard(method) |
| 469 | raw = read_raw_fif(raw_fname).crop(0, stop).load_data() |
| 470 | |
| 471 | # The None cases help reveal bugs but are time consuming. |
| 472 | if noise_cov: |
| 473 | noise_cov = read_cov(test_cov_name) |
| 474 | noise_cov["projs"] = [] # avoid warnings |
| 475 | else: |
| 476 | noise_cov = None |
| 477 | events = read_events(event_name) |
| 478 | picks = pick_types( |
| 479 | raw.info, meg=True, stim=False, ecg=False, eog=False, exclude="bads" |
| 480 | )[::4] |
| 481 | raw.pick(picks[::4]) |
| 482 | raw.del_proj() |
| 483 | del picks |
| 484 | epochs = Epochs(raw, events[:4], event_id, tmin, tmax, baseline=None, preload=True) |
| 485 | |
| 486 | # test essential core functionality |
| 487 | |
| 488 | # Test ICA raw |
| 489 | ica = ICA(noise_cov=noise_cov, n_components=n_components, method=method, max_iter=1) |
| 490 | with pytest.raises(ValueError, match="Cannot check for channels of t"): |
| 491 | "meg" in ica |
| 492 | |
| 493 | print(ica) # to test repr |
| 494 | repr_ = ica.__repr__() |
| 495 | repr_html_ = ica._repr_html_() |
| 496 | assert repr_ == f"<ICA | no decomposition, method: {method}>" |
| 497 | assert method in repr_html_ |
| 498 | assert "max_iter=1" in repr_html_ |
| 499 | |
| 500 | # test fit checker |
| 501 | with pytest.raises(RuntimeError, match="No fit available"): |
| 502 | ica.get_sources(raw) |
| 503 | with pytest.raises(RuntimeError, match="No fit available"): |
| 504 | ica.get_sources(epochs) |
| 505 | |
| 506 | # Test error upon empty epochs fitting |
| 507 | with pytest.raises(RuntimeError, match="none were found"): |
| 508 | ica.fit(epochs[0:0]) |
| 509 | |
| 510 | # test decomposition |
| 511 | with pytest.warns(UserWarning, match="did not converge"): |
| 512 | ica.fit(raw) |
| 513 | repr(ica) # to test repr |
| 514 | repr_ = ica.__repr__() |
| 515 | repr_html_ = ica._repr_html_() |
| 516 | assert "raw data decomposition" in repr_ |
| 517 | assert f"{ica.n_components_} ICA components" in repr_ |
| 518 | assert "Available PCA components" in repr_html_ |
| 519 | assert "mag" in ica # should now work without error |
| 520 | |
| 521 | # test re-fit |
| 522 | unmixing1 = ica.unmixing_matrix_ |
| 523 | with pytest.warns(UserWarning, match="did not converge"): |
nothing calls this directly
no test coverage detected