Repository: mne-tools/mne-python

Issue:
default for mask_type
Hi,
I was recently a bit surprised by the fact that when finding trigger events with a mask, `mne.find_events` defaults to `mask_type='not_and'`, whereas the `AcqParserFIF` class defaults to `mask_type='and'`

I cannot recall now if this was done deliberately, or is it a mistake?




Discussion:
I guess it's a mistake.

I guess this is related to #3284 
and it seems that `mask_type='and'` is (was?) supposed to become the default behavior?
possibly :)

@Eric89GXL is it so that `mask_type='and'` was supposed to become default behavior for `mne.find_events` by 0.14?

I think we had planned to change it, must have forgotten. So we need to do a deprecation cycle to change it

Resolving patch:
diff --git a/mne/event.py b/mne/event.py
--- a/mne/event.py
+++ b/mne/event.py
@@ -189,7 +189,7 @@ def _read_events_fif(fid, tree):
 
 
 def read_events(filename, include=None, exclude=None, mask=None,
-                mask_type='not_and'):
+                mask_type=None):
     """Read events from fif or text file.
 
     See :ref:`tut_epoching_and_averaging` as well as :ref:`ex_read_events`
@@ -216,7 +216,8 @@ def read_events(filename, include=None, exclude=None, mask=None,
         If None (default), no masking is performed.
     mask_type: 'and' | 'not_and'
         The type of operation between the mask and the trigger.
-        Choose 'and' for MNE-C masking behavior.
+        Choose 'and' for MNE-C masking behavior. The default ('not_and')
+        will change to 'and' in 0.16.
 
         .. versionadded:: 0.13
 
@@ -422,7 +423,7 @@ def find_stim_steps(raw, pad_start=None, pad_stop=None, merge=0,
 
 def _find_events(data, first_samp, verbose=None, output='onset',
                  consecutive='increasing', min_samples=0, mask=0,
-                 uint_cast=False, mask_type='not_and'):
+                 uint_cast=False, mask_type=None):
     """Help find events."""
     if min_samples > 0:
         merge = int(min_samples // 1)
@@ -495,7 +496,7 @@ def _find_events(data, first_samp, verbose=None, output='onset',
 def find_events(raw, stim_channel=None, output='onset',
                 consecutive='increasing', min_duration=0,
                 shortest_event=2, mask=None, uint_cast=False,
-                mask_type='not_and', verbose=None):
+                mask_type=None, verbose=None):
     """Find events from raw file.
 
     See :ref:`tut_epoching_and_averaging` as well as :ref:`ex_read_events`
@@ -541,7 +542,8 @@ def find_events(raw, stim_channel=None, output='onset',
 
     mask_type: 'and' | 'not_and'
         The type of operation between the mask and the trigger.
-        Choose 'and' for MNE-C masking behavior.
+        Choose 'and' for MNE-C masking behavior. The default ('not_and')
+        will change to 'and' in 0.16.
 
         .. versionadded:: 0.13
 
@@ -674,6 +676,12 @@ def find_events(raw, stim_channel=None, output='onset',
 
 def _mask_trigs(events, mask, mask_type):
     """Mask digital trigger values."""
+    if mask_type is None:
+        mask_type = 'not_and'
+        if mask is not None:
+            warn('The default mask type "not_and" will change to "and" in '
+                 '0.16, set it explicitly to avoid this warning.',
+                 DeprecationWarning)
     if not isinstance(mask_type, string_types) or \
             mask_type not in ('not_and', 'and'):
         raise ValueError('mask_type must be "not_and" or "and", got %s'


Test patch:
diff --git a/mne/tests/test_event.py b/mne/tests/test_event.py
--- a/mne/tests/test_event.py
+++ b/mne/tests/test_event.py
@@ -192,7 +192,7 @@ def test_find_events():
     events11 = find_events(raw, mask=3, mask_type='not_and')
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter('always')
-        events22 = read_events(fname, mask=3)
+        events22 = read_events(fname, mask=3, mask_type='not_and')
         assert_true(sum('events masked' in str(ww.message) for ww in w) == 1)
     assert_array_equal(events11, events22)
 
@@ -210,7 +210,7 @@ def test_find_events():
     raw._data[stim_channel_idx, 5:] = 0
     # 1 == '0b1', 2 == '0b10', 3 == '0b11', 4 == '0b100'
 
-    assert_raises(TypeError, find_events, raw, mask="0")
+    assert_raises(TypeError, find_events, raw, mask="0", mask_type='and')
     assert_raises(ValueError, find_events, raw, mask=0, mask_type='blah')
     # testing mask_type. default = 'not_and'
     assert_array_equal(find_events(raw, shortest_event=1, mask=1,