-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add mne.preprocessing.unify_bad_channels #12014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
a85093c
adding unify channels to preproc
anaradanovic 02ecd49
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0284caa
Update mne/preprocessing/unify_bads.py
anaradanovic c3e9794
Update mne/preprocessing/unify_bads.py
anaradanovic aeb7a42
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 32f8b35
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c222956
updates to inprogress work unify bads
anaradanovic 0fa5b18
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2c200a1
Move unify_bad_channels function to preprocessing/bads.py
anaradanovic 80c329d
add function to namespace
anaradanovic fc91787
style fixes
anaradanovic d77cfc1
Merge branch 'unifying_bads' of github.com:anaradanovic/mne-python in…
anaradanovic 58b96c3
test draft
nordme 7c28118
make functions work
nordme d89431e
style fixes
nordme 9b745cb
style fix
nordme b32f318
fixes
nordme 023db18
adding ch_name check to function
anaradanovic ce03592
moving len check to first check
anaradanovic dc8a71a
reconcile with Ana
nordme d64c00c
Merge remote-tracking branch 'anaradanovic/unifying_bads' into unifych
nordme 7e38dd5
changing ch_name check
anaradanovic 10b2e99
Merge remote-tracking branch 'anaradanovic/unifying_bads' into unifych
nordme 2d4528e
Update mne/preprocessing/bads.py
anaradanovic a525f33
Update mne/preprocessing/bads.py
anaradanovic ccba935
Update mne/preprocessing/bads.py
anaradanovic e005014
Update mne/preprocessing/bads.py
anaradanovic adfb46b
Update mne/preprocessing/bads.py
anaradanovic cfa1c74
Update mne/preprocessing/bads.py
anaradanovic 3085fa0
Update mne/preprocessing/bads.py
anaradanovic 12b8e84
Update mne/preprocessing/bads.py
anaradanovic 9cb0cf3
further changes on unify_bad_channels
anaradanovic 52c4d21
Apply suggestions from code review
drammock 83407f6
fixes for Ana fixes
nordme fe15459
Merge remote-tracking branch 'anaradanovic/unifying_bads' into unifych
nordme df45b86
move tests file
nordme 8b37d1e
Update mne/channels/channels.py
drammock 2cfc6da
Merge remote-tracking branch 'anaradanovic/unifying_bads' into unifych
nordme b7834d5
Apply more suggestions from code review
drammock 47db7e6
Merge remote-tracking branch 'anaradanovic/unifying_bads' into unifych
nordme 0309925
Apply suggestions from code review
nordme 6c610d1
pytest fix
nordme 292c3e4
Update mne/channels/channels.py
larsoner 2fa2fdf
Merge pull request #1 from nordme/unifych
anaradanovic 7f80011
tst:ping CIs
anaradanovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import pytest | ||
| from mne.channels import unify_bad_channels | ||
|
|
||
|
|
||
| def test_error_raising(raw, epochs): | ||
| """Tests input checking.""" | ||
| with pytest.raises(TypeError, match=r"must be an instance of list"): | ||
| unify_bad_channels("bad input") | ||
| with pytest.raises(ValueError, match=r"insts must not be empty"): | ||
| unify_bad_channels([]) | ||
| with pytest.raises(TypeError, match=r"each object in insts must be an instance of"): | ||
| unify_bad_channels(["bad_instance"]) | ||
| with pytest.raises(ValueError, match=r"same type"): | ||
| unify_bad_channels([raw, epochs]) | ||
| with pytest.raises(ValueError, match=r"Channels do not match across"): | ||
| raw_alt1 = raw.copy() | ||
| raw_alt1.drop_channels(raw.info["ch_names"][-1]) | ||
| unify_bad_channels([raw, raw_alt1]) # ch diff preserving order | ||
| with pytest.raises(ValueError, match=r"sorted differently"): | ||
| raw_alt2 = raw.copy() | ||
| new_order = [raw.ch_names[-1]] + raw.ch_names[:-1] | ||
| raw_alt2.reorder_channels(new_order) | ||
| unify_bad_channels([raw, raw_alt2]) | ||
|
|
||
|
|
||
| def test_bads_compilation(raw): | ||
| """Tests that bads are compiled properly. | ||
|
|
||
| Tests two cases: a) single instance passed to function with an existing | ||
| bad, and b) multiple instances passed to function with varying compilation | ||
| scenarios including empty bads, unique bads, and partially duplicated bads | ||
| listed out-of-order. | ||
|
|
||
| Only the Raw instance type is tested, since bad channel implementation is | ||
| controlled across instance types with a MixIn class. | ||
| """ | ||
| assert raw.info["bads"] == [] | ||
| chns = raw.ch_names[:3] | ||
| no_bad = raw.copy() | ||
| one_bad = raw.copy() | ||
| one_bad.info["bads"] = [chns[1]] | ||
| three_bad = raw.copy() | ||
| three_bad.info["bads"] = chns | ||
| # scenario 1: single instance passed with actual bads | ||
| s_out = unify_bad_channels([one_bad]) | ||
| assert len(s_out) == 1, len(s_out) | ||
| assert s_out[0].info["bads"] == [chns[1]], (s_out[0].info["bads"], chns[1]) | ||
| # scenario 2: multiple instances passed | ||
| m_out = unify_bad_channels([one_bad, no_bad, three_bad]) | ||
| assert len(m_out) == 3, len(m_out) | ||
| expected_order = [chns[1], chns[0], chns[2]] | ||
| for inst in m_out: | ||
| assert inst.info["bads"] == expected_order |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.