Skip to content

Commit

Permalink
Make callable check more fine, doc, add noqa
Browse files Browse the repository at this point in the history
  • Loading branch information
withmywoessner committed Dec 6, 2023
1 parent 1b836ad commit f3e8841
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
66 changes: 30 additions & 36 deletions mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,48 +839,38 @@ def _reject_setup(self, reject, flat):
"previous ones"
)

# Skip this check if old_reject, reject, old_flat, and flat are
# callables
is_callable = False
for rej in (reject, flat, old_reject, old_flat):
for key, val in rej.items():
if callable(val):
is_callable = True

# copy thresholds for channel types that were used previously, but not
# passed this time
for key in set(old_reject) - set(reject):
reject[key] = old_reject[key]

if not is_callable:
# make sure new thresholds are at least as stringent
# as the old ones
for key in reject:
if key in old_reject and reject[key] > old_reject[key]:
raise ValueError(
bad_msg.format(
kind="reject",
key=key,
new=reject[key],
old=old_reject[key],
op=">",
)
# make sure new thresholds are at least as stringent as the old ones
for key in reject:
# Skip this check if old_reject and reject are callables
if callable(reject[key]):
continue
if key in old_reject and reject[key] > old_reject[key]:
raise ValueError(
bad_msg.format(
kind="reject",
key=key,
new=reject[key],
old=old_reject[key],
op=">",
)
)

# same for flat thresholds
for key in set(old_flat) - set(flat):
flat[key] = old_flat[key]
for key in flat:
if key in old_flat and flat[key] < old_flat[key]:
raise ValueError(
bad_msg.format(
kind="flat",
key=key,
new=flat[key],
old=old_flat[key],
op="<",
)
# same for flat thresholds
for key in set(old_flat) - set(flat):
flat[key] = old_flat[key]
for key in flat:
if callable(flat[key]):
continue
if key in old_flat and flat[key] < old_flat[key]:
raise ValueError(
bad_msg.format(
kind="flat", key=key, new=flat[key], old=old_flat[key], op="<"
)
)

# after validation, set parameters
self._bad_dropped = False
Expand Down Expand Up @@ -1544,7 +1534,7 @@ def drop(self, indices, reason="USER", verbose=None):
Set epochs to remove by specifying indices to remove or a boolean
mask to apply (where True values get removed). Events are
correspondingly modified.
reason : str
reason : list | tuple | str
Reason for dropping the epochs ('ECG', 'timeout', 'blink' etc).
Default: 'USER'.
%(verbose)s
Expand Down Expand Up @@ -3180,6 +3170,10 @@ class Epochs(BaseEpochs):
See :meth:`~mne.Epochs.equalize_event_counts`
- 'USER'
For user-defined reasons (see :meth:`~mne.Epochs.drop`).
When dropping based on flat or reject parameters the tuple of
reasons contains a tuple of channels that satisfied the rejection
criteria.
filename : str
The filename of the object.
times : ndarray
Expand Down
2 changes: 1 addition & 1 deletion mne/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3828,7 +3828,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
.. note:: If ``reject`` is a callable, than **any** criteria can be
used to reject epochs (including maxima and minima).
"""
""" # noqa: E501

docdict[
"reject_drop_bad"
Expand Down

0 comments on commit f3e8841

Please sign in to comment.