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
[MRG] Handle events with non-unique event time samples #6688
Conversation
I am realizing that the Any advice @larsoner ? |
You need to
For example if in neither |
This pull request introduces 2 alerts when merging c03b591 into bf5df34 - view on LGTM.com new alerts:
|
@sappelhoff you also need to update some tests |
Okay, I think this is a reasonable proposal now @jasmainak @larsoner @agramfort @massich Before I start to implement testing, please let me know what you think. Also: I need advise on what I need to edit if I want this parameter to be available in |
Please go ahead and write the tests. It will help us check the logic better. |
Codecov Report
@@ Coverage Diff @@
## master #6688 +/- ##
==========================================
+ Coverage 89.48% 89.48% +<.01%
==========================================
Files 420 420
Lines 75474 75596 +122
Branches 12369 12388 +19
==========================================
+ Hits 67535 67647 +112
- Misses 5134 5137 +3
- Partials 2805 2812 +7 |
mne/tests/test_epochs.py
Outdated
"""Test handling of duplicate events.""" | ||
# A general test case | ||
EVENT_ID = {'aud': 1, 'vis': 2} | ||
EVENTS = np.array([[0, 0, 1], [0, 0, 2]]) |
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.
why capital letters?
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.
because these are my "constants" for the test
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.
I would rename them EXPECTED_BLA
and I would not use them on the input. ;)
Okay, tests are fully implemented now. Ready for another review :-) |
mne/epochs.py
Outdated
@@ -183,6 +184,93 @@ def _save_split(epochs, fname, part_idx, n_parts, fmt): | |||
end_file(fid) | |||
|
|||
|
|||
def _handle_duplicate_events(events, event_id, event_repeated): |
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.
i like event_repeated_policy
better.
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.
_handle
is a really ugly name.
what about def _apply_duplicate_events_policy(evetns, event_id, policy)
or simply _duplicate_events_policy
?
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.
I'd rather not make the name longer. There is a tradeoff between explicit name clarity and usability. There is a good reason we don't go farther down the road of making it even more explicit like how_to_behave_when_events_occur_on_the_same_sample
. I think event_repeated
is clear enough as it is and more in line with how we tend to balance clarity with brevity.
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.
I'll stay with event_repeated
then, but will rename _handle_duplicate_events
-> _handle_event_repeated
why don't you like "handle" @massich ? We are "handling" a situation after all?
mne/epochs.py
Outdated
@@ -183,6 +184,93 @@ def _save_split(epochs, fname, part_idx, n_parts, fmt): | |||
end_file(fid) | |||
|
|||
|
|||
def _handle_duplicate_events(events, event_id, event_repeated): |
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.
_handle
is a really ugly name.
what about def _apply_duplicate_events_policy(evetns, event_id, policy)
or simply _duplicate_events_policy
?
mne/tests/test_epochs.py
Outdated
"""Test handling of duplicate events.""" | ||
# A general test case | ||
EVENT_ID = {'aud': 1, 'vis': 2} | ||
EVENTS = np.array([[0, 0, 1], [0, 0, 2]]) |
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.
I would rename them EXPECTED_BLA
and I would not use them on the input. ;)
mne/tests/test_epochs.py
Outdated
@@ -57,6 +59,66 @@ | |||
rng = np.random.RandomState(42) | |||
|
|||
|
|||
def test_handle_duplicate_events(): |
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.
can we parametrize some of it? (I've not checked)
all the code doing the job (the part inside |
@sappelhoff while trying the code I tried to the make the test more ambitious. It breaks the tests. Please have a look. |
I am following what @agramfort and @jasmainak told me:
I feel like I can use your feedback well for step 2. @massich :-) |
Thanks for the reviews everybody. I addressed almost everything and the code is much better now (in the second iteration). Unfortunately I won't have time to do a third iteration ... so it'd be great if somebody could take it from here! |
This pull request introduces 1 alert when merging 66fd60a into bf03e17 - view on LGTM.com new alerts:
|
Let us know when it's ready for reviews.
… |
it's ready now - I just fixed a LGTM issue and a pydocstyle thing .... CIs should come back all green now. |
Co-Authored-By: Alexandre Gramfort <alexandre.gramfort@m4x.org>
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.
@jasmainak or @massich feel free to merge if happy
glad I didn't volunteer for this issue ;-) @massich I let you merge since I didn't follow the developments very closely |
LGTM |
* add skeleton * show blocker * clarify docstr * add option 'drop' * find new event code and update event_id * dont reuse event codes that are in events * typo * continue work in private func * use event_id combination to make up new event_id * improve docstr * flat is better than nested * add first test * fix lists and concat->concatenate * add more tests * one more test * add event_repeated param to epochs class * do not put np.nan into int array * better copy handling * also consider 'prior-to-event' codes in selecting new code * test fallback for prior event codes and mixing up * update event_id after removing vals from events * test keeping homogeneous 'prior-to-event' code * revert to 'drop' behavior if duplicates have equal event code * add short example to notes section * make the test more ambitious + reveal issues * only delete indices after loop * fix aud/vis to be same code as vis/aud * fix alex's tests * _handle_duplicate_events -> _handle_event_repeated * use _check_option instead of custom code * remove duplicated tests * simplify pruning of event_id * improve logging msg and readability * cleanup section for setting new events[:, 1] val * event_code -> event_val to disambiguate between key/value/code * refactor: pull _merge_events into its own func * incorporate several points by @jona-sassenhagen * more feedback by jona * improve doc * minor docs * add whatsnew * get rid of superfluous loop * fix pydocstyle * np.testing can go away Co-Authored-By: Alexandre Gramfort <alexandre.gramfort@m4x.org> * using for...else construct
fixes #6665
To Do
event_id
by removing a key-value-pair if the value is no longer inevents
afterhandle_duplicate_events
event_repeated
is "merge" but a duplicate actually has the same event code, switch to "drop" behavior