def test_tfr_with_inverse_operator(method): """Test time freq with MNE inverse computation.""" tmin, tmax, event_id = -0.2, 0.5, 1 # Setup for reading the raw data raw = read_raw_fif(fname_data) events = find_events(raw, stim_channel='STI 014') inv = read_inverse_operator(fname_inv) inv = prepare_inverse_operator(inv, nave=1, lambda2=1. / 9., method=method) raw.info['bads'] += ['MEG 2443', 'EEG 053'] # bads + 2 more # picks MEG gradiometers picks = pick_types(raw.info, meg=True, eeg=False, eog=True, stim=False, exclude='bads') # Load condition 1 event_id = 1 events3 = events[:3] # take 3 events to keep the computation time low epochs = Epochs(raw, events3, event_id, tmin, tmax, picks=picks, baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6), preload=True) # Compute a source estimate per frequency band bands = dict(alpha=[10, 10]) label = read_label(fname_label) # XXX someday we should refactor this so that you don't have to pass # method -- maybe `prepare_inverse_operator` should add a `method` # to it and when `prepared=True` the value passed in can be ignored # (or better, default method=None means "dSPM if unprepared" and if they # actually pass a value, we check against `inv['method']`) stcs = source_band_induced_power(epochs, inv, bands, method=method, n_cycles=2, use_fft=False, pca=True, label=label, prepared=True) stc = stcs['alpha'] assert len(stcs) == len(list(bands.keys())) assert np.all(stc.data > 0) assert_allclose(stc.times, epochs.times, atol=1e-6) stcs_no_pca = source_band_induced_power(epochs, inv, bands, method=method, n_cycles=2, use_fft=False, pca=False, label=label, prepared=True) assert_allclose(stcs['alpha'].data, stcs_no_pca['alpha'].data) # Compute a source estimate per frequency band epochs = Epochs(raw, events[:10], event_id, tmin, tmax, picks=picks, baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6), preload=True) freqs = np.arange(7, 30, 2) # define frequencies of interest power, phase_lock = source_induced_power( epochs, inv, freqs, label, baseline=(-0.1, 0), baseline_mode='percent', n_cycles=2, n_jobs=None, method=method, prepared=True) assert np.all(phase_lock > 0) assert np.all(phase_lock <= 1) assert 5 < np.max(power) < 7
def test_tfr_with_inverse_operator(): """Test time freq with MNE inverse computation""" tmin, tmax, event_id = -0.2, 0.5, 1 # Setup for reading the raw data raw = io.Raw(fname_data) events = find_events(raw, stim_channel='STI 014') inverse_operator = read_inverse_operator(fname_inv) inv = prepare_inverse_operator(inverse_operator, nave=1, lambda2=1. / 9., method="dSPM") raw.info['bads'] += ['MEG 2443', 'EEG 053'] # bads + 2 more # picks MEG gradiometers picks = pick_types(raw.info, meg=True, eeg=False, eog=True, stim=False, exclude='bads') # Load condition 1 event_id = 1 events3 = events[:3] # take 3 events to keep the computation time low epochs = Epochs(raw, events3, event_id, tmin, tmax, picks=picks, baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6), preload=True) # Compute a source estimate per frequency band bands = dict(alpha=[10, 10]) label = read_label(fname_label) stcs = source_band_induced_power(epochs, inv, bands, n_cycles=2, use_fft=False, pca=True, label=label, prepared=True) stc = stcs['alpha'] assert_true(len(stcs) == len(list(bands.keys()))) assert_true(np.all(stc.data > 0)) assert_array_almost_equal(stc.times, epochs.times) stcs_no_pca = source_band_induced_power(epochs, inv, bands, n_cycles=2, use_fft=False, pca=False, label=label, prepared=True) assert_array_almost_equal(stcs['alpha'].data, stcs_no_pca['alpha'].data) # Compute a source estimate per frequency band epochs = Epochs(raw, events[:10], event_id, tmin, tmax, picks=picks, baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6), preload=True) frequencies = np.arange(7, 30, 2) # define frequencies of interest power, phase_lock = source_induced_power(epochs, inv, frequencies, label, baseline=(-0.1, 0), baseline_mode='percent', n_cycles=2, n_jobs=1, prepared=True) assert_true(np.all(phase_lock > 0)) assert_true(np.all(phase_lock <= 1)) assert_true(np.max(power) > 10)