-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
FIX: Warn when bridged interpolation uses bad channels #14287
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
Open
Deepnar
wants to merge
1
commit into
mne-tools:main
Choose a base branch
from
Deepnar:fix/14263-warn-bridged-bads
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+54
−3
Open
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Exclude pre-existing bad channels that are not bridged from :func:`~mne.preprocessing.interpolate_bridged_electrodes` interpolation, by `Deepesh Sonar`_. |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -83,18 +83,59 @@ def test_interpolate_bridged_electrodes(): | |||||
| idx0 = inst.ch_names.index("EEG 001") | ||||||
| idx1 = inst.ch_names.index("EEG 002") | ||||||
| ch_names_orig = inst.ch_names.copy() | ||||||
| inst.info["bads"] = ["EEG 003"] | ||||||
| bads_orig = inst.info["bads"].copy() | ||||||
| # reference interpolation using the same source channels, i.e. | ||||||
| # excluding the pre-existing bad like the bridged version does | ||||||
| inst2 = inst.copy() | ||||||
| inst2.info["bads"] = ["EEG 001", "EEG 002"] | ||||||
| inst2.info["bads"] = ["EEG 001", "EEG 002", "EEG 003"] | ||||||
| inst2.interpolate_bads() | ||||||
| data_interp_reg = inst2.get_data(picks=["EEG 001", "EEG 002"]) | ||||||
| # a pre-existing bad that is not bridged must not contribute: poisoning | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # its data must leave the bridged interpolation result unchanged ... | ||||||
| inst_clean = interpolate_bridged_electrodes(inst.copy(), [(idx0, idx1)]) | ||||||
| data_clean = inst_clean.get_data(picks=["EEG 001", "EEG 002"]) | ||||||
| inst_pois = inst.copy() | ||||||
| inst_pois.apply_function(lambda x: np.full_like(x, 1.0), picks=["EEG 003"]) | ||||||
| data_bad_poisoned = inst_pois.get_data(picks="EEG 003").copy() | ||||||
| inst_pois = interpolate_bridged_electrodes(inst_pois, [(idx0, idx1)]) | ||||||
| assert np.array_equal( | ||||||
| inst_pois.get_data(picks=["EEG 001", "EEG 002"]), data_clean | ||||||
| ) | ||||||
| # ... and the pre-existing bad itself must be left untouched | ||||||
| assert np.array_equal(inst_pois.get_data(picks="EEG 003"), data_bad_poisoned) | ||||||
| assert inst_pois.info["bads"] == bads_orig | ||||||
| inst = interpolate_bridged_electrodes(inst, [(idx0, idx1)]) | ||||||
| data_interp = inst.get_data(picks=["EEG 001", "EEG 002"]) | ||||||
| assert not any(["virtual" in ch for ch in inst.ch_names]) | ||||||
| assert inst.ch_names == ch_names_orig | ||||||
| assert inst.info["bads"] == bads_orig | ||||||
| assert np.array_equal(data_interp, data_clean) | ||||||
| inst.info["bads"] = [] | ||||||
| # check closer to regular interpolation than original data | ||||||
| assert 1e-6 < np.mean(np.abs(data_interp - data_interp_reg)) < 5.4e-5 | ||||||
| assert 1e-6 < np.mean(np.abs(data_interp - data_interp_reg)) < 6.5e-5 | ||||||
|
|
||||||
| # a channel that is both pre-existing bad and bridged must still be | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # repaired as a bridged target rather than being excluded (checked on | ||||||
| # copies so the shared instances stay pristine for the checks below) | ||||||
| for inst in (raw, epochs, evoked): | ||||||
| idx0 = inst.ch_names.index("EEG 001") | ||||||
| idx1 = inst.ch_names.index("EEG 002") | ||||||
| inst_pois = inst.copy() | ||||||
| inst_pois.info["bads"] = ["EEG 001", "EEG 003"] | ||||||
| bads_orig = inst_pois.info["bads"].copy() | ||||||
| data_bad_before = inst_pois.get_data(picks="EEG 003").copy() | ||||||
| inst_pois.apply_function(lambda x: np.full_like(x, 1.0), picks=["EEG 001"]) | ||||||
| data_bridged_poisoned = inst_pois.get_data(picks="EEG 001").copy() | ||||||
| inst_pois = interpolate_bridged_electrodes(inst_pois, [(idx0, idx1)]) | ||||||
| assert not any(["virtual" in ch for ch in inst_pois.ch_names]) | ||||||
| assert inst_pois.info["bads"] == bads_orig | ||||||
| # the bridged bad was repaired ... | ||||||
| assert not np.array_equal( | ||||||
| inst_pois.get_data(picks="EEG 001"), data_bridged_poisoned | ||||||
| ) | ||||||
| # ... while the non-bridged bad was left untouched | ||||||
| assert np.array_equal(inst_pois.get_data(picks="EEG 003"), data_bad_before) | ||||||
|
|
||||||
| for inst in (raw, epochs, evoked): | ||||||
| idx0 = inst.ch_names.index("EEG 001") | ||||||
|
|
||||||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.