Skip to content

Commit

Permalink
Merge pull request #2637 from Eric89GXL/quiet-warnings
Browse files Browse the repository at this point in the history
FIX: Fix some test warnings, DRY code
  • Loading branch information
agramfort committed Nov 24, 2015
2 parents fc4d533 + 33e2503 commit ec092ad
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 170 deletions.
7 changes: 2 additions & 5 deletions mne/preprocessing/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from ..epochs import _BaseEpochs
from ..viz import (plot_ica_components, plot_ica_scores,
plot_ica_sources, plot_ica_overlay)
from ..viz.utils import (_prepare_trellis, tight_layout,
from ..viz.utils import (_prepare_trellis, tight_layout, plt_show,
_setup_vmin_vmax)
from ..viz.topomap import (_prepare_topo_plot, _check_outlines,
plot_topomap)
Expand Down Expand Up @@ -2249,8 +2249,6 @@ def _find_max_corrs(all_maps, target, threshold):
def _plot_corrmap(data, subjs, indices, ch_type, ica, label, show, outlines,
layout, cmap, contours):
"""Customized ica.plot_components for corrmap"""
import matplotlib.pyplot as plt

title = 'Detected components'
if label is not None:
title += ' of type ' + label
Expand Down Expand Up @@ -2297,8 +2295,7 @@ def _plot_corrmap(data, subjs, indices, ch_type, ica, label, show, outlines,
tight_layout(fig=fig)
fig.subplots_adjust(top=0.8)
fig.canvas.draw()
if show is True:
plt.show()
plt_show(show)
return fig


Expand Down
2 changes: 1 addition & 1 deletion mne/time_frequency/psd.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def compute_epochs_psd(epochs, picks=None, fmin=0, fmax=np.inf, tmin=None,
if tmin is not None or tmax is not None:
time_mask = _time_mask(epochs.times, tmin, tmax)
else:
time_mask = Ellipsis
time_mask = slice(None)

data = epochs.get_data()[:, picks][..., time_mask]
if proj:
Expand Down
11 changes: 3 additions & 8 deletions mne/time_frequency/tfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ..io.meas_info import Info
from ..utils import check_fname
from .multitaper import dpss_windows
from ..viz.utils import figure_nobar
from ..viz.utils import figure_nobar, plt_show
from ..externals.h5io import write_hdf5, read_hdf5
from ..externals.six import string_types

Expand Down Expand Up @@ -725,8 +725,7 @@ def plot(self, picks=None, baseline=None, mode='mean', tmin=None,
if title:
fig.suptitle(title)
colorbar = False # only one colorbar for multiple axes
if show:
plt.show()
plt_show(show)
return fig

def _onselect(self, eclick, erelease, baseline, mode, layout):
Expand Down Expand Up @@ -843,7 +842,6 @@ def plot_topo(self, picks=None, baseline=None, mode='mean', tmin=None,
The figure containing the topography.
"""
from ..viz.topo import _imshow_tfr, _plot_topo
import matplotlib.pyplot as plt
times = self.times.copy()
freqs = self.freqs
data = self.data
Expand All @@ -870,10 +868,7 @@ def plot_topo(self, picks=None, baseline=None, mode='mean', tmin=None,
title=title, border=border, x_label='Time (ms)',
y_label='Frequency (Hz)', fig_facecolor=fig_facecolor,
font_color=font_color)

if show:
plt.show()

plt_show(show)
return fig

def _check_compat(self, tfr):
Expand Down
9 changes: 3 additions & 6 deletions mne/viz/_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ..utils import get_subjects_dir, logger, _check_subject, verbose
from ..fixes import _get_args
from ..defaults import _handle_default
from .utils import mne_analyze_colormap, _prepare_trellis, COLORS
from .utils import mne_analyze_colormap, _prepare_trellis, COLORS, plt_show
from ..externals.six import BytesIO


Expand Down Expand Up @@ -262,8 +262,7 @@ def _plot_mri_contours(mri_fname, surf_fnames, orientation='coronal',
if show:
plt.subplots_adjust(left=0., bottom=0., right=1., top=1., wspace=0.,
hspace=0.)
plt.show()

plt_show(show)
return fig if img_output is None else outs


Expand Down Expand Up @@ -820,9 +819,7 @@ def plot_sparse_source_estimates(src, stcs, colors=None, linewidth=2,

if fig_name is not None:
plt.title(fig_name)

if show:
plt.show()
plt_show(show)

surface.actor.property.backface_culling = True
surface.actor.property.shading = True
Expand Down
4 changes: 2 additions & 2 deletions mne/viz/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import numpy as np

from .utils import plt_show
from ..externals.six import string_types
from ..fixes import tril_indices, normalize_colors

Expand Down Expand Up @@ -409,6 +410,5 @@ def plot_connectivity_circle(con, node_names, indices=None, n_lines=None,

fig.canvas.mpl_connect('button_press_event', callback)

if show:
plt.show()
plt_show(show)
return fig, axes
8 changes: 4 additions & 4 deletions mne/viz/decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import numpy as np
import warnings

from .utils import plt_show


def plot_gat_matrix(gat, title=None, vmin=None, vmax=None, tlim=None,
ax=None, cmap='RdBu_r', show=True, colorbar=True,
Expand Down Expand Up @@ -82,8 +84,7 @@ def plot_gat_matrix(gat, title=None, vmin=None, vmax=None, tlim=None,
ax.set_ylim(tlim[2:])
if colorbar is True:
plt.colorbar(im, ax=ax)
if show is True:
plt.show()
plt_show(show)
return fig if ax is None else ax.get_figure()


Expand Down Expand Up @@ -182,8 +183,7 @@ def plot_gat_times(gat, train_time='diagonal', title=None, xmin=None,
'AUC' if 'roc' in repr(gat.scorer_) else r'%'))
if legend is True:
ax.legend(loc='best')
if show is True:
plt.show()
plt_show(show)
return fig if ax is None else ax.get_figure()


Expand Down
36 changes: 13 additions & 23 deletions mne/viz/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@

import numpy as np

from ..utils import verbose, get_config, set_config
from ..utils import logger
from ..utils import verbose, get_config, set_config, logger
from ..io.pick import pick_types, channel_type
from ..io.proj import setup_proj
from ..fixes import Counter, _in1d
from ..time_frequency import compute_epochs_psd
from .utils import tight_layout, figure_nobar, _toggle_proj
from .utils import _toggle_options, _layout_figure, _setup_vmin_vmax
from .utils import _channels_changed, _plot_raw_onscroll, _onclick_help
from .utils import (tight_layout, figure_nobar, _toggle_proj, _toggle_options,
_layout_figure, _setup_vmin_vmax, _channels_changed,
_plot_raw_onscroll, _onclick_help, plt_show)
from ..defaults import _handle_default


Expand Down Expand Up @@ -156,9 +155,7 @@ def plot_epochs_image(epochs, picks=None, sigma=0., vmin=None,
plt.colorbar(im, cax=ax3)
tight_layout(fig=this_fig)

if show:
plt.show()

plt_show(show)
return figs


Expand Down Expand Up @@ -238,10 +235,7 @@ def plot_drop_log(drop_log, threshold=0, n_max_plot=20, subject='Unknown',
plt.ylabel('% of epochs rejected')
plt.xlim((-width / 2.0, (n_plot - 1) + width * 3 / 2))
plt.grid(True, axis='y')

if show:
plt.show()

plt_show(show)
return fig


Expand Down Expand Up @@ -390,7 +384,6 @@ def plot_epochs(epochs, picks=None, scalings=None, n_epochs=20,
with home/end and page down/page up keys. Butterfly plot can be toggled
with ``b`` key. Right mouse click adds a vertical line to the plot.
"""
import matplotlib.pyplot as plt
epochs.drop_bad_epochs()
scalings = _handle_default('scalings_plot_raw', scalings)

Expand All @@ -409,11 +402,10 @@ def plot_epochs(epochs, picks=None, scalings=None, n_epochs=20,

callback_close = partial(_close_event, params=params)
params['fig'].canvas.mpl_connect('close_event', callback_close)
if show:
try:
plt.show(block=block)
except TypeError: # not all versions have this
plt.show()
try:
plt_show(show, block=block)
except TypeError: # not all versions have this
plt_show(show)

return params['fig']

Expand Down Expand Up @@ -471,7 +463,6 @@ def plot_epochs_psd(epochs, fmin=0, fmax=np.inf, tmin=None, tmax=None,
fig : instance of matplotlib figure
Figure distributing one image per channel across sensor topography.
"""
import matplotlib.pyplot as plt
from .raw import _set_psd_plot_params
fig, picks_list, titles_list, ax_list, make_label = _set_psd_plot_params(
epochs.info, proj, picks, ax, area_mode)
Expand Down Expand Up @@ -515,8 +506,7 @@ def plot_epochs_psd(epochs, fmin=0, fmax=np.inf, tmin=None, tmax=None,
ax.set_xlim(freqs[0], freqs[-1])
if make_label:
tight_layout(pad=0.1, h_pad=0.1, w_pad=0.1, fig=fig)
if show:
plt.show()
plt_show(show)
return fig


Expand Down Expand Up @@ -1437,7 +1427,7 @@ def _open_options(params):
params['fig_options'].canvas.mpl_connect('close_event', close_callback)
try:
params['fig_options'].canvas.draw()
params['fig_options'].show()
params['fig_options'].show(warn=False)
if params['fig_proj'] is not None:
params['fig_proj'].canvas.draw()
except Exception:
Expand Down Expand Up @@ -1495,7 +1485,7 @@ def _plot_histogram(params):
params['histogram'].suptitle('Peak-to-peak histogram', y=0.99)
params['histogram'].subplots_adjust(hspace=0.6)
try:
params['histogram'].show()
params['histogram'].show(warn=False)
except:
pass
if params['fig_proj'] is not None:
Expand Down
16 changes: 7 additions & 9 deletions mne/viz/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from ..io.pick import channel_type, pick_types, _picks_by_type
from ..externals.six import string_types
from ..defaults import _handle_default
from .utils import _draw_proj_checkbox, tight_layout, _check_delayed_ssp
from .utils import (_draw_proj_checkbox, tight_layout, _check_delayed_ssp,
plt_show)
from ..utils import logger
from ..fixes import partial
from ..io.pick import pick_info
Expand Down Expand Up @@ -99,7 +100,7 @@ def _butterfly_onselect(xmin, xmax, ch_types, evoked, text=None):
fig.suptitle('Average over %.2fs - %.2fs' % (xmin, xmax), fontsize=15,
y=0.1)
tight_layout(pad=2.0, fig=fig)
plt.show()
plt_show()
if text is not None:
text.set_visible(False)
close_callback = partial(_topo_closed, ax=ax, lines=vert_lines,
Expand Down Expand Up @@ -314,9 +315,8 @@ def _plot_evoked(evoked, picks, exclude, unit, show,
plot_type=plot_type)
_draw_proj_checkbox(None, params)

if show and plt.get_backend() != 'agg':
plt.show()
fig.canvas.draw() # for axes plots update axes.
plt_show(show)
fig.canvas.draw() # for axes plots update axes.
tight_layout(fig=fig)

return fig
Expand Down Expand Up @@ -756,8 +756,7 @@ def whitened_gfp(x, rank=None):
fig.subplots_adjust(**params)
fig.canvas.draw()

if show is True:
plt.show()
plt_show(show)
return fig


Expand Down Expand Up @@ -800,6 +799,5 @@ def plot_snr_estimate(evoked, inv, show=True):
if evoked.comment is not None:
ax.set_title(evoked.comment)
plt.draw()
if show:
plt.show()
plt_show(show)
return fig

0 comments on commit ec092ad

Please sign in to comment.