Skip to content

Commit

Permalink
BUG: Fix passing of channel type (mne-tools#8638)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Dec 9, 2020
1 parent 89cb6bb commit 74e0985
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 76 deletions.
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Bugs

- Fix bug with compensated CTF data when picking channels without preload (:gh:`8318` by `Eric Larson`_)

- Fix bug with plotting MEG topographies where the wrong extrapolation made was used in ICA (:gh:`8637` by `Eric Larson`_)

- Fix bug when merging fNIRS channels in :func:`mne.viz.plot_evoked_topomap` and related functions (:gh:`8306` by `Robert Luke`_)

- Fix bug where events could overflow when writing to FIF (:gh:`8448` by `Eric Larson`_)
Expand Down
1 change: 0 additions & 1 deletion examples/preprocessing/plot_run_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
.. note:: This example does quite a bit of processing, so even on a
fast machine it can take about a minute to complete.
"""

# Authors: Denis Engemann <[email protected]>
#
# License: BSD (3-clause)
Expand Down
4 changes: 2 additions & 2 deletions examples/visualization/plot_evoked_topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
# Animating the topomap
# ---------------------
#
# Instead of using a still image we can plot magnetometer data as an animation
# (animates only in matplotlib interactive mode)
# Instead of using a still image we can plot magnetometer data as an animation,
# which animates properly only in matplotlib interactive mode.

# sphinx_gallery_thumbnail_number = 9
times = np.arange(0.05, 0.151, 0.01)
Expand Down
9 changes: 7 additions & 2 deletions mne/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def plot_joint(self, times="peaks", title='', picks=None,
@fill_doc
def animate_topomap(self, ch_type=None, times=None, frame_rate=None,
butterfly=False, blit=True, show=True, time_unit='s',
sphere=None):
sphere=None, *, extrapolate=_EXTRAPOLATE_DEFAULT,
verbose=None):
"""Make animation of evoked data as topomap timeseries.
The animation can be paused/resumed with left mouse button.
Expand Down Expand Up @@ -418,6 +419,10 @@ def animate_topomap(self, ch_type=None, times=None, frame_rate=None,
.. versionadded:: 0.16
%(topomap_sphere_auto)s
%(topomap_extrapolate)s
.. versionadded:: 0.22
%(verbose_meth)s
Returns
-------
Expand All @@ -433,7 +438,7 @@ def animate_topomap(self, ch_type=None, times=None, frame_rate=None,
return _topomap_animation(
self, ch_type=ch_type, times=times, frame_rate=frame_rate,
butterfly=butterfly, blit=blit, show=show, time_unit=time_unit,
sphere=sphere)
sphere=sphere, extrapolate=extrapolate, verbose=verbose)

def as_type(self, ch_type='grad', mode='fast'):
"""Compute virtual evoked using interpolated fields.
Expand Down
10 changes: 6 additions & 4 deletions mne/preprocessing/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ def plot_components(self, picks=None, ch_type=None, res=64,
contours=6, image_interp='bilinear',
inst=None, plot_std=True, topomap_args=None,
image_args=None, psd_args=None, reject='auto',
sphere=None):
sphere=None, verbose=None):
return plot_ica_components(self, picks=picks, ch_type=ch_type,
res=res, vmin=vmin,
vmax=vmax, cmap=cmap, sensors=sensors,
Expand All @@ -1810,19 +1810,21 @@ def plot_components(self, picks=None, ch_type=None, res=64,
inst=inst, plot_std=plot_std,
topomap_args=topomap_args,
image_args=image_args, psd_args=psd_args,
reject=reject, sphere=sphere)
reject=reject, sphere=sphere,
verbose=verbose)

@copy_function_doc_to_method_doc(plot_ica_properties)
def plot_properties(self, inst, picks=None, axes=None, dB=True,
plot_std=True, topomap_args=None, image_args=None,
psd_args=None, figsize=None, show=True, reject='auto',
reject_by_annotation=True):
reject_by_annotation=True, *, verbose=None):
return plot_ica_properties(self, inst, picks=picks, axes=axes,
dB=dB, plot_std=plot_std,
topomap_args=topomap_args,
image_args=image_args, psd_args=psd_args,
figsize=figsize, show=show, reject=reject,
reject_by_annotation=reject_by_annotation)
reject_by_annotation=reject_by_annotation,
verbose=verbose)

@copy_function_doc_to_method_doc(plot_ica_sources)
def plot_sources(self, inst, picks=None, start=None,
Expand Down
7 changes: 4 additions & 3 deletions mne/viz/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ..io.meas_info import create_info
from ..io.pick import pick_types, _picks_to_idx
from ..time_frequency.psd import psd_multitaper
from ..utils import _reject_data_segments
from ..utils import _reject_data_segments, verbose


@fill_doc
Expand Down Expand Up @@ -250,11 +250,11 @@ def _get_psd_label_and_std(this_psd, dB, ica, num_std):
return psd_ylabel, psds_mean, spectrum_std


@fill_doc
@verbose
def plot_ica_properties(ica, inst, picks=None, axes=None, dB=True,
plot_std=True, topomap_args=None, image_args=None,
psd_args=None, figsize=None, show=True, reject='auto',
reject_by_annotation=True):
reject_by_annotation=True, *, verbose=None):
"""Display component properties.
Properties include the topography, epochs image, ERP/ERF, power
Expand Down Expand Up @@ -308,6 +308,7 @@ def plot_ica_properties(ica, inst, picks=None, axes=None, dB=True,
%(reject_by_annotation_raw)s
.. versionadded:: 0.21.0
%(verbose)s
Returns
-------
Expand Down
18 changes: 12 additions & 6 deletions mne/viz/tests/test_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
make_fixed_length_events)
from mne.io import read_raw_fif
from mne.preprocessing import ICA, create_ecg_epochs, create_eog_epochs
from mne.utils import (run_tests_if_main, requires_sklearn, _click_ch_name,
from mne.utils import (requires_sklearn, _click_ch_name, catch_logging,
_close_event)
from mne.viz.ica import _create_properties_layout, plot_ica_properties
from mne.viz.utils import _fake_click
Expand Down Expand Up @@ -70,7 +70,12 @@ def test_plot_ica_components():
plt.close('all')

# test interactive mode (passing 'inst' arg)
ica.plot_components([0, 1], image_interp='bilinear', inst=raw, res=16)
with catch_logging() as log:
ica.plot_components([0, 1], image_interp='bilinear', inst=raw, res=16,
verbose='debug', ch_type='grad')
log = log.getvalue()
assert 'grad data' in log
assert 'Interpolation mode local to mean' in log
fig = plt.gcf()

# test title click
Expand Down Expand Up @@ -133,7 +138,11 @@ def test_plot_ica_properties():
_create_properties_layout(figsize=(2, 2), fig=fig)

topoargs = dict(topomap_args={'res': 4, 'contours': 0, "sensors": False})
ica.plot_properties(raw, picks=0, **topoargs)
with catch_logging() as log:
ica.plot_properties(raw, picks=0, verbose='debug', **topoargs)
log = log.getvalue()
assert raw.ch_names[0] == 'MEG 0113'
assert 'Interpolation mode local to mean' in log, log
ica.plot_properties(epochs, picks=1, dB=False, plot_std=1.5, **topoargs)
ica.plot_properties(epochs, picks=1, image_args={'sigma': 1.5},
topomap_args={'res': 4, 'colorbar': True},
Expand Down Expand Up @@ -396,6 +405,3 @@ def test_plot_instance_components():
_fake_click(fig, ax, [line.get_xdata()[0], line.get_ydata()[0]], 'data')
_fake_click(fig, ax, [-0.1, 0.9]) # click on y-label
fig.canvas.key_press_event('escape')


run_tests_if_main()
13 changes: 9 additions & 4 deletions mne/viz/tests/test_topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,27 @@ def test_plot_projs_topomap():
plot_projs_topomap([eeg_proj], info_meg)


def test_plot_topomap_animation():
def test_plot_topomap_animation(capsys):
"""Test topomap plotting."""
# evoked
evoked = read_evokeds(evoked_fname, 'Left Auditory',
baseline=(None, 0))
# Test animation
_, anim = evoked.animate_topomap(ch_type='grad', times=[0, 0.1],
butterfly=False, time_unit='s')
butterfly=False, time_unit='s',
verbose='debug')
anim._func(1) # _animate has to be tested separately on 'Agg' backend.
out, _ = capsys.readouterr()
assert 'Interpolation mode local to 0' in out
plt.close('all')


def test_plot_topomap_animation_nirs(fnirs_evoked):
def test_plot_topomap_animation_nirs(fnirs_evoked, capsys):
"""Test topomap plotting for nirs data."""
fig, anim = fnirs_evoked.animate_topomap(ch_type='hbo')
fig, anim = fnirs_evoked.animate_topomap(ch_type='hbo', verbose='debug')
anim._func(1) # _animate has to be tested separately on 'Agg' backend.
out, _ = capsys.readouterr()
assert 'Interpolation mode head to 0' in out
assert len(fig.axes) == 2
plt.close('all')

Expand Down
Loading

0 comments on commit 74e0985

Please sign in to comment.