1
- """finds bad channels."""
1
+ """Find bad channels."""
2
2
3
3
# Authors: The PyPREP developers
4
4
# SPDX-License-Identifier: MIT
@@ -44,6 +44,11 @@ class NoisyChannels:
44
44
Whether or not PyPREP should strictly follow MATLAB PREP's internal
45
45
math, ignoring any improvements made in PyPREP over the original code
46
46
(see :ref:`matlab-diffs` for more details). Defaults to ``False``.
47
+ ransac : bool
48
+ Whether RANSAC should be used for bad channel detection, in addition
49
+ to other methods. RANSAC can detect bad channels that other
50
+ methods are unable to catch, but also slows down noisy channel
51
+ detection considerably. Defaults to ``True``.
47
52
48
53
References
49
54
----------
@@ -53,7 +58,15 @@ class NoisyChannels:
53
58
54
59
"""
55
60
56
- def __init__ (self , raw , do_detrend = True , random_state = None , matlab_strict = False ):
61
+ def __init__ (
62
+ self ,
63
+ raw ,
64
+ do_detrend = True ,
65
+ random_state = None ,
66
+ matlab_strict = False ,
67
+ * ,
68
+ ransac = True ,
69
+ ):
57
70
# Make sure that we got an MNE object
58
71
assert isinstance (raw , mne .io .BaseRaw )
59
72
@@ -68,6 +81,9 @@ def __init__(self, raw, do_detrend=True, random_state=None, matlab_strict=False)
68
81
)
69
82
self .matlab_strict = matlab_strict
70
83
84
+ assert isinstance (ransac , bool ), f"ransac must be boolean, got: { ransac } "
85
+ self .ransac = ransac
86
+
71
87
# Extra data for debugging
72
88
self ._extra_info = {
73
89
"bad_by_deviation" : {},
@@ -187,18 +203,20 @@ def get_bads(self, verbose=False, as_dict=False):
187
203
188
204
return bads
189
205
190
- def find_all_bads (self , ransac = True , channel_wise = False , max_chunk_size = None ):
206
+ def find_all_bads (self , ransac = None , channel_wise = False , max_chunk_size = None ):
191
207
"""Call all the functions to detect bad channels.
192
208
193
209
This function calls all the bad-channel detecting functions.
194
210
195
211
Parameters
196
212
----------
197
- ransac : bool, optional
213
+ ransac : bool | None
198
214
Whether RANSAC should be used for bad channel detection, in addition
199
215
to the other methods. RANSAC can detect bad channels that other
200
216
methods are unable to catch, but also slows down noisy channel
201
- detection considerably. Defaults to ``True``.
217
+ detection considerably. If ``None`` (default), then the value at
218
+ instantiation of the ``NoisyChannels`` class is taken (defaults
219
+ to ``True``), else the instantiation value is overwritten.
202
220
channel_wise : bool, optional
203
221
Whether RANSAC should predict signals for chunks of channels over the
204
222
entire signal length ("channel-wise RANSAC", see `max_chunk_size`
@@ -218,12 +236,20 @@ def find_all_bads(self, ransac=True, channel_wise=False, max_chunk_size=None):
218
236
effect. Defaults to ``None``.
219
237
220
238
"""
239
+ if ransac is not None and ransac != self .ransac :
240
+ assert isinstance (ransac , bool ), f"ransac must be boolean, got: { ransac } "
241
+ logger .warning (
242
+ f"Overwriting `ransac` value. Was `{ self .ransac } ` at instantiation "
243
+ f"of NoisyChannels. Now setting to `{ ransac } `."
244
+ )
245
+ self .ransac = ransac
246
+
221
247
# NOTE: Bad-by-NaN/flat is already run during init, no need to re-run here
222
248
self .find_bad_by_deviation ()
223
249
self .find_bad_by_hfnoise ()
224
250
self .find_bad_by_correlation ()
225
251
self .find_bad_by_SNR ()
226
- if ransac :
252
+ if self . ransac :
227
253
self .find_bad_by_ransac (
228
254
channel_wise = channel_wise , max_chunk_size = max_chunk_size
229
255
)
0 commit comments