MCPcopy
hub / github.com/mne-tools/mne-python / pick_channels

Function pick_channels

mne/_fiff/pick.py:257–311  ·  view source on GitHub ↗

Pick channels by names. Returns the indices of ``ch_names`` in ``include`` but not in ``exclude``. Parameters ---------- ch_names : list of str List of channels. include : list of str List of channels to include (if empty include all available). .. note

(ch_names, include, exclude=(), ordered=True, *, verbose=None)

Source from the content-addressed store, hash-verified

255
256@verbose
257def pick_channels(ch_names, include, exclude=(), ordered=True, *, verbose=None):
258 """Pick channels by names.
259
260 Returns the indices of ``ch_names`` in ``include`` but not in ``exclude``.
261
262 Parameters
263 ----------
264 ch_names : list of str
265 List of channels.
266 include : list of str
267 List of channels to include (if empty include all available).
268
269 .. note:: This is to be treated as a set. The order of this list
270 is not used or maintained in ``sel``.
271
272 exclude : list of str
273 List of channels to exclude (if empty do not exclude any channel).
274 Defaults to [].
275 %(ordered)s
276 %(verbose)s
277
278 Returns
279 -------
280 sel : array of int
281 Indices of good channels.
282
283 See Also
284 --------
285 pick_channels_regexp, pick_types
286 """
287 if len(np.unique(ch_names)) != len(ch_names):
288 raise RuntimeError("ch_names is not a unique list, picking is unsafe")
289 _validate_type(ordered, bool, "ordered")
290 _check_excludes_includes(include)
291 _check_excludes_includes(exclude)
292 if not isinstance(include, list):
293 include = list(include)
294 if len(include) == 0:
295 include = list(ch_names)
296 if not isinstance(exclude, list):
297 exclude = list(exclude)
298 sel, missing = list(), list()
299 for name in include:
300 if name in ch_names:
301 if name not in exclude:
302 sel.append(ch_names.index(name))
303 else:
304 missing.append(name)
305 if len(missing) and ordered:
306 raise ValueError(
307 f"Missing channels from ch_names required by include:\n{missing}"
308 )
309 if not ordered:
310 sel = np.unique(sel)
311 return np.array(sel, int)
312
313
314def pick_channels_regexp(ch_names, regexp):

Callers 15

test_correctionFunction · 0.90
_check_channel_namesFunction · 0.90
test_picks_by_channelsFunction · 0.90
test_io_raw_additionalFunction · 0.90
test_set_channel_typesFunction · 0.90
test_interpolation_eegFunction · 0.90
test_interpolation_megFunction · 0.90
test_interpolate_meg_ctfFunction · 0.90
test_comparision_with_cFunction · 0.90
test_find_eventsFunction · 0.90
subtract_evokedMethod · 0.85

Calls 3

_validate_typeFunction · 0.85
_check_excludes_includesFunction · 0.85
appendMethod · 0.45

Tested by 11

test_correctionFunction · 0.72
_check_channel_namesFunction · 0.72
test_picks_by_channelsFunction · 0.72
test_io_raw_additionalFunction · 0.72
test_set_channel_typesFunction · 0.72
test_interpolation_eegFunction · 0.72
test_interpolation_megFunction · 0.72
test_interpolate_meg_ctfFunction · 0.72
test_comparision_with_cFunction · 0.72
test_find_eventsFunction · 0.72