def test_plot_raw_psd(): """Test plotting of raw psds.""" raw = _get_raw() # normal mode raw.plot_psd(average=False) # specific mode picks = pick_types(raw.info, meg='mag', eeg=False)[:4] raw.plot_psd(tmax=None, picks=picks, area_mode='range', average=False, spatial_colors=True) raw.plot_psd(tmax=20., color='yellow', dB=False, line_alpha=0.4, n_overlap=0.1, average=False) plt.close('all') ax = plt.axes() # if ax is supplied: pytest.raises(ValueError, raw.plot_psd, ax=ax, average=True) raw.plot_psd(tmax=None, picks=picks, ax=ax, average=True) plt.close('all') ax = plt.axes() with pytest.raises(ValueError, match='2 axes must be supplied, got 1'): raw.plot_psd(ax=ax, average=True) plt.close('all') ax = plt.subplots(2)[1] raw.plot_psd(tmax=None, ax=ax, average=True) plt.close('all') # topo psd ax = plt.subplot() raw.plot_psd_topo(axes=ax) plt.close('all') # with channel information not available for idx in range(len(raw.info['chs'])): raw.info['chs'][idx]['loc'] = np.zeros(12) with pytest.warns(RuntimeWarning, match='locations not available'): raw.plot_psd(spatial_colors=True, average=False) # with a flat channel raw[5, :] = 0 for dB, estimate in itertools.product((True, False), ('power', 'amplitude')): with pytest.warns(UserWarning, match='[Infinite|Zero]'): fig = raw.plot_psd(average=True, dB=dB, estimate=estimate) ylabel = fig.axes[1].get_ylabel() ends_dB = ylabel.endswith('mathrm{(dB)}$') if dB: assert ends_dB, ylabel else: assert not ends_dB, ylabel if estimate == 'amplitude': assert r'fT/cm/\sqrt{Hz}' in ylabel, ylabel else: assert estimate == 'power' assert '(fT/cm)²/Hz' in ylabel, ylabel ylabel = fig.axes[0].get_ylabel() if estimate == 'amplitude': assert r'fT/\sqrt{Hz}' in ylabel else: assert 'fT²/Hz' in ylabel # test reject_by_annotation raw = _get_raw() raw.set_annotations(Annotations([1, 5], [3, 3], ['test', 'test'])) raw.plot_psd(reject_by_annotation=True) raw.plot_psd(reject_by_annotation=False) plt.close('all') # test fmax value checking with pytest.raises(ValueError, match='not exceed one half the sampling'): raw.plot_psd(fmax=50000) # test xscale value checking with pytest.raises(ValueError, match="Invalid value for the 'xscale'"): raw.plot_psd(xscale='blah') # gh-5046 raw = read_raw_fif(raw_fname, preload=True).crop(0, 1) picks = pick_types(raw.info) raw.plot_psd(picks=picks, average=False) raw.plot_psd(picks=picks, average=True) plt.close('all') raw.set_channel_types( { 'MEG 0113': 'hbo', 'MEG 0112': 'hbr', 'MEG 0122': 'fnirs_raw', 'MEG 0123': 'fnirs_od' }, verbose='error') fig = raw.plot_psd() assert len(fig.axes) == 10 plt.close('all') # gh-7631 data = 1e-3 * np.random.rand(2, 100) info = create_info(['CH1', 'CH2'], 100) raw = RawArray(data, info) picks = pick_types(raw.info, misc=True) raw.plot_psd(picks=picks, spatial_colors=False) plt.close('all')
def test_plot_raw_psd(raw, raw_orig): """Test plotting of raw psds.""" raw_unchanged = raw.copy() # normal mode fig = raw.plot_psd(average=False) fig.canvas.resize_event() # specific mode picks = pick_types(raw.info, meg='mag', eeg=False)[:4] raw.plot_psd(tmax=None, picks=picks, area_mode='range', average=False, spatial_colors=True) raw.plot_psd(tmax=20., color='yellow', dB=False, line_alpha=0.4, n_overlap=0.1, average=False) plt.close('all') # one axes supplied ax = plt.axes() raw.plot_psd(tmax=None, picks=picks, ax=ax, average=True) plt.close('all') # two axes supplied _, axs = plt.subplots(2) raw.plot_psd(tmax=None, ax=axs, average=True) plt.close('all') # need 2, got 1 ax = plt.axes() with pytest.raises(ValueError, match='of length 2, while the length is 1'): raw.plot_psd(ax=ax, average=True) plt.close('all') # topo psd ax = plt.subplot() raw.plot_psd_topo(axes=ax) plt.close('all') # with channel information not available for idx in range(len(raw.info['chs'])): raw.info['chs'][idx]['loc'] = np.zeros(12) with pytest.warns(RuntimeWarning, match='locations not available'): raw.plot_psd(spatial_colors=True, average=False) # with a flat channel raw[5, :] = 0 for dB, estimate in itertools.product((True, False), ('power', 'amplitude')): with pytest.warns(UserWarning, match='[Infinite|Zero]'): fig = raw.plot_psd(average=True, dB=dB, estimate=estimate) # check grad axes title = fig.axes[0].get_title() ylabel = fig.axes[0].get_ylabel() ends_dB = ylabel.endswith('mathrm{(dB)}$') unit = '(fT/cm)²/Hz' if estimate == 'power' else r'fT/cm/\sqrt{Hz}' assert title == 'Gradiometers', title assert unit in ylabel, ylabel if dB: assert ends_dB, ylabel else: assert not ends_dB, ylabel # check mag axes title = fig.axes[1].get_title() ylabel = fig.axes[1].get_ylabel() unit = 'fT²/Hz' if estimate == 'power' else r'fT/\sqrt{Hz}' assert title == 'Magnetometers', title assert unit in ylabel, ylabel # test reject_by_annotation raw = raw_unchanged raw.set_annotations(Annotations([1, 5], [3, 3], ['test', 'test'])) raw.plot_psd(reject_by_annotation=True) raw.plot_psd(reject_by_annotation=False) plt.close('all') # test fmax value checking with pytest.raises(ValueError, match='must not exceed ½ the sampling'): raw.plot_psd(fmax=50000) # test xscale value checking with pytest.raises(ValueError, match="Invalid value for the 'xscale'"): raw.plot_psd(xscale='blah') # gh-5046 raw = raw_orig.crop(0, 1) picks = pick_types(raw.info, meg=True) raw.plot_psd(picks=picks, average=False) raw.plot_psd(picks=picks, average=True) plt.close('all') raw.set_channel_types({'MEG 0113': 'hbo', 'MEG 0112': 'hbr', 'MEG 0122': 'fnirs_cw_amplitude', 'MEG 0123': 'fnirs_od'}, verbose='error') fig = raw.plot_psd() assert len(fig.axes) == 10 plt.close('all') # gh-7631 data = 1e-3 * np.random.rand(2, 100) info = create_info(['CH1', 'CH2'], 100) raw = RawArray(data, info) picks = pick_types(raw.info, misc=True) raw.plot_psd(picks=picks, spatial_colors=False) plt.close('all')
icas_names.append(icas_name) icas.append(ica) return icas, icas_names icas,icas_names = ica_function(save = False, overwrite= False) #icas[0]._pre_whiten(${1:raws_filt}, info, picks=64) bm = icas[0].get_components() #plot_psd(m) #%% b = icas[0].get_components() raw = RawArray(b, raws_filt[0].info) raw.plot_psd(area_mode=None, show=True, average=False,fmin =1.0, fmax=80.0, dB=False) #%% Load saved icas from icas_names = paths #BUG ICAS_NAMES not defined, you should run def loading_icas (): icas = [] for subj in range (len(subjects)): icas_names = os.path.join(dir_icas,'S'+ str(subjects[subj]) + '_ica.fif') loaded_ica = read_ica(icas_names[subj]) icas.append(loaded_ica) return icas