diff --git a/mne/viz/raw.py b/mne/viz/raw.py index 6e0e750856d..4713b644267 100644 --- a/mne/viz/raw.py +++ b/mne/viz/raw.py @@ -575,6 +575,12 @@ def plot_raw_psd(raw, tmin=0., tmax=np.inf, fmin=0, fmax=np.inf, proj=False, # Convert PSDs to dB if dB: psds = 10 * np.log10(psds) + if np.any(np.isinf(psds)): + where = np.flatnonzero(np.isinf(psds.min(1))) + chs = [raw.ch_names[i] for i in picks[where]] + raise ValueError("Infinite value in PSD for channel(s) %s. " + "These channels might be dead." % + ', '.join(chs)) unit = 'dB' else: unit = 'power' diff --git a/mne/viz/tests/test_raw.py b/mne/viz/tests/test_raw.py index c236410fea8..31e2987b982 100644 --- a/mne/viz/tests/test_raw.py +++ b/mne/viz/tests/test_raw.py @@ -151,6 +151,9 @@ def test_plot_raw_psd(): # topo psd raw.plot_psd_topo() plt.close('all') + # with a flat channel + raw[5, :] = 0 + assert_raises(ValueError, raw.plot_psd) def test_plot_sensors():