def test_psdestimator(): """Test methods of PSDEstimator.""" raw = io.read_raw_fif(raw_fname) events = read_events(event_name) picks = pick_types(raw.info, meg=True, stim=False, ecg=False, eog=False, exclude='bads') picks = picks[1:13:3] epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=True) epochs_data = epochs.get_data() psd = PSDEstimator(2 * np.pi, 0, np.inf) y = epochs.events[:, -1] X = psd.fit_transform(epochs_data, y) assert (X.shape[0] == epochs_data.shape[0]) assert_array_equal(psd.fit(epochs_data, y).transform(epochs_data), X) # Test init exception pytest.raises(ValueError, psd.fit, epochs, y) pytest.raises(ValueError, psd.transform, epochs)
def test_psdestimator(): """Test methods of PSDEstimator """ raw = io.Raw(raw_fname, preload=False) events = read_events(event_name) picks = pick_types( raw.info, meg=True, stim=False, ecg=False, eog=False, exclude='bads') picks = picks[1:13:3] epochs = Epochs( raw, events, event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=True) epochs_data = epochs.get_data() psd = PSDEstimator(2 * np.pi, 0, np.inf) y = epochs.events[:, -1] X = psd.fit_transform(epochs_data, y) assert_true(X.shape[0] == epochs_data.shape[0]) assert_array_equal(psd.fit(epochs_data, y).transform(epochs_data), X) # Test init exception assert_raises(ValueError, psd.fit, epochs, y) assert_raises(ValueError, psd.transform, epochs, y)
# psde.transform = [channels x freqs] psd = psde.transform(w) return psd if __name__ == '__main__': sr = StreamReceiver(window_size=w_seconds, amp_name=amp_name, amp_serial=amp_serial) sfreq = sr.sample_rate psde = PSDEstimator(sfreq=sfreq, fmin=fmin, fmax=fmax, bandwidth=None, adaptive=False, low_bias=True, n_jobs=1, normalization='length', verbose=None) ch_names = sr.get_channel_names() fq_res = 1 / w_seconds hz_list = [] f = fmin while f < fmax: hz_list.append(f) f += fq_res picks = [ch_names.index(ch) for ch in channel_picks] psd = get_psd(sr, psde, picks).T # freq x ch assert len(hz_list) == psd.shape[0], (len(hz_list), psd.shape[0]) cv2.namedWindow("img", cv2.WINDOW_AUTOSIZE)