def test_compute_proj_raw(): """Test SSP computation on raw""" # Test that the raw projectors work raw_time = 2.5 # Do shorter amount for speed raw = Raw(raw_fname, preload=True).crop(0, raw_time, False) for ii in (0.25, 0.5, 1, 2): with warnings.catch_warnings(True) as w: projs = compute_proj_raw(raw, duration=ii - 0.1, stop=raw_time, n_grad=1, n_mag=1, n_eeg=0) assert_true(len(w) == 1) # test that you can compute the projection matrix projs = activate_proj(projs) proj, nproj, U = make_projector(projs, raw.ch_names, bads=[]) assert_true(nproj == 2) assert_true(U.shape[1] == 2) # test that you can save them raw.info['projs'] += projs raw.save(op.join(tempdir, 'foo_%d_raw.fif' % ii), overwrite=True) # Test that purely continuous (no duration) raw projection works with warnings.catch_warnings(True) as w: projs = compute_proj_raw(raw, duration=None, stop=raw_time, n_grad=1, n_mag=1, n_eeg=0) assert_true(len(w) == 1) # test that you can compute the projection matrix projs = activate_proj(projs) proj, nproj, U = make_projector(projs, raw.ch_names, bads=[]) assert_true(nproj == 2) assert_true(U.shape[1] == 2) # test that you can save them raw.info['projs'] += projs raw.save(op.join(tempdir, 'foo_rawproj_continuous_raw.fif')) # test resampled-data projector, upsampling instead of downsampling # here to save an extra filtering (raw would have to be LP'ed to be equiv) raw_resamp = cp.deepcopy(raw) raw_resamp.resample(raw.info['sfreq'] * 2, n_jobs=2) with warnings.catch_warnings(True) as w: projs = compute_proj_raw(raw_resamp, duration=None, stop=raw_time, n_grad=1, n_mag=1, n_eeg=0) projs = activate_proj(projs) proj_new, _, _ = make_projector(projs, raw.ch_names, bads=[]) assert_array_almost_equal(proj_new, proj, 4) # test with bads raw.load_bad_channels(bads_fname) # adds 2 bad mag channels with warnings.catch_warnings(True) as w: projs = compute_proj_raw(raw, n_grad=0, n_mag=0, n_eeg=1) # test that bad channels can be excluded proj, nproj, U = make_projector(projs, raw.ch_names, bads=raw.ch_names) assert_array_almost_equal(proj, np.eye(len(raw.ch_names)))
def test_load_bad_channels(): """Test reading/writing of bad channels """ # Load correctly marked file (manually done in mne_process_raw) raw_marked = Raw(fif_bad_marked_fname) correct_bads = raw_marked.info['bads'] raw = Raw(fif_fname) # Make sure it starts clean assert_array_equal(raw.info['bads'], []) # Test normal case raw.load_bad_channels(bad_file_works) # Write it out, read it in, and check raw.save(op.join(tempdir, 'foo_raw.fif')) raw_new = Raw(op.join(tempdir, 'foo_raw.fif')) assert_equal(correct_bads, raw_new.info['bads']) # Reset it raw.info['bads'] = [] # Test bad case assert_raises(ValueError, raw.load_bad_channels, bad_file_wrong) # Test forcing the bad case with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') raw.load_bad_channels(bad_file_wrong, force=True) n_found = sum(['1 bad channel' in str(ww.message) for ww in w]) assert_equal(n_found, 1) # there could be other irrelevant errors # write it out, read it in, and check raw.save(op.join(tempdir, 'foo_raw.fif'), overwrite=True) raw_new = Raw(op.join(tempdir, 'foo_raw.fif')) assert_equal(correct_bads, raw_new.info['bads']) # Check that bad channels are cleared raw.load_bad_channels(None) raw.save(op.join(tempdir, 'foo_raw.fif'), overwrite=True) raw_new = Raw(op.join(tempdir, 'foo_raw.fif')) assert_equal([], raw_new.info['bads'])
def test_load_bad_channels(): """Test reading/writing of bad channels """ # Load correctly marked file (manually done in mne_process_raw) raw_marked = Raw(fif_bad_marked_fname) correct_bads = raw_marked.info['bads'] raw = Raw(fif_fname) # Make sure it starts clean assert_array_equal(raw.info['bads'], []) # Test normal case raw.load_bad_channels(bad_file_works) # Write it out, read it in, and check raw.save(op.join(tempdir, 'foo_raw.fif')) raw_new = Raw(op.join(tempdir, 'foo_raw.fif')) assert_equal(correct_bads, raw_new.info['bads']) # Reset it raw.info['bads'] = [] # Test bad case assert_raises(ValueError, raw.load_bad_channels, bad_file_wrong) # Test forcing the bad case with warnings.catch_warnings(record=True) as w: raw.load_bad_channels(bad_file_wrong, force=True) assert_equal(len(w), 1) # write it out, read it in, and check raw.save(op.join(tempdir, 'foo_raw.fif')) raw_new = Raw(op.join(tempdir, 'foo_raw.fif')) assert_equal(correct_bads, raw_new.info['bads']) # Check that bad channels are cleared raw.load_bad_channels(None) raw.save(op.join(tempdir, 'foo_raw.fif')) raw_new = Raw(op.join(tempdir, 'foo_raw.fif')) assert_equal([], raw_new.info['bads'])
def test_load_bad_channels(): """Test reading/writing of bad channels """ # Load correctly marked file (manually done in mne_process_raw) raw_marked = Raw(fif_bad_marked_fname) correct_bads = raw_marked.info['bads'] raw = Raw(fif_fname) # Make sure it starts clean assert_array_equal(raw.info['bads'], []) # Test normal case raw.load_bad_channels(bad_file_works) # Write it out, read it in, and check raw.save('foo_raw.fif') raw_new = Raw('foo_raw.fif') assert_equal(correct_bads, raw_new.info['bads']) # Reset it raw.info['bads'] = [] # Test bad case assert_raises(ValueError, raw.load_bad_channels, bad_file_wrong) # Test forcing the bad case with warnings.catch_warnings(record=True) as w: raw.load_bad_channels(bad_file_wrong, force=True) assert_equal(len(w), 1) # write it out, read it in, and check raw.save('foo_raw.fif') raw_new = Raw('foo_raw.fif') assert_equal(correct_bads, raw_new.info['bads']) # Check that bad channels are cleared raw.load_bad_channels(None) raw.save('foo_raw.fif') raw_new = Raw('foo_raw.fif') assert_equal([], raw_new.info['bads'])