diff --git a/doc/changes/dev/14225.newfeature.rst b/doc/changes/dev/14225.newfeature.rst new file mode 100644 index 00000000000..c81ee2d528b --- /dev/null +++ b/doc/changes/dev/14225.newfeature.rst @@ -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`_. diff --git a/mne/epochs.py b/mne/epochs.py index f313a94e2ac..0fedc8dd41e 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -1723,6 +1723,7 @@ def _get_data( picks=None, item=None, *, + exclude=(), units=None, tmin=None, tmax=None, @@ -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. @@ -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) @@ -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: @@ -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 ` for an @@ -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 diff --git a/mne/evoked.py b/mne/evoked.py index 01fac80a46e..fcfac17670e 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -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. @@ -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 ------- @@ -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) diff --git a/mne/io/base.py b/mne/io/base.py index 7d41bb20be6..47b7b3af8fe 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -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, @@ -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. @@ -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)