Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/dev/14225.newfeature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``exclude`` parameter to :meth:`mne.io.Raw.get_data`, :meth:`mne.Epochs.get_data`, and :meth:`mne.Evoked.get_data` by `Carina Forster`_.
28 changes: 26 additions & 2 deletions mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,7 @@ def _get_data(
picks=None,
item=None,
*,
exclude=(),
units=None,
tmin=None,
tmax=None,
Expand All @@ -1740,6 +1741,14 @@ def _get_data(
%(picks_all)s
item : slice | array-like | str | list | None
See docstring of get_data method.
exclude : list[str] | Literal["bads"]
Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are
excluded; pass an empty list or tuple (the default) to include all
channels. Note: ``exclude`` is currently only applied when ``picks``
is ``None``; it is ignored when ``picks!=None`` (to be fixed in a
future release).

.. versionadded:: 1.13
%(units)s
tmin : int | float | None
Start time of data to get in seconds.
Expand Down Expand Up @@ -1806,7 +1815,7 @@ def _get_data(

orig_picks = picks
if orig_picks is None:
picks = _picks_to_idx(self.info, picks, "all", exclude=())
picks = _picks_to_idx(self.info, picks, "all", exclude=exclude)
else:
picks = _picks_to_idx(self.info, picks)

Expand Down Expand Up @@ -1992,6 +2001,7 @@ def get_data(
tmin: int | float | None = None,
tmax: int | float | None = None,
*,
exclude: list[str] | Literal["bads"] | tuple = (),
copy: bool = True,
verbose: bool | str | int | None = None,
) -> np.ndarray:
Expand Down Expand Up @@ -2019,6 +2029,14 @@ def get_data(
End time of data to get in seconds.

.. versionadded:: 0.24.0
exclude : list[str] | Literal["bads"]
Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are
excluded; pass an empty list or tuple (the default) to include all
channels. Note: ``exclude`` is currently only applied when ``picks``
is ``None``; it is ignored when ``picks!=None`` (to be fixed in a
future release).

.. versionadded:: 1.13
copy : bool
Whether to return a copy of the object's data, or (if possible) a view.
See :ref:`the NumPy docs <numpy:basics.copies-and-views>` for an
Expand All @@ -2044,7 +2062,13 @@ def get_data(
when possible when ``copy=False``.
"""
return self._get_data(
picks=picks, item=item, units=units, tmin=tmin, tmax=tmax, copy=copy
picks=picks,
exclude=exclude,
item=item,
units=units,
tmin=tmin,
tmax=tmax,
copy=copy,
)

@verbose
Expand Down
9 changes: 8 additions & 1 deletion mne/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def get_data(
units: str | dict | None = None,
tmin: float | None = None,
tmax: float | None = None,
exclude: list[str] | Literal["bads"] | tuple = (),
) -> np.ndarray:
"""Get evoked data as 2D array.

Expand All @@ -253,6 +254,12 @@ def get_data(
Start time of data to get in seconds.
tmax : float | None
End time of data to get in seconds.
exclude : list[str] | Literal["bads"]
Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are
excluded; pass an empty list or tuple (the default) to include all
channels.

.. versionadded:: 1.13

Returns
-------
Expand All @@ -266,7 +273,7 @@ def get_data(
# Avoid circular import
from .io.base import _get_ch_factors

picks = _picks_to_idx(self.info, picks, "all", exclude=())
picks = _picks_to_idx(self.info, picks, "all", exclude=exclude)

start, stop = self._handle_tmin_tmax(tmin, tmax)

Expand Down
11 changes: 10 additions & 1 deletion mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ def get_data(
return_times: bool = False,
units: str | dict | None = None,
*,
exclude: list[str] | Literal["bads"] | tuple = (),
tmin: int | float | None = None,
tmax: int | float | None = None,
verbose: bool | str | int | None = None,
Expand All @@ -961,6 +962,14 @@ def get_data(
return_times : bool
Whether to return times as well. Defaults to False.
%(units)s
exclude : list[str] | Literal["bads"]
Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are
excluded; pass an empty list or tuple (the default) to include all
channels. Note: ``exclude`` is currently only applied when ``picks``
is not ``None``; it is ignored when ``picks=None`` (to be fixed in a
future release).

.. versionadded:: 1.13
tmin : int | float | None
Start time of data to get in seconds. The ``tmin`` parameter is
ignored if the ``start`` parameter is bigger than 0.
Expand Down Expand Up @@ -997,7 +1006,7 @@ def get_data(
# allocation and ~40 us of name resolution on every call.
picks = np.arange(self.info["nchan"])
else:
picks = _picks_to_idx(self.info, picks, "all", exclude=())
picks = _picks_to_idx(self.info, picks, "all", exclude=exclude)

# Get channel factors for conversion into specified unit
# (vector of ones if no conversion needed)
Expand Down
Loading