def test_simulate_sparse_stc_single_hemi(): """Test generation of sparse source estimate.""" fwd = read_forward_solution_meg(fname_fwd, force_fixed=True, use_cps=True) n_times = 10 tmin = 0 tstep = 1e-3 times = np.arange(n_times, dtype=np.float) * tstep + tmin labels_single_hemi = [ read_label( op.join(data_path, 'MEG', 'sample', 'labels', '%s.label' % label)) for label in label_names_single_hemi ] stc_1 = simulate_sparse_stc(fwd['src'], len(labels_single_hemi), times, labels=labels_single_hemi, random_state=0) assert (stc_1.data.shape[0] == len(labels_single_hemi)) assert (stc_1.data.shape[1] == n_times) # make sure we get the same result when using the same seed stc_2 = simulate_sparse_stc(fwd['src'], len(labels_single_hemi), times, labels=labels_single_hemi, random_state=0) assert_array_equal(stc_1.lh_vertno, stc_2.lh_vertno) assert_array_equal(stc_1.rh_vertno, stc_2.rh_vertno)
def test_simulate_sparse_stc_single_hemi(_get_fwd_labels): """Test generation of sparse source estimate.""" fwd, labels = _get_fwd_labels labels_single_hemi = labels[1:] # keep only labels in one hemisphere n_times = 10 tmin = 0 tstep = 1e-3 times = np.arange(n_times, dtype=np.float) * tstep + tmin stc_1 = simulate_sparse_stc(fwd['src'], len(labels_single_hemi), times, labels=labels_single_hemi, random_state=0) assert (stc_1.data.shape[0] == len(labels_single_hemi)) assert (stc_1.data.shape[1] == n_times) # make sure we get the same result when using the same seed stc_2 = simulate_sparse_stc(fwd['src'], len(labels_single_hemi), times, labels=labels_single_hemi, random_state=0) assert_array_equal(stc_1.lh_vertno, stc_2.lh_vertno) assert_array_equal(stc_1.rh_vertno, stc_2.rh_vertno)
def test_simulate_sparse_stc(_get_fwd_labels): """Test generation of sparse source estimate.""" fwd, labels = _get_fwd_labels n_times = 10 tmin = 0 tstep = 1e-3 times = np.arange(n_times, dtype=np.float) * tstep + tmin pytest.raises(ValueError, simulate_sparse_stc, fwd['src'], len(labels), times, labels=labels, location='center', subject='sample', subjects_dir=subjects_dir) # no non-zero values mylabels = [] for label in labels: this_label = label.copy() this_label.values.fill(1.) mylabels.append(this_label) for location in ('random', 'center'): random_state = 0 if location == 'random' else None stc_1 = simulate_sparse_stc(fwd['src'], len(mylabels), times, labels=mylabels, random_state=random_state, location=location, subjects_dir=subjects_dir) assert_equal(stc_1.subject, 'sample') assert (stc_1.data.shape[0] == len(mylabels)) assert (stc_1.data.shape[1] == n_times) # make sure we get the same result when using the same seed stc_2 = simulate_sparse_stc(fwd['src'], len(mylabels), times, labels=mylabels, random_state=random_state, location=location, subjects_dir=subjects_dir) assert_array_equal(stc_1.lh_vertno, stc_2.lh_vertno) assert_array_equal(stc_1.rh_vertno, stc_2.rh_vertno) # Degenerate cases pytest.raises(ValueError, simulate_sparse_stc, fwd['src'], len(mylabels), times, labels=mylabels, location='center', subject='foo', subjects_dir=subjects_dir) # wrong subject del fwd['src'][0]['subject_his_id'] # remove subject pytest.raises(ValueError, simulate_sparse_stc, fwd['src'], len(mylabels), times, labels=mylabels, location='center', subjects_dir=subjects_dir) # no subject fwd['src'][0]['subject_his_id'] = 'sample' # put back subject pytest.raises(ValueError, simulate_sparse_stc, fwd['src'], len(mylabels), times, labels=mylabels, location='foo') # bad location err_str = 'Number of labels' with pytest.raises(ValueError, match=err_str): simulate_sparse_stc( fwd['src'], len(mylabels) + 1, times, labels=mylabels, random_state=random_state, location=location, subjects_dir=subjects_dir)
def test_simulate_sparse_stc(): """Test generation of sparse source estimate.""" fwd = read_forward_solution_meg(fname_fwd, force_fixed=True, use_cps=True) labels = [read_label(op.join(data_path, 'MEG', 'sample', 'labels', '%s.label' % label)) for label in label_names] n_times = 10 tmin = 0 tstep = 1e-3 times = np.arange(n_times, dtype=np.float) * tstep + tmin pytest.raises(ValueError, simulate_sparse_stc, fwd['src'], len(labels), times, labels=labels, location='center', subject='sample', subjects_dir=subjects_dir) # no non-zero values for label in labels: label.values.fill(1.) for location in ('random', 'center'): random_state = 0 if location == 'random' else None stc_1 = simulate_sparse_stc(fwd['src'], len(labels), times, labels=labels, random_state=random_state, location=location, subjects_dir=subjects_dir) assert_equal(stc_1.subject, 'sample') assert (stc_1.data.shape[0] == len(labels)) assert (stc_1.data.shape[1] == n_times) # make sure we get the same result when using the same seed stc_2 = simulate_sparse_stc(fwd['src'], len(labels), times, labels=labels, random_state=random_state, location=location, subjects_dir=subjects_dir) assert_array_equal(stc_1.lh_vertno, stc_2.lh_vertno) assert_array_equal(stc_1.rh_vertno, stc_2.rh_vertno) # Degenerate cases pytest.raises(ValueError, simulate_sparse_stc, fwd['src'], len(labels), times, labels=labels, location='center', subject='foo', subjects_dir=subjects_dir) # wrong subject del fwd['src'][0]['subject_his_id'] pytest.raises(ValueError, simulate_sparse_stc, fwd['src'], len(labels), times, labels=labels, location='center', subjects_dir=subjects_dir) # no subject pytest.raises(ValueError, simulate_sparse_stc, fwd['src'], len(labels), times, labels=labels, location='foo') # bad location err_str = 'Number of labels' with pytest.raises(ValueError, match=err_str): simulate_sparse_stc( fwd['src'], len(labels) + 1, times, labels=labels, random_state=random_state, location=location, subjects_dir=subjects_dir)
def test_simulate_sparse_stc(): """ Test generation of sparse source estimate """ fwd = read_forward_solution_meg(fname_fwd, force_fixed=True) labels = [read_label(op.join(data_path, "MEG", "sample", "labels", "%s.label" % label)) for label in label_names] n_times = 10 tmin = 0 tstep = 1e-3 times = np.arange(n_times, dtype=np.float) * tstep + tmin stc_1 = simulate_sparse_stc(fwd["src"], len(labels), times, labels=labels, random_state=0) assert_true(stc_1.data.shape[0] == len(labels)) assert_true(stc_1.data.shape[1] == n_times) # make sure we get the same result when using the same seed stc_2 = simulate_sparse_stc(fwd["src"], len(labels), times, labels=labels, random_state=0) assert_array_equal(stc_1.lh_vertno, stc_2.lh_vertno) assert_array_equal(stc_1.rh_vertno, stc_2.rh_vertno)
def test_simulate_sparse_stc_single_hemi(): """Test generation of sparse source estimate.""" fwd = read_forward_solution_meg(fname_fwd, force_fixed=True, use_cps=True) n_times = 10 tmin = 0 tstep = 1e-3 times = np.arange(n_times, dtype=np.float) * tstep + tmin labels_single_hemi = [read_label(op.join(data_path, 'MEG', 'sample', 'labels', '%s.label' % label)) for label in label_names_single_hemi] stc_1 = simulate_sparse_stc(fwd['src'], len(labels_single_hemi), times, labels=labels_single_hemi, random_state=0) assert (stc_1.data.shape[0] == len(labels_single_hemi)) assert (stc_1.data.shape[1] == n_times) # make sure we get the same result when using the same seed stc_2 = simulate_sparse_stc(fwd['src'], len(labels_single_hemi), times, labels=labels_single_hemi, random_state=0) assert_array_equal(stc_1.lh_vertno, stc_2.lh_vertno) assert_array_equal(stc_1.rh_vertno, stc_2.rh_vertno)