Esempio n. 1
0
#
# .. warning::
#    Both :func:`~mne.pick_channels` and :func:`~mne.pick_channels_regexp`
#    operate on lists of channel names, so they are unaware of which channels
#    (if any) have been marked as "bad" in ``info['bads']``. Use caution to
#    avoid accidentally selecting bad channels.
#
#
# Obtaining channel type information
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# Sometimes it can be useful to know channel type based on its index in the
# data array. For this case, use :func:`mne.channel_type`, which takes
# an :class:`~mne.Info` object and a single integer channel index:

print(mne.channel_type(info, 25))

# %%
# To obtain several channel types at once, you could embed
# :func:`~mne.channel_type` in a :term:`list comprehension`, or use the
# :meth:`~mne.io.Raw.get_channel_types` method of a :class:`~mne.io.Raw`,
# :class:`~mne.Epochs`, or :class:`~mne.Evoked` instance:

picks = (25, 76, 77, 319)
print([mne.channel_type(info, x) for x in picks])
print(raw.get_channel_types(picks=picks))

# %%
# Alternatively, you can get the indices of all channels of *all* channel types
# present in the data, using :func:`~mne.channel_indices_by_type`,
# which returns a :class:`dict` with channel types as keys, and lists of
Esempio n. 2
0
#
# .. warning::
#    Both :func:`~mne.pick_channels` and :func:`~mne.pick_channels_regexp`
#    operate on lists of channel names, so they are unaware of which channels
#    (if any) have been marked as "bad" in ``info['bads']``. Use caution to
#    avoid accidentally selecting bad channels.
#
#
# Obtaining channel type information
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# Sometimes it can be useful to know channel type based on its index in the
# data array. For this case, use :func:`mne.channel_type`, which takes
# an :class:`~mne.Info` object and a single integer channel index:

print(mne.channel_type(info, 25))

###############################################################################
# To obtain several channel types at once, you could embed
# :func:`~mne.channel_type` in a :term:`list comprehension`:

print([mne.channel_type(info, x) for x in (25, 76, 77, 319)])

###############################################################################
# Alternatively, you can get the indices of all channels of *all* channel types
# present in the data, using :func:`~mne.channel_indices_by_type`,
# which returns a :class:`dict` with channel types as keys, and lists of
# channel indices as values:

ch_idx_by_type = mne.channel_indices_by_type(info)
print(ch_idx_by_type.keys())
Esempio n. 3
0
def pick_types(
        info,
        eeg=False,
        seeg=False,
        ecog=False,
        include=(),
        exclude="bads",
        selection=None,
):
    """Pick channels by type and names.

    Parameters
    ----------
    info : dict
        The measurement info.
    eeg : bool
        If True include EEG channels.
    seeg : bool
        Stereotactic EEG channels.
    ecog : bool
        Electrocorticography channels.
    include : list of str
        List of additional channels to include. If empty do not include any.
    exclude : list of str | str
        List of channels to exclude. If 'bads' (default), exclude channels
        in ``info['bads']``.
    selection : list of str
        Restrict sensor channels (MEG, EEG) to this list of channel names.

    Returns
    -------
    sel : array of int
        Indices of good channels.
    """
    # only issue deprecation warning if there are MEG channels in the data and
    # if the function was called with the default arg for meg
    deprecation_warn = False

    exclude = []
    nchan = info["nchan"]
    pick = np.zeros(nchan, dtype=bool)

    for param in (
            eeg,
            seeg,
            ecog,
    ):
        if not isinstance(param, bool):
            w = ("Parameters for all channel types (with the exception of "
                 '"meg", "ref_meg" and "fnirs") must be of type bool, not {}.')
            raise ValueError(w.format(type(param)))

    param_dict = dict(
        eeg=eeg,
        seeg=seeg,
        ecog=ecog,
    )
    # avoid triage if possible
    for k in range(nchan):
        ch_type = channel_type(info, k)
        pick[k] = param_dict[ch_type]

    # restrict channels to selection if provided
    if selection is not None:
        # the selection only restricts these types of channels
        sel_kind = [FIFF.FIFFV_EEG_CH]
        for k in np.where(pick)[0]:
            if (info["chs"][k]["kind"] in sel_kind
                    and info["ch_names"][k] not in selection):
                pick[k] = False

    myinclude = [info["ch_names"][k] for k in range(nchan) if pick[k]]
    myinclude += include

    if len(myinclude) == 0:
        sel = np.array([], int)
    else:
        sel = pick_channels(info["ch_names"], myinclude, exclude)

    if deprecation_warn:
        warn(
            "The default of meg=True will change to meg=False in version 0.22"
            ", set meg explicitly to avoid this warning.",
            DeprecationWarning,
        )
    return sel