diff --git a/mne/channels/layout.py b/mne/channels/layout.py index f7484115b9e..09d1d880e28 100644 --- a/mne/channels/layout.py +++ b/mne/channels/layout.py @@ -656,7 +656,7 @@ def _auto_topomap_coords(info, picks, ignore_overlap=False, to_sphere=True): locs3d = np.array([ch['loc'][:3] for ch in chs]) # If electrode locations are not available, use digization points - if _check_ch_locs(chs): + if not _check_ch_locs(chs): logging.warning('Did not find any electrode locations (in the info ' 'object), will attempt to use digitization points ' 'instead. However, if digitization points do not ' diff --git a/mne/utils.py b/mne/utils.py index 3825b59254a..56a86f5ec4f 100644 --- a/mne/utils.py +++ b/mne/utils.py @@ -2388,8 +2388,9 @@ def _check_ch_locs(chs): The channels from info['chs'] """ locs3d = np.array([ch['loc'][:3] for ch in chs]) - return (locs3d == 0).all() or \ - (~np.isfinite(locs3d)).all() or np.allclose(locs3d, 0.) + return not ((locs3d == 0).all() or + (~np.isfinite(locs3d)).all() or + np.allclose(locs3d, 0.)) def _clean_names(names, remove_whitespace=False, before_dash=True): diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index eec5cce7633..4d6f19a7815 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -415,7 +415,7 @@ def _plot_lines(data, info, picks, fig, axes, spatial_colors, unit, units, if not gfp_only: chs = [info['chs'][i] for i in idx] locs3d = np.array([ch['loc'][:3] for ch in chs]) - if spatial_colors is True and _check_ch_locs(chs): + if spatial_colors is True and not _check_ch_locs(chs): warn('Channel locations not available. Disabling spatial ' 'colors.') spatial_colors = selectable = False @@ -2122,22 +2122,21 @@ def plot_compare_evokeds(evokeds, picks=None, gfp=False, colors=None, # and now for 3 "legends" .. # a head plot showing the sensors that are being plotted if show_sensors: - if not _check_ch_locs(one_evoked.info['chs']): - pos = _auto_topomap_coords(one_evoked.info, pos_picks, - ignore_overlap=True, to_sphere=True) - else: + _validate_type(show_sensors, (np.int, bool, str, type(None)), + "show_sensors", "numeric, str, None or bool") + if not _check_ch_locs(np.array(one_evoked.info['chs'])[pos_picks]): warn("Cannot find channel coordinates in the supplied Evokeds. " "Not showing channel locations.") - - if show_sensors is True: - ymin, ymax = np.abs(ax.get_ylim()) - show_sensors = "lower right" if ymin > ymax else "upper right" else: + if show_sensors is True: + ymin, ymax = np.abs(ax.get_ylim()) + show_sensors = "lower right" if ymin > ymax else "upper right" + + pos = _auto_topomap_coords(one_evoked.info, pos_picks, + ignore_overlap=True, to_sphere=True) head_pos = {'center': (0, 0), 'scale': (0.5, 0.5)} pos, outlines = _check_outlines(pos, np.array([1, 1]), head_pos) - _validate_type(show_sensors, (np.int, bool, str), - "show_sensors", "numeric, str or bool") show_sensors = _check_loc_legal(show_sensors, "show_sensors") _plot_legend(pos, ["k"] * len(picks), ax, list(), outlines, show_sensors, size=25) diff --git a/mne/viz/tests/test_evoked.py b/mne/viz/tests/test_evoked.py index ba1832e3a39..78719bf018f 100644 --- a/mne/viz/tests/test_evoked.py +++ b/mne/viz/tests/test_evoked.py @@ -196,7 +196,10 @@ def test_plot_evoked(): evoked.plot_white([cov, cov], time_unit='s') # plot_compare_evokeds: test condition contrast, CI, color assignment - plot_compare_evokeds(evoked.copy().pick_types(meg='mag')) + fig = plot_compare_evokeds(evoked.copy().pick_types(meg='mag'), + show_sensors=True) + assert len(fig.axes) == 2 + plot_compare_evokeds( evoked.copy().pick_types(meg='grad'), picks=[1, 2], show_sensors="upper right", show_legend="upper left")