-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Warn when Epochs events fall outside the raw data range (#12989) #14004
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
CedricConday
wants to merge
12
commits into
mne-tools:main
Choose a base branch
from
CedricConday:fix/warn-out-of-bounds-events
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.
+77
−1
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
635ad29
Warn when Epochs events fall outside the raw data (#12989)
CedricConday 797e8ec
rename changelog fragment to PR number
CedricConday 8e53258
Narrow out-of-bounds warning to event sample positions (#12989)
CedricConday 244ea62
[autofix.ci] apply automated fixes
autofix-ci[bot] 1d8d166
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5ab7993
[autofix.ci] apply automated fixes
autofix-ci[bot] 7c1faed
Add on_outside option to control out-of-bounds events warning
CedricConday 254d87b
Address review: keyword-only on_outside, move logic to BaseEpochs, fi…
CedricConday f283d01
ci: fix EpochsFIF first_samp crash, test for old env without warnings…
CedricConday 1e7cea9
docs: document on_outside param on EpochsArray (fix numpydoc/build_docs)
CedricConday 11f6a3b
test(ica): silence out-of-bounds event warning where tests feed full …
ebdc197
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| When creating :class:`mne.Epochs`, a warning is now emitted if any ``events`` have sample numbers outside the recorded data, since the corresponding epochs are otherwise silently dropped; this is configurable via the new ``on_outside`` parameter (``'raise'`` | ``'warn'`` | ``'ignore'``), by `Cedric Conday`_. |
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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| # Copyright the MNE-Python contributors. | ||
|
|
||
| import pickle | ||
| import warnings | ||
| from copy import deepcopy | ||
| from datetime import timedelta | ||
| from functools import partial | ||
|
|
@@ -5278,3 +5279,25 @@ def test_empty_error(method, epochs_empty): | |
| pytest.importorskip("pandas") | ||
| with pytest.raises(RuntimeError, match="is empty."): | ||
| getattr(epochs_empty.copy(), method[0])(**method[1]) | ||
|
|
||
|
|
||
| def test_epochs_warn_out_of_bounds_events(): | ||
| """Warn when event sample numbers fall outside the recorded data (gh-12989).""" | ||
| sfreq = 100.0 | ||
| info = create_info(3, sfreq, "eeg") | ||
| raw = RawArray(np.random.default_rng(0).standard_normal((3, 1000)), info) | ||
| oob = np.array([[2000, 0, 1]]) | ||
| # event sample 2000 is past the 1000-sample recording -> warn (default) | ||
| with pytest.warns(RuntimeWarning, match="outside the recorded data"): | ||
| mne.Epochs(raw, oob, tmin=-0.2, tmax=0.5, baseline=None) | ||
| # on_outside="raise" turns it into an error | ||
| with pytest.raises(ValueError, match="outside the recorded data"): | ||
| mne.Epochs(raw, oob, tmin=-0.2, tmax=0.5, baseline=None, on_outside="raise") | ||
| # on_outside="ignore" stays silent | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| mne.Epochs(raw, oob, tmin=-0.2, tmax=0.5, baseline=None, on_outside="ignore") | ||
| # an in-range event whose epoch window merely clips the edge must NOT warn | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| mne.Epochs(raw, np.array([[990, 0, 1]]), tmin=0, tmax=0.5, baseline=None) | ||
|
Comment on lines
+5297
to
+5303
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. Warnings count as errors in our tests, so we don't need to catch them. |
||
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.
Should make sure this new param is kwarg only.
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.
Likewise, when the param is added to
EpochsArray, it should be as kwarg-only (like some others there).