-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
change find_events to accomodate neuromag bug #1102
Conversation
@dgwakeman I fear this will change the default behavior for all other systems ... Let's see what Travis says. |
Yep, this is an API change so we'll have to deprecate and notify users who have 0 as the default. In the meantime, we could add a config var "MNE_EVENTS_DURATION" to allow users to set a default permanently if people are so inclined. |
Yea, I think that's what we should do at least. I'm still not sure I understand all consequences of the proposed change, practically ... |
Well, in order to make the config var useful the units of the variable would need to change (it would need to be in samples not seconds). Personally, I think that makes more sense given the nature of the bug in Neuromag systems (I haven't seen one yet which lasted multiple samples, though please speak up if I am wrong, as I haven't looked at extremely high sampling rates). That though would have a much more drastic impact on peoples work (I suspect). Whereas, I doubt that in practice anyone has a trigger which lasts for a single sample (this change would have a smaller if at all noticeable impact). I think in some cases it may correct for previous errors when people have not noticed them, but that would be it. |
I'm -1 on the config file idea. Adding things like this to the config file is "dangerous", i.e., if I work together with someone on the same data we may get different results even though the data, scripts, MNE-Python version are 100% identical. I propose we comment-out the changes @dgwakeman made and instead issue a warning if |
The internal |
Thinking about it more, I don't like the idea of adding a warning to 0.8; it would be annoying to see all these warnings which in most cases are not even necessary bc only some systems are affected. How about we add a check to the end of |
yes, +1 |
I agree with the post check and warning in case it happens. The warning should be explicit that min_duration should be > 0 |
@@ -437,7 +437,7 @@ def _find_events(data, first_samp, verbose=None, output='onset', | |||
|
|||
@verbose | |||
def find_events(raw, stim_channel=None, verbose=None, output='onset', | |||
consecutive='increasing', min_duration=0): | |||
consecutive='increasing', min_duration=None, one_sample=True): |
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.
default should be min_duration=0
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 also use a more descriptive name for the new argument, maybe one_sample_warning=True
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.
Or making it more flexible without more code, short_event_warning : int
as n_samples below which a warning should be issued
Can someone (maybe @dengemann) help me track down these travis errors? I am not familiar with travis (also, I noticed I need to rewrite the error message). Is the test data simulated? If that is the case, it is likely strange test data. Thanks |
@dgwakeman it seems your contribution works and detects the bugs you're looking for in arbitrary tests. I thin we should not raise a ValueError here but just issue that exact message using |
@dengemann thanks for your pointers they will be included in the next commit. I have to say, I disagree about just issuing a warning and I feel extremely strongly about this. This is a common error on the most prolific MEG system. One of the errors created in travis by this points out an example in the test_raw.fif file. at sample 30033 to 30035 the system goes from a trigger value of 3 to 2 to 0. This is an example of this problem in the file (this is not a new trigger 2, but a residual value on the trigger channel due to the binary system having the first value set to 0 before the second value). And I have many examples in neuromag data from several sites (also with the problem on the "rising edge"). If users don't check their warnings, they will be averaging their conditions wrong. |
@dgwakeman I'm actually not feeling as strongly as you about ValueError VS warn.warnings. The failing tests certainly support your case ;-) and I regularly argue for exceptions rather than for warnings. I think @agramfort suggested a warning here, I might be mistaken though. |
@dgwakeman you can search for 'ERROR' in the travis output to see what's going on. It seems to be easy to fix, it's only one test int
|
@@ -437,7 +437,8 @@ def _find_events(data, first_samp, verbose=None, output='onset', | |||
|
|||
@verbose | |||
def find_events(raw, stim_channel=None, verbose=None, output='onset', | |||
consecutive='increasing', min_duration=0): | |||
consecutive='increasing', min_duration=0, | |||
short_event_warn=1): |
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 name it
shortest_event
warn suggests a warning and I am happy with the value error.
ok, this passed travis (I added a test to confirm this aspect is working). I also added in Alex's comments from previous commit. The only deviation was the comments. I tried to further simplify them (with a minor change to the code to make it easier to explain) |
n_short_events = np.sum(np.diff(events[:, 0]) < shortest_event) | ||
if n_short_events > 0: | ||
raise ValueError("You have %i events shorter than the " | ||
"short_event_warn. These are very unusual and you " |
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.
@dgwakeman this may seem nitpicky ... but if we don't care about minor things like this will sum up.
so, one whitespace over-indented here.
besides my nitpick LGTM! |
change find_events to accomodate neuromag bug
fixing the nitpick in master myself thanks @dgwakeman ! |
@dgwakeman I hope we did not discourage you with our nitpicking ;-) looking forward to seeing future PRs |
I have changed the defaults for find_events. This sets the default min_duration to 2 samples. This is useful, because a common Neuromag system "bug" exists which can result in the first sample of an event having a value less than the true trigger value (due to the combined binary trigger numbers). e.g. a trigger of 17 can have one sample of 16 prior to the real trigger value of 17.