Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude parameter to raw.plot_psd() #9519

Merged
merged 4 commits into from Jul 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Expand Up @@ -81,6 +81,8 @@ Enhancements

- Update :func:`mne.preprocessing.realign_raw` with Numpy-recommended polynomial fitting method (:gh:`9514` by `Erica Peterson`_)

- Add ``exclude`` parameter to :meth:`mne.io.Raw.plot_psd` and :meth:`mne.Epochs.plot_psd` (:gh:`9519` by `Clemens Brunner`_)

Bugs
~~~~
- Fix bug with :meth:`mne.Epochs.crop` and :meth:`mne.Evoked.crop` when ``include_tmax=False``, where the last sample was always cut off, even when ``tmax > epo.times[-1]`` (:gh:`9378` **by new contributor** |Jan Sosulski|_)
Expand Down
4 changes: 2 additions & 2 deletions mne/epochs.py
Expand Up @@ -1127,7 +1127,7 @@ def plot_psd(self, fmin=0, fmax=np.inf, tmin=None, tmax=None,
xscale='linear', area_mode='std', area_alpha=0.33,
dB=True, estimate='auto', show=True, n_jobs=1,
average=False, line_alpha=None, spatial_colors=True,
sphere=None, verbose=None):
sphere=None, exclude='bads', verbose=None):
return plot_epochs_psd(self, fmin=fmin, fmax=fmax, tmin=tmin,
tmax=tmax, proj=proj, bandwidth=bandwidth,
adaptive=adaptive, low_bias=low_bias,
Expand All @@ -1137,7 +1137,7 @@ def plot_psd(self, fmin=0, fmax=np.inf, tmin=None, tmax=None,
show=show, n_jobs=n_jobs, average=average,
line_alpha=line_alpha,
spatial_colors=spatial_colors, sphere=sphere,
verbose=verbose)
exclude=exclude, verbose=verbose)

@copy_function_doc_to_method_doc(plot_epochs_psd_topomap)
def plot_psd_topomap(self, bands=None, tmin=None,
Expand Down
4 changes: 2 additions & 2 deletions mne/io/base.py
Expand Up @@ -1511,7 +1511,7 @@ def plot_psd(self, fmin=0, fmax=np.inf, tmin=None, tmax=None, proj=False,
area_mode='std', area_alpha=0.33, dB=True, estimate='auto',
show=True, n_jobs=1, average=False, line_alpha=None,
spatial_colors=True, sphere=None, window='hamming',
verbose=None):
exclude='bads', verbose=None):
return plot_raw_psd(self, fmin=fmin, fmax=fmax, tmin=tmin, tmax=tmax,
proj=proj, n_fft=n_fft, n_overlap=n_overlap,
reject_by_annotation=reject_by_annotation,
Expand All @@ -1520,7 +1520,7 @@ def plot_psd(self, fmin=0, fmax=np.inf, tmin=None, tmax=None, proj=False,
dB=dB, estimate=estimate, show=show, n_jobs=n_jobs,
average=average, line_alpha=line_alpha,
spatial_colors=spatial_colors, sphere=sphere,
window=window, verbose=verbose)
window=window, exclude=exclude, verbose=verbose)

@copy_function_doc_to_method_doc(plot_raw_psd_topo)
def plot_psd_topo(self, tmin=0., tmax=None, fmin=0, fmax=100, proj=False,
Expand Down
5 changes: 3 additions & 2 deletions mne/viz/_figure.py
Expand Up @@ -2383,7 +2383,8 @@ def _line_figure(inst, axes=None, picks=None, **kwargs):

def _psd_figure(inst, proj, picks, axes, area_mode, tmin, tmax, fmin, fmax,
n_jobs, color, area_alpha, dB, estimate, average,
spatial_colors, xscale, line_alpha, sphere, window, **kwargs):
spatial_colors, xscale, line_alpha, sphere, window, exclude,
**kwargs):
"""Instantiate a new power spectral density figure."""
from .. import BaseEpochs
from ..io import BaseRaw
Expand All @@ -2409,7 +2410,7 @@ def _psd_figure(inst, proj, picks, axes, area_mode, tmin, tmax, fmin, fmax,
_check_option('area_mode', area_mode, [None, 'std', 'range'])
_check_option('xscale', xscale, ('log', 'linear'))
sphere = _check_sphere(sphere, inst.info)
picks = _picks_to_idx(inst.info, picks)
picks = _picks_to_idx(inst.info, picks, exclude=exclude)
titles = _handle_default('titles', None)
units = _handle_default('units', None)
scalings = _handle_default('scalings', None)
Expand Down
10 changes: 8 additions & 2 deletions mne/viz/epochs.py
Expand Up @@ -917,7 +917,7 @@ def plot_epochs_psd(epochs, fmin=0, fmax=np.inf, tmin=None, tmax=None,
xscale='linear', area_mode='std', area_alpha=0.33,
dB=True, estimate='auto', show=True, n_jobs=1,
average=False, line_alpha=None, spatial_colors=True,
sphere=None, verbose=None):
sphere=None, exclude='bads', verbose=None):
"""%(plot_psd_doc)s.

Parameters
Expand Down Expand Up @@ -962,6 +962,12 @@ def plot_epochs_psd(epochs, fmin=0, fmax=np.inf, tmin=None, tmax=None,
%(plot_psd_line_alpha)s
%(plot_psd_spatial_colors)s
%(topomap_sphere_auto)s
exclude : list of str | 'bads'
Channels names to exclude from being shown. If 'bads', the bad channels
are excluded. Pass an empty list to plot all channels (including
channels marked "bad", if any).

.. versionadded:: 0.24.0
%(verbose)s

Returns
Expand All @@ -981,6 +987,6 @@ def plot_epochs_psd(epochs, fmin=0, fmax=np.inf, tmin=None, tmax=None,
line_alpha=line_alpha, area_alpha=area_alpha, color=color,
spatial_colors=spatial_colors, n_jobs=n_jobs, bandwidth=bandwidth,
adaptive=adaptive, low_bias=low_bias, normalization=normalization,
window='hamming')
window='hamming', exclude=exclude)
plt_show(show)
return fig
10 changes: 8 additions & 2 deletions mne/viz/raw.py
Expand Up @@ -373,7 +373,7 @@ def plot_raw_psd(raw, fmin=0, fmax=np.inf, tmin=None, tmax=None, proj=False,
area_mode='std', area_alpha=0.33, dB=True, estimate='auto',
show=True, n_jobs=1, average=False, line_alpha=None,
spatial_colors=True, sphere=None, window='hamming',
verbose=None):
exclude='bads', verbose=None):
"""%(plot_psd_doc)s.

Parameters
Expand Down Expand Up @@ -416,6 +416,12 @@ def plot_raw_psd(raw, fmin=0, fmax=np.inf, tmin=None, tmax=None, proj=False,
%(window-psd)s

.. versionadded:: 0.22.0
exclude : list of str | 'bads'
Channels names to exclude from being shown. If 'bads', the bad channels
are excluded. Pass an empty list to plot all channels (including
channels marked "bad", if any).

.. versionadded:: 0.24.0
%(verbose)s

Returns
Expand All @@ -438,7 +444,7 @@ def plot_raw_psd(raw, fmin=0, fmax=np.inf, tmin=None, tmax=None, proj=False,
line_alpha=line_alpha, area_alpha=area_alpha, color=color,
spatial_colors=spatial_colors, n_jobs=n_jobs, n_fft=n_fft,
n_overlap=n_overlap, reject_by_annotation=reject_by_annotation,
window=window)
window=window, exclude=exclude)
plt_show(show)
return fig

Expand Down
2 changes: 1 addition & 1 deletion mne/viz/tests/test_figure.py
Expand Up @@ -15,4 +15,4 @@ def test_browse_figure_constructor():
def test_psd_figure_constructor():
"""Test error handling in MNELineFigure constructor."""
with pytest.raises(TypeError, match='an instance of Raw or Epochs, got'):
_psd_figure('foo', *((None,) * 19))
_psd_figure('foo', *((None,) * 20))
2 changes: 1 addition & 1 deletion mne/viz/topomap.py
Expand Up @@ -759,7 +759,7 @@ def plot_topomap(data, pos, vmin=None, vmax=None, cmap=None, sensors=True,
%(topomap_border)s
%(topomap_ch_type)s

..versionadded:: 0.24.0
.. versionadded:: 0.24.0
cnorm : matplotlib.colors.Normalize | None
Colormap normalization, default None means linear normalization. If not
None, ``vmin`` and ``vmax`` arguments are ignored. See Notes for more
Expand Down