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)
| 255 | |
| 256 | @verbose |
| 257 | def 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 | |
| 314 | def pick_channels_regexp(ch_names, regexp): |