def test_ica_additional(): # Test additional functionality stop2 = 500 ica = ICA(n_components=3, max_n_components=4) ica.decompose_raw(raw, picks=None, start=start, stop=stop2) # epochs extraction from raw fit assert_raises(RuntimeError, ica.get_sources_epochs, epochs) ica = ICA(n_components=3, max_n_components=4) ica.decompose_raw(raw, picks=picks, start=start, stop=stop2) sources = ica.get_sources_epochs(epochs) assert_true(sources.shape[1] == ica.n_components) sources = ica.get_sources_raw(raw) # score funcs raw sfunc_test = [ ica.find_sources_raw(raw, target='EOG 061', score_func=n, start=0, stop=10) for n, f in score_funcs.items() ] # check lenght of scores [assert_true(ica.n_components == len(scores)) for scores in sfunc_test] # check univariate stats scores = ica.find_sources_raw(raw, score_func=stats.skew) # check exception handling assert_raises(ValueError, ica.find_sources_raw, raw, target=np.arange(1)) ## score funcs epochs ## # check lenght of scores sfunc_test = [ ica.find_sources_epochs(epochs_eog, target='EOG 061', score_func=n) for n, f in score_funcs.items() ] # check lenght of scores [assert_true(ica.n_components == len(scores)) for scores in sfunc_test] # check univariat stats scores = ica.find_sources_epochs(epochs, score_func=stats.skew) # check exception handling assert_raises(ValueError, ica.find_sources_epochs, epochs, target=np.arange(1)) # ecg functionality ecg_scores = ica.find_sources_raw(raw, target='MEG 1531', score_func='pearsonr') ecg_events = ica_find_ecg_events(raw, sources[np.abs(ecg_scores).argmax()]) assert_true(ecg_events.ndim == 2) # eog functionality eog_scores = ica.find_sources_raw(raw, target='EOG 061', score_func='pearsonr') eog_events = ica_find_eog_events(raw, sources[np.abs(eog_scores).argmax()]) assert_true(eog_events.ndim == 2) # Test ica fiff export raw3 = raw.copy() raw3._preloaded = False assert_raises(ValueError, ica.export_sources, raw3, start=0, stop=100) ica_raw = ica.export_sources(raw, start=0, stop=100) assert_true(ica_raw.last_samp - ica_raw.first_samp == 100) ica_chans = [ch for ch in ica_raw.ch_names if 'ICA' in ch] assert_true(ica.n_components == len(ica_chans)) test_ica_fname = op.join(op.abspath(op.curdir), 'test_ica.fif') ica_raw.save(test_ica_fname) ica_raw2 = fiff.Raw(test_ica_fname, preload=True) assert_array_almost_equal(ica_raw._data, ica_raw2._data) os.remove(test_ica_fname) # regression test for plot method assert_raises(ValueError, ica.plot_sources_raw, raw, order=np.arange(50)) assert_raises(ValueError, ica.plot_sources_epochs, epochs, order=np.arange(50))
def test_ica_additional(): # Test additional functionality stop2 = 500 ica = ICA(n_components=3, max_n_components=4) ica.decompose_raw(raw, picks=None, start=start, stop=stop2) # epochs extraction from raw fit assert_raises(RuntimeError, ica.get_sources_epochs, epochs) ica = ICA(n_components=3, max_n_components=4) ica.decompose_raw(raw, picks=picks, start=start, stop=stop2) sources = ica.get_sources_epochs(epochs) assert_true(sources.shape[1] == ica.n_components) sources = ica.get_sources_raw(raw) # score funcs raw sfunc_test = [ica.find_sources_raw(raw, target='EOG 061', score_func=n, start=0, stop=10) for n, f in score_funcs.items()] # check lenght of scores [assert_true(ica.n_components == len(scores)) for scores in sfunc_test] # check univariate stats scores = ica.find_sources_raw(raw, score_func=stats.skew) # check exception handling assert_raises(ValueError, ica.find_sources_raw, raw, target=np.arange(1)) ## score funcs epochs ## # check lenght of scores sfunc_test = [ica.find_sources_epochs(epochs_eog, target='EOG 061', score_func=n) for n, f in score_funcs.items()] # check lenght of scores [assert_true(ica.n_components == len(scores)) for scores in sfunc_test] # check univariat stats scores = ica.find_sources_epochs(epochs, score_func=stats.skew) # check exception handling assert_raises(ValueError, ica.find_sources_epochs, epochs, target=np.arange(1)) # ecg functionality ecg_scores = ica.find_sources_raw(raw, target='MEG 1531', score_func='pearsonr') ecg_events = ica_find_ecg_events(raw, sources[np.abs(ecg_scores).argmax()]) assert_true(ecg_events.ndim == 2) # eog functionality eog_scores = ica.find_sources_raw(raw, target='EOG 061', score_func='pearsonr') eog_events = ica_find_eog_events(raw, sources[np.abs(eog_scores).argmax()]) assert_true(eog_events.ndim == 2) # Test ica fiff export raw3 = raw.copy() raw3._preloaded = False assert_raises(ValueError, ica.export_sources, raw3, start=0, stop=100) ica_raw = ica.export_sources(raw, start=0, stop=100) assert_true(ica_raw.last_samp - ica_raw.first_samp == 100) ica_chans = [ch for ch in ica_raw.ch_names if 'ICA' in ch] assert_true(ica.n_components == len(ica_chans)) test_ica_fname = op.join(op.abspath(op.curdir), 'test_ica.fif') ica_raw.save(test_ica_fname) ica_raw2 = fiff.Raw(test_ica_fname, preload=True) assert_array_almost_equal(ica_raw._data, ica_raw2._data) os.remove(test_ica_fname) # regression test for plot method assert_raises(ValueError, ica.plot_sources_raw, raw, order=np.arange(50)) assert_raises(ValueError, ica.plot_sources_epochs, epochs, order=np.arange(50))