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

Function test_ica_additional

mne/preprocessing/tests/test_ica.py:648–1035  ·  view source on GitHub ↗

Test additional ICA functionality.

(method, tmp_path, short_raw_epochs)

Source from the content-addressed store, hash-verified

646@pytest.mark.slowtest
647@pytest.mark.parametrize("method", ["picard", "fastica"])
648def test_ica_additional(method, tmp_path, short_raw_epochs):
649 """Test additional ICA functionality."""
650 _skip_check_picard(method)
651 raw, epochs, epochs_eog = short_raw_epochs
652 few_picks = np.arange(5)
653
654 # test if n_components=None works
655 ica = ICA(n_components=None, method=method, max_iter=1)
656 with _baseline_corrected, pytest.warns(UserWarning, match="did not converge"):
657 ica.fit(epochs)
658 _assert_ica_attributes(ica, epochs.get_data("data"), limits=(0.05, 20))
659
660 test_cov = read_cov(test_cov_name)
661 ica = ICA(noise_cov=test_cov, n_components=3, method=method)
662 assert ica.info is None
663 with pytest.warns(RuntimeWarning, match="normalize_proj"):
664 ica.fit(raw, picks=few_picks)
665 _assert_ica_attributes(ica, raw.get_data(np.arange(5)), limits=(1, 90))
666 assert isinstance(ica.info, Info)
667 assert ica.n_components_ < 5
668
669 ica = ICA(n_components=3, method=method, max_iter=1)
670 with pytest.raises(RuntimeError, match="No fit"):
671 ica.save("")
672
673 with pytest.warns(Warning, match="converge"):
674 ica.fit(raw, np.arange(1, 6))
675 _assert_ica_attributes(ica, raw.get_data(np.arange(1, 6)))
676
677 # check Kuiper index threshold
678 assert_allclose(ica._get_ctps_threshold(), 0.5)
679 with pytest.raises(TypeError, match="str or numeric"):
680 ica.find_bads_ecg(raw, threshold=None)
681 with pytest.warns(RuntimeWarning, match="is longer than the signal"):
682 ica.find_bads_ecg(raw, threshold=0.25)
683 # check invalid measure argument
684 with pytest.raises(ValueError, match="Invalid value"):
685 ica.find_bads_ecg(
686 raw, method="correlation", measure="unknown", threshold="auto"
687 )
688 # check passing a ch_name to find_bads_ecg
689 with pytest.warns(RuntimeWarning, match="longer"):
690 _, scores_1 = ica.find_bads_ecg(raw, threshold="auto")
691 with pytest.warns(RuntimeWarning, match="longer"):
692 _, scores_2 = ica.find_bads_ecg(raw, raw.ch_names[1], threshold="auto")
693 assert scores_1[0] != scores_2[0]
694
695 # test corrmap
696 ica2 = ica.copy()
697 ica3 = ica.copy()
698 corrmap(
699 [ica, ica2], (0, 0), threshold="auto", label="blinks", plot=True, ch_type="mag"
700 )
701 with pytest.raises(RuntimeError, match="No component detected"):
702 corrmap(
703 [ica, ica2],
704 (0, 0),
705 threshold=2,

Callers

nothing calls this directly

Calls 15

fitMethod · 0.95
saveMethod · 0.95
_get_ctps_thresholdMethod · 0.95
find_bads_ecgMethod · 0.95
copyMethod · 0.95
get_componentsMethod · 0.95
get_sourcesMethod · 0.95
applyMethod · 0.95
score_sourcesMethod · 0.95
find_bads_eogMethod · 0.95
read_covFunction · 0.90

Tested by

no test coverage detected